otelllm

package
v0.46.0 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2026 License: Apache-2.0 Imports: 11 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

func WithContentCapture(enabled bool) Option

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

func WithContentMaxBytes(n int) Option

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

func WithMeter(m metric.Meter) Option

WithMeter supplies the Meter used to record latency and token metrics. Without it, no metrics are produced.

func WithModel

func WithModel(model string) Option

WithModel sets the gen_ai.request.model attribute, e.g. "claude-opus-4-8".

func WithSystem

func WithSystem(system string) Option

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

func WithTracer(t trace.Tracer) Option

WithTracer supplies the Tracer used to open per-call spans. Without it, no spans are produced.

Jump to

Keyboard shortcuts

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