agents-go
Deploying

Telemetry

Traces and metrics, and wiring an OpenTelemetry exporter.

The runtime emits sink-neutral spans and metrics for session, turn, and model activity. By default they go to a no-op tracer; wire the OpenTelemetry plugin to export them.

The seam

Config.Telemetry (and AgentSessionOptions.Telemetry) accepts a telemetry.Tracer. Leave it nil for the no-op default, or pass a tracer from a plugin. Nothing in the core depends on OpenTelemetry — the exporter lives in plugins/otel, and its pipeline.Plugin (built in the next section) satisfies telemetry.Tracer:

session, _ := agents.NewSession(agents.Config{
    LLM:       "openai/gpt-4o",
    Telemetry: pipeline.Plugin, // the otel-backed tracer built below
})

Wiring OpenTelemetry + Prometheus

plugins/otel builds a pipeline and registers it as a plugin. This example exposes a Prometheus scrape endpoint:

import (
    "github.com/webdeveloperben/agents-go/plugin"
    otelplugin "github.com/webdeveloperben/agents-go/plugins/otel"
)

pipeline, err := otelplugin.NewPipeline(ctx,
    otelplugin.WithServiceName("support-agent"),
    otelplugin.WithSink(otelplugin.NewPrometheusSink(otelplugin.PrometheusSinkOptions{
        Server: &otelplugin.MetricsServerConfig{ListenAddress: ":9464"},
    })),
)
if err != nil {
    return err
}

registry := plugin.NewRegistry(logger)
_ = registry.Register(pipeline.Plugin)
_ = registry.Init(ctx)
defer func() { _ = registry.Close() }()
// Prometheus scrapes pipeline.Plugin.MetricsAddress() at /metrics

What you get

  • Spans around session lifecycle, turns, and generation steps — so you can trace where a slow reply spent its time.
  • Metrics for usage and model calls, plus false-interruption and auto-resume counters surfaced by the runtime.

Telemetry runs off the latency-critical path — spans and metrics are recorded around the reply, not inside the generation loop, so instrumentation never slows a turn. See Latency & interruption.

On this page