Documentation
¶
Overview ¶
Package telemetry provides OpenTelemetry integration for GopherAgent via the EventHandler system. It is an optional import: applications that do not need tracing never pay for it.
Wire it at startup:
tp := sdktrace.NewTracerProvider(sdktrace.WithBatcher(exporter))
tracer := tp.Tracer("gopheragent")
loop.OnEvent(telemetry.NewOTelHandler(tracer))
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewOTelHandler ¶
func NewOTelHandler(tracer trace.Tracer) agent.EventHandler
NewOTelHandler returns an agent.EventHandler that instruments every agent iteration with OpenTelemetry tracing.
This is the lightweight, zero-configuration alternative to the richer instrumentation path (agent.WithTracer + the otelllm decorator + the oteltools middleware). It needs only an EventHandler registration and produces one coarse span per iteration derived from stream events, but — being event-driven — it cannot open true child spans for LLM calls or capture tool latency. Prefer the WithTracer path when you need nested spans and per-call timings. The two are mutually exclusive: enabling both double-instruments each iteration.
Span lifecycle per session key:
- Root span "agent.iteration" is opened lazily on the first event.
- "tool_call" → span event "tool.execute" with tool name attribute.
- "action_required" → span event "hitl.action_required".
- "error" → RecordError + SetStatus(Error) + End.
- "done" → SetStatus(Ok) + End.
The tracer's parent context is the ctx passed to RunIteration / RunIterationStream, so the agent spans nest correctly inside existing traces.
Types ¶
This section is empty.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package otelllm provides an OpenTelemetry instrumenting decorator for any agent.LLMProvider.
|
Package otelllm provides an OpenTelemetry instrumenting decorator for any agent.LLMProvider. |
|
Package otelsetup wires an OpenTelemetry OTLP pipeline for gopheragent with a single call.
|
Package otelsetup wires an OpenTelemetry OTLP pipeline for gopheragent with a single call. |
|
Package oteltools provides an OpenTelemetry tools.Middleware that traces each tool execution and records latency and error metrics.
|
Package oteltools provides an OpenTelemetry tools.Middleware that traces each tool execution and records latency and error metrics. |
|
Package semconv holds the OpenTelemetry attribute keys and metric names shared by the gopheragent instrumentation packages (otelllm, oteltools, and the agent loop).
|
Package semconv holds the OpenTelemetry attribute keys and metric names shared by the gopheragent instrumentation packages (otelllm, oteltools, and the agent loop). |
|
Package spanattr carries request-scoped span attributes — tenant, user, feature flag, request ID — on a context.Context, so every span started under that ctx (agent run, iteration, chat, execute_tool, sub-agent runs) can be stamped with them without threading values through each instrumentation layer.
|
Package spanattr carries request-scoped span attributes — tenant, user, feature flag, request ID — on a context.Context, so every span started under that ctx (agent run, iteration, chat, execute_tool, sub-agent runs) can be stamped with them without threading values through each instrumentation layer. |