otelllm

package
v0.45.0 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2026 License: Apache-2.0 Imports: 10 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 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 gen_ai.system attribute (model vendor), e.g. "anthropic".

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