In this lesson, you will learn how distributed tracing provides a granular, end-to-end view of a request's journey across your microservices architecture.
While logs tell you what happened and metrics tell you how your system is performing, distributed tracing tells you where time is being spent as a request travels through your cluster. In a microservices environment, a single user action—like "checkout"—might trigger calls across a dozen different services. Tracing is the secret to untangling this web.
The Core Building Blocks
- Spans: A span represents a single unit of work. It records the start and end time of a specific operation, such as a database query or an HTTP request to another service. Each span includes a
span_id, aname, and metadata (tags). - Traces: A trace is the "big picture." It is a collection of spans that share the same
trace_id. If you visualize a trace, you see a hierarchical tree of operations that illustrates how one request sparked subsequent requests downstream. - Context Propagation: This is the most critical piece of the puzzle. When Service A calls Service B, it must pass a "trace header" (typically
traceparentorx-b3-traceid) to Service B. This allows Service B to attach its own spans to the originaltrace_id, maintaining the continuity of the request path across network boundaries.
Conceptual Example
Imagine a user hits your Gateway service. The sequence looks like this:
- Trace ID:
abc-123Span 1: Gateway receives request (10ms)Span 2: Gateway callsOrderService(Passesabc-123context)Span 3:OrderServicevalidates request (5ms)Span 4:OrderServicecallsDatabase(20ms)
Without context propagation, these operations would look like isolated events. With it, the tracing backend stitches them together into a single timeline, allowing you to see exactly which service caused a latency bottleneck.
Key Takeaway: Distributed tracing enables you to visualize the lifecycle of a request by stitching together disparate spans using a unique trace ID passed across service boundaries.