Skip to main content

Crate rig_otel

Crate rig_otel 

Source
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.usage and tool and model-request metrics (rig.tool.*, rig.model.*), read from Rig’s spans, so no agent code changes.
  • Sessions: set_session gives a span and everything under it a session.id, the attribute AWS Bedrock AgentCore groups a conversation’s traces by.
  • Traces across processes: inject and extract carry the W3C traceparent and baggage headers, 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 main

Structs§

Telemetry
The providers behind the exported traces and metrics. Dropping it flushes and shuts them down.
TelemetryBuilder
Configures Telemetry. By default: OTLP over HTTP from the OTEL_* variables, Rig’s spans at info, no logs unless RUST_LOG is set.

Enums§

AwsErroraws
Why the CloudWatch exporters could not be set up.
InitError
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>, with gen_ai.operation.name invoke_agent and gen_ai.agent.name.
extract
Read the trace context and baggage of an incoming request, to continue its trace: pass it to OpenTelemetrySpanExt::set_parent or to set_session.
init
Set up traces and metrics over OTLP from the standard OTEL_* variables, as the process’s global tracing subscriber. Logs go to stderr too when RUST_LOG is set. The returned Telemetry flushes what is buffered when dropped, so keep it until the end of main.
inject
Write the current span’s trace context (traceparent) and baggage (a session, say) into headers, for an outgoing request: the other side continues this trace.
set_session
Make span (before anything runs in it) the start of session id in this process: it and every span under it get the session.id attribute, and calls made under it carry the session to other processes, in the baggage header inject writes.