Overview
When your agents span multiple processes or services (e.g., Agent A calls Agent B via HTTP), you need to propagate the trace context so all spans appear in the same trace. TraceCtrl provides two helpers that wrap OpenTelemetry’s W3C Trace Context propagation:Injecting Context (Outgoing Requests)
On the calling side, inject thetraceparent header into your outgoing request:
Extracting Context (Incoming Requests)
On the receiving side, extract the trace context from incoming headers:API Reference
inject_trace_headers(headers: dict | None = None) → dict
Injects W3C traceparent (and optionally tracestate) into the given headers dict. If no dict is provided, creates and returns a new one.
extract_trace_headers(headers: dict) → Context
Extracts the trace context from incoming headers and activates it. Returns the OpenTelemetry Context object. All subsequent spans in this execution context will be children of the incoming trace.
Full Example: Two-Service Agent
agent_a.py
agent_b.py
This uses the standard W3C Trace Context specification (
traceparent header). It works with any OpenTelemetry-compatible service, not just TraceCtrl agents.
