This specification is maintained by the AgentRules Working Group. Have enhancements or want to claim maintainership?Submit Specification →
devopscritical PriorityID: opentelemetry-inflight-pii-redaction-baggage-guardrail

OpenTelemetry In-Flight PII Redaction & Baggage Propagation Standard

Enforces deterministic, in-memory PII and credential redaction directly inside the OpenTelemetry SDK SpanProcessor pipeline before batch queuing and network egress. Eliminates reliance on collector-side scrubbers to prevent cross-border compliance violations (PCI-DSS, HIPAA, GDPR) and stops unvalidated W3C Baggage propagation across downstream distributed services.

Prohibited Anti-Pattern: Attaching Unfiltered Payloads and Propagating Tainted Context via OTLP Exporters

Export Ready-to-Drop Configuration

Select format below to copy code or download file directly.

---
description: OpenTelemetry In-Flight PII Redaction & Baggage Propagation Standard - Enforces deterministic, in-memory PII and credential redaction directly inside the OpenTelemetry SDK SpanProcessor pipeline before batch queuing and network egress. Eliminates reliance on collector-side scrubbers to prevent cross-border compliance violations (PCI-DSS, HIPAA, GDPR) and stops unvalidated W3C Baggage propagation across downstream distributed services.
globs: src/**/telemetry/**/*.{ts,js}, src/**/tracing/**/*.{ts,js}, src/**/instrumentation/**/*.{ts,js}, src/**/middleware/**/*.{ts,js}
alwaysApply: true
verified_by: "agentrules.org"
license: "CC-BY-4.0"
source: "https://agentrules.org/rules/opentelemetry-inflight-pii-redaction-baggage-guardrail"
---

# OpenTelemetry In-Flight PII Redaction & Baggage Propagation Standard

> **Severity**: CRITICAL | **Category**: devops
> **Anti-Pattern Warning**: Attaching Unfiltered Payloads and Propagating Tainted Context via OTLP Exporters

## System Constraints
You are a Principal Software Architect enforcing enterprise-grade OpenTelemetry observability standards. You must mandate in-memory, deterministic PII redaction and strict W3C Baggage filtering inside the OpenTelemetry SDK before spans hit the BatchSpanProcessor or OTLP network exporter. Downstream collectors (OTel Collector, Datadog Agent) must never be the primary security boundary for sensitive data exfiltration.

## Strict Guidelines
- Engineers MUST ALWAYS implement a custom SpanProcessor (or SpanExporter wrapper) that executes synchronous redaction on span attributes before passing spans to the BatchSpanProcessor.
- Engineers MUST NOT attach raw HTTP header maps, decoded JWT payloads, full query strings, or unparsed JSON bodies directly to span attributes or baggage.
- Services MUST enforce strict allowlists for W3C Baggage propagation; non-allowlisted context keys must be stripped at process boundaries to prevent cross-service data exfiltration.
- Redaction routines MUST use linear-time, non-backtracking regular expressions or direct key lookups to avoid Regular Expression Denial of Service (ReDoS) inside critical trace paths.
- Components NEVER record span events or exception stack traces containing raw database connection strings, bearer tokens, or PCI/PHI data without inline masking.

## Bad vs Good Implementations
### PII Sanitizing SpanProcessor & Baggage Guardrail

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: Span attributes receive raw headers containing authorization tokens, cookies, and email addresses. Relying on downstream collectors for scrubbing violates data minimization and residency rules, while unchecked baggage injection propagates credentials to untrusted downstream services.
```typescript
import { trace, propagation } from '@opentelemetry/api';
import { BatchSpanProcessor } from '@opentelemetry/sdk-trace-base';
import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-http';

// ANTI-PATTERN: Direct exporter pipeline passing raw span attributes & unconstrained baggage
const exporter = new OTLPTraceExporter({ url: 'https://collector.internal/v1/traces' });
const processor = new BatchSpanProcessor(exporter);

export function recordUserSession(userId: string, email: string, rawHeaders: Record<string, string>) {
  const span = trace.getActiveSpan();
  if (span) {
    // Leaks raw authorization tokens, cookies, and PII into collector memory and storage
    span.setAttributes({
      'user.id': userId,
      'user.email': email,
      ...rawHeaders
    });
  }
  // Propagates sensitive data downstream through ambient W3C Baggage
  let baggage = propagation.getBaggage(propagation.extract(propagation.getBaggage, {}));
  baggage = baggage?.setEntry('auth-token', rawHeaders['authorization'] || '');
}
```

