Bookmarks

Distributed tracing

An observability method: a request that travels through several services is assigned an end-to-end trace made of spans, so you can see where it slowed down or failed.

Also: request tracing, end-to-end tracing

checked 18 Nov

All terms

In a monolith, logs are enough: a request comes in, a response is recorded. In a distributed system, a request passes through a gateway, several services, queues and databases, and each has its own log with its own timestamps and its own ordering of entries. Reassembling the picture by hand is nearly impossible, so the request is tagged with a shared identifier and its path is recorded as a single trace.

Trace and span

A trace is the entire path of a single request through the system. A span is one segment of work with a known start and end: handling a request in a service, running an SQL query, publishing a message to a queue. Spans nest inside one another and form a tree: the root is the arrival of the request, and its children are its internal steps and outgoing calls.

Span fieldWhat it records
Operation namewhat was done: a handler, an SQL query, publishing to a queue
Timethe start and end timestamps of the segment
Trace IDthe identifier of the whole trace, shared by all of its spans
Span ID and parentits own identifier and the parent span; the root has no parent
Status and attributessuccess or failure; attributes — for example, the HTTP route, the address being called

How a trace travels between services

Having received a request, each service passes the tracing context along — in the HTTP headers, in the queue message properties, in the gRPC metadata. The standard format is W3C Trace Context: the traceparent header carries the identifiers of the trace and the current span, while tracestate holds data specific to a particular tracing system.

http
traceparent: 00-0af7651916cd43dd8448eb211c80319c-b7ad6b7169203331-01#            ^version ^trace-id (32 chars)  ^parent-id (16)  ^flags

Each service reads these headers, continues the trace and records its own spans with the tracer. Example: a request passes through a gateway, the order service and a database; the total time is 320 ms, of which 290 ms is taken up by an SQL query without an index. The trace immediately shows the slow segment that would otherwise have to be pieced together by hand from the logs of three services.

Where it is used

  • finding delays and errors: which call slowed the request down, where it failed
  • a dependency map: which services actually call each other, and how often

The idea came from Google: in 2010 the company described Dapper, its internal system for tracing requests across large distributed systems. Today traces are usually collected to the OpenTelemetry standard: an SDK adds tracing to code and libraries, and exporters send the data to a backend of your choice — Jaeger, Zipkin or a cloud service.

Sources

the term is written from these pages

Verified 18 Nov

Not to be confused with

what it is mixed up with and how it differs

  • observability

    Observability is the general approach to understanding a system’s state from its signals; tracing is one of the three signals, alongside metrics and logs.

  • APMapplication performance monitoring

    APM platforms include tracing as one of their features; distributed tracing is the technique itself, independent of any product.

In depth in the references

where the topic is covered in detail