The Trace: Assembly, and Why Nobody Ever Builds the Tree

Span vs Trace, Crisply

A span is one row: one operation, in one process, with a start and an end. A trace is the set of every span sharing one trace_id. They are linked by exactly two fields and nothing else:

  1. Group by trace_id. Every span the request touched carries the same 16 bytes, propagated across every process boundary by the traceparent header (see Context Propagation). This is the only thing that makes them one trace.

  2. Join child → parent by parent_span_id. Each span names its parent's span_id. Edges are stored on the child, which is why the graph can be assembled incrementally and out of order.

  3. The root is the span with no parent. Empty parent_span_id. If two spans in a trace both have no parent, you have two roots and the UI will show two trees. If none do, you have an orphaned fragment.

That is the whole data model. There is no trace object, no manifest, no span count, no "expected children," and no terminator. The trace is a GROUP BY, executed by the backend, over rows that were written by dozens of machines that never spoke to each other.

What the trace means: one request, seven spans, five processes
What the trace means: one request, seven spans, five processes
What the collector actually receives — ordered by arrival time

  t+0.000s  span e7  postgres CLIENT   parent b4   trace T
  t+0.004s  span b4  cart SERVER       parent b2   trace T
  t+0.006s  span d6  redis CLIENT      parent c5   trace T
  t+0.011s  span b2  cart CLIENT       parent a1   trace T
  t+0.019s  span c5  pricing SERVER    parent c3   trace T
  t+0.020s  span c3  pricing CLIENT    parent a1   trace T
  t+0.031s  span a1  gateway SERVER    parent --   trace T   <-- root
  t+9.412s  span f8  email PRODUCER    parent a1   trace T   <-- ?!

  Leaves first, root near-last, and one span nine seconds later from
  a worker whose BatchSpanProcessor had not yet hit its 5s timer.
  Nothing in this stream says "that was all of them."

There is no completion signal. A backend that must decide "is this trace done?" can only start a timer and hope. That single missing bit is what makes tail sampling (see Tail-Based Sampling) expensive: to judge a trace you must hold all of it in RAM for a fixed wait, so your buffer is span rate × span size × wait and the physics stop you there.

You can see the heuristic in the source. The OTel Collector's tail_sampling processor exposes decision_wait (default 30s) and num_traces (default 50000 traces held in memory) — and, revealingly, a knob that implements the shortcut from the Span part and ships turned off: decision_wait_after_root_received, default 0s.

What it does. By default a trace gets exactly one deadline, anchored on the arrival of its first span: decide at first_span + decision_wait. That timer has to be sized for your worst straggler, so every ordinary trace — the overwhelming majority, finished milliseconds after the root — sits in RAM for the full 30 s anyway. Set the knob and the processor watches for a span with an empty parent_span_id, recognises it as the root, and opens a second, earlier deadline. The decision fires at whichever comes first:

default — one deadline, anchored on the FIRST span to arrive

  ├─ first span ·············· root ·················┤ DECIDE
  t0                          t0+2.1s                t0+30.0s
                                                     ^ 27.9s of pure waiting, per trace,
                                                       multiplied by num_traces in RAM

decision_wait_after_root_received: 5s — a second, earlier deadline

  ├─ first span ·············· root ·····┤ DECIDE
  t0                          t0+2.1s    t0+7.1s
                                         ^ min(t0+30.0s, root+5.0s)

  ... and span f8, the email PRODUCER, still lands at t0+9.4s —
      2.3s AFTER the decision was made and the trace was released.

Why it ships disabled. Note what the knob is not: it is not decide_when_root_arrives. It still makes you name a grace period, because the root's arrival is an acceleration hint, not a declaration that the trace is complete — exactly the point made in the Span part. You are choosing how long to keep waiting for work the request never waited for itself. Set the grace shorter than your async tail and those spans are simply not in the trace when the policies run: a latency policy sees a truncated trace, an error policy misses an error that happened in the consumer, and the sampled trace lands in storage missing its most interesting branch.

And the late span still has to go somewhere. When it arrives, its trace entry is gone from the pending map. The processor looks it up in the decision cache — sampled_cache_size / non_sampled_cache_size, both default 0, meaning inactive — and if it hits, the span inherits the verdict the trace already got. If the cache is off, or the LRU has since evicted the entry, that span is treated as a brand-new trace and evaluated on its own: one orphan span, sampled or dropped independently of the twenty spans it belongs to. So the practical rule is a pair, not a single setting — if you enable decision_wait_after_root_received, enable the decision caches too, and size the grace against how long your slowest fire-and-forget consumer actually takes, not against how fast you would like decisions to be.

Storage backends dodge the whole problem: Jaeger and Tempo write spans as they arrive and assemble the trace at query time, so they never have to decide it is finished. Only a component that must make an irreversible choice about a whole trace — a tail sampler — is forced to guess, which is why the Tail-Based Sampling part's cost model is really a restatement of this one missing bit.

Orphan Spans

An orphan is a span whose parent_span_id names a span the backend never receives. Backends do not error on this — Jaeger renders a partial tree rooted at the orphan, and its own adjuster logs the giveaway warning invalid parent span IDs=[...]; skipping clock skew adjustment. Causes, roughly in order of how often they bite:

CauseShape of the damage
Parent's process was SIGKILLed before its span ended (see The Span)A subtree floats. Common on OOM-kill and on scale-down.
Parent was dropped by the collector's memory_limiter, or by a full sending_queueRandom spans vanish under load — i.e. exactly during the incident (see The Collector).
Parent is still open because the request hasn't finished, and you queried earlyTransient: refresh in 30 seconds and the parent appears. Deeply confusing the first time.
Mixed sampling configs across servicesOne service head-samples at a different rate and ignores the inherited decision (see Head-Based Sampling), so its spans are missing from otherwise-kept traces.
The parent is in a service that isn't instrumentedThe nasty one — see below.

The uninstrumented hop deserves its own treatment, because its two variants fail in opposite ways and only one of them is honest. Service B sits between A and C and emits no spans:

An uninstrumented middle hop: one variant loses the trace, the other silently falsifies it
An uninstrumented middle hop: one variant loses the trace, the other silently falsifies it

The propagating case is worse precisely because it is plausible. You get a connected, complete-looking trace in which a hop has been deleted from existence: B is absent from the service dependency graph, and its entire latency is attributed to the CLIENT/SERVER gap between A and C — which you will read, correctly by the rules of the Span part, as "network and queueing." Sidecars and API gateways with tracing disabled but header pass-through enabled produce this exact shape. The non-propagating case merely loses you the connection: two traces, both internally truthful, and a visibly missing edge that eventually prompts someone to ask why.

Clock Skew

Every span's start and end are read off the clock of whatever machine ran the code (see The Span), and a trace puts spans from many machines on one axis. Nothing anywhere checks that those machines agree about the time. A fleet on chrony/ntpd usually agrees to a few milliseconds — but that is an operational habit, not a guarantee, and a VM live-migration, a bad NTP peer, or a smeared leap second puts a host tens of milliseconds to seconds out.

When that happens you get a trace that is physically impossible: a child that starts before its parent — the callee answering before the caller asked.

Host A's clock is right. Host B's clock is 30ms BEHIND.
Each machine stamps its own span, honestly, off its own clock.

what really happened            what each host wrote down
─────────────────────           ─────────────────────────
A calls at    100ms             A: CLIENT  start 100  end 160
B works 110 → 150               B: SERVER  start  80  end 120   (110-30, 150-30)
A gets reply  160ms

rendered on one shared axis:

          80ms     100ms    120ms    140ms    160ms
          |--------|--------|--------|--------|
A  CLIENT          [==========================]
B  SERVER [=================]
          ^ the child starts 20ms BEFORE its parent

The one thing to hold onto: the durations are still correct — it is only the positions that are wrong. B's 40ms is a subtraction of two readings from B's own clock, so the skew cancels out. The 100ms and the 80ms, though, came from two different clocks, and comparing them is the mistake. Same-machine arithmetic survives skew; cross-machine arithmetic does not. That is why the Span part's CLIENT-minus-SERVER gap is trustworthy (it is a difference of two durations) while where that gap sits is not.

Jaeger ships an adjuster that tries to repair the picture by sliding the child until it fits inside its parent. Its guess: the parent bar is longer than the child bar, the leftover is network time, and — assume — half of it was the request going out and half was the reply coming back. So centre the child in the parent. On our example: leftover is 60 − 40 = 20ms, half is 10ms, so slide the child to start 10ms after the parent — from 80 to 110, exactly right.

The algorithm from model/adjuster/clockskew.go, in order:

  1. Child already fits inside the parent? Delta is 0 — nothing to fix, no warning. Most spans land here.

  2. Child longer than the parent? Physically impossible for a real nested call. Adjust only if the child also starts before the parent, and then just line up the starts: delta = parent.StartTime − child.StartTime.

  3. Otherwise, split the difference. Assume the network took the same time in both directions: latency = (parentDuration − childDuration) / 2, then delta = parent.StartTime + latency − child.StartTime. This is the centring move from the example above — and the assumption that causes the trap below.

  4. Push the delta down the subtree, recomputing whenever the hostKey changes. Moved spans get the warning This span's timestamps were adjusted by <delta>; ones it refuses to move get max clock skew adjustment delta of <max> exceeded; not applying calculated delta of <delta>.

Trace-Shape Vocabulary (you need this for Reading a Trace)

Four words that come up every time someone reads a trace. Each one has a plain meaning and one specific way people misread it.

TermIn one sentenceThe common misread
Waterfall The bar chart view: one horizontal bar per span, all on the same time axis, indented by depth. It shows how long and what overlapped — nothing else. Two bars sitting next to each other is a drawing decision, not proof that one caused the other.
Critical path The chain of spans where making one faster makes the whole request faster. When a parent fires several calls in parallel, only the slowest one counts. Speeding up the others saves exactly zero. And the longest bar on screen is usually just the root span, which tells you nothing.
Serial vs. parallel children Did these calls run one after another, or all at once? Answer it by comparing start times, not by looking at the layout. Overlapping intervals = parallel. Each child starting where the last one ended = serial. Since UIs stack siblings by start time, ten parallel calls draw the same staircase as ten serial ones.
The gap Time inside the parent that no child span accounts for — the parent's duration minus the union of its children's intervals. Use the union, never the sum: adding up overlapping children double-counts and shrinks the gap you're hunting for. A gap is real work with no span on it — CPU, GC, lock waits, pool waits, or a call nobody instrumented.

Here is all four at once. Read the numbers, then the notes underneath:

                  0ms        80ms       160ms       240ms      320ms
                  |-----------|-----------|-----------|-----------|
a1 gateway SRV    [========================================================]  312.4ms
 b2 cart CLI        [========]                                                 48.1ms
  b4 cart SRV        [=====]                                                   31.7ms
 c3 pricing CLI     [===========]                                              62.9ms
  c5 pricing SRV     [=======]                                                 44.2ms
   d6 redis CLI           [=]                                                   6.8ms
 (no span here)                 <------------ gap 249.0ms ----------->
  1. Parallel, not serial. b2 and c3 overlap in time, so cart and pricing ran at the same time — even though the UI stacks them like steps.

  2. Union, not sum. Together they cover [11.9, 75.3] = 63.4ms of wall clock. Gap = 312.4 − 63.4 = 249.0ms. Adding them instead (48.1 + 62.9 = 111.0) would report a 201.4ms gap and quietly hide 47.6ms of overlap.

  3. Only the slowest child is on the critical path. That's c3. Make cart infinitely fast and the request finishes at the same time.

  4. The answer isn't in the trace. 79.7% of this request sits in a gap with no span in it. That is the finding — and tracing can't tell you what's inside it (see Where Tracing Stops).

  • Guarantees: Every span that arrives can be attached to its trace by trace_id and to its parent by parent_span_id, incrementally, in any arrival order, with no coordination between the emitting processes.
  • Does not guarantee: That the trace is complete, that the backend can tell whether it is complete, that a parent exists for every child, or that timestamps from two hosts are comparable. A rendered trace is a best-effort reconstruction, and it can be confidently wrong without any component reporting an error.