Skip to content
Blog

Distributed Tracing: How to Read a Trace and Find the Slow Span

Distributed Tracing: How to Read a Trace and Find the Slow Span

When the alert says checkout got slow, the metrics dashboard confirms p95 climbing. Neither tells you which of the six services in the order path ate the time. That answer lives in the trace, the record distributed tracing keeps of each request's path through the services. The hard part is knowing where to look inside it.

According to the Grafana Labs 2025 observability survey, 57% of organizations already collect traces, against 95% that collect metrics. Collecting is not enough, because a checkout trace has dozens of spans and reading it without a method tends to stop at the wrong span.

This tutorial uses three real traces from KeepWatch, the OpServices application observability platform. They are a normal checkout, another one four times slower and a booking that failed. The six steps follow the order in which the on-call engineer investigates.

All examples come from the KeepWatch lab. Loja and Viagens are demo applications that send telemetry over OTLP; the numbers cited come from those runs.

 

What a trace records and the order to read it in

Each request generates a trace, which is its complete path through the services. A trace is divided into spans, one for each operation: an HTTP call, a database query, a piece of code. All spans of the same request carry the same trace_id.

Reading a trace means answering four questions in this order: which request to look at, where the time went, which span failed and what its log recorded.

The parent and child span relationship and the field-by-field anatomy of a span are covered in the guide to traces in observability. Deploying distributed tracing, from instrumentation to backend, is the subject of the post on how distributed tracing works. Here the starting point is a trace you already have open.

The trace_id ties everything together. It travels between services in the traceparent header, defined by the W3C Trace Context specification.

In that header the trace identifier takes 32 hexadecimal characters and the parent span identifier takes 16. The 32-character identifier is the same one shown at the top of each trace and the one that links the trace to the log in step 6.

This logic applies to any tool that reads OpenTelemetry data, since the span format comes from the standard and the interface merely displays it.

 

Step 1: find the right trace, not the most recent one

In six hours the lab's loja-web service alone generated 28,370 traces. Opening the most recent one is a lottery, because it almost always shows a normal request that teaches nothing about the problem.

Start from the symptom, because it defines the sort order and the filter. For slowness, sort by Slowest and filter by the service or operation the alert named. For failures, switch the result to With error. The minimum and maximum duration filter trims the list to the range you care about, such as everything past p95.

The facets panel lets you filter by attribute: service.name, status.code, error.type and the http.* and messaging.* groups, among others. When the starting point is a log, the line itself leads to its trace. When it is a failed synthetic test, the failure card opens the trace of that run.

In the lab list, the loja-web p95 for the period was 525.8 ms, while the four checkouts at the top exceeded 1.7 s. Three of them started right at the top of the hour: 17:00:00, 18:00:03 and 13:00:05. A timing coincidence like that calls for cross-checking against the job schedule before it becomes a conclusion.

The lab trace list sorted by Slowest and filtered to the loja-web service puts those four checkouts first, which makes them the natural candidates to open.

 

 

 

Step 2: read the waterfall from top to bottom

In the waterfall view, each span becomes a bar. The first row is the root, which represents the whole request from the point of view of whoever received it. Indentation shows who called whom, the width of the bar is the duration and the horizontal position marks when the span started.

In this example, POST /checkout took 491.4 ms, with 22 spans across six services. After validating the cart in 12.3 ms, loja-web calls the catalog (84.5 ms), payment (221.4 ms) and delivery (172.0 ms). The bars form a staircase, since each call only starts when the previous one ends.

A staircase indicates sequence; overlapping bars indicate parallelism. In this checkout, catalog, payment and delivery add up to 477.9 ms of the root's 491.4 ms. If the order is not mandatory, running the calls in parallel shortens the total.

When the order is a business rule, such as never shipping an order without an approved charge, the total time is the sum of the steps. The only option left is to shorten one of them.

In the 491.4 ms checkout waterfall, the three steps of the staircase (catalog, payment and delivery) sit one after the other under the root.

 

 

 

