Course contentsShow
← System Design
Lesson 1230 of 1,91931. Observability: TracingFree lesson

Trace Context Fundamentals

Understanding trace ID, span ID, and parent span ID as the core identifiers that link distributed operations together.

Trace Context Fundamentals

What you'll learn: How trace ID, span ID, and parent span ID work together to connect distributed operations across service boundaries.

The Core Identifiers

When a request travels through multiple services, tracing systems need a way to link all the operations together. Trace context is the set of identifiers that gets passed along with each request, enabling this linkage.

Think of it like a family tree: the trace ID identifies the entire family lineage (one per request), the span ID identifies each individual person, and the parent span ID points to who their parent is.

The Three Key Fields

Trace ID: A unique identifier (often a 128-bit or 64-bit hex string) assigned when a request enters your system. It remains constant across all services and spans for that request. Example: a3f8c9d2e5b7a1c4

Span ID: A unique identifier for each individual operation or span within the trace. Every API call, database query, or processing step gets its own span ID. Example: 7b2e3f9a

Parent Span ID: References the span ID that initiated the current span. This creates the parent-child relationship that builds the tree structure of your trace. The root span (first operation) has no parent.

Propagation Across Services

When Service A calls Service B, it includes trace context (trace ID, current span ID, and other metadata) in request headers. Service B creates a new span with a fresh span ID but keeps the same trace ID and sets Service A's span ID as its parent span ID.

Key Takeaway: Trace ID ties the entire distributed request together, span IDs identify individual operations, and parent span IDs create the hierarchical structure—these three identifiers form the backbone of distributed tracing.