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 ¶
- func BeginObservation(ctx context.Context, meta ObservationMeta) (context.Context, func(ObservationEnd))
- func BeginTurn(ctx context.Context, meta TurnMeta) (context.Context, func(TurnEnd))
- func PreparePayload(raw string, maxBytes int, redact bool) string
- func RecordEvent(ctx context.Context, name string, attrs map[string]string)
- func RedactJSON(raw string) string
- func SummarizeMessage(msg agentkit.ModelMessage) string
- func SummarizeMessages(messages []agentkit.ModelMessage, maxBytes int, redact bool) string
- func TruncatePayload(raw string, maxBytes int) string
- func TurnIDFrom(ctx context.Context) string
- func WithExporter(ctx context.Context, exp Exporter) context.Context
- func WithTurnID(ctx context.Context, turnID string) context.Context
- type Exporter
- type ObservationEnd
- type ObservationKind
- type ObservationMeta
- type RecordedEvent
- type RecordedObservation
- type RecordedTurn
- type RecordingExporter
- func (r *RecordingExporter) BeginObservation(ctx context.Context, meta ObservationMeta) (context.Context, func(ObservationEnd))
- func (r *RecordingExporter) BeginTurn(ctx context.Context, meta TurnMeta) (context.Context, func(TurnEnd))
- func (r *RecordingExporter) Flush(context.Context) error
- func (r *RecordingExporter) RecordEvent(_ context.Context, name string, attrs map[string]string)
- func (r *RecordingExporter) Shutdown(context.Context) error
- func (r *RecordingExporter) Snapshot() (turns []RecordedTurn, observations []RecordedObservation, ...)
- type TurnEnd
- type TurnMeta
- type Usage
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BeginObservation ¶
func BeginObservation(ctx context.Context, meta ObservationMeta) (context.Context, func(ObservationEnd))
BeginObservation starts a nested observation on the exporter stored in ctx.
func PreparePayload ¶
PreparePayload applies optional redaction and truncation for exporter payloads.
func RecordEvent ¶
RecordEvent records a point-in-time event on the active trace.
func RedactJSON ¶
RedactJSON scrubs sensitive keys from JSON objects before export.
func SummarizeMessage ¶
func SummarizeMessage(msg agentkit.ModelMessage) string
SummarizeMessage returns a compact text summary of a model message.
func SummarizeMessages ¶
func SummarizeMessages(messages []agentkit.ModelMessage, maxBytes int, redact bool) string
SummarizeMessages JSON-encodes a message list for exporter input.
func TruncatePayload ¶
TruncatePayload limits payload size for external export.
func TurnIDFrom ¶
TurnIDFrom returns the active turn id when present.
func WithExporter ¶
WithExporter stores an exporter on the context for downstream runtime code.
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.
func ExporterFrom ¶
ExporterFrom returns the exporter on ctx, or Noop when unset.
type ObservationEnd ¶
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
}
ObservationMeta describes a nested observation such as an LLM call or tool.
type RecordedEvent ¶
type RecordedObservation ¶
type RecordedObservation struct {
Meta ObservationMeta
End ObservationEnd
}
type RecordedTurn ¶
type RecordingExporter ¶
type RecordingExporter struct {
Turns []RecordedTurn
Observations []RecordedObservation
Events []RecordedEvent
FlushCalls int
ShutdownCalls int
// contains filtered or unexported fields
}
RecordingExporter captures telemetry calls for tests.
func (*RecordingExporter) BeginObservation ¶
func (r *RecordingExporter) BeginObservation(ctx context.Context, meta ObservationMeta) (context.Context, func(ObservationEnd))
func (*RecordingExporter) RecordEvent ¶
func (*RecordingExporter) Snapshot ¶
func (r *RecordingExporter) Snapshot() (turns []RecordedTurn, observations []RecordedObservation, events []RecordedEvent)