observability

package
v0.5.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 25, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultRunQueryLimit   = 50
	MaxRunQueryLimit       = 200
	DefaultEventQueryLimit = 200
	MaxEventQueryLimit     = 1000
)

Variables

This section is empty.

Functions

func CloneEvent

func CloneEvent(event core.Event) core.Event

func CloneRawMessage

func CloneRawMessage(value json.RawMessage) json.RawMessage

func DeleteEventsForRun added in v0.3.1

func DeleteEventsForRun(ctx context.Context, store EventStore, runID string) (int64, error)

DeleteEventsForRun deletes all stored events of runID when the store implements EventRunPurger; otherwise it is a no-op reporting 0, so retention callers work unchanged against stores without purge support.

func EventAllowedByPreset added in v0.3.0

func EventAllowedByPreset(typ core.EventType, preset core.EventFilterPreset) bool

EventAllowedByPreset reports whether an event type belongs in the query view.

func NewEventFanoutSink

func NewEventFanoutSink(sinks ...core.EventSink) core.EventSink

func NormalizeEvent

func NormalizeEvent(event core.Event, now time.Time) core.Event

func ParentSpanFromContext added in v0.2.2

func ParentSpanFromContext(ctx context.Context) string

ParentSpanFromContext returns the parent span ID stored in ctx, if any.

func PurgeEventsBefore added in v0.3.1

func PurgeEventsBefore(ctx context.Context, store EventStore, cutoff time.Time) (int64, error)

PurgeEventsBefore deletes events older than cutoff when the store implements EventStorePurger; otherwise it is a no-op reporting 0.

func StampEventTenant added in v0.4.4

func StampEventTenant(ctx context.Context, event *core.Event)

StampEventTenant binds an unstamped event to the authenticated tenant. Principal-less local/CLI execution keeps the legacy empty tenant.

func TenantIDFromContext added in v0.4.4

func TenantIDFromContext(ctx context.Context) string

TenantIDFromContext returns the authenticated tenant carried by ctx.

func TraceFromContext added in v0.1.1

func TraceFromContext(ctx context.Context) (traceID, spanID string)

TraceFromContext returns the trace and span IDs stored in ctx by WithTrace. Both values are empty strings when no trace context is present.

func WithTrace added in v0.1.1

func WithTrace(ctx context.Context, traceID, spanID string) context.Context

WithTrace returns a new context carrying the given trace and span IDs. The IDs are automatically copied into core.Event fields by the runtime's emit path when this context is propagated through Run / RunHybrid / Stream.

func WithTraceParent added in v0.2.2

func WithTraceParent(ctx context.Context, traceID, spanID, parentSpanID string) context.Context

WithTraceParent returns a context with trace, span, and optional parent span IDs.

Types

type Attribute

type Attribute struct {
	Key   string
	Value string
}

type EventHub

type EventHub struct {
	// contains filtered or unexported fields
}

func NewEventHub

func NewEventHub() *EventHub

func (*EventHub) DroppedEvents added in v0.3.0

func (hub *EventHub) DroppedEvents() int64

DroppedEvents reports how many event deliveries were dropped because a subscriber's buffer was full. A growing value means consumers are falling behind and events are being lost.

func (*EventHub) PublishEvent

func (hub *EventHub) PublishEvent(ctx context.Context, record EventRecord) error

func (*EventHub) Subscribe

type EventPublisher

type EventPublisher interface {
	PublishEvent(ctx context.Context, record EventRecord) error
}

type EventQuery

type EventQuery struct {
	TenantID      string
	AfterSequence int64
	Limit         int
	// Preset selects a read-side event view (product_ui or diagnostic).
	// Empty defaults to diagnostic (full stream). Filtering is projection-only;
	// Append always stores every event.
	Preset core.EventFilterPreset
}

func NormalizeEventQuery

func NormalizeEventQuery(query EventQuery) EventQuery

type EventRecord

type EventRecord struct {
	ID        int64      `json:"id"`
	Sequence  int64      `json:"sequence"`
	Event     core.Event `json:"event"`
	CreatedAt time.Time  `json:"created_at"`
}

