Video in progress

What is distributed tracing, and what do trace and span mean?

Distributed tracing follows the path of a single request across several services. A trace is the request's full path, and a span is one operation on that path (an HTTP call, a SQL query), with its own start time and duration.

📖 Answer

Imagine a user clicks "Place order" and the response takes 4 seconds. The request went through gateway → order-service → inventory-service → payment-service. Which one is slow?

Each service writes its own log, but linking them is hard. With tracing:

  • the whole request gets one traceId;
  • each step is a span, with its own spanId and its parent span's ID;
  • the result is a tree, and Jaeger, Zipkin or Tempo shows it on a timeline.
order-service  POST /orders            [==========================] 4.1s
  inventory    GET /stock               [==]                          0.2s
  payment      POST /charge                [=====================]    3.6s
    payment    SELECT ... FROM cards          [===================]   3.4s

You can see at a glance: the time went into the SQL query in payment-service.

The traceId is passed from service to service through HTTP headers. In Java, OpenTelemetry or Micrometer Tracing usually does this automatically.