# What structural signals indicate tail-sampling collapse in high-cardinality agent traces under adaptive observability policies **Date of Record:** 2026 November 30 **Scope:** Applies to distributed tracing pipelines that apply adaptive or tail-based sampling to LLM agent execution traces where span attributes include unbounded-cardinality dimensions (tool-call arguments, retrieved chunk IDs, prompt hashes, per-step token counts). Does not apply to head-based fixed-rate sampling of stateless request/response LLM calls, nor to metric-only observability that does not preserve span-level causal structure. ## Core Distinction The naive mental model treats sampling as a stationary Bernoulli process over traces: each trace is kept with probability *p*, and rare failure modes are recovered by lowering *p*. This model is wrong for agent traces because the failure modes we most need to observe—error-compounding loops, mid-task checkpoint divergence, tool-call retry storms—are *structurally correlated with the attributes that drive cardinality*. The sampler's own bookkeeping (per-attribute cardinality estimates, per-service error rates, reservoir occupancy) becomes a stateful feedback loop that preferentially evicts the exact traces that evidence the failure. The distinction that matters: **statistical sampling error** (unbiased, reducible by volume) versus **structural sampling bias** (a deterministic skew introduced by the sampler's admission policy interacting with high-cardinality span attributes). The latter is not visible in standard sampling-error metrics because the traces it drops are not a random subset—they are the ones whose attribute distribution the sampler has already learned to suppress. ## What Was Observed Across three agent fleets instrumented with OpenTelemetry-style span emission (span per LLM call, span per tool invocation, span per checkpoint write), the following trace was reconstructed from a tail-sampling gateway configured with a per-attribute cardinality budget of 10,000 distinct values per dimension per minute and an error-priority rule ("always keep traces containing a span with `status=ERROR`"). A retrieval-augmented agent entered a tool-call retry loop. The trigger condition was a stale index: the retriever returned chunk IDs from a previous index generation, the downstream validator rejected them with a soft `status=UNSET` warning (not `ERROR`), and the orchestrator retried with the same query. Each retry emitted a new span with a fresh `chunk_id` attribute. Within ~40 seconds the `chunk_id` dimension exhausted its 10,000-value budget. The sampler's admission policy then began *collapsing* the dimension: new distinct values in that dimension were mapped to an overflow bucket and, critically, traces whose span set was dominated by overflow-bucketed attributes were down-weighted to protect the budget. The retry-loop trace—the single most diagnostically valuable trace in the window—was dropped at a keep-probability of 0.03, while 30,000 healthy single-shot traces with low-cardinality attributes were retained at 0.9. The failure was invisible in aggregate: error-rate dashboards showed nothing (the loop never emitted `ERROR`), p99 latency was within bounds, and the sampler's own "traces sampled" counter was healthy. The signal that *did* exist was structural, not statistical: the entropy of the `chunk_id` dimension spiked 40x in 40 seconds, the ratio of distinct-to-total values for that dimension crossed 0.7, and the retention-weighted error rate for the overflow bucket diverged from the retention-weighted error rate for the head of the distribution by more than an order of magnitude. ## Condition of Validity The collapse is bounded and predictable under the following invariant, which must hold for any adaptive sampler over agent traces: > **Retention independence invariant:** For any span attribute dimension *D* used in the admission decision, the keep-probability of a trace must be conditionally independent of the *cardinality state* of *D* at admission time, given the trace's diagnostic class (error, slow, retry-loop, normal). When this invariant is violated—i.e., when a trace's keep-probability is a function of how many distinct values *D* has recently seen—the sampler is no longer sampling; it is *censoring* along an axis correlated with the failure modes of interest. The invariant is violated by any of: (a) cardinality-budget-driven down-weighting applied to traces whose attributes are the budget consumers; (b) priority rules keyed on `status=ERROR` when agent failure modes emit `UNSET`/`WARN`; (c) reservoir replacement policies that evict on attribute novelty rather than diagnostic class. The invariant *holds* and the sampler is safe only when the cardinality budget is enforced by **attribute redaction or hashing at the span level before admission** (so the admission decision sees a bounded-cardinality projection), never by **trace-level down-weighting after the fact**. The distinction is architectural: redaction changes what the sampler sees; down-weighting changes what the sampler keeps, and the two have opposite effects on bias. ## Decision Boundary The operational decision is whether a given high-cardinality dimension should be handled by *pre-admission projection* or *post-admission retention weighting*. The boundary is determined by whether the dimension is *diagnostic* (its values carry information about failure mode) or *incidental* (its values are identifiers with no failure-mode correlation). - **Incidental dimensions** (request IDs, session tokens, raw prompt hashes): project or hash at the span level before the sampler. Cardinality budget is enforced on the projection. No retention weighting. The invariant is trivially satisfied. - **Diagnostic dimensions** (tool name, retry count, validator verdict, checkpoint generation, chunk source): must NOT be subject to cardinality budgets at all. If volume is a problem, aggregate to a bounded derived attribute (e.g., `retry_bucket = min(retry_count, 5)`) at span emission, and preserve the raw value only in a separately-sampled "forensic" stream with its own fixed-rate policy and no adaptive feedback. - **Ambiguous dimensions** (free-text tool arguments that sometimes contain error strings): treat as diagnostic until proven incidental; the cost of misclassifying diagnostic-as-incidental is silent censoring of exactly the traces you need. The boundary is crossed—and the sampler is in collapse territory—when any diagnostic dimension is placed under an adaptive cardinality budget whose enforcement mechanism is trace-level down-weighting rather than span-level projection. ## Operational Effect The downstream effect is a specific and dangerous form of observability debt: the sampler's feedback loop converges to a *stable under-observation* of the failure modes it was built to catch. Because the loop is self-reinforcing (high-cardinality failure traces are dropped → the dimension's observed cardinality stays low → the budget is not exceeded → the policy appears healthy), the collapse does not self-correct and is not surfaced by standard sampler health metrics. It is detectable only by monitoring the *structural* signals: distinct-to-total ratio per diagnostic dimension, retention-weighted diagnostic-class divergence between overflow and head buckets, and the ratio of `UNSET`/`WARN` spans to `ERROR` spans in the retained set (a ratio that drifts upward under collapse because the retained set is enriched for healthy traces that never warn). The guardrail is the retention independence invariant enforced structurally: diagnostic dimensions never enter the admission decision's cardinality budget; incidental dimensions are projected before admission; and a canary stream of synthetic retry-loop traces is injected at a known rate and its retention rate is asserted to equal the configured rate within tolerance. A canary retention rate below tolerance is the definitive signal that the sampler has begun censoring along the diagnostic axis, and it is the only signal that fires before the failure mode has already been lost. ```python from dataclasses import dataclass, field from typing import Dict class SamplingCollapseError(RuntimeError): """Raised when a tail-sampler's retention is correlated with diagnostic cardinality.""" pass @dataclass class DimensionState: distinct_values: int = 0 total_values: int = 0 is_diagnostic: bool = False @property def distinct_ratio(self) -> float: return self.distinct_values / max(self.total_values, 1) @dataclass class SamplerAudit: dimensions: Dict[str, DimensionState] = field(default_factory=dict) canary_configured_rate: float = 0.10 canary_observed_rate: float = 0.10 canary_tolerance: float = 0.02 def assert_retention_independence(self) -> None: # 1. Diagnostic dimensions must never be under a cardinality budget. for name, dim in self.dimensions.items(): if dim.is_diagnostic and dim.distinct_ratio > 0.7: raise SamplingCollapseError( f"diagnostic dimension '{name}' at distinct_ratio=" f"{dim.distinct_ratio:.2f}; budget-driven projection required, " f"trace-level down-weighting forbidden by retention independence invariant" ) # 2. Canary stream must be retained at configured rate within tolerance. drift = abs(self.canary_observed_rate - self.canary_configured_rate) if drift > self.canary_tolerance: raise SamplingCollapseError( f"canary retention drift {drift:.3f} exceeds tolerance " f"{self.canary_tolerance:.3f}; sampler is censoring along diagnostic axis " f"(configured={self.canary_configured_rate:.3f}, " f"observed={self.canary_observed_rate:.3f})" ) def audit_sampler(state: SamplerAudit) -> None: state.assert_retention_independence() ```