Course contentsShow
← Cloud and Infrastructure
Lesson 2076 of 2,98944. Observability - TracingFree lesson

Spans, Traces, and Context Propagation

Understanding spans as building blocks of traces and how context is propagated across service boundaries.

Spans, Traces, and Context Propagation

You'll learn how spans form traces and how tracing context flows across distributed service boundaries.

The Building Blocks

Think of a trace as a complete journey through your distributed system—like tracking a package from warehouse to doorstep. Each span represents one leg of that journey: a single operation or unit of work with a start time, duration, and outcome.

A span is the atomic unit of work in distributed tracing. When your API endpoint receives a request, that creates a span. When it calls a database, that's a child span. When it calls another microservice, that's another child span. Together, these parent-child relationships form a tree structure—your trace.

Context Propagation: The Glue

Here's the critical piece: how does span B "know" it belongs to the same trace as span A when they run in different processes or services?

Context propagation solves this by passing trace metadata (trace ID, span ID, sampling decisions) across service boundaries. This happens through:

  • HTTP headers (like traceparent in W3C Trace Context)
  • Message queue attributes
  • gRPC metadata
  • Service mesh sidecars

When Service A calls Service B, it injects the trace context into the outbound request. Service B extracts that context and creates a child span linked to the same trace. This way, the entire distributed transaction stays connected, even across network hops, language boundaries, and infrastructure layers.

Without proper context propagation, you'd have disconnected spans—isolated operations with no way to reconstruct the full request flow.

Key Takeaway: Spans are individual operations that link together to form traces, and context propagation is the mechanism that connects spans across service boundaries, enabling end-to-end visibility in distributed systems.