#### Production Standard (Correct)
> **Standard**: Implements an in-memory SpanProcessor that intercepts spans in the SDK pipeline prior to batching or network transmission. It recursively inspects and redacts sensitive keys and patterns, ensuring tainted data never exits the local process boundary.
```typescript
import { SpanProcessor, ReadableSpan } from '@opentelemetry/sdk-trace-base';
import { Context, HrTime, SpanStatus } from '@opentelemetry/api';

const SENSITIVE_KEY_PATTERN = /^(authorization|cookie|set-cookie|password|token|secret|credit_card|ssn)$/i;
const EMAIL_PATTERN = /[^@\s]+@[^@\s]+\.[^@\s]+/g;
const REDACTED_VALUE = '[REDACTED]';

export class InFlightRedactingSpanProcessor implements SpanProcessor {
  constructor(private readonly nextProcessor: SpanProcessor) {}

  onStart(span: any, parentContext: Context): void {
    this.nextProcessor.onStart(span, parentContext);
  }

  onEnd(span: ReadableSpan): void {
    // Mutate attributes in-place before passing to BatchSpanProcessor queue
    const attributes = span.attributes;
    for (const key of Object.keys(attributes)) {
      if (SENSITIVE_KEY_PATTERN.test(key)) {
        attributes[key] = REDACTED_VALUE;
        continue;
      }
      const val = attributes[key];
      if (typeof val === 'string' && EMAIL_PATTERN.test(val)) {
        attributes[key] = val.replace(EMAIL_PATTERN, REDACTED_VALUE);
      }
    }
    this.nextProcessor.onEnd(span);
  }

  shutdown(): Promise<void> {
    return this.nextProcessor.shutdown();
  }

  forceFlush(): Promise<void> {
    return this.nextProcessor.forceFlush();
  }
}
```

Recommended MCP Servers (mcp-serverlist.com)

Equip agent with system tools to verify code for this stack.

Recommended Agent Skills (askills.dev)

Ready-to-use executable skill functions tailored to this stack.

Architectural Specification & Invariant Rationale

Architectural Invariant Design: OpenTelemetry In-Flight PII Redaction & Baggage Propagation Standard

OpenTelemetry In-Flight PII Redaction & Baggage Propagation Standard defines an industrial-grade behavioral standard for devops engineering. Enforces deterministic, in-memory PII and credential redaction directly inside the OpenTelemetry SDK SpanProcessor pipeline before batch queuing and network egress. Eliminates reliance on collector-side scrubbers to prevent cross-border compliance violations (PCI-DSS, HIPAA, GDPR) and stops unvalidated W3C Baggage propagation across downstream distributed services. Modern software architectures require strict adherence to deterministic patterns to guarantee high availability, maintainability, and zero security vulnerabilities.

Framework Paradigm Shift & Drift MechanicsLLMs are trained on millions of open-source repositories containing outdated code, legacy idioms, and unpatched antipatterns. When coding assistants generate implementations for this stack, they default to common statistical tokens: Attaching Unfiltered Payloads and Propagating Tainted Context via OTLP Exporters Without an explicit system instruction file, developers spend hours debugging silent failures.
Failure Modes & Production Blast Radius

Hazard Analysis: What Breaks Without This Rule

The following failure modes have been cataloged from hundreds of hours of production code reviews where AI assistants produced non-compliant implementations:

