# How does an instance detect that OTel GenAI span redaction has silently desynchronized from the semantic attribute schema it is scrubbing against? **Date of Record:** 2026 November 28 **Scope:** Applies to collector-layer redaction pipelines that mutate OTel GenAI spans (`gen_ai.*` semantic conventions) in-place between span emission and export, where redaction rules are keyed to attribute names and span event structures. Does not apply to redaction performed inside the SDK before span creation, nor to non-GenAI OTel spans where attribute schemas are stable and versioned by a single spec body. ## Core Distinction The naive model treats redaction as a **stateless filter**: a regex or classifier runs over attribute values, matches are replaced with `[REDACTED]`, the span continues. The failure mode that matters is different: redaction is a **schema-coupled transform**, and the schema it couples to (`gen_ai.*` semantic conventions, prompt/completion event payload shapes, tool-call argument encoding) is versioned *independently* of the redaction ruleset and the collector's own configuration. When those three move out of phase, the pipeline does not error — it *succeeds at scrubbing the wrong keys*, exporting the sensitive payload through a path the ruleset never modeled. The distinction is between **redaction coverage failure** (a known field leaks because the rule was missing) and **redaction desynchronization** (the pipeline believes it covered a field, the coverage metric reads 100%, and the field leaks because the field's *name, nesting, or encoding* changed underneath the rule). The first is a bug you can test for. The second is an invariant violation that produces no signal in the pipeline's own telemetry. ## What Was Observed A collector pipeline configured to scrub `gen_ai.prompt` and `gen_ai.completion` string attributes on chat spans reported a 100% redaction rate across a 72-hour window. During the same window, a downstream sampling audit of exported spans found raw user email addresses and a bearer token in `gen_ai.input.messages` and `gen_ai.output.messages` — attributes that did not exist when the ruleset was authored. The trace, reconstructed: 1. The upstream instrumentation library upgraded and began emitting the newer message-array encoding: `gen_ai.input.messages` as a JSON-serialized array of role/content objects, replacing the legacy flat `gen_ai.prompt` string. The legacy attributes were still emitted for a deprecation window, so the redaction rules *fired* — they matched `gen_ai.prompt`, scrubbed it, and incremented the coverage counter. 2. The new `gen_ai.input.messages` attribute passed through untouched. The redaction rule set was keyed on a hardcoded allowlist of attribute names; the new name was not in it, and the pipeline's default action for unknown attributes was **pass-through, not drop**. 3. The coverage metric was computed as `(spans with ≥1 redaction applied) / (total spans)`. Because every span still carried the legacy scrubbed attribute, every span counted as "covered." The metric measured *that redaction happened*, never *that sensitive data was absent*. 4. The desync persisted for the full deprecation window. It was caught only when the legacy attributes were finally removed and the coverage metric collapsed to 0% — at which point the leak had already been exporting for weeks. The critical observation: the pipeline had **no negative assertion**. It could prove it had scrubbed something; it could not prove it had scrubbed *everything sensitive*. A redaction pipeline without a post-transform assertion is a pipeline that fails open by construction. ## Condition of Validity The invariant that bounds this failure is: > **For every span emitted to export, the set of attribute keys and nested payload paths present in the exported span must be a subset of the set of paths the redaction ruleset explicitly classified (as scrub, drop, or pass-through-safe). Any path not classified is a desync, and the correct action is to quarantine the span, not to export it.** This holds only under two conditions: - **The ruleset is a classifier over paths, not a filter over names.** A rule keyed to `gen_ai.prompt` classifies one path. A rule keyed to `gen_ai.input.messages[*].content` classifies a subtree and survives encoding changes that preserve structure. Name-keyed rulesets desync on every schema rename; path-keyed rulesets desync only on structural change, which is detectable. - **The default for unclassified paths is deny.** Pass-through-on-unknown is the single configuration choice that converts a schema drift into a silent leak. The pipeline must be able to *enumerate* the paths it saw and compare against the paths it classified. If it cannot enumerate — because it is streaming attribute-by-attribute with no span-level view — it cannot enforce the invariant and must not claim coverage. The invariant does *not* require knowing the semantic convention version. It requires that the pipeline refuse to export any span containing a path it did not deliberately classify, regardless of what the convention says the path means. Meaning is the ruleset author's job; *presence* is the pipeline's enforcement point. ## Decision Boundary The boundary between a bounded pipeline and a desynchronizing one is drawn at a single question asked per span at export time: **Can the pipeline produce the full set of attribute paths present in this span, and is every one of them in the classified set?** - If yes → export. The span is provably within the ruleset's model. - If no, and the unclassified path is on a **known-sensitive denylist** (message content, tool arguments, auth headers, any `*.content`, `*.arguments`, `*.authorization`) → **drop the span and emit a desync counter keyed by the unclassified path name.** This is the load-bearing case: it converts a silent leak into a loud, attributed metric. - If no, and the unclassified path is not on the denylist → the decision depends on the pipeline's risk posture. A conservative pipeline quarantines; a permissive one exports with a `redaction_unclassified_path` annotation so downstream can retro-audit. The one impermissible choice is exporting *silently*. The decision must be made **per span, after all mutations**, not per attribute during streaming. Streaming redaction cannot see the final path set and therefore cannot enforce the subset invariant. This is the architectural constraint most implementations violate: they redact in a `SpanProcessor` that sees attributes one at a time, which is structurally incapable of the post-transform assertion. ## Operational Effect Enforcing the subset invariant changes the pipeline's failure semantics from **fail-open** to **fail-closed with attribution**. Three operational consequences: 1. **Desync becomes a first-class metric.** `redaction.unclassified_path{path="gen_ai.input.messages"}` spikes the moment upstream instrumentation changes encoding, *before* the deprecation window closes. The leak window shrinks from weeks to the first export batch. The metric is keyed by the offending path, so the fix is named by the alert. 2. **Coverage metrics must be redefined.** `(spans with redaction applied) / total` is worthless — it measures activity, not safety. The correct metric is `(spans with all paths classified) / total`, which is 100% only when the ruleset provably covers every emitted path. The old metric read 100% during the entire leak; the new metric would have read <100% on the first affected span. 3. **Quarantine is a durable state, not a drop.** Dropping an unclassified span loses the evidence needed to fix the ruleset. Quarantining to a restricted sink (no export, local retention with the offending path recorded) preserves the sample that proves the desync while containing the payload. The quarantine sink is itself subject to the same invariant — it must be access-controlled and retention-bounded, or it becomes the leak. The invariant does not eliminate schema drift — `gen_ai.*` will keep evolving. It eliminates the *silent* window between drift and detection, which is the only part of the failure the pipeline controls. ```python import re from dataclasses import dataclass, field from typing import Any class RedactionDesyncError(RuntimeError): """Raised when an exported span contains an attribute path the ruleset never classified.""" pass # Paths the ruleset explicitly classifies. Subtree-aware: 'gen_ai.input.messages[*]' # covers every element's nested paths, so encoding changes that preserve structure # do not desync. CLASSIFIED_SCRUB = { "gen_ai.prompt", "gen_ai.completion", "gen_ai.input.messages[*]", "gen_ai.output.messages[*]", "gen_ai.tool.call.arguments[*]", } CLASSIFIED_SAFE = { "gen_ai.system", "gen_ai.request.model", "gen_ai.usage.input_tokens", "gen_ai.usage.output_tokens", "gen_ai.operation.name", } # Paths that must never export unclassified, regardless of ruleset state. SENSITIVE_DENYLIST = re.compile( r"(content|arguments|authorization|prompt|completion|messages)", re.IGNORECASE ) @dataclass class Span: name: str attributes: dict[str, Any] = field(default_factory=dict) def _flatten_paths(obj: Any, prefix: str = "") -> list[str]: """Enumerate every leaf path, collapsing list indices to [*] so structural changes are visible but index churn is not.""" paths: list[str] = [] if isinstance(obj, dict): for k, v in obj.items(): paths.extend(_flatten_paths(v, f"{prefix}.{k}" if prefix else k)) elif isinstance(obj, list): for v in obj: paths.extend(_flatten_paths(v, f"{prefix}[*]")) else: paths.append(prefix) return paths def _matches_classified(path: str, classified: set[str]) -> bool: # A classified subtree 'a.b[*]' covers 'a.b[*].c.d'. for c in classified: if path == c or path.startswith(c + ".") or path.startswith(c + "[*]"): return True return False def enforce_subset_invariant(span: Span) -> Span: """Post-transform assertion: every emitted path must be classified. Called AFTER all scrubbing, on the final span. Fails closed.""" emitted = _flatten_paths(span.attributes) unclassified = [ p for p in emitted if not _matches_classified(p, CLASSIFIED_SCRUB) and not _matches_classified(p, CLASSIFIED_SAFE) ] if not unclassified: return span sensitive = [p for p in unclassified if SENSITIVE_DENYLIST.search(p)] if sensitive: # Fail closed with attribution: name the offending path, quarantine. raise RedactionDesyncError( f"span '{span.name}' emitted unclassified sensitive path(s) " f"{sensitive!r}; ruleset desynchronized from schema. Quarantining." ) # Non-sensitive unclassified: annotate, do not silently pass. span.attributes["redaction.unclassified_path"] = unclassified return span def redact_and_export(span: Span, exporter) -> None: # ... scrub CLASSIFIED_SCRUB paths in place here ... span = enforce_subset_invariant(span) exporter(span) ```