Skip to main content
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.

Wire OTLP

Use WithObservabilityConfig — the same block configures traces, metrics, and logs:
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.

Bring your own metrics

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.

Agent API metrics

Emitted by Agent.Run and Agent.Stream: Stream metrics cover the dispatch phase — not per-token streaming duration.

Runtime metrics

Emitted per LLM call, tool execution, retriever search, and memory operation on the in-process, Temporal, and Restate runtimes.

LLM

Tools

Retriever

Memory

Each memory operation family has .started, .completed, .failed counters and a .latency_ms histogram.

Common attributes

Runtime metrics include attributes when available:

Export to Prometheus

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:
Prometheus scrape_configs entry:
The agent exports to localhost:4317 (OTLP gRPC), the collector bridges to Prometheus on :8889:

Telemetry vs metrics

See Telemetry.

Example

Observability

OTLP traces, metrics, and logs

Tracing

Distributed spans for the same operations

Token Usage

Per-run token totals on AgentRunResult