func CloneEventRecord

func CloneEventRecord(record EventRecord) EventRecord

type EventRunPurger added in v0.3.1

type EventRunPurger interface {
	EventStore
	DeleteEventsForRun(ctx context.Context, runID string) (int64, error)
}

EventRunPurger is an optional EventStore extension for the retention cascade: DeleteEventsForRun removes every stored event of a run when the run itself is deleted, so event history does not outlive its run.

type EventStore

type EventStore interface {
	Append(ctx context.Context, event core.Event) (EventRecord, error)
	ListRuns(ctx context.Context, query RunQuery) ([]RunSummary, error)
	ListEvents(ctx context.Context, runID string, query EventQuery) ([]EventRecord, error)
	ListScopedEvents(ctx context.Context, query ScopedEventQuery) ([]EventRecord, error)
}

type EventStorePurger added in v0.3.1

type EventStorePurger interface {
	EventStore
	PurgeEventsBefore(ctx context.Context, cutoff time.Time) (int64, error)
}

EventStorePurger is an optional EventStore extension for age-based retention: PurgeEventsBefore removes events that occurred before cutoff, bounding the otherwise append-only event table.

type EventStoreSink

type EventStoreSink struct {
	// contains filtered or unexported fields
}

func NewEventStoreSink

func NewEventStoreSink(store EventStore, publishers ...EventPublisher) *EventStoreSink

func (*EventStoreSink) Emit

func (sink *EventStoreSink) Emit(ctx context.Context, event core.Event) error

type EventSubscription

type EventSubscription struct {
	Events <-chan EventRecord
	Cancel func()
}

type EventSubscriptionFilter

type EventSubscriptionFilter struct {
	TenantID  string
	RunID     string
	EpisodeID string
	SessionID string
	Buffer    int
}

type MetricName

type MetricName string
const (
	MetricRuntimeEventsTotal         MetricName = "agentflow_runtime_events_total"
	MetricRunDurationSeconds         MetricName = "agentflow_run_duration_seconds"
	MetricToolDurationSeconds        MetricName = "agentflow_tool_duration_seconds"
	MetricQueueJobsTotal             MetricName = "agentflow_queue_jobs_total"
	MetricQueueJobsQueued            MetricName = "agentflow_queue_jobs_queued"
	MetricQueueJobsRunning           MetricName = "agentflow_queue_jobs_running"
	MetricQueueJobsDeadLetter        MetricName = "agentflow_queue_jobs_dead_letter"
	MetricMemoryTierRecords          MetricName = "agentflow_memory_tier_records"
	MetricMemoryTierMigrationsTotal  MetricName = "agentflow_memory_tier_migrations_total"
	MetricMemoryRecallLatencySeconds MetricName = "agentflow_memory_recall_latency_seconds"
	MetricLLMTokensTotal             MetricName = "agentflow_llm_tokens_total"
	MetricLLMDurationSeconds         MetricName = "agentflow_llm_duration_seconds"
	MetricLLMErrorsTotal             MetricName = "agentflow_llm_errors_total"
	MetricToolErrorsTotal            MetricName = "agentflow_tool_errors_total"
)

type NoopRecorder

type NoopRecorder struct{}

func (NoopRecorder) AddCounter added in v0.5.0

func (NoopRecorder) IncCounter

func (NoopRecorder) IncCounter(context.Context, MetricName, ...Attribute)

func (NoopRecorder) ObserveHistogram

func (NoopRecorder) ObserveHistogram(context.Context, MetricName, float64, ...Attribute)

func (NoopRecorder) SetGauge

type NoopTracer

type NoopTracer struct{}

func (NoopTracer) Start

type Recorder

type Recorder interface {
	IncCounter(ctx context.Context, name MetricName, attrs ...Attribute)
	// AddCounter adds a non-negative delta in one operation. Token and byte
	// totals must use this instead of issuing one IncCounter call per unit.
	AddCounter(ctx context.Context, name MetricName, value float64, attrs ...Attribute)
	ObserveHistogram(ctx context.Context, name MetricName, value float64, attrs ...Attribute)
	SetGauge(ctx context.Context, name MetricName, value float64, attrs ...Attribute)
}

