Documentation
¶
Overview ¶
Package otelllm provides an OpenTelemetry instrumenting decorator for any agent.LLMProvider. It wraps GenerateStream with a span and records call latency plus prompt/completion token metrics, without touching the concrete provider packages (pkg/llm/*).
It imports only the OpenTelemetry API (trace + metric), never the SDK, so it is a no-op — and returns the wrapped provider unchanged — when no Tracer or Meter is supplied.
Usage:
llm := otelllm.NewProvider(p,
otelllm.WithSystem("anthropic"), otelllm.WithModel(model),
otelllm.WithTracer(tel.Tracer), otelllm.WithMeter(tel.Meter))
loop := agent.New(sessions, registry, llm)
For a RouterProvider, wrap each backing provider before registering it so the gen_ai.request.model attribute is correct per route.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewProvider ¶
func NewProvider(next agent.LLMProvider, opts ...Option) agent.LLMProvider
NewProvider wraps next with tracing and metrics. When neither a Tracer nor a Meter is supplied it returns next unchanged, so wiring the decorator without providers costs nothing on the hot path.
Types ¶
type Option ¶
type Option func(*config)
Option configures NewProvider.
func WithContentCapture ¶ added in v0.46.0
WithContentCapture records prompts and completions on the chat span as gen_ai.system_instructions / gen_ai.input.messages / gen_ai.output.messages. It overrides OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT. Off by default: content is PII and the largest telemetry cost driver. Media bytes are never captured.
func WithContentMaxBytes ¶ added in v0.46.0
WithContentMaxBytes caps each captured text field (default semconv.DefaultContentMaxBytes); the whole input payload is bounded to a fixed multiple of it, keeping the newest messages.
func WithMeter ¶
WithMeter supplies the Meter used to record latency and token metrics. Without it, no metrics are produced.
func WithSystem ¶
WithSystem sets the model vendor, e.g. "anthropic". It is emitted as gen_ai.provider.name (and gen_ai.system under semconv.SchemaLegacy).
func WithTracer ¶
WithTracer supplies the Tracer used to open per-call spans. Without it, no spans are produced.