WEBORDERSPAYMENTSDATABASELOG STORE0 lines1log = logging.getLogger("pay")2ctx = {"trace_id": tid}3log.info("charge start", extra=ctx)4log.debug("card ok", extra=ctx)5log.warning("db slow", extra=ctx)TRACE 4bf92f35…weborderspaymentsdb0500 ms1000 ms1250 ms1200 ms1120 ms950 ms
Back: four services on one request lane; middle: the log storeFront: the payments code, and the trace view (a span waterfall)Movers: the request envelope and log lines flying to the storeOne checkout request crosses four services: web, orders, payments and the database. Each program writes log lines (records of events) that an agent ships to one log store; levels decide which lines are kept. One trace id travels with the request in the traceparent header, and each service records a span, so the trace view draws a waterfall in which the database query is the slow part. Searching the logs for the trace id finds the line that explains it. The checkout, its four services and its timings are an illustration, not a measurement. The arithmetic holds: the spans nest, and their self times add up to the whole 1,250 ms.

The question

  1. A shopper clicks Pay. The request crosses four services: web, orders, payments and the database. Monitoring shows checkout got slow, but not why. Logs and traces answer where the time went and what went wrong.

Logs

Traces

Cost

What happens

;; step 1/10 · request
web → orders → payments → db, and back
monitoring: checkout is slow (a number)
logs:   what happened inside each program
traces: where the time went, end to end

The checkout, its four services and its timings are an illustration, not a measurement. The arithmetic holds: the spans nest, and their self times add up to the whole 1,250 ms. In the W3C Trace Context header the trace id is 16 bytes (32 hex digits) and the parent id 8 bytes (16 hex digits); the last field holds flags, where 01 means sampled. The trace id used here is the example from the specification.