Skip to main content

Module trace

Module trace 

Source
Expand description

W3C Trace Context propagation.

Propagation is default-on and dependency-free — a trace_id shared across the whole agent tree (ingested from an upstream traceparent or minted from the run id), threaded into every process’s log lines, the spawn payload, and outbound MCP _meta. So a single run — supervisor + every subagent + every tool call — is one correlatable, auditable trace, with no collector required. Span export (OTLP) is the only otel-gated part.

traceparent = 00-<32-hex trace-id>-<16-hex span-id>-<2-hex flags>.

Structs§

TraceContext
A W3C trace context for one process: the shared trace id, this process’s span id, and the sampling flags.

Functions§

new_span_id
A fresh 8-byte (16-hex) span id, unique per call (time ⊕ pid ⊕ counter). Public so the otel span export can mint child span ids under the run trace.
outbound_traceparent
An outbound traceparent for a given trace id with a fresh child span — for stamping onto MCP _meta / the LLM header so downstream services see this agent as their parent (W3C-correct).
parse
Parse a traceparent. Returns None for any malformed or all-zero (invalid per spec) value.
resolve
Resolve the trace context for a run: continue an upstream traceparent if a valid one is supplied (same trace id, fresh span), else mint a fresh trace deterministically from the run id (so retries of a run share a trace id).