What Exactly Is a Trace?
Nandan Jadhav
Say you are ordering food through a food delivery app. You pick your favourite dishes, place the order, complete the payment, and then see the fancy UI or animation telling you that your order is being prepared and will be delivered in approximately 45 minutes.
While you made all your choices, selected your favourite food items, and completed the payment, the application and the systems behind it went through a whole lot of activity in the background.
Think about the different steps involved.
Placing the order → Restaurant accepting it → Order sent to the kitchen → Order ready → Delivery driver picking it up → Final delivery
In observability, the journey of a request through multiple services can be represented as a trace. The individual operations that make up that journey are represented as spans.
Let’s say the food you received is cold.
To figure out what went wrong, you would look at the timeline of the entire journey rather than looking at the restaurant or the delivery driver in isolation. You would want to understand where the delay happened and which part of the process caused it.
The same concept applies to distributed applications.
Understanding the terminology
Trace: The complete journey of a single request or transaction as it moves through different services.
Span: An individual unit of work within a trace. A span contains information such as the operation, service, start time, duration, and other attributes. A span can also be associated with logs or events.
Context Propagation: The mechanism used to pass trace context, such as trace and span identifiers, between services so that individual operations can be connected to the same trace.
A Real World IT Example
Now let’s take a real world example of an ecommerce checkout.
A user goes to their favourite shopping website and finds the product they were looking for on sale. The user clicks “Buy Now” on the online store.
The request might flow across multiple services.
API Gateway → Authentication Service → Payment Service → Inventory Service → Inventory Database → Response
Suppose the checkout was painfully slow.
By looking at the trace, you notice that the inventory database query took 4 seconds, while most of the other operations completed in milliseconds.
The slow database query could be caused by several things, such as a missing index, a locked table due to a concurrent transaction, or high CPU utilisation on the database server.
Without a trace, you might simply see a generic timeout or increased latency on your monitoring dashboard.
With a trace, the waterfall view can show where the request spent most of its time, giving the relevant team a clear starting point for investigation.
This is one of the biggest advantages of distributed tracing.
Instead of simply knowing that a request was slow, you can see where the time was spent.
In a real observability environment, traces can also be correlated with metrics and logs to provide additional context during an investigation.
Key Takeaways
- A trace represents the journey of a request through one or more services.
- A trace is made up of individual operations called spans.
- Spans contain information such as duration, service, operation, and other attributes.
- Context propagation connects operations across different services to the same trace.
- A trace waterfall helps engineers identify where a request spent its time.
- Traces are particularly useful when investigating latency and failures in distributed applications.
A metric can tell you something is slow.
A trace can show you where the time was spent.