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 propagators: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:extract_trace_headers returns an OpenTelemetry Context object. You don’t normally need to use it directly — OpenTelemetry’s propagator activates the extracted context for you.
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. Returns the OpenTelemetry Context object.
Full Example: Two-Service Strands Agent
The Strands instrumentor is the canonical, PyPI-published path. Two services, twoAgent instances, trace propagated across the HTTP boundary.
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.
