Distributed tracing

Observability and operations Mid-level Python 3.13+ PostgreSQL 17+ Reviewed By Best Latest Apps

Order the steps

Order how one trace is built across two services.

  • The gateway starts a trace and a root span
  • The backend assembles the tree by parent ids
  • It calls Orders with a traceparent header
  • Orders starts a child span and one for its DB query
  • Each service exports its spans to the collector

Choose an answer, then open Show answer below to check it.

Show answer

Answer: A C D E B

  1. The gateway starts a trace and a root span It creates the trace id.
  2. It calls Orders with a traceparent header Context travels with the request.
  3. Orders starts a child span and one for its DB query Same trace id, new span ids.
  4. Each service exports its spans to the collector Asynchronously.
  5. The backend assembles the tree by parent ids One waterfall for the request.

30-second answer

Each request gets a trace id; each unit of work (an HTTP handler, a database query, a call to another service) is a span with a start, duration, parent and attributes. Services pass the trace context along in headers (W3C traceparent), so the backend can assemble the whole tree. A trace shows where time went across services for one request, which metrics (aggregates) and logs (separate lines) can't show on their own.

Practise saying it · 30 s. No recording, just a timer

Explain tracing.

Say your answer out loud, then check which of these points you covered:

  • Trace and spans
  • traceparent propagation
  • Where time went
  • OpenTelemetry
  • Sampling

Deep dive

OpenTelemetry is the vendor-neutral standard for SDKs and the wire format.

Sample: head-based (decide at the start) is cheap; tail-based keeps slow and failed traces.

Propagate context through queues by putting it in message headers.

Link logs to traces with the trace id.

Common mistakes

  • Dropping context at a queue or thread boundary.
  • Tracing at 100% in high-traffic production without a budget.
  • Spans with no useful attributes.

Senior take & follow-ups

Trace, span, propagation via traceparent, what it uniquely shows, sampling.

Follow-up questions

Think of your answer first, then open the hint.

  1. Head vs tail sampling?

    Show hint

    Head is decided up front; tail keeps interesting traces after they finish.

  2. How does context cross Kafka?

    Show hint

    In message headers.

Suggest a fix if something here is wrong or out of date.