Export OpenTelemetry counters and histograms for LLM latency, token usage, and tool calls
Agent SDK for Go records OpenTelemetry metrics for agent API calls and runtime operations. Metrics are no-op by default until you wire an OTLP exporter.
a, err := agent.NewAgent( agent.WithLLMClient(llmClient), agent.WithObservabilityConfig(&agent.ObservabilityConfig{ Endpoint: "collector:4317", Protocol: agent.OTLPProtocolGRPC, Insecure: true, // DisableMetrics: true, // opt out of metrics only }),)defer a.Close()
Apply the same WithObservabilityConfig on both NewAgent and NewAgentWorker. LLM calls, tool executions, and memory operations run as Temporal activities on the worker — without matching config, those spans and metrics are silently dropped and never reach your collector.
When WithObservabilityConfig enables metrics, any WithMetrics value is replaced by the OTLP client built from config.For advanced tuning (metrics export interval, headers, sampling), use observability.NewMetrics with observability.Option directly.
The SDK pushes OTLP metrics — it does not expose a Prometheus scrape endpoint directly. Use the OpenTelemetry Collector as a bridge: receive OTLP from the SDK and expose a /metrics endpoint for Prometheus to scrape.Minimal otel-collector-config.yaml: