Skip to content

Lesson 1 of 13 · 14m

What a Span Actually Carries

The W3C trace context on the wire, span kinds that survive queues, and why a correlation ID in your logs isn't a trace.

Here is what happens when a request hits your edge service: a 128-bit trace ID gets minted (or read from the incoming traceparent header), a root span is opened with a start timestamp, and every downstream hop re-uses that trace ID with its own 64-bit span ID. The trace is the request's family tree. Each span records an operation's name, start and end, its parent's span ID, a kind, a status, and a bag of attributes. That is the whole model. Everything else — Jaeger UI waterfalls, exemplars, tail sampling — is downstream of those fields being correct.

The wire format is the W3C Trace Context spec, a full W3C Recommendation since November 23, 2021. One header:

traceparent: 00-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-01

Version 00, then the 32-hex-digit trace ID, then the 16-hex-digit parent (span) ID, then flags — 01 means sampled. A second header, tracestate, carries vendor-specific entries as an ordered, comma-separated list capped at 32 entries. If you are inventing X-Correlation-ID or X-Request-ID headers in 2026, you are rebuilding a solved problem with a worse spec.

Logs with a request ID are not tracing

The mental model to kill here is "tracing is just logs that share a correlation ID." Logs are points; spans are intervals with a parent pointer. A span knows its own duration and where it sits in the causality tree, so a backend can reconstruct "this request spent 212 ms inside POST /checkout, of which 190 ms was the INSERT on order_items" without anyone correlating timestamps by eye. Instrumentation libraries do the timing for you; you write the span boundaries.

Span kind is the field everyone leaves as internal and shouldn't. It takes five values: server, client, internal, producer, consumer. The producer/consumer pair exists because message queues break the nesting assumption. A consumer span's parent is the producing span — which ran in a different process, maybe hours ago — not the HTTP handler that happened to poll the queue. Get this wrong and your Kafka-backed service shows every message as a child of the poller loop, which makes the waterfall useless. When one consumer batch fan-in aggregates many producers, use span links: one span, many linked trace parents.

Context has to survive your async boundaries

Inside a process, OpenTelemetry keeps the current SpanContext in an implicit Context object — a scoped token, not magic. The bugs appear where the scope doesn't: work handed to a thread pool, a goroutine, a CompletableFuture stage, a setImmediate. If the trace looks like it restarts mid-request, someone dropped the context across a boundary; most SDKs ship wrappers (Context.wrap(), context.propagate helpers) precisely because this is the common break.

Across the wire, context lives in headers on every hop: Kafka message headers, SQS message attributes, gRPC metadata. Baggage — the separate W3C Baggage spec — is for small cross-cutting keys like tenant_id, and it propagates to everything downstream. Never put PII, emails, or tokens in baggage; it rides every outgoing request and lands in backends you didn't intend.

Land on the practice

  • Propagate with the standard W3C propagators; extract traceparent at your edge, inject it on every outbound call, and mark the sampled flag honestly.
  • Set span.set_status(StatusCode.ERROR) from the real failure path, not the HTTP code of a wrapper that swallowed the exception.
  • Name server spans from the route template (POST /users/:id), never the raw path — the reason becomes a whole lesson later.
  • Use producer/consumer kinds on queue hops, and span links on batch consumers.

OpenTelemetry itself — the merger of OpenTracing and OpenCensus, formed in May 2019 — is what made this model boring enough to be universal. Boring is the goal. The trace model should be the least interesting part of your system.

Was this lesson helpful?

Sign in to rate

Keep reading

Related articles from the SudoSecurity blog.