Skip to content

OpenTelemetry architecture

How telemetry hooks into a run, what each part does, and what connectors must do (almost nothing). User documentation: Observability. Design decisions: 0003.

Where it hooks in

flowchart LR CLI["CLI: --otel flags<br/>cli_otel.telemetry_for"] --> T["telemetry.start<br/>(Telemetry: session + spans)"] P["run_to_bundle"] -->|start_run| RS["RunSpans<br/>run span"] E["run_episode"] -->|episode| ES["EpisodeSpans<br/>scenario span"] E -->|invoke_agent ctx| ES ENV["Environment.record"] -->|listeners| ES IR["run_packs (after grading)"] -->|grade(results)| RS P -->|finish, ids| B["write_bundle: otel/ids.json"] T --> X["BatchSpanProcessor<br/>CountingExporter -> OTLP / console / file"]
  1. The CLI resolves TelemetryConfig (telemetry/config.py) and, when enabled, calls telemetry.start, which imports OpenTelemetry, builds the tracer provider and exporter (tracer.py) and makes the Telemetry hub active (hub.py). It always calls telemetry.stop in a finally.
  2. run_to_bundle opens the run span (RunSpans.start).
  3. run_episode opens the scenario span (RunSpans.episode) and runs the connector inside EpisodeSpans.invoke_agent, which opens the invoke_agent span, registers on_event on env.listeners, and (in nest mode) attaches the span as the current context.
  4. Every Environment.record call reaches on_event: tool_call opens an execute_tool span and tool_result closes it; model_call becomes a chat span; fault, control_signal, approval_* and handoff become events.
  5. When the connector returns, end_agent closes the agent span and records the episode's measures (tool calls, halt time, post-signal actions, errors).
  6. After Inspect has graded every epoch, run_packs calls RunSpans.grade(results): finding events, the grade span and result attributes are added, and each scenario span ends with its episode's end time.
  7. run_to_bundle finishes the run span and passes RunSpans.ids() to write_bundle, which writes otel/ids.json before the report (the report reads it for links).

connectors check traces its first pass the same way and checks the result with telemetry.validate.check_episode. mcp serve traces the session as one scenario span.

Connectors' responsibilities

None beyond what conformance already requires: record tool calls through Environment.call, model calls as model_call events (with meta.model and, when the framework reports it, meta.usage with input_tokens and output_tokens), approvals through Environment.review, and handoffs as handoff events. Two optional extras:

  • A connector that sends requests to an outside agent adds telemetry.propagation_headers() to them (the HTTP connector does).
  • A connector that launches a process adds telemetry.propagation_env() to its environment (the MCP connector does, and also writes trace_context into the task file).

Both return {} when telemetry is off or not in nest mode.

Threads and context

Inspect runs each episode in a worker thread. Spans are created with explicit parents (the scenario or agent span), so tool calls made from framework threads still land in the right place. Only framework spans rely on the attached context; a framework that starts its own threads without copying the context produces separate traces.

Privacy

EpisodeSpans._content is the only place content is set: it returns immediately when capture is off or the scenario is confidential, and otherwise passes the value through redaction.clean (secrets, emails, the local denylist, the size cap). Fault parameters, finding rule ids and step references are omitted for confidential scenarios, and their ids appear as confidential:<hash>; control-signal reasons are never emitted.

Tests

  • tests/unit/test_otel.py: settings, the span tree, events, status rules, granularity, sampling, exporter failures, the disabled path, privacy (against real pack texts, planted markers and the confidential fixture pack), the bundle sidecar and report links, propagation, framework nesting, and the CLI.
  • tests/unit/test_otel_golden.py with scripts/gen_otel_golden.py: normalised span trees per connector.
  • tests/integration/test_otel_collector.py: a real Collector over HTTP and gRPC (Docker; CI job otel-integration).
  • The conformance kit's otel check, for every connector.

Semantic-convention validation with OTel Weaver was not set up: Weaver ships as a container or a release binary, neither available in this build's offline environment. The golden files and check_episode are the safeguard (see the build log).