# What happens when an instance redacts PII at the OTel span boundary but the parent trace context carries the unredacted prompt **Date of Record:** 2026 December 4 **Scope:** Applies to LLM agent runtimes that emit OpenTelemetry spans with prompt/completion attributes and perform PII redaction at the span-export layer (processor, exporter, or collector) rather than at the attribute-emission layer. Does not apply to systems where redaction occurs before any span attribute is populated, nor to traces that never propagate parent context across process boundaries. ## Core Distinction The failure mode is not "redaction missed a field." It is a **split-brain between two representations of the same logical event**: the redacted span that reaches the collector and the unredacted parent `trace_id`/`span_id` lineage that survives in baggage, log correlation IDs, or downstream child spans. Redaction applied at the export path is *stateless with respect to trace topology*. It rewrites `gen_ai.prompt` on the span it sees, but the same string may already be (a) copied into a log line with `trace_id` attached, (b) embedded in a child span's `gen_ai.tool.input` attribute, or (c) propagated as W3C `baggage` to a downstream service that re-emits it. The invariant that must hold is: **for a given `trace_id`, every attribute derived from the same source text is redacted by the same policy version before any of them leaves the trust boundary.** Span-level redaction does not enforce this; it enforces only per-span attribute hygiene. ## What Was Observed An agent runtime emitted the following during a tool-calling turn. The LLM completion contained a user's email and a partial card number. The runtime populated three OTel surfaces from that one completion: 1. Parent span `agent.turn` with `gen_ai.completion` = full text. 2. Child span `tool.email.send` with `gen_ai.tool.input` = JSON containing the same email. 3. A structured log record `email_dispatch` with `trace_id=`, `recipient=`. A `SpanProcessor` configured with a regex redactor (`\b[\w.]+@[\w.]+\.\w+\b` → `[REDACTED_EMAIL]`) was attached. It correctly scrubbed surface (1). It did **not** touch surface (2), because the redactor was registered only against the `gen_ai.completion` key, and the tool-input attribute name was `gen_ai.tool.input`. It did **not** touch surface (3), because logs bypass the span processor entirely and are exported by a `LogRecordExporter` with no redaction hook. The collector received: ``` trace_id=4bf9... span=agent.turn gen_ai.completion="...[REDACTED_EMAIL]..." trace_id=4bf9... span=tool.email.send gen_ai.tool.input={"recipient":"alice@corp.example"} log: trace_id=4bf9... recipient=alice@corp.example ``` The trace was "redacted" by the dashboard's span-attribute view and simultaneously unredacted by log correlation. An auditor querying `trace_id=4bf9...` across both signals reconstructed the PII. The redaction was *locally correct and globally insufficient*. A second, subtler observation: the redactor was **versioned by deploy time, not by trace**. A rolling deploy swapped the regex from the email pattern to a stricter one mid-trace. Spans emitted before the swap carried the old redaction; spans after carried the new. The same `trace_id` now mixed two redaction policies, and a downstream join on `trace_id` produced a record where the *redaction marker itself* (`[REDACTED_EMAIL]` vs `[PII]`) leaked the fact that a specific field had been PII at a specific time — a metadata leak even though the value was gone. ## Condition of Validity This failure is bounded and predictable under the following conditions, and the guardrail is only *required* when all three hold: - **Multi-surface derivation.** The same source text is projected into ≥2 OTel signals (spans + logs, or parent + child spans, or spans + baggage) that share a `trace_id`. - **Out-of-band redaction.** Redaction is applied at a processor/exporter/collector stage rather than at the point where the attribute value is constructed in application code. - **Heterogeneous attribute schemas.** The redactor is keyed on attribute *names* (or a fixed allowlist) rather than on the *provenance* of the value, so any new attribute name (e.g., `gen_ai.tool.input`, `gen_ai.retrieval.chunk`) silently bypasses the policy. If redaction happens at value construction — a single `RedactingAttributeFactory` that every span, log, and baggage setter must call — the failure cannot occur because there is exactly one egress point per trace. If all surfaces are guaranteed to flow through one exporter with one policy, per-trace consistency is trivially satisfied. The dangerous middle ground is the common one: framework-provided span processors (which only see spans) plus a separate log pipeline plus ad-hoc `baggage.set()` calls. ## Decision Boundary The architect must choose, per trace, between two enforceable invariants and cannot have both cheaply: - **Invariant A (provenance-bound redaction):** every attribute value that originates from LLM output or tool I/O passes through a single redaction function at construction time, and the redaction policy version is stamped into the span as `redaction.policy.version`. Cost: every instrumentation site must be audited; a missed site is a silent leak. Benefit: per-trace consistency is structural, and policy-version joins are exact. - **Invariant B (trace-scoped redaction at the collector):** the collector buffers all signals for a `trace_id`, applies one policy version to the whole trace, and only then exports. Cost: introduces a buffering window (trace-completion detection), which conflicts with low-latency streaming and with long-running agent traces that never "complete." Benefit: single policy application point. The boundary is crossed when a system claims Invariant B but implements a span processor (which cannot see logs and cannot buffer to trace completion). The tell is the presence of a `SpanProcessor` doing regex work while a `LoggerProvider` exists in the same process. At that point the system is actually running a broken Invariant A: provenance is not tracked, and only the attribute names someone remembered to register are covered. The correct move when Invariant B's latency cost is unacceptable is to **narrow the trace** — emit PII-bearing attributes only on a dedicated child span that is exported to a restricted, short-retention backend, and keep the parent trace PII-free by construction — rather than to widen the regex. ## Operational Effect Concretely, the unguarded configuration produces three observable symptoms that operators should treat as red flags: 1. **Correlation-based reconstruction.** Any `trace_id` join across span and log backends yields PII that neither backend reports as present. Detection: run the redactor's own patterns against the *joined* view, not per-signal. 2. **Policy-version skew within a trace.** Spans in one trace carry different redaction markers. Detection: group by `trace_id`, count distinct `redaction.policy.version` values; >1 is a violation. 3. **Schema-drift bypass.** A new attribute name introduced by a framework upgrade (e.g., `gen_ai.tool.input` replacing `tool.arguments`) silently escapes the name-keyed redactor. Detection: assert that the set of attributes matching PII regexes, measured *after* redaction on the collector, is empty — an egress-side assertion, not an ingress-side one. The guardrail that bounds all three is an **egress-side negative assertion**: before any batch leaves the trust boundary, scan every attribute on every signal for the union of PII patterns and fail the export (not just log) if any match. This catches provenance gaps, schema drift, and version skew in one check, because it validates the *output* rather than trusting the *input path*. ## Operational Effect on Agent Behavior A redaction failure is not merely a compliance event; it degrades the agent's own auditability. When the redactor is name-keyed and the runtime adds a new tool, the resulting trace is *partially* redacted. A downstream verification agent that replays the trace to audit tool calls will see a redacted parent completion but an unredacted tool input, and will conclude the tool was called with data the model never saw — a false inconsistency that poisons the replay. The redaction layer, meant to protect data, becomes a source of **trace-integrity divergence** that the verification loop cannot distinguish from a genuine hallucinated tool call. ```python import re from dataclasses import dataclass, field from typing import Any PII_PATTERNS = [ re.compile(r"\b[\w.]+@[\w.]+\.\w+\b"), re.compile(r"\b(?:\d[ -]?){13,16}\b"), ] class RedactionInvariantViolation(RuntimeError): """Raised when a trace's exported signals are not uniformly redacted.""" @dataclass class Signal: trace_id: str kind: str # "span" | "log" attributes: dict[str, Any] redaction_policy_version: str = "v0" def _contains_pii(text: str) -> bool: return any(p.search(text) for p in PII_PATTERNS) def assert_egress_redaction(signals: list[Signal]) -> None: """Egress-side negative assertion: no signal may leave with raw PII, and all signals for a trace must share one redaction policy version.""" by_trace: dict[str, set[str]] = {} for sig in signals: for key, value in sig.attributes.items(): if isinstance(value, str) and _contains_pii(value): raise RedactionInvariantViolation( f"PII survived redaction on trace={sig.trace_id} " f"kind={sig.kind} attr={key}" ) by_trace.setdefault(sig.trace_id, set()).add(sig.redaction_policy_version) for trace_id, versions in by_trace.items(): if len(versions) > 1: raise RedactionInvariantViolation( f"policy-version skew within trace={trace_id}: {sorted(versions)}" ) # Trigger: parent span redacted, child tool-input span not, log unredacted. signals = [ Signal("4bf9", "span", {"gen_ai.completion": "mail [REDACTED_EMAIL]"}, "v1"), Signal("4bf9", "span", {"gen_ai.tool.input": '{"recipient":"alice@corp.example"}'}, "v1"), Signal("4bf9", "log", {"recipient": "alice@corp.example"}, "v0"), ] try: assert_egress_redaction(signals) except RedactionInvariantViolation as exc: # Correct behavior: fail the export, do not ship the batch. print(f"export blocked: {exc}") raise ```