Documentation
¶
Overview ¶
Package oteltools provides an OpenTelemetry tools.Middleware that traces each tool execution and records latency and error metrics. It wraps tools through the existing tools.Chain mechanism, so pkg/tools itself is never modified.
It imports only the OpenTelemetry API (trace + metric), never the SDK. When no Tracer or Meter is supplied it returns an identity middleware, so wiring it without providers leaves the tool unwrapped and costs nothing on the hot path.
Usage:
err := reg.Register(tools.Chain(myTool,
oteltools.Instrument(oteltools.WithTracer(tel.Tracer), oteltools.WithMeter(tel.Meter))))
if err != nil {
return err
}
When wired under an agent loop that opens iteration spans (agent.WithTracer), these tool spans nest as children of the iteration span automatically via ctx.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Instrument ¶
func Instrument(opts ...Option) tools.Middleware
Instrument returns a tools.Middleware that opens an "execute_tool <name>" span and records duration + error metrics for each call. With neither a Tracer nor a Meter it returns an identity middleware (the tool is passed through unwrapped).
Types ¶
type Option ¶
type Option func(*config)
Option configures Instrument.
func WithContentCapture ¶ added in v0.46.0
WithContentCapture records tool arguments and results on the execute_tool span as gen_ai.tool.call.arguments / gen_ai.tool.call.result. It overrides OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT. Off by default.
func WithContentMaxBytes ¶ added in v0.46.0
WithContentMaxBytes caps each captured field (default semconv.DefaultContentMaxBytes).
func WithTracer ¶
WithTracer supplies the Tracer used to open per-Execute spans.