Expand description
OpenTelemetry for Rig agents in one call.
Rig already describes every agent run, model call and tool call as
tracing spans that follow the OpenTelemetry GenAI semantic conventions.
This crate sends them on, and adds what an observability backend needs
beyond the spans:
- Traces over OTLP, to any collector (Jaeger, Grafana Tempo,
Honeycomb, Langfuse, Phoenix, AWS CloudWatch), configured by the standard
OTEL_*variables. - Metrics:
gen_ai.client.operation.duration,gen_ai.client.token.usageand tool and model-request metrics (rig.tool.*,rig.model.*), read from Rig’s spans, so no agent code changes. - Sessions:
set_sessiongives a span and everything under it asession.id, the attribute AWS Bedrock AgentCore groups a conversation’s traces by. - Traces across processes:
injectandextractcarry the W3Ctraceparentandbaggageheaders, so an agent calling another over HTTP (A2A, MCP) makes one trace.
Spans and metrics carry the instrumentation scope
opentelemetry.instrumentation.rig, the prefix AgentCore Observability and
Evaluations read spans from.
// OTEL_EXPORTER_OTLP_ENDPOINT, OTEL_SERVICE_NAME, ... choose where and as what.
let _telemetry = rig_otel::init()?; // flushes when dropped, at the end of mainStructs§
- Telemetry
- The providers behind the exported traces and metrics. Dropping it flushes and shuts them down.
- Telemetry
Builder - Configures
Telemetry. By default: OTLP over HTTP from theOTEL_*variables, Rig’s spans atinfo, no logs unlessRUST_LOGis set.
Enums§
- AwsError
aws - Why the CloudWatch exporters could not be set up.
- Init
Error - Why telemetry could not be set up.
Constants§
- SCOPE
- The instrumentation scope of everything this crate exports. AWS Bedrock
AgentCore reads spans whose scope starts with
opentelemetry.instrumentation.. - SESSION_
ID - The attribute, and baggage entry, a session id travels as.
Functions§
- agent_
span - The outer span of one agent run, named and tagged the way GenAI backends
read an agent run:
invoke_agent <name>, withgen_ai.operation.nameinvoke_agentandgen_ai.agent.name. - extract
- Read the trace context and baggage of an incoming request, to continue
its trace: pass it to
OpenTelemetrySpanExt::set_parentor toset_session. - init
- Set up traces and metrics over OTLP from the standard
OTEL_*variables, as the process’s globaltracingsubscriber. Logs go to stderr too whenRUST_LOGis set. The returnedTelemetryflushes what is buffered when dropped, so keep it until the end ofmain. - inject
- Write the current span’s trace context (
traceparent) and baggage (a session, say) intoheaders, for an outgoing request: the other side continues this trace. - set_
session - Make
span(before anything runs in it) the start of sessionidin this process: it and every span under it get thesession.idattribute, and calls made under it carry the session to other processes, in thebaggageheaderinjectwrites.