type RecorderFunc

type RecorderFunc func(ctx context.Context, name MetricName, value float64, attrs ...Attribute)

func (RecorderFunc) AddCounter added in v0.5.0

func (fn RecorderFunc) AddCounter(ctx context.Context, name MetricName, value float64, attrs ...Attribute)

func (RecorderFunc) IncCounter

func (fn RecorderFunc) IncCounter(ctx context.Context, name MetricName, attrs ...Attribute)

func (RecorderFunc) ObserveHistogram

func (fn RecorderFunc) ObserveHistogram(context.Context, MetricName, float64, ...Attribute)

func (RecorderFunc) SetGauge

type RunQuery

type RunQuery struct {
	TenantID string
	Status   RunStatus
	Limit    int
	Offset   int
}

func NormalizeRunQuery

func NormalizeRunQuery(query RunQuery) RunQuery

type RunStatus

type RunStatus string
const (
	RunStatusRunning   RunStatus = "running"
	RunStatusPaused    RunStatus = "paused"
	RunStatusCompleted RunStatus = "completed"
	RunStatusFailed    RunStatus = "failed"
	RunStatusCancelled RunStatus = "cancelled"
)

func StatusAfterEvent

func StatusAfterEvent(current RunStatus, eventType core.EventType) RunStatus

type RunSummary

type RunSummary struct {
	RunID         string         `json:"run_id"`
	TenantID      string         `json:"tenant_id,omitempty"`
	ScenarioName  string         `json:"scenario_name,omitempty"`
	Status        RunStatus      `json:"status"`
	EventCount    int64          `json:"event_count"`
	FirstSeenAt   time.Time      `json:"first_seen_at"`
	LastSeenAt    time.Time      `json:"last_seen_at"`
	LastEventType core.EventType `json:"last_event_type"`
}

type ScopedEventQuery added in v0.3.0

type ScopedEventQuery struct {
	TenantID  string
	EpisodeID string
	SessionID string
	AfterID   int64
	Limit     int
	Preset    core.EventFilterPreset
}

ScopedEventQuery lists events across runs that share an Episode or Session. Exactly one of EpisodeID or SessionID must be set. AfterID is a global store cursor (EventRecord.ID), not a per-run sequence.

func NormalizeScopedEventQuery added in v0.3.0

func NormalizeScopedEventQuery(query ScopedEventQuery) ScopedEventQuery

type SequencedEventStore added in v0.3.1

type SequencedEventStore interface {
	EventStore
	AppendSequenced(ctx context.Context, sequence int64, event core.Event) (EventRecord, error)
}

SequencedEventStore is an optional EventStore extension used by the framework outbox relay: AppendSequenced inserts an event with a per-run sequence minted earlier (when the event was parked in the outbox), instead of assigning a fresh one. Delivery is idempotent: when (run_id, sequence) is already present the store returns the existing record and a nil error, so relay retries and concurrent relays never duplicate an event.

type Span

type Span interface {
	RecordError(err error)
	SetAttributes(attrs ...Attribute)
	End()
}

type SpanName

type SpanName string
const (
	SpanRuntimeEvent      SpanName = "agentflow.runtime.event"
	SpanRun               SpanName = "agentflow.run"
	SpanToolCall          SpanName = "agentflow.tool.call"
	SpanLLMCall           SpanName = "agentflow.llm.call"
	SpanMCPRPC            SpanName = "agentflow.mcp.rpc"
	SpanContextPrepare    SpanName = "agentflow.context.prepare"
	SpanQueueJob          SpanName = "agentflow.queue.job"
	SpanMemoryTierRecall  SpanName = "agentflow.memory.tier.recall"
	SpanMemoryTierMigrate SpanName = "agentflow.memory.tier.migrate"
)

type Tracer

type Tracer interface {
	Start(ctx context.Context, name SpanName, attrs ...Attribute) (context.Context, Span)
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL