W3C Trace Context and Baggage
W3C Trace Context, published by the W3C Distributed Tracing Working Group, defines the traceparent and tracestate HTTP headers that carry a distributed trace across services and vendors. W3C Baggage, from the same group, defines the baggage header for application-defined properties. With this skill the agent parses, validates, generates, mutates and forwards these headers as a tracer, a pass-through proxy or an edge service.
Follow the workflow below step by step. Every rule here comes from a source in Sources, with the section it cites. When a rule and the pinned source disagree, the source wins; when the source has a newer revision than the pin, follow the refresh steps.
Citations: "§" is Trace Context Level 1, "L2 §" is Trace Context Level 2, "Baggage §" is W3C Baggage.
Inputs (fill in, or ask before starting)
- Role: forwarder (a proxy, load balancer or message bus that passes headers through), participant (a tracer or propagator that adds its own span), originator (a client that starts traces), edge (a service at a trust boundary), and whether it also reads or writes
baggage. - Trust boundary: which inbound callers and outbound targets are external or untrusted. This decides restarts and stripping.
- Your
tracestatekey, if you participate: a simple key or, in Level 1, atenant@systemmulti-tenant key. - Target version: Trace Context Level 1 (default) for
traceparentandtracestate. Trace Context Level 2 is a preview (posture: build): implement it behind a switch. W3C Baggage (Candidate Recommendation Snapshot, posture: build) is the only Baggage line. Seereferences/versions.md. - Revision: the pinned revision in Sources, unless the user names another.
- Sources: when refreshing this skill or when a rule looks out of date, re-read every URL in Sources first, check the W3C publication history pages for Trace Context Level 1, Level 2 and Baggage for a newer publication or status, check the
Erratalabel onw3c/trace-context, and update the pins.
Invariants
traceparentformat. Version00isversion-trace-id-parent-id-trace-flags: 2, 32, 16 and 2 lowercase hex characters, 55 in total (§ 3.2.2). Versionffis invalid (§ 3.2.2.1).- Invalid IDs void the header. An all-zero or non-lowercase-hex
trace-idorparent-idMUST make the vendor ignoretraceparent(§ 3.2.2.3, § 3.2.2.4); then start a new trace and deletetracestate(§ 4.3). - Header names. Accept
traceparentandtracestatein any case; send them lowercase (§ 3.2.1, § 3.3.1). Sendbaggagelowercase (Baggage § 3.1). - Forward what you receive. A vendor receiving
traceparentortracestateMUST send it on outgoing requests (§ 3.4, § 3.5). Iftraceparentis unchanged,tracestateMUST NOT be modified (§ 3.4). - Only four
traceparentmutations. Updateparent-id; updatesampled, which MUST come with a newparent-id; restart the trace; downgrade the version. No other mutation is allowed (§ 3.4). - Flags are a bit field. Test bits with a mask (§ 3.2.2.5). Undefined flags MUST be written as zero (§ 3.2.2.5.2). In Level 1 that includes bit
0x02; in Level 2 the random trace-id flag MUST be copied unchanged when continuing a trace (L2 § 3.2.2.5.2). - Higher versions. Parse the first three fields with the
00layout, check the dashes, never assume anything about unknown fields, and write the outgoing header as00(§ 3.2.4). tracestatedepends ontraceparent. Do not parse it whentraceparentfailed; its failure MUST NOT affecttraceparent(§ 3.3). AtracestatewithouttraceparentMUST be discarded (§ 4.2).tracestatelist rules. At most 32 members; one entry per key; keys and values follow the § 3.3.1.3 grammar; multiple fields are combined in order per RFC 7230 (§ 3.3.1.1, § 3.3.1.4).tracestateorder and truncation. Keep unmodified pairs in order, put new and updated pairs on the left (§ 3.5, § 4.3), and truncate whole entries only: longer than 128 characters first, then from the right (§ 3.3.1.5).- No personal data in trace headers. No PII in
traceparentortracestate, and no user-identifiable seed for ID generators (§ 6, § 6.1, § 6.2). - Baggage values are percent-encoded. Everything outside
baggage-octet, and%itself, MUST be percent-encoded; invalid UTF-8 MUST decode to U+FFFD;=may appear in values (Baggage § 3.3.1.3). - Baggage limits. Propagate every member while the result is at most 64 members and 8192 bytes, across all
baggageheaders combined; never propagate a partial member (Baggage § 3.3.2).
Workflow
- Pick the version. Use Trace Context Level 1 and W3C Baggage. Turn on Trace Context Level 2 only behind a switch.
->
references/versions.md✓ The target level is recorded, and nothing from the editor's drafts (traceresponse, thetraceServer-Timing metric) is emitted. - Choose the compliance level per request. Forward only, or participate (§ 2.3). A forwarder never changes
tracestatewithout changingtraceparent(§ 3.4, § 4.4). ->references/processing-and-privacy.md✓ Each component has a documented role, and pass-through components forward both headers byte for byte. - Parse
traceparent. Validate the version prefix, length, hex and all-zero rules; handle higher versions per § 3.2.4. ->references/traceparent.md✓ The invalid examples in the reference are rejected, the valid ones parse, and a01-…-01-extraheader parses its first three fields. - Parse
tracestate. Only aftertraceparentsucceeded. Combine multiple fields, accept empty members, and discard invalid entries or the whole header (§ 4.3). ->references/tracestate.md✓ A malformedtracestatenever causes a newtrace-id; a lonetracestateis dropped. - Start or continue the trace. With no valid
traceparent, generate a random 16-bytetrace-idand 8-byteparent-id(§ 4.2, § 8.2); otherwise keep thetrace-idand mint a newparent-id(§ 4.3). Setsampledfrom the recording decision. ->references/traceparent.md✓ No all-zero IDs;sampledonly changes together withparent-id; undefined flag bits go out as0. - Write the outgoing headers. Put your
tracestateentry on the left, keep the rest in order, enforce 32 members and truncate whole entries. ->references/tracestate.md✓ The Congo and Rojo example in the reference reproduces exactly. - Handle
baggage. Parse with the Baggage grammar, percent-encode values, keep properties, respect the limits, and forward it. ->references/baggage.md✓Amélieround-trips asAm%C3%A9lie; a value containing=survives; 64 members of under 8192 bytes are all forwarded. - Apply the trust boundary. Decide restarts at front gates, guard against
sampledabuse, striptracestateandbaggagetoward external systems, and return trace headers in responses only to participants. ->references/processing-and-privacy.md✓ The trust-boundary checklist is answered for every edge, and CORS allows the headers the browser app sends. - Upgrade (only when asked). Follow the Level 1 to Level 2 checklist behind the switch.
->
references/versions.md✓ Flags03keep bit0x02across the component, and Level 1 behaviour is unchanged with the switch off.
Verify before done
- Version
00traceparentvalues are exactly 55 lowercase-hex-and-dash characters, with non-zero IDs (§ 3.2.2). - Invalid
traceparentrestarts the trace and deletestracestate(§ 4.3); a lonetracestateis discarded (§ 4.2). - Higher versions are parsed by the § 3.2.4 algorithm and re-emitted as
00. - Flags are tested with masks, and undefined bits are written as zero (§ 3.2.2.5); Level 2 mode preserves the random flag (L2 § 3.2.2.5.2).
- Unchanged
traceparentmeans unchangedtracestate(§ 3.4). -
tracestatekeeps order, has your entry on the left, no duplicate keys, at most 32 members, and truncates whole entries (§ 3.3.1, § 3.5). - At least 512 characters of
tracestateare propagated, or the lower limit is documented (§ 3.3.1.5). -
baggagevalues are percent-encoded and decoded with U+FFFD; limits apply to allbaggageheaders together (Baggage § 3.3.1.3, § 3.3.2). - No PII in trace headers; ID generators use no user-identifiable seed (§ 6.1, § 6.2).
- Public endpoints rate-limit recording and do not trust
sampledblindly (§ 7.2). - Nothing from the editor's drafts is emitted, and Level 2 behaviour sits behind a switch.
Reference index
references/versions.md: Trace Context Level 1, Trace Context Level 2 and W3C Baggage with their W3C status, what Level 2 and the editor's drafts change, the upgrade checklist and the preview. Load for steps 1 and 9.references/traceparent.md: grammar, field rules, valid and invalid examples, sampled and random flags, higher-version parsing with a parser sketch, mutations and ID generation. Load for steps 3 and 5.references/tracestate.md: header combining, Level 1 and Level 2 key grammars, values, limits and truncation, mutations, the worked example and common mistakes. Load for steps 4 and 6.references/baggage.md: grammar, keys, values, properties, percent-encoding with an encode and decode sketch, limits, mutations, security and privacy. Load for step 7.references/processing-and-privacy.md: forwarding versus participating, the processing model and decision table, other protocols, privacy, security and the trust-boundary checklist. Load for steps 2 and 8.
Related skills
opentelemetryfor OpenTelemetry instrumentation and context propagation, whose Baggage implementations the W3C Working Group audits (Baggage, Status):npx skills add ScaleDockHQ/scaledock-skills --skill opentelemetry.opentelemetry-genaifor tracing generative AI calls on top of the same context:npx skills add ScaleDockHQ/scaledock-skills --skill opentelemetry-genai.
Sources
Status uses the publishing body's own maturity term. Checked is the date the source was last read.
- Trace Context (latest version): W3C Recommendation, Level 1 of 23 November 2021 (same document as the Level 1 URL), checked 2026-10-05.
- Trace Context Level 1: W3C Recommendation, 23 November 2021 (REC-trace-context-1-20211123), checked 2026-10-05.
- Trace Context Level 2: W3C Candidate Recommendation Draft, 28 March 2024 (CRD-trace-context-2-20240328), checked 2026-10-05.
- Propagation format for distributed context: Baggage: W3C Candidate Recommendation Snapshot, 30 May 2024 (CR-baggage-20240530), checked 2026-10-05.
- Trace Context editor's draft: Editor's Draft,
w3c/trace-contextcommitacab820(2026-06-29), checked 2026-10-05. - Baggage editor's draft: Editor's Draft,
w3c/baggagecommitbfe9a3b(2026-06-30), checked 2026-10-05. - Trace Context Protocols Registry: W3C Working Group Note, 19 November 2019, checked 2026-10-05.