Help us shape the future of Go! Take the 2026 Go Developer Survey

telemetry

package
v0.4.21 Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package telemetry defines the observability exporter boundary for AgentKit. Session JSONL remains the source of truth; exporters mirror turn/step/tool activity to external systems such as Langfuse.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Exporter

type Exporter interface {
	BeginTurn(ctx context.Context, meta TurnMeta) (context.Context, func(TurnEnd))
	BeginObservation(ctx context.Context, meta ObservationMeta) (context.Context, func(ObservationEnd))
	RecordEvent(ctx context.Context, name string, attrs map[string]string)
	Flush(ctx context.Context) error
	Shutdown(ctx context.Context) error
}

Exporter mirrors agent activity to an external observability backend.

var Noop Exporter = noopExporter{}

Noop is the default exporter that discards all telemetry.

type ObservationEnd

type ObservationEnd struct {
	Output string
	Err    error
	Usage  *Usage
	// ActualModel is the catalog model id that served the call (after router/fallback/provider default).
	// When set on llm.generation, exporters should prefer this over ObservationMeta.Model (planned).
	ActualModel string
	// CompletionStartTime is when the model first produced output (TTFT boundary).
	// Zero means unavailable, e.g. the stream ended before any content arrived.
	CompletionStartTime time.Time
	// FirstTextTime is when the first user-visible text or thinking delta arrived.
	// Langfuse TTFT prefers this over CompletionStartTime when set.
	FirstTextTime time.Time
}

ObservationEnd closes an observation.

type ObservationKind

type ObservationKind string

ObservationKind selects how an observation is exported.

const (
	KindSpan       ObservationKind = "span"
	KindGeneration ObservationKind = "generation"
	KindTool       ObservationKind = "tool"
)

type ObservationMeta

type ObservationMeta struct {
	Name  string
	Kind  ObservationKind
	Model string
	Input string
	// GenerationMessages carries the full assembled prompt for exporters that
	// optimize generation input recording (e.g. Langfuse). Does not affect LLM calls.
	GenerationMessages []agentkit.ModelMessage
	// ToolNames lists model-visible tools for an LLM generation.
	ToolNames []string
	// AgentID labels which agent produced this observation.
	AgentID string
	// SessionID labels the session that produced this observation.
	SessionID string
	// Scope marks a span that should parent nested generations (e.g. subagent.turn).
	Scope bool
	// Attributes are merged into exporter metadata (tool paths, delegate task, etc.).
	Attributes map[string]string
}

ObservationMeta describes a nested observation such as an LLM call or tool.

type Toolkit added in v0.3.33

type Toolkit interface {
	WithExporter(context.Context, Exporter) context.Context
	ExporterFrom(context.Context) Exporter
	WithTurnID(context.Context, string) context.Context
	WithToolParent(context.Context, string) context.Context
	WithScopeParent(context.Context, string) context.Context
	ToolParentFrom(context.Context) string
	ScopeParentFrom(context.Context) string
	BeginTurn(context.Context, TurnMeta) (context.Context, func(TurnEnd))
	BeginObservation(context.Context, ObservationMeta) (context.Context, func(ObservationEnd))
	RecordEvent(context.Context, string, map[string]string)
	ObservationMetaFromContext(context.Context, ObservationMeta) ObservationMeta
	ContextObservationAttrs(context.Context) map[string]string
	EnrichEventAttrs(context.Context, map[string]string) map[string]string
	FormatMessage(agentkit.ModelMessage) string
	FormatGenerationInputForExport(prev, cur []agentkit.ModelMessage, maxFieldBytes int, dedupePrefix bool) string
	RedactJSON(string) string
	PreparePayload(raw string, maxBytes int, redact bool) string
	AttachmentSpanAttrs(attachments []agentkit.InboundAttachment) map[string]string
}

Toolkit is the standard ctx-scoped telemetry helper surface (implementation: runtime/telemetry).

type TurnEnd

type TurnEnd struct {
	Output     string
	Err        error
	Usage      *Usage
	Steps      int
	StopReason string
}

TurnEnd closes a turn trace.

type TurnMeta

type TurnMeta struct {
	TurnID            string
	SessionID         string
	DeliverySessionID string
	AgentID           string
	PlatformID        string
	UserID            string
	// WorkspaceKey is the tenant workspace routing key (TurnEnvelope.Workspace).
	WorkspaceKey string
	// AttachmentSources lists inbound attachment paths (comma-separated, no base64).
	AttachmentSources string
	// Model is the session-effective model id for trace metadata (session/global
	// override applied; falls back to the agent's configured default).
	Model string
	Input string
}

TurnMeta describes one agent RunTurn boundary.

type Usage

type Usage struct {
	InputTokens  int
	OutputTokens int
	TotalTokens  int
}

Usage carries token accounting for generations and turn totals.

Jump to

Keyboard shortcuts

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