# What structural signals indicate span-to-signal correlation collapse in GenAI observability pipelines **Date of Record:** 2026 November 20 **Scope:** Applies to agent frameworks that emit OpenTelemetry-style spans enriched with token accounting and asynchronous safety-classifier verdicts, where span identity is correlated to those signals via trace/span IDs at collection time. Does not apply to synchronous in-process instrumentation where cost and safety are computed inline before the span closes. ## Core Distinction There are two ways a "cost" or "safety" attribute can attach to an agent span, and they fail differently. **Inline attribution** computes tokens and safety verdicts inside the emitting process, before `span.end()`, so the value is part of the span payload and travels with it atomically. **Deferred correlation** ships the span on one channel and the cost/safety signals on another (a billing meter, a moderation queue, a streaming classifier), then joins them downstream on `(trace_id, span_id)`. The non-obvious invariant is this: **deferred correlation is only sound if the join key is both unique per emission and stable across the signal's full lifecycle.** GenAI spans violate this in a way ordinary RPC spans do not, because a single logical agent step routinely emits *multiple* LLM calls (retries, tool-augmented re-prompts, self-consistency sampling), each of which can produce its own cost record and its own safety verdict, while the framework assigns them a shared or reused span identity. The structural signal of collapse is not a missing value—it is a *plausible but wrong* value: a span that reports a cost or a safety verdict that belongs to a sibling call. ## What Was Observed A tool-using agent step emitted one parent span `agent.step` and, under a retry-on-timeout policy, three child LLM calls within it. The instrumentation reused the parent span's `span_id` as the correlation key for all three calls' token meters (a common shortcut when the SDK does not surface per-call span IDs). Downstream, the cost aggregator summed three records against one span ID and the safety pipeline attached the verdict of the *second* (a benign re-prompt) call because it arrived last and overwrote the first. The observable structural signatures, in order of reliability: 1. **Cardinality mismatch between emission and join.** The LLM gateway logged 3 completions for the trace; the observability store showed 1 span carrying a summed cost and 1 safety verdict. A `count(distinct span_id)` on the cost stream that is strictly less than the completion count on the gateway stream is the primary indicator. 2. **Last-writer-wins on safety attributes.** Safety verdicts carry an arrival timestamp; when two verdicts share a join key, the stored one is the later arrival, not the higher-severity or the first. The signature is a span whose `safety.verdict` timestamp postdates the span's own `end_time`—physically impossible for inline attribution, diagnostic of deferred overwrite. 3. **Cost that fails a conservation check.** Sum of per-span costs across a trace should equal the trace's total metered tokens. When per-span cost is inflated by fan-in (three calls summed onto one span) while another sibling span reports zero, the *trace total* is correct but the *per-span distribution* is corrupted—so any per-step budget enforcement reads the wrong step. 4. **Orphaned verdicts on retried spans.** A retry that mints a fresh `span_id` leaves the prior attempt's safety verdict pointing at a span that was discarded, so a flagged generation has no surviving span to attach to. ## Condition of Validity The correlation is valid only when all three hold: - **Emission uniqueness:** each LLM call that produces a distinct cost or safety record has a distinct, non-reused `span_id` for the duration of that record's lifecycle. - **Join-key immutability:** the key written into the cost/safety stream at emission equals the key stored in the span store; no downstream re-keying (e.g., trace-level rollup) happens before the join. - **Arrival-order independence:** the join result does not depend on which signal arrives first, because safety classifiers are asynchronous and may lag the span by seconds to minutes. When any of these is violated, the pipeline does not fail loudly—it produces internally consistent-looking telemetry that misattributes cost and safety to the wrong agent action. ## Decision Boundary The boundary is between **fan-in correlation** (many calls → one span key) and **fan-out correlation** (one call → many signal records). Fan-in is safe only for *aggregate* consumers (trace-level cost dashboards) and unsafe for *per-action* consumers (per-step budget gates, per-step safety blocking). Fan-out is safe only if the join is idempotent and severity-ordered rather than arrival-ordered. Concretely: if your safety gate blocks an agent action based on the verdict correlated to a span, you are on the unsafe side of the boundary whenever retries or multi-call steps exist. The correct guardrail is to require a **1:1 call-to-span mapping at emission** (mint a child span per LLM call, carry `gen_ai.request.id` as the true join key), and to treat any span whose cost/safety cardinality exceeds 1 as *unresolved* rather than summing or overwriting. Severity must be resolved by `max(severity)` over the record set, never by arrival time. ## Operational Effect Downstream, the collapse manifests as two coupled failures. First, **budget gates fire on the wrong step**: a step that made one cheap call inherits a sibling's expensive retry cost and is throttled, while the actually-expensive step passes. Second, **safety blocking becomes non-deterministic under replay**: because the stored verdict depends on arrival order, replaying the same trace through the pipeline can attach a different verdict, so an auditor cannot reproduce why an action was allowed or blocked. The continuity invariant to enforce is that **the correlated (cost, safety) tuple for a span must be a pure function of the span's own call set, independent of arrival order and retry history.** Violations should be surfaced as data-quality faults, not silently aggregated. ```python from dataclasses import dataclass, field from typing import Optional class CorrelationCollapseError(RuntimeError): """Raised when span-to-signal correlation cannot be resolved soundly.""" @dataclass class SignalRecord: span_id: str kind: str # "cost" | "safety" value: float arrival_ts: float # monotonic arrival time at the collector @dataclass class Span: span_id: str end_time: float records: list = field(default_factory=list) def resolve_span_signals(span: Span, records: list) -> dict: """Join cost/safety records to a span with a soundness guard. Enforces: 1:1 call-to-span mapping, arrival-order independence, and severity-max (not last-writer-wins) for safety verdicts. """ attached = [r for r in records if r.span_id == span.span_id] cost_records = [r for r in attached if r.kind == "cost"] safety_records = [r for r in attached if r.kind == "safety"] # Fan-in on cost: multiple distinct calls collapsed onto one span key. if len(cost_records) > 1: raise CorrelationCollapseError( f"span {span.span_id} carries {len(cost_records)} cost records; " "fan-in correlation is unsound for per-action consumers" ) # Safety verdict timestamped after the span closed => deferred overwrite. for r in safety_records: if r.arrival_ts > span.end_time and len(safety_records) > 1: raise CorrelationCollapseError( f"span {span.span_id} has {len(safety_records)} safety verdicts " "with post-close arrivals; arrival-order-dependent join" ) resolved = {} if cost_records: resolved["cost"] = cost_records[0].value if safety_records: # Severity is resolved by max, never by arrival time. resolved["safety"] = max(r.value for r in safety_records) return resolved ```