Parent span time and child span time

A wide bar on a parent span does not mean it spent all that time itself, because the bar includes the time of its children. In payment, the service itself took 216.1 ms to handle POST /cobrar. The 221.4 ms measured by loja-web also include the round trip over the network, a difference step 3 explains.

Within those 216.1 ms, the internal operation montar-transacao took 146.5 ms and the call to the payment gateway took 68.7 ms. In this trace the suspect for payment is the service's own code. The third party is cleared.

The useful question, then, is which child fills the parent's bar. When no child fills it, a gap is left between the bars. That gap is time spent in uninstrumented code, in a queue or on the network.

 

Step 3: compare with a slow trace of the same operation

On its own, a trace does not say whether 221 ms of payment is a lot. A comparison does: another checkout, at 17:00 the same day, took 1.99 s with the same 22 spans. The Span list tab puts those spans in a table sorted by duration, with the type and start time of each one.

The type of each span is the SpanKind described in the OpenTelemetry concepts documentation. A call between services appears twice: as Client in the calling service and as Server in the service that handled it.

The difference between the two is the time the request spent outside the server. When it is large, the time was lost along the way and not in the code of the called service.

In the slow trace, loja-web waited 736.0 ms for payment, which worked for 362.7 ms. The other 373 ms fell before the request arrived and after the response left. That interval can hold network time, queueing, an exhausted connection pool or a busy caller. In the catalog, the server only started 127 ms after the call.

When that interval grows in several services at once, suspicion falls on a saturated shared resource and not on a code bug. The same trace shows another deviation that deserves the next step: SELECT produto, which took 10.9 ms in the normal checkout, took 200.5 ms.

In the Span list tab of the 1.99 s checkout, the payment Client and Server spans appear with the start time and duration of each one.

 

 

The Service map tab draws the same trace as a graph, with the called service's time on each arrow. The database appears under the service that queried it; third parties sit in dashed boxes marked as external.

 

Step 4: open the SQL query of the database span

A database span is a Client span that stores the text of the executed query. In the SQL queries tab, KeepWatch lists the trace's queries from slowest to fastest.

The query appears parameterized: SELECT sku, nome, preco FROM produto WHERE sku = ?. That is what the OpenTelemetry conventions ask for in the db.query.text attribute: parameter values are only recorded when someone enables that collection. That is why the SKU the customer bought is not stored in the traces backend.

That same query took 10.9 ms in the normal checkout and 200.5 ms in the slow one, 18 times more. When the text stays the same and the time changes, the question moves from the code to the database at that minute: locking, I/O or concurrency. The next place to look is the database metrics for the same time window.

This tab also reveals the N+1 problem when it exists: the same SELECT repeated dozens of times in a staircase, one per list item. In that case the fix lives in the code that builds the query and not in the table index.

In the SQL queries tab of the slow checkout, the SELECT produto query sits at the top of the list.

 

 

Capturing the exact query is what unlocked the diagnosis at Brazil's Butantan Institute. SESuite, a document management platform, sometimes took 3 to 5 minutes per operation. The usual response was to restart the service or add hardware.

With OpenTelemetry traces and the exact SQL Server query, we found the cause: a slow query and excessive memory consumption by Java. Tuning the database and the application reduced the slowness without new hardware, as the Butantan Institute case study shows.

To hear the customer's side, listen to OpCast #06, where Claudia Anania, CIO of the Butantan Institute, explains how IT sustained vaccine production (in Portuguese).

 

Step 5: follow the error down to the deepest span

The error climbs the waterfall, from the span that failed up to the root. In the lab's POST /reservar, four of the seven spans carry the error mark. The mark runs from the root down to the GDS /emitir call that the viagens-reserva service makes to the GDS.

The GDS is the reservation system travel agencies use to issue tickets.

The cause is in the deepest span with an error, because the ones above only passed the failure along.

Open that span and read the attributes before the message. The instrumentation fills in attributes on every call, while the message is free text written by whoever programmed the service.

