Trace Context and Propagation
You'll learn how distributed tracing maintains continuity across multiple services by generating and passing unique identifiers.
The Core Idea
Imagine sending a package through multiple shipping facilities. Each facility needs to know it's handling the same package from the same order. Distributed tracing works similarly—when a request flows through multiple services, each service needs to know it's part of the same transaction.
Trace IDs and span IDs are the identifiers that make this possible.
How IDs Are Generated
A trace ID is a unique identifier (typically 16 or 32 hex characters) generated when a request enters your system. This ID represents the entire end-to-end transaction—like an order number for your package.
A span ID identifies each individual operation within that trace—like tracking numbers for each leg of the journey (warehouse → truck → distribution center).
The first service that receives a request typically generates both IDs. Each subsequent service creates new span IDs for its operations while preserving the original trace ID.
Propagation Across Boundaries
The magic happens at service boundaries. When Service A calls Service B, it must pass along the trace context—usually via HTTP headers (like traceparent in W3C standards) or message metadata.
Service B reads these headers, extracts the trace ID, generates its own span ID as a child of Service A's span, and continues the chain. This creates a parent-child relationship showing how operations connect.
Without propagation, each service would think it's handling a brand-new request, losing the ability to correlate operations that belong together.
Key Takeaway: Trace IDs unify distributed operations into a single logical transaction, while span IDs track individual steps, and both must be explicitly propagated across service boundaries to maintain observability continuity.