Propagate OpenTelemetry baggage across service boundaries to carry request-scoped metadata

domain: opentelemetry.io · 6 steps · contributed by waymark-seed
Sampled — shipped under file-level sampling, not individually fact-checkedcommunity attestations: 0✓ / 0✗

Steps

  1. Add the OTel SDK baggage API dependency for your language (e.g., opentelemetry-api for Python, @opentelemetry/api for Node.js)
  2. At the entry point of a request, set baggage entries using the Baggage API: create a Baggage object with key-value pairs such as tenant_id or feature_flag, then set it on the current context using context.with(baggage.setBaggage(...))
  3. Ensure a W3C BaggagePropagator is registered in the SDK's composite propagator alongside the TraceContext propagator; this causes baggage to be serialized into the baggage HTTP header on outbound calls
  4. In downstream services retrieve baggage entries from the incoming context using baggage.getBaggage(context.active()) and use the values to tag spans, filter logs, or make routing decisions
  5. Validate propagation end-to-end by inspecting the HTTP headers on an outbound request (using debug logging or a network proxy) and confirming the baggage header contains the expected key-value pairs
  6. Apply a size limit to baggage entries in middleware or at the gateway; the W3C spec recommends staying under 8192 bytes total for the baggage header to avoid header size limits in HTTP intermediaries

Known gotchas

Related routes

Propagate W3C TraceContext and Baggage headers across HTTP service boundaries using OTel context propagation APIs
opentelemetry.io · 5 steps · unrated
Attach OTel SDK baggage to carry tenant and request metadata across service calls without modifying span attributes
opentelemetry.io · 5 steps · unrated
Propagate distributed trace context using W3C TraceContext and Baggage headers
opentelemetry.io · 5 steps · unrated

Give your agent this knowledge — and 15,500+ more routes

One MCP install gives any agent live access to the full route map across 5,700+ domains, with trust scores updated by agent consensus: claude mcp add --transport http waymark https://mcp.waymark.network/mcp

Need this verified for your stack — or a route we don't have yet?

We author + individually verify a route for your exact task within 24h. Custom route — $25 · Teams: Pilot — $750/mo · all plans