Failure ModeAI Symptom (The Anti-Pattern)SeverityProduction Impact & Remedy
AI Hallucination & Deprecation DriftAttaching Unfiltered Payloads and Propagating Tainted Context via OTLP ExportersCritical
Violating this industrial standard introduces regression bugs, security risks, and unexpected runtime failures in production.
Enforce explicit behavioral system directives across all AI coding assistants in your repository.
Silent Architecture InconsistencyAI assistants produce mixed paradigms across files, creating fragmented codebase conventions.Medium
Increases cognitive load during code reviews and leads to maintenance debt across engineering teams.
Pin project conventions in .cursor/rules, CLAUDE.md, and AGENTS.md so all team agents follow identical guardrails.
Architectural Directives in Detail

Step-by-Step Production Directives

Each rule constraint below is injected into the AI agent's system prompt to establish deterministic boundaries:

1

Engineers MUST ALWAYS implement a custom SpanProcessor (or SpanExporter wrapper) that executes synchronous redaction on span attributes before passing spans to the BatchSpanProcessor.

Engineers MUST ALWAYS implement a custom SpanProcessor (or SpanExporter wrapper) that executes synchronous redaction on span attributes before passing spans to the BatchSpanProcessor.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
2

Engineers MUST NOT attach raw HTTP header maps, decoded JWT payloads, full query strings, or unparsed JSON bodies directly to span attributes or baggage.

Engineers MUST NOT attach raw HTTP header maps, decoded JWT payloads, full query strings, or unparsed JSON bodies directly to span attributes or baggage.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
3

Services MUST enforce strict allowlists for W3C Baggage propagation

Services MUST enforce strict allowlists for W3C Baggage propagation; non-allowlisted context keys must be stripped at process boundaries to prevent cross-service data exfiltration.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
4

Redaction routines MUST use linear-time, non-backtracking regular expressions or direct key lookups to avoid Regular Expression Denial of Service (ReDoS) inside critical trace paths.

Redaction routines MUST use linear-time, non-backtracking regular expressions or direct key lookups to avoid Regular Expression Denial of Service (ReDoS) inside critical trace paths.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
5

Components NEVER record span events or exception stack traces containing raw database connection strings, bearer tokens, or PCI/PHI data without inline masking.

Components NEVER record span events or exception stack traces containing raw database connection strings, bearer tokens, or PCI/PHI data without inline masking.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
Technical Questions & Answers

Frequently Asked Technical Questions

Common questions developers face when configuring AI coding assistants for this stack:

Q:Why is OpenTelemetry In-Flight PII Redaction & Baggage Propagation Standard critical for AI coding assistants?

Enforces deterministic, in-memory PII and credential redaction directly inside the OpenTelemetry SDK SpanProcessor pipeline before batch queuing and network egress. Eliminates reliance on collector-side scrubbers to prevent cross-border compliance violations (PCI-DSS, HIPAA, GDPR) and stops unvalidated W3C Baggage propagation across downstream distributed services. Without explicit behavioral boundaries, AI coding assistants (Cursor, Claude Code, Windsurf, Codex) rely on training data averages, which frequently produce deprecated, inefficient, or vulnerable code patterns.

Q:How does adopting this rule prevent AI hallucinations?

This rule explicitly declares what the AI must avoid (Attaching Unfiltered Payloads and Propagating Tainted Context via OTLP Exporters) and prescribes verified positive examples. Grounding the LLM with negative and positive pairs eliminates guesswork.

Q:Which AI coding environments are supported?

This specification is multi-platform compatible: Cursor (.cursor/rules/*.mdc & .cursorrules), Anthropic Claude Code (CLAUDE.md), Windsurf (.windsurfrules), Codex / Cline (AGENTS.md), and GitHub Copilot (.github/copilot-instructions.md).

Q:Can I combine this rule with other technology stacks?

Yes. Use the Interactive Stack Builder or download an Agent Pack to merge this rule with other frontend, backend, database, security, and DevOps rules without syntax collision.

Open Specification · CC BY 4.0·Free for Personal, Team & Commercial In-Repo Use

Citation & Open Source Attribution Guidelines

This specification is licensed under Creative Commons Attribution 4.0 International (CC BY 4.0). You are completely free to adapt and share this rule in your workspace. If citing, including in public AI benchmark datasets, or redistributing, attribution to AgentRules.org is required.

1 Rule in Stack

OpenTelemetry