Context Propagation: 55 Bytes That Decide Everything Downstream
The traceparent Header, Field by Field
W3C Trace Context became an official Recommendation (Level 1) on 23 November 2021. For version 00 the header is a fixed length — exactly 55 characters of lowercase hex and three hyphens. No whitespace, no optional parts, nothing to negotiate:
traceparent: 00-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-01
\/ \______________________________/ \______________/ \/
1 2 3 4
1 version 2 hex "00" is the only defined version. "ff" is invalid.
2 trace-id 32 hex 16 bytes. Constant for the whole trace. All-zero = invalid.
3 parent-id 16 hex 8 bytes. The SENDER's span id. All-zero = invalid.
4 trace-flags 2 hex ONE BYTE of bit flags, of which only two are
defined: 01 = sampled, 02 = random. See below.
2 + 1 + 32 + 1 + 16 + 1 + 2 = 55 characters
on the wire with the field name: "traceparent: " + 55 = 68 bytesUnpacking field 4. "2 hex" means one byte. One byte is 8 on/off switches, and two hex characters are just how you write 8 switches down. The spec uses two of them. The other six are empty.
switch 1 "sampled" worth 01
switch 2 "random" worth 02
switch 3-8 unused always 0
add up the switches that are ON:
00 nothing on
01 sampled <- what you see on almost every header
02 random
03 sampled + random
(the spec calls them bit 0 and bit 1, counting from the right)01 = sampled. The sender is telling you it recorded this trace. That is the whole meaning. Whether you have to do anything about it is the next subsection — short answer, no.
02 = random. This is a promise about the trace-id, not about this request. The sender is certifying one thing: the last 7 bytes of my trace-id are genuine random digits.
To see why that deserves a bit in the header, start with the problem it solves. Two services that never talk to each other have to reach the same keep-or-drop verdict about the same trace. If they disagree you get half a trace — the edge kept its spans, a mid-tier service dropped its own, and what lands in storage has a hole in the middle.
The usual fix is the 01 bit: decide once at the edge, and everyone downstream obeys. That is OTel's default, and it is the next subsection. But it forces a single rate on the whole fleet. A mid-tier service that fans in from everywhere may need to keep less than the edge does — and then it needs its own way to decide, one that still agrees with what the edge already decided.
The trick is to give every service the same random number and let each apply its own cutoff. The trace-id is the only number every service already has. So you read its last 14 hex digits as a number:
trace-id 4bf92f3577b34da6a3ce929d0e0e4736
└────────────┘
last 7 bytes = 14 hex digits
ce929d0e0e4736 the number this trace actually got
ffffffffffffff the biggest it could possibly be
0ccccccccccccc the 5% line
ce92... sits far above the 5% line, so this trace is dropped.
Every service does that arithmetic alone and gets the same answer,
with no coordination and no extra header. And a service that wants
1% just draws a lower line -- so everything it keeps, the 5% service
kept as well. The decisions nest, which is what stops a trace from
being kept at one hop and dropped at the next.All of it collapses if those digits are not actually random. Plenty of systems build trace-ids some other way — a counter, an id copied from an upstream request, a shard number baked into the low bytes. Then "below the 5% line" is not a 5% sample. It is whatever that system's numbering happens to produce, which could be everything or nothing. The 02 flag is the sender saying these digits are safe to use this way.
Note the spec pins this to the right-most 7 bytes only. The left-hand bytes are free — some systems put a timestamp there — which is precisely why the requirement is written about the right-hand end.
If the flag is absent you cannot assume either way, so the randomness has to come from somewhere else. OpenTelemetry's answer is to carry it explicitly: 56 bits — the same 7 bytes' worth — written into tracestate as rv in the ot section, next to the threshold as th. That is one of the jobs tracestate (below) exists to do, and the Head-Based Sampling part is where it gets spent.
The six unused switches. Leave them at 0 — the spec requires it, and a future version will claim them. If a header arrives with one of them set, ignore it and pass it on. Do not reject the header. And if you want to send your own data alongside a trace, it goes in tracestate, below. Not here.
Five rules in the spec account for most of the real-world breakage:
| Rule | What the spec says | What goes wrong |
|---|---|---|
| Header is shorter than 55 chars | Don't try to parse it. Start a new trace. | A proxy that truncates the header raises no error anywhere. It just mints a fresh trace id, and the two halves of your request never join up (see The Trace). |
| Version number is higher than you know | Still try to read it. The trace-id and parent-id are always at the same character positions — check the hex and the hyphens, then use them. Don't throw the header away. | The layout is fixed on purpose so a v00 parser keeps working in a v01 fleet. Code that checks len == 55 exactly breaks the moment v01 appends a field after the flags. |
| trace-id is all zeros | 00000000000000000000000000000000 is invalid — ignore the whole traceparent. | Classic bug in hand-rolled propagators: allocate a zeroed buffer, forget to fill it. The receiver doesn't error, it silently begins a new trace. |
| parent-id is all zeros | Same rule: 0000000000000000 invalidates the header. | It looks like a reasonable way to say "I'm the root, I have no parent." It isn't. A root sends no traceparent at all. |
version = ff | Invalid, explicitly. | It's reserved as a marker value. Never emit it. |
The third field is
parent-id, not "span-id." Older OpenTracing-era docs call it span-id and the habit has outlived the spec. The value is the id of the span in the sender. The receiver stores it as its own span'sparentSpanIdand generates a brand-new id for itself. In other words: the header always describes the hop you just left, never the one you're entering.
The Sampled Bit — Advice, Not an Order
trace-flags = 01 means "the caller may have recorded trace data." The spec goes out of its way to say this is advisory — the receiver is allowed to ignore it — and gives three reasons why:
Trust and abuse. A caller outside your trust boundary could set the bit on every request and force you to sample 100%.
The caller might simply be buggy.
The two sides see different load. A rate the caller can afford may be far too much for a callee that fans in from everywhere, so the callee may need to sample down.
In practice almost nobody uses that freedom — and that is the hinge into the Head-Based Sampling part. OTel's default sampler is parentbased_always_on, which means: if the incoming traceparent says sampled, record; if it says not sampled, don't. That one default is what turns a decision made once, at the edge into a decision for the entire fleet. It's also why head-based sampling can't be undone downstream: by the time service 19 turns out to be the slow one, it was told 40ms into the request never to write anything down.
tracestate — the Vendor Scratchpad
traceparent is rigid on purpose: four fields, one shape, 55 characters, nothing optional. That rigidity is what makes it universal — and it means a vendor has nowhere to put anything else. Datadog's native span id is 64 bits, not the 128 the header mandates. A sampling rate doesn't fit in a one-bit flag. A tenant or region hint has no field at all. tracestate is the second header where all that surplus lives.
The reason it must be a standard header, rather than every vendor inventing x-mytool-state, is one rule that every participant signs up to: entries you don't recognise get copied through untouched. That rule is the entire feature. It's what lets private state cross a hop its owner doesn't control.
One request, two vendors, three hops
A. your edge — the Datadog tracer writes its own entry
tracestate: dd=s:2;p:8f1e2a
B. a partner service, instrumented with Honeycomb
it reads "dd=..." and understands nothing about it
spec says: MUST NOT drop it, MUST NOT rewrite it
it prepends its own entry
tracestate: hc=t61rcWkgMzE,dd=s:2;p:8f1e2a
C. back inside your fleet — Datadog downgrades sampling priority
update = delete the old dd entry, re-insert at the FRONT
tracestate: dd=s:0;p:8f1e2a,hc=t61rcWkgMzEDatadog's private state made the round trip through a system that had no idea what it meant. Without step B's leave-it-alone guarantee, that state dies at the boundary, and on the way back Datadog can only rebuild from traceparent — losing its native span ids and its sampling rate, which is exactly the information needed to weight the trace correctly.
tracestate: ot=th:c,congo=t61rcWkgMzE,rojo=00f067aa0ba902b7
key lowercase, begins with a letter or digit, up to 256 chars — one per vendor
value opaque printable ASCII, up to 256 chars — only its owner can parse it
list MUST accept up to 32 list-members; SHOULD propagate >= 512 chars total
order LEFT-MOST = most recently mutatedWhy the order carries meaning. Picture a proxy fifteen services deep that finds the header over its size budget. It has to drop something — but every value is opaque. congo=t61rcWkgMzE might be a load-bearing sampling threshold or a debug flag nobody reads; there is no way to tell by looking. So the spec stops trying to rank entries by importance and substitutes something it can compute: recency. And it makes recency free to read off by mandating that any mutation moves your entry to the front. Position becomes the last-touched ordering — no timestamps, no extra bytes.
Adding or updating means moving to the front. There is no "edit in place." A vendor changing its own entry deletes it and re-inserts it at the head of the list. Deleting is just deleting.
Truncation eats the back — but oversized entries go first. The trimming rule is two-pass: first drop entries longer than 128 characters, working right-to-left; if it still doesn't fit, keep dropping from the right. The first pass punishes whoever is hogging the shared budget; the second falls back to pure position.
So eviction is least-recently-touched, for free. The vendors that survive a trim are the ones nearest the current hop — the ones still in the call path, most likely to need their state on the next hop. Entries from systems fifteen hops upstream, whose work is already finished, age off the back.
The debugging tell: if your vendor's entry keeps vanishing, but only on your long call chains, nothing is stripping it and no proxy is misconfigured. It is aging out of the back of the list. The fix is upstream — fewer vendors writing entries, or smaller ones — not a header allow-list.
In practice the 32-member cap is rarely what bites; you'd need 32 distinct vendors touching one trace. The ~512-character budget is the real ceiling, and it is shared. That is why OpenTelemetry packs all of its state into a single entry keyed ot, with semicolon-separated sub-keys, capped at 256 characters total — one modest list-member instead of six. Two sub-keys matter:
ot=th:<hex> | Sampling threshold, 1–14 lowercase hex digits, right-padded with zeros to 56 bits. Probability = (256 − threshold) / 256. th:0 = 100%; th:c = 25%. |
|---|---|
ot=rv:<14 hex> | Explicit 56-bit randomness, used when the trace-id itself can't be trusted to be random. MUST NOT be modified once set. |
This is OTEP 235 — consistent probability sampling — carried on the wire. It's what lets a sampler further downstream (see Head-Based Sampling), or a Collector doing tail sampling (see Tail-Based Sampling), learn the effective sampling rate of a span it didn't sample itself. That number is the only way to turn a sampled population back into unbiased counts.
baggage Is a Different Header and a Different Idea
W3C Baggage (Candidate Recommendation, May 2024) is your own key/value data, travelling alongside the trace. The compliance floor: a platform MUST propagate every list-member as long as the total stays within 64 list-members and 8192 bytes.
Legacy Formats and the Interop Tax
| Format | On the wire | OTel propagator name |
|---|---|---|
| B3 multi (Zipkin) | X-B3-TraceId (16 or 32 hex), X-B3-SpanId, X-B3-ParentSpanId, X-B3-Sampled (1/0/absent=defer), X-B3-Flags (1=debug) | b3multi |
| B3 single | b3: {TraceId}-{SpanId}-{Sampling}-{ParentSpanId}, e.g. b3: 80f1..eff7-e457..6bd1-1-05e3..3b90. Sampling is 1/0/d (debug)/absent. | b3 |
| Jaeger | uber-trace-id: {trace-id}:{span-id}:{parent-span-id}:{flags}, colon-separated, all hex; flags 01=sampled, 02=debug. Baggage rides as uberctx-{key}. | jaeger |
| AWS X-Ray | X-Amzn-Trace-Id: Root=1-5759e988-bd862e3fe1be46a994272793;Parent=53995c3f42cd8ad8;Sampled=1 — the root id is epoch-seconds + 24 random hex, so it is not a uniformly random 128-bit value. | xray |
| Datadog | x-datadog-trace-id, x-datadog-parent-id (decimal, 64-bit), x-datadog-sampling-priority, x-datadog-origin | (vendor SDK / contrib) |
The knob is OTEL_PROPAGATORS, default tracecontext,baggage. It also accepts b3, b3multi, jaeger, xray, ottrace, and none. Listing several builds a composite propagator, which behaves asymmetrically: on the way in it tries each format in order and takes the first that yields a valid context; on the way out it writes all of them. That asymmetry is exactly what a migration needs — and it isn't free. tracecontext,baggage,b3multi,jaeger on every request is roughly 68 + 117 + ~180 + ~90 ≈ 455 bytes of context headers per hop.
A half-migrated fleet doesn't fail by losing traces — it fails by producing traces that break in the middle. A B3-only service sitting between two TraceContext services extracts nothing, starts a new root, and leaves you with two traces that both look complete and are both wrong about where the latency is. Migrate by injecting both formats everywhere first, and only then stop extracting the old one.
In-Process Propagation Is the Harder Half
Crossing a process is the easy half: it's a header, and the answer is 55 characters long. The hard half is inside one process — carrying the active Context from the framework's entry point down to the line 14 frames deep that creates the child span, through thread pools, futures, and event loops. That's where traces actually break.
| Runtime | How context travels | Where it leaks |
|---|---|---|
| Go | An explicit context.Context as the first argument. No hidden ambient state at all. | Verbose but hard to break — until someone writes go doWork() capturing nothing, or parks a ctx in a struct field that outlives the request. |
| Java / .NET | Thread-local storage (ThreadLocal / AsyncLocal). The Java agent goes further and rewrites executor bytecode so submitted Runnables carry the context with them. | A hand-rolled thread pool the agent doesn't recognise, or a native thread started outside instrumented code. |
| Python | contextvars.ContextVar. asyncio tasks copy the context when they're created. | ThreadPoolExecutor and multiprocessing do not copy it. A loop.run_in_executor hop loses context unless you pass it across yourself. |
| Node.js | AsyncLocalStorage, built on async_hooks. | Callbacks registered before the store was entered; some native addons and older promise libraries that don't take part in async resource tracking. |
Where Propagation Breaks Structurally
Some boundaries aren't a bug you can fix in your code — the header has nowhere to ride:
| Boundary | Why the header doesn't survive | What to do |
|---|---|---|
| Kafka / SQS / SNS | There's no HTTP header to put it in, and producer and consumer are separated in time — the parent may have finished hours before the child starts. | Inject it into message headers (Kafka record headers; SQS MessageAttributes, capped at 10 per message). When a consumer handles a batch, the batch span should point at each message with a Link, not a parent — a span can only have one parent (see The Span). |
| Batch / cron jobs | No inbound request exists, so there's no context to continue. | Accept it: the job is a root. Correlate with a stable attribute such as job.run_id, rather than inventing a parent. |
| Browser → server (RUM) | Cross-origin, traceparent counts as a non-simple header: it triggers a CORS preflight and is blocked unless the server replies with Access-Control-Allow-Headers: traceparent, tracestate, baggage. | Add those to the allow list and budget an extra round trip for the OPTIONS preflight. Every RUM rollout hits this on day one. |
| Proxies, WAFs, API gateways | Header allow-list policies drop unknown headers without saying so; some change header case or collapse duplicates. | Explicitly allow the four headers end to end. Verify by asserting on the header at the first hop inside the perimeter, not at the edge. |
| Serverless cold starts | The platform's wrapper may create the root span before your handler has initialised the SDK, so init-time work lands outside the trace. | Initialise the provider at module scope, and when running under X-Ray use the platform's own context (Lambda's _X_AMZN_TRACE_ID) as the parent. |
| gRPC | Context travels in metadata, not HTTP headers. Keys are lowercased, and a -bin suffix means base64 binary — so a text propagator writing a -bin key corrupts data silently. | Use your language's gRPC instrumentation. Never hand-copy values between metadata and headers. |
| Pooled / pipelined protocols | Connection-level protocols with no per-message header space — raw TCP, some DB wire protocols, WebSocket frames — have nowhere to put 55 bytes. | There's no fix at the transport layer. Instrument the client side only; the server side becomes a separate trace joined by an attribute, and you live with the gap (see Where Tracing Stops). |
- Guarantees: If
traceparentarrives intact and the receiver runs a TraceContext propagator, the child span shares the trace-id and takes the sender's span id as its parent — with no clock, no registry, and no coordination between the two processes. - Does not guarantee: That the trace is complete, that the sampled bit will be honoured, or that anything stays connected inside a process. The header only covers the wire; every gap between the socket and the line that creates your span is your SDK's problem and your code's problem.