with one click
opentelemetry-python-propagation
// W3C Trace Context propagation (inject/extract) for OpenTelemetry Python — manual and automatic, including baggage.
// W3C Trace Context propagation (inject/extract) for OpenTelemetry Python — manual and automatic, including baggage.
[HINT] Download the complete skill directory including SKILL.md and all related files
| name | opentelemetry-python-propagation |
| description | W3C Trace Context propagation (inject/extract) for OpenTelemetry Python — manual and automatic, including baggage. |
| tech_stack | ["opentelemetry"] |
| language | ["python"] |
| capability | ["observability"] |
| version | OpenTelemetry Python unversioned |
| collected_at | "2026-01-14T00:00:00.000Z" |
Source: https://opentelemetry.io/docs/languages/python/propagation/
Propagation moves trace context between services and processes, enabling end-to-end distributed traces across service boundaries. OpenTelemetry Python uses W3C Trace Context HTTP headers (traceparent/tracestate) plus W3C Baggage.
Instrumentation libraries for Flask, Django, Jinja2, and Celery propagate context automatically — no manual code needed. Always prefer this over manual propagation.
from opentelemetry import baggage
from opentelemetry.trace.propagation.tracecontext import TraceContextTextMapPropagator
from opentelemetry.baggage.propagation import W3CBaggagePropagator
ctx = baggage.set_baggage("hello", "world")
headers = {}
W3CBaggagePropagator().inject(headers, ctx)
TraceContextTextMapPropagator().inject(headers, ctx)
# Forward `headers` in your outgoing HTTP request
from opentelemetry.trace.propagation.tracecontext import TraceContextTextMapPropagator
from opentelemetry.baggage.propagation import W3CBaggagePropagator
carrier = {'traceparent': headers['Traceparent']}
ctx = TraceContextTextMapPropagator().extract(carrier=carrier)
b2 = {'baggage': headers['Baggage']}
ctx2 = W3CBaggagePropagator().extract(b2, context=ctx)
# Use propagated context in a new span
with tracer.start_span("api2_span", context=ctx2):
print(baggage.get_baggage('hello', ctx2))
| Class | Purpose |
|---|---|
TraceContextTextMapPropagator | W3C Trace Context — inject/extract traceparent and tracestate |
W3CBaggagePropagator | W3C Baggage — inject/extract user-defined key-value pairs across services |
baggage.set_baggage(key, value) | Set a baggage entry on the current context |
baggage.get_baggage(key, ctx) | Read a baggage entry from a context |
Both propagators follow the same interface: .inject(carrier, context) and .extract(carrier, context) where carrier is a dict-like object (e.g., HTTP headers dict).
/*traceparent=00-0123...*/), enabling propagation through database logs. Supported by some Python instrumentations — not universal.opentelemetry-python-sdk for TracerProvider setup (needed before any propagation code runs).opentelemetry-python-otlp to export the full distributed trace to a collector.opentelemetry-python-fastapi which handles propagation automatically — manual code only needed for outbound calls to other services.