Skip to content

Context Propagation: Context, Propagators and W3C Headers: OTCA practice questions

Context propagation is what lets OpenTelemetry connect telemetry produced in different services into one picture. Two ideas are involved. Context is the in-process object that carries execution-scoped values, such as the active span and baggage, across API boundaries within one process.

By Ibrahim Yesilay · Published · Updated

Independent community practice, not affiliated with or endorsed by CNCF or The Linux Foundation.

What Context Propagation: Context, Propagators and W3C Headers covers in OTCA

Context propagation is what lets OpenTelemetry connect telemetry produced in different services into one picture. Two ideas are involved. Context is the in-process object that carries execution-scoped values, such as the active span and baggage, across API boundaries within one process. Propagation is the mechanism that serializes that state into a message going to another process and deserializes it on the other side.

A Context is immutable. Writing a value never changes an existing Context; it returns a new Context that contains the old values plus the new one. Languages with implicit context also offer operations to get the current Context and to attach or detach one, and most users touch context through tracing or baggage APIs rather than directly.

Crossing a process boundary is the job of propagators. The Propagators API currently defines the TextMapPropagator, which injects values into and extracts values from a carrier as string key-value pairs, typically HTTP headers. Inject reads the value from a Context and writes it into a mutable carrier on the outgoing side. Extract reads the carrier on the incoming side and returns a new Context. If a value cannot be parsed, Extract must not throw and must not overwrite an existing valid value. A SpanContext created through extraction reports IsRemote as true, which is how samplers know the parent came from another process. Several propagators can be grouped into a composite propagator that runs them in order.

The default propagator format is W3C Trace Context. Its traceparent header has the form version-traceid-parentid-traceflags, for example 00-a0892f3577b34da6a3ce929d0e0e4736-f03067aa0ba902b7-01. The trace ID is 16 bytes, the span ID 8 bytes, and the trailing flags byte carries the sampled bit, so 01 means sampled. The optional tracestate header carries vendor-specific data. Baggage travels in its own W3C Baggage header and holds application-defined name and value pairs. The Baggage API works even when no SDK is installed, so baggage can still flow through a service that only has a propagator configured.

When an SDK is configured with environment variables, OTEL_PROPAGATORS selects propagators as a comma-separated list and defaults to tracecontext,baggage. Other known values include b3 for the single B3 header, b3multi for the separate X-B3 headers, xray, and none. The jaeger and ottrace values are deprecated in favour of W3C Trace Context. Without any configuration, the bare API uses no-op propagators, so nothing is injected.

Propagation also interacts with sampling. Under the default ParentBased sampler, a span with a sampled remote parent is sampled, and a span with an unsampled remote parent is dropped. Finally, treat incoming context from untrusted sources with care and never put secrets or personal data into baggage, because it is sent to downstream services.

Key points

  • Context is immutable and carries values in-process; propagators move it across process boundaries.
  • TextMapPropagator injects into and extracts from carriers such as HTTP headers, and Extract must not throw on bad input.
  • The W3C traceparent header is version-traceid-parentid-traceflags, where flags 01 means sampled.
  • OTEL_PROPAGATORS defaults to tracecontext,baggage; b3 injects the single header and b3multi the multi-header form.
  • The Baggage API is fully functional without an installed SDK.
  • Extracted SpanContexts are remote, so ParentBased samples or drops children based on the parent's sampled flag.

Three sample questions

21 OTCA questions on Context Propagation: Context, Propagators and W3C Headers, 21 with explanations. How practice works

Question 1

An incoming request carries this header:
traceparent: 00-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-01
What does the final field 01 mean?
  1. A.The traceparent format version is 01
  2. B.The caller's span is the first span of the trace
  3. C.The tracestate header carries one list member
  4. D.The sampled flag is set in trace-flags

Correct answer: D

The traceparent value is version "-" trace-id "-" parent-id "-" trace-flags. Here 00 is the version, the 32-hex trace-id is 16 bytes, the 16-hex parent-id is 8 bytes, and 01 is trace-flags. Version 00 only defines one flag, sampled (FLAG_SAMPLED = 00000001). The W3C spec gives "base16(trace-flags) = 01 // sampled" as its example. Why the other options are wrong. "The traceparent format version is 01": The version is the first field (00 here); the specification assumes version 00 and forbids ff. "The caller's span is the first span of the trace": Trace-flags say nothing about the span's position in the trace; the parent-id identifies the caller's span. "The tracestate header carries one list member": Tracestate is a separate header, and its member count is not encoded in traceparent.

Sources: W3C Recommendation: Trace Context, OpenTelemetry docs: Context propagation

Question 2

Which of these traceparent values MUST a receiving service ignore according to the W3C Trace Context specification?
  1. A.00-00000000000000000000000000000000-00f067aa0ba902b7-01
  2. B.00-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-00
  3. C.00-a0892f3577b34da6a3ce929d0e0e4736-f03067aa0ba902b7-01
  4. D.00-0af7651916cd43dd8448eb211c80319c-b7ad6b7169203331-01

Correct answer: A

The W3C spec says a trace-id of all zeros is an invalid value and "If the trace-id value is invalid (for example if it contains non-allowed characters or all zeros), vendors MUST ignore the traceparent." The first option has an all-zero trace-id. The other three use version 00, a 32-character lowercase hex trace-id, a 16-character lowercase hex parent-id and valid flags. Why the other options are wrong. "00-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902…": It is valid; flags 00 only mean the caller did not sample the request, which is an allowed state. "00-a0892f3577b34da6a3ce929d0e0e4736-f03067aa0ba902…": It is a valid sampled traceparent (this exact value appears in the OpenTelemetry context propagation docs). "00-0af7651916cd43dd8448eb211c80319c-b7ad6b71692033…": It is valid: lowercase hex, non-zero IDs of the correct length, version 00 and the sampled flag set.

Sources: W3C Recommendation: Trace Context, OpenTelemetry docs: Context propagation

Question 3

An OpenTelemetry service is configured with the B3 propagator. An incoming request carries B3 headers with the debug flag set. What does the Propagators API specification require on extract?
  1. A.Drop the debug flag, because OpenTelemetry has no debug concept in TraceFlags
  2. B.Keep the debug flag for later requests and also set the sampled trace flag
  3. C.Reuse the incoming X-B3-SpanId as the span ID of the new server-side span
  4. D.Mark the context as not sampled until the local sampler confirms the debug flag

Correct answer: B

The B3 extract requirements say propagators "MUST preserve a debug trace flag, if received, and propagate it with subsequent requests. Additionally, an OpenTelemetry implementation MUST set the sampled trace flag when the debug flag is set." They also MUST attempt both single and multi-header formats (single takes precedence) and MUST NOT reuse X-B3-SpanId for the server-side span. Why the other options are wrong. "Drop the debug flag, because OpenTelemetry has no…": The debug flag must be preserved and propagated, not dropped. "Reuse the incoming X-B3-SpanId as the span ID of t…": The spec says propagators MUST NOT reuse X-B3-SpanId as the server-side span ID, because OpenTelemetry does not share one ID across both sides of a request. "Mark the context as not sampled until the local sa…": The sampled flag MUST be set when debug is set; it is not left unsampled.

Sources: OpenTelemetry spec: Propagators API, OpenTelemetry spec: SDK environment variables

Practice this topic

Focus mode keeps every question on Context Propagation: Context, Propagators and W3C Headers until you leave it. 10 free guest answers, then a free account; no credit card.

Or open OTCA practice across all topics.

Sources

The explanation above was checked against these official documents.

Frequently asked questions

Why does my service start new traces even though the caller sends trace headers?

A common cause is a propagator mismatch: if the caller sends only B3 headers but the service uses the default tracecontext,baggage propagators, the incoming context is not understood. Configure a matching propagator such as b3 or b3multi.

Is baggage automatically added to spans?

No. Baggage lives in the Context and travels in its own header; adding baggage values to spans, metrics or logs is a separate step.