Among the attributes, http.response.status_code shows that the GDS answered 503, while viagens-web returned 502 to the client. The status code changes along the way: the 502 the client saw is the symptom. The cause is the third party's 503.

The exception message recorded on the span says HTTP Error 502: GDS unavailable, while the attribute shows 503. When the two disagree, the service log decides, which is the subject of the next step.

The With error filter reads the span status, not the HTTP code. In OpenTelemetry a span completed without failure has status Unset and a failure becomes Error; Ok only appears when the developer sets it on purpose.

That is why the filter also returns requests that succeeded for the client. In the lab, a flight search returned 200 even with the Redis cache span in error, because the response came straight from the GDS.

In the booking trace, the error mark runs from the root down to GDS /emitir. Opening that span shows the attributes discussed above.

 

 

 

Step 6: confirm in the log of the failed span

The span's Logs tab holds the lines the services wrote during that trace, with the span's own line highlighted.

In the booking, viagens-reserva logged GDS refused /emitir with 503 and viagens-web logged booking 7c580aeb not confirmed: Bad Gateway. The log confirms that the 503 in the attribute was right.

This link depends on the log carrying the trace context. The OpenTelemetry log data model reserves the TraceId and SpanId fields for it. An application that logs without them produces lines no tool can tie back to the trace.

The current OpenTelemetry convention says to record the exception in the log. Recording it as a span event is marked as deprecated in the specification for exceptions on spans, although it is still the default. That is what the lab did in step 5.

In practice the detailed reason for the error lives in the log, while the trace says where and when to look for it.

To see the surrounding context or lines of other levels, the Open in Logs button leads to a search already filtered by the trace. Trace and log answer different questions, as the guide to logs in observability explains: the trace shows where and how much, the log shows why.

In the Logs tab of the GDS /emitir span, the two error lines appear right below the Open in Logs button.

 

 

 

When the trace shows less than what happened

Three situations make the waterfall tell an incomplete story without any warning on screen.

Broken trace. A service that does not forward traceparent, such as a misconfigured proxy or an uninstrumented queue consumer, starts a new trace. The waterfall ends in a span with no child; the continuation shows up as another trace with a different trace_id.

Uninstrumented third party. A payment gateway, a shipping API and an email service appear as external calls. The KeepWatch External calls tab warns that in these cases what is measured is your side: the time the caller waited, network included.

Head sampling. In this model the decision to keep a trace is made at the start of the request, when nobody knows whether it will be slow. Because the discard is random, the rare trace you care about disappears as often as the normal ones.

Tail-based sampling decides at the end and keeps every trace with an error or above a duration threshold.

 

 

Where to start reading traces in your environment

Pick an operation the business feels, such as checkout, invoice issuing or booking. Open ten traces of it: five normal and five among the slowest. Comparing the two groups teaches more than any single trace, because it shows which step of the staircase grows when the operation gets worse.

Before that, check three prerequisites. Every service on the path must propagate traceparent, otherwise the trace comes out broken. The log must record the trace_id and the span_id, otherwise step 6 does not exist. Sampling must keep errors and slowness, otherwise the trace you need never reaches the screen.

Once these three points are settled, the investigation no longer depends on whoever knows the system by heart. The path from symptom to log line is recorded in every request. To instrument your applications and read their traces in KeepWatch, talk to an OpServices expert.

Application Observability

Find the slow span in minutes, not hours.

KeepWatch shows the path of each request, the time of every step and the error behind it, on a single screen.

Explore KeepWatch →

Pedro Tebaldi

I have been at OpServices since 2011, where I am Marketing Manager and Product Manager of KeepGreen, an IT incident management platform that cleans up alerts, points to the root cause with AI, writes the post-mortem and analyzes cloud costs. I also lead the company's artificial intelligence governance projects. I have written on this blog since 2013, with more than 550 articles published on monitoring, observability, SRE and ITSM. LinkedIn

plugins premium WordPress