Tracing

What a trace is, how to read one when a request is slow or wrong, and how traces differ from logs and metrics on OpenShift.

Updated CompTech Team

A user says the order page was slow. The Orders pod log shows a 200. The Catalog pod log shows a 200. PostgreSQL shows nothing unusual. The time was spent in one call between them, and no single log line contains both ends. A trace does. It is the record of one request as it crosses processes, with the time spent in each hop.

Metrics tell you the service is slower than last week. Logs tell you what one process thought. Traces tell you which hop of which request. You want all three, and you want them joined by an id. Wiring the id through the services is OpenTelemetry. A mesh can create the hops for you, which is Service mesh. This page is how to read the result.

Spans

A span is one timed operation: handling the HTTP request, the query, the call to Catalog, the publish to Kafka. A span has a name, a start, a duration, a trace id and a span id, and usually a parent span id. Spans that share a trace id are one trace. The parent links are why a UI can draw a tree instead of a list.

The trace id is generated at the edge, on the first request. Every hop has to copy it onto the outbound call. The standard header is W3C traceparent. If Orders generates a trace id and Catalog starts a new one, you have two traces and you are back to reading logs. Propagation is the whole technique. The application does not need a custom header called X-Request-Id, though keeping one for humans is harmless. traceparent is what the libraries already understand.

A span can carry attributes: http.route, db.statement with the literal values stripped, messaging.destination. Attributes are how you find the trace later. They are also how a password ends up in the trace store. Do not put a card number, a session, or the full text of a customer prompt on a span. The security overview applies to the trace backend as much as to the database.

What you do with one

Take a slow request from the smoke test or from a user report. You need its trace id. If the application returns traceparent on the response, or logs the trace id on the access line, you have it. Paste it into the trace UI.

orders  GET /orders          820 ms
  catalog GET /products/2    740 ms
    postgres SELECT ...       18 ms
  redis GET catalog:product:2  4 ms
  kafka produce orders.placed  30 ms

The tree says Catalog ate the time, and Catalog's database did not. The next place you look is Catalog's own outbound calls, or a lock, or a cold cache, not the SQL you were about to tune. A trace that stops at the process boundary is a propagation bug: the outbound client was not instrumented. Fix that before you draw conclusions from the picture.

Errors are spans too. A 500 with an exception attribute on the span that failed is a shorter path than grepping three Deployments. The status on the span is what the UI colours. A span marked OK that returned a wrong total is still a successful span. Tracing does not know your business rule. The test from Application testing does.

Sampling

A trace per request is the right setting in a lab and the wrong setting at a volume where the trace store costs more than the service. Sampling keeps a fraction. Head sampling decides at the start of the trace, so you either have the whole tree or nothing. Tail sampling keeps the slow and the failed ones and drops the boring successes, which is what you want in production and which costs a collector that can see the finished trace. Start with a sample of everything in the test namespace. Sample in production once you know which attributes you search on.

A sampled-out request has no trace. The log line should still carry the trace id, so you can see that the trace was dropped rather than never started.

Where the traces go

The applications export spans in OTLP to a collector. The collector forwards to a store. In our lab that store is Tempo, queried from Grafana, the same Grafana the Redis and Data Grid metrics use. Jaeger is the other UI people know. Either one can sit behind the collector, which is why the application talks to the collector and not to the store directly. Changing the store then does not mean changing every Deployment.

The Red Hat build of OpenTelemetry is the operator that installs the collector and, optionally, injects the agent. The next lab is the YAML. For a single .NET or Java service, the manual instrumentation in the microservices lab is enough to see one trace and confirm the path before you install anything cluster-wide.

Logs, metrics, traces

Signal Question it answers Where it lives in this lab
Metric Is the service slower or busier than usual, right now? Prometheus, Grafana. Redis and Data Grid exporters.
Log What did this process print at that moment? The pod log, or the cluster log store.
Trace Which hop of this one request took the time, or threw? Tempo, via the collector.

Join them with the trace id. A log line that prints the trace id can be the search key in Grafana. A metric with no exemplar can still tell you the minute to search. A trace with no metric still cannot tell you whether this slowness is one user or all of them. During a platform drill, take the trace id of the first failed smoke-test request and file it with the recovery time. "It was slow" is not a finding. "Catalog's span was 740 ms and the SQL span was 18 ms" is.

A header you can follow

traceparent looks like this:

traceparent: 00-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-01

The middle field is the trace id. The next is the span id. The last flags say whether the caller sampled the trace. An outbound client that does not copy this header starts a new trace, and the tree breaks at that process. The check is mechanical: call Orders, read the trace id from its log, and confirm Catalog's log contains the same id. If Catalog has a different one, fix the client before you tune anything.

Baggage is a second header, for a few pieces of context you intend to pass (a tenant id, a test-run id). It is not a place for the user's name. Anything you put in baggage is copied to every hop, including hops you did not write.

Names that search well

A span named HTTP GET is every request. A span named GET /orders/{id} is a route you can graph. Use the low-cardinality route, and put the order id in an attribute if you need it. High-cardinality names (one span name per order id) make the trace store expensive and the search useless.

Attribute Put it on the span when
http.route The template, not the raw URL with a query string full of ids.
db.system postgresql, redis, infinispan. The statement text stays parameterised.
server.address The Service you meant to call. A pod IP here means the client bypassed DNS.
error.type The exception class, not the message if the message quotes user input.

In Grafana, open Explore, pick Tempo, and search { resource.service.name = "orders" } with a minimum duration. The trace id from the Orders log should open the same tree. If Explore returns nothing, the collector is not forwarding, which is the next lab, not a missing index in the application. Confirm the collector Service with oc get svc -n opentelemetry before you change the application. A Service with no endpoints is a collector that is not running, and no amount of header copying will produce a tree.

A habit

When a request is slow or wrong, open the trace before you open five terminals. If there is no trace, that is the bug you file: this service does not propagate traceparent. If there is a trace, write the span name that took the time in the incident note. The next similar incident starts there.

Keep one saved trace from a healthy request. When a later request looks wrong, the comparison is a tree you already trust, not a recollection of how long Catalog "usually" takes.

What's next

OpenTelemetry is the collector, the agent and the environment variables. Service mesh adds the hops that the application forgot to instrument, and adds mTLS. The metrics half for a particular data service stays in that service's monitoring lab.