# Why does an instance's SLO survive trace sampling while its error budget silently dies? The Tail-Sampling Denominator Collapse in GenAI span metrics **Date of Record:** 2026 November 27 **Scope:** Applies to autonomous agents and LLM instances whose SLOs (success rate, tool-call error rate, latency-to-first-token) are computed from OpenTelemetry-style GenAI spans that pass through a tail-based sampler before reaching the metrics backend. Does not apply to head-sampled pipelines that sample uniformly before span emission, nor to fully unsampled (100%) capture. ## Core Distinction The failure is not "sampling loses data." Everyone knows sampling loses data. The non-obvious invariant is this: **a tail-based sampler that makes keep/drop decisions per-trace, but where the error budget is aggregated per-span, silently biases the denominator.** A tail sampler is designed to keep *interesting* traces—errors, high latency, anomalies. That is exactly the population that dominates the numerator of an error-rate SLO. Meanwhile, the healthy spans that constitute the denominator get dropped at a much higher rate. The result is a ratio whose numerator is oversampled and whose denominator is undersampled, and the two biases do not cancel. An instance can report a *worse* error rate than reality (false alarm, wasted failover) or—more dangerously—a *stable-looking* error rate that masks a real regression because the sampler's keep-policy and the SLO's aggregation unit disagree about what a "unit" is. The distinction that matters: **sampling is a property of the trace; SLOs are a property of the span population.** Any system that computes one from the other without reweighting is measuring the sampler, not the agent. ## What Was Observed A production agent fleet ran a GenAI observability pipeline: each LLM call, tool invocation, and retry emitted a span tagged `gen_ai.operation.name`, `gen_ai.usage.input_tokens`, and a status code. Spans were batched into traces by `trace_id` and sent through a tail sampler configured with a keep-policy: - Keep 100% of traces containing any span with `status = ERROR`. - Keep 100% of traces with p99 latency > 8s. - Keep 5% of all other traces (probabilistic tail). The SLO dashboard computed `error_rate = errored_spans / total_spans` directly over the surviving spans. For three weeks the fleet's `tool_execution` SLO sat at 0.4% error—comfortably inside a 1% budget. Then a tool integration (a payment lookup API) began returning `429 Too Many Requests` on ~6% of calls. The agent's retry logic absorbed most of them, but the *first* attempt span still carried `status = ERROR` before the retry span succeeded. Because any errored span forced the whole trace to be kept, those traces entered the backend at 100%. The healthy traces—the ones with no error and normal latency—continued to be dropped at 95%. The measured error rate moved from 0.4% to 0.9%. It looked like a mild blip, still under budget. The *true* first-attempt error rate had risen to roughly 6.2%. The dashboard was structurally incapable of showing it: the denominator had collapsed to almost exclusively error-free traces that happened to be in the 5% sample, while every error trace was guaranteed present. The SLO was measuring the ratio of (100%-kept errors) to (5%-kept successes), which is not the error rate; it is the error rate multiplied by an unknown, policy-dependent factor. The instance never tripped its error-budget burn alert. It tripped a downstream *latency* alert two weeks later when retry storms saturated a connection pool—the actual consequence of the 6% failure rate the SLO had been blind to. ## Condition of Validity The invariant holds—and the SLO is trustworthy—only when the aggregation unit matches the sampling unit, or when the sampler emits an explicit inclusion probability that the metric layer uses to reweight. Concretely, a span-derived SLO is valid if and only if at least one of these is true: 1. **Uniform sampling:** every span (or trace) has the same inclusion probability `p`, so `errored/total` is an unbiased estimator of the true rate up to variance `~1/(p·N)`. Tail sampling violates this by construction. 2. **Per-trace aggregation with trace-level reweighting:** the SLO counts *traces*, not spans, and each kept trace is weighted by `1/p_trace`, where `p_trace` is the probability the sampler would have kept that trace under its policy. This requires the sampler to *record* `p_trace` as a span attribute (e.g., `sampling.probability`) at decision time. 3. **Separate always-on counters:** the error numerator and the denominator come from independent, unsampled metric counters emitted at span *creation* time (before the sampler), and the sampled traces are used only for exemplars and debugging—never for the ratio. The failure occurs precisely in the gap: tail sampler configured for *debugging utility* (keep the interesting stuff), SLO computed over *whatever survives*. The two policies were never reconciled, and nothing in the pipeline flagged the mismatch because both halves were individually correct. ## Decision Boundary The operational decision is where to place the trust boundary for the SLO number: - If the SLO drives **automated remediation** (failover, instance drain, model rollback), it MUST be computed from unsampled counters or from reweighted trace-level estimates with a known inclusion probability. A tail-sampled span ratio is a decision boundary you must not cross with an actuator attached. - If the SLO drives only **human dashboards**, a tail-sampled ratio is tolerable *provided* the dashboard labels it as "sampled, biased toward errors" and never renders it next to a budget-burn threshold as if comparable. - The boundary condition to detect: `keep_rate(error_traces) / keep_rate(healthy_traces) ≠ 1`. When this ratio exceeds ~2×, the span-ratio SLO is more than 100% biased and must be reclassified. In the observed incident the ratio was 100% / 5% = 20×. A guardrail that bounds this: the sampler MUST emit `sampling.probability` per kept trace, and the metric layer MUST either reweight or refuse to emit a ratio when the observed probability distribution is non-uniform across status classes. Refusing to emit is better than emitting a confidently wrong number. ## Operational Effect The downstream consequence is a class of **silent SLO divergence**: the agent's reported health and its actual health decouple, and the decoupling is invisible because the metric is internally consistent (a real ratio of real spans) and stable (the bias is constant as long as the sampler policy is constant). The instance does not fail; it *misreports*, and it misreports in the direction that suppresses alarms, because tail samplers are tuned to keep failures and the SLO is tuned to count them—so failures inflate the numerator while successes starve the denominator, and the ratio drifts toward a ceiling that looks like "acceptable noise." Recovery requires re-deriving the SLO from pre-sampler counters, backfilling the true rate for the affected window, and re-running the error-budget burn calculation—because every alert decision made during the divergence window was made on a number that was not the error rate. The invariant to encode: **a sampled ratio is only an estimator of the population ratio if the inclusion probability is independent of the outcome class.** Tail sampling makes inclusion *dependent* on the outcome class by design. Therefore any SLO over tail-sampled spans must carry an explicit reweighting factor or be rejected at emission. ```python import math from dataclasses import dataclass class SamplingBiasError(RuntimeError): """Raised when an SLO ratio is computed over spans whose inclusion probability is correlated with the outcome class (tail sampling).""" pass @dataclass class SpanClassStats: kept: int inclusion_prob: float # probability this class survives the sampler def compute_reweighted_error_rate( errored: SpanClassStats, healthy: SpanClassStats, max_bias_ratio: float = 2.0, ) -> float: """Return an unbiased error-rate estimate, or refuse. The estimator is (errored_kept / p_err) / (errored_kept/p_err + healthy_kept/p_healthy). If the keep-probability ratio exceeds max_bias_ratio, the span-ratio SLO is structurally untrustworthy and we refuse rather than emit. """ if errored.inclusion_prob <= 0 or healthy.inclusion_prob <= 0: raise SamplingBiasError( f"non-positive inclusion probability: " f"err={errored.inclusion_prob}, healthy={healthy.inclusion_prob}" ) bias_ratio = errored.inclusion_prob / healthy.inclusion_prob if bias_ratio > max_bias_ratio: raise SamplingBiasError( f"tail-sampler bias ratio {bias_ratio:.2f}x exceeds " f"{max_bias_ratio:.2f}x: errored spans kept at " f"{errored.inclusion_prob:.0%}, healthy at " f"{healthy.inclusion_prob:.0%}. Span-ratio SLO is invalid; " f"re-derive from pre-sampler counters." ) est_err = errored.kept / errored.inclusion_prob est_healthy = healthy.kept / healthy.inclusion_prob denom = est_err + est_healthy if denom <= 0: raise SamplingBiasError("empty population after reweighting") return est_err / denom def evaluate_slo( errored: SpanClassStats, healthy: SpanClassStats, budget: float = 0.01, ) -> str: try: rate = compute_reweighted_error_rate(errored, healthy) except SamplingBiasError as exc: # Fail closed: an actuator must never fire on a biased ratio. return f"REFUSED: {exc}" burn = rate / budget return ( f"error_rate={rate:.4%} budget={budget:.2%} " f"burn={burn:.2f}x -> {'BREACH' if burn >= 1.0 else 'OK'}" ) # Observed incident: 100% of error traces kept, 5% of healthy traces kept. print(evaluate_slo( errored=SpanClassStats(kept=620, inclusion_prob=1.00), healthy=SpanClassStats(kept=3100, inclusion_prob=0.05), )) # -> REFUSED: tail-sampler bias ratio 20.00x exceeds 2.00x ... ```