liveBook · Manning

Correlation id

As explained in Secure APIs

A trace ID is an identifier shared by telemetry records belonging to the same request execution or distributed processing path.

A trace ID is a shared identifier for telemetry records belonging to one request. It links the spans created as that request moves through processing steps. section 11.3 section 11.2

Without a trace ID, separate logs are difficult to connect to a request or to one another. With it, you can reconstruct the request’s sequence, follow failures across services, and investigate the input that caused an upstream error. section 11.2 section 11.3

Following a request through OpenTelemetry

A GET /books request produces spans for response processing and request details. Each span contains the same context.trace_id, such as 0x3b0367766ff238a8f6d7bdc8dc4b375b, while each has its own span ID. Searching logs for that trace ID gathers the records into one request story. section 11.3

Application code can add a custom span with OpenTelemetry’s start_as_current_span(). The span inherits the current trace context, so attributes such as user.sub and cart details remain connected to the request’s other spans. section 11.4

Figure 11.6 Adding traces to our logs allows us to correlate them and determine the original input that caused an error in an upstream service.
figure

Use the figure to see how adding traces connects logs across services and reveals the original input behind an upstream error. section 11.2

How Secure APIs covers it

How deep it goes
Explains request and distributed-service correlation, then demonstrates shared context in OpenTelemetry span logs and custom spans.
Examples
Uses GET /books span logs, distributed quote processing, and a POST /carts custom span with user and cart attributes.
What it assumes
Assumes familiarity with API requests while introducing logs, traces, spans, and their correlation from basic operational problems.
What you can do after
Diagnose and debug requests with OpenTelemetry by searching a trace ID and creating correlated custom spans.
How it connects
Connects logs, traces, spans, distributed systems, observability, and OpenTelemetry instrumentation.

Also explained in

Compare how 5 books explain correlation id →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Secure APIs. The section links point to the parts of the book it draws on.