← Concepts

阅读中文版本

Trace Context Propagation

Trace context propagation carries trace and span identifiers across process and protocol boundaries so one distributed trace spans every service.

observability

Definition

Trace context propagation is the transfer of trace identifiers and sampling decisions across service boundaries, typically through message headers, so spans created in different processes join one trace.

Context and scope

It is required for any distributed trace that crosses HTTP, gRPC, or message queues.

Common misconceptions

  • tracing works automatically once each service emits spans
  • trace context can be inferred from timestamps and host names

Anti-patterns

  • creating a new trace per service instead of continuing the parent
  • failing to propagate sampling decisions to downstream services

Related concepts

Related examples

Authoritative source

https://www.w3.org/TR/trace-context/

Definition

Trace context propagation is the transfer of trace identifiers and sampling decisions across service boundaries, typically through message headers, so spans created in different processes join one trace.

It is required for any distributed trace that crosses HTTP, gRPC, or message queues. Compared to simpler alternatives, this concept fits best when the trade-off it represents is the one the system actually cares about.

When to use it

A common use case is applying it at the boundary where the cost of getting it wrong is highest, and the scenario usually involves a concrete guarantee the system must uphold. Unlike an ad hoc approach, it makes that guarantee explicit, reviewable, and testable.

How it works

A standard header such as traceparent encodes the trace identifier, parent span, and flags, letting the receiver continue the same trace rather than start a disjoint one.

Asynchronous hops need the context attached to the message, because no in-process call carries the header across a queue or scheduled job.

Trade-offs and alternatives

Context must be sanitised at trust boundaries; untrusted clients that can set trace identifiers can otherwise pollute or join traces they should not. The main drawback is the extra complexity it introduces, so the benefit should clearly outweigh that cost before a team adopts it.

Common misconceptions

A persistent misconception is that tracing works automatically once each service emits spans. Another is that trace context can be inferred from timestamps and host names. For example, an engineer who assumes otherwise may design around a guarantee that does not actually exist, which only becomes obvious under load or failure.

Anti-patterns to avoid

Two recurring anti-patterns are to creating a new trace per service instead of continuing the parent and to failing to propagate sampling decisions to downstream services. Both tend to surface as hard-to-debug production issues rather than obvious test failures. Related concepts include Exemplars Linking Metrics to Traces, Operational Dashboard Design, Selecting Service Level Indicators.