This specification is maintained by the AgentRules Working Group. Have enhancements or want to claim maintainership?Submit Specification →
securitycritical PriorityID: opentelemetry-w3c-pii-redaction-envelope

OpenTelemetry W3C Trace Context Zero-Retention PII Redaction Standard

Enforces deterministic, automated sanitization and cryptographically keyed tokenization of sensitive payload attributes within OpenTelemetry context envelopes and W3C trace propagation headers. Guarantees that personal identifiable information (PII), credentials, and regulated data are redacted in-memory before spans and baggage egress trust boundaries.

Prohibited Anti-Pattern: Unredacted Egress of Regulated PII and Auth Tokens via W3C Baggage and Span Attributes

Export Ready-to-Drop Configuration

Select format below to copy code or download file directly.

---
description: OpenTelemetry W3C Trace Context Zero-Retention PII Redaction Standard - Enforces deterministic, automated sanitization and cryptographically keyed tokenization of sensitive payload attributes within OpenTelemetry context envelopes and W3C trace propagation headers. Guarantees that personal identifiable information (PII), credentials, and regulated data are redacted in-memory before spans and baggage egress trust boundaries.
globs: src/telemetry/**/*.ts, src/tracing/**/*.ts, src/middleware/**/*.ts, otel-collector-config*.yaml
alwaysApply: true
verified_by: "agentrules.org"
license: "CC-BY-4.0"
source: "https://agentrules.org/rules/opentelemetry-w3c-pii-redaction-envelope"
---

# OpenTelemetry W3C Trace Context Zero-Retention PII Redaction Standard

> **Severity**: CRITICAL | **Category**: security
> **Anti-Pattern Warning**: Unredacted Egress of Regulated PII and Auth Tokens via W3C Baggage and Span Attributes

## System Constraints
You are a Principal Security Architect enforcing zero-retention data hygiene in OpenTelemetry telemetry pipelines. You must mandate strict attribute sanitization, zero plain-text PII in W3C Baggage or Span Context, and deterministic redaction pipelines at both client-side propagators and collector egress interfaces.

## Strict Guidelines
- Engineers MUST ALWAYS sanitize or HMAC-hash any sensitive identifier (email, account ID, SSN, IP address) before recording it to span attributes or W3C Baggage.
- Engineers MUST NOT propagate raw HTTP authentication headers, session cookies, or sensitive query parameters through W3C `baggage` or `tracestate` headers across service boundaries.
- Span processors MUST execute synchronously in memory before exporter dispatch to ensure zero raw PII is written to exporter network buffers or disk caches.
- Telemetry pipelines MUST use explicit allow-lists for W3C baggage keys permitted to traverse egress perimeter boundaries.
- Components NEVER log, trace, or export unredacted credit card data (PCI DSS), national identity numbers, or authentication secrets under any span event or exception recording.

## Bad vs Good Implementations
### SpanProcessor Context Sanitization and Baggage Redaction

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: Directly captures plain-text PII (email) and authentication tokens into span attributes. When transmitted across W3C headers or exported to centralized APM platforms, this causes compliance violations (GDPR, HIPAA, PCI DSS) and data leaks.
```typescript
import { SpanProcessor, ReadableSpan } from '@opentelemetry/sdk-trace-base';
import { Context, baggageUtils } from '@opentelemetry/api';

export class UnsafeLoggingSpanProcessor implements SpanProcessor {
  forceFlush(): Promise<void> { return Promise.resolve(); }
  shutdown(): Promise<void> { return Promise.resolve(); }
  
  onStart(span: any, parentContext: Context): void {
    // ANTI-PATTERN: Blindly attaching unsanitized request payloads and raw user identifiers
    const rawEmail = '[email protected]';
    const rawAuth = 'Bearer eyJhbGciOi...';
    span.setAttribute('user.email', rawEmail);
    span.setAttribute('http.request.header.authorization', rawAuth);
  }
  
  onEnd(span: ReadableSpan): void {
    // Spans exported with plain text sensitive data to external SaaS aggregators
  }
}
```

#### Production Standard (Correct)
> **Standard**: Implements an in-memory SpanProcessor that guarantees zero-retention of authorization headers and deterministic HMAC-SHA256 pseudonymization of PII prior to span egress.
```typescript
import { SpanProcessor, ReadableSpan } from '@opentelemetry/sdk-trace-base';
import { Context, Span } from '@opentelemetry/api';
import { createHmac } from 'crypto';

export class PIIRedactingSpanProcessor implements SpanProcessor {
  private readonly hmacSecret: Buffer;
  private static readonly BLOCKED_ATTRIBUTES = new Set([
    'http.request.header.authorization',
    'http.request.header.cookie',
    'user.password',
    'credit_card.number'
  ]);

  constructor(hmacSecret: Buffer) {
    this.hmacSecret = hmacSecret;
  }

  forceFlush(): Promise<void> { return Promise.resolve(); }
  shutdown(): Promise<void> { return Promise.resolve(); }

  onStart(span: Span, _parentContext: Context): void {
    // Handled dynamically via interceptors; initial hook retains clean state
  }

  onEnd(span: ReadableSpan): void {
    const attributes = span.attributes;
    for (const key of Object.keys(attributes)) {
      if (PIIRedactingSpanProcessor.BLOCKED_ATTRIBUTES.has(key)) {
        delete (attributes as Record<string, unknown>)[key];
        continue;
      }
      if (key === 'user.email' && typeof attributes[key] === 'string') {
        const raw = attributes[key] as string;
        (attributes as Record<string, unknown>)[key] = this.pseudonymize(raw);
      }
    }
  }

  private pseudonymize(value: string): string {
    return createHmac('sha256', this.hmacSecret).update(value).digest('hex');
  }
}
```

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 W3C Trace Context Zero-Retention PII Redaction Standard

OpenTelemetry W3C Trace Context Zero-Retention PII Redaction Standard defines an industrial-grade behavioral standard for security engineering. Enforces deterministic, automated sanitization and cryptographically keyed tokenization of sensitive payload attributes within OpenTelemetry context envelopes and W3C trace propagation headers. Guarantees that personal identifiable information (PII), credentials, and regulated data are redacted in-memory before spans and baggage egress trust boundaries. 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: Unredacted Egress of Regulated PII and Auth Tokens via W3C Baggage and Span Attributes 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 DriftUnredacted Egress of Regulated PII and Auth Tokens via W3C Baggage and Span AttributesCritical
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 sanitize or HMAC-hash any sensitive identifier (email, account ID, SSN, IP address) before recording it to span attributes or W3C Baggage.

Engineers MUST ALWAYS sanitize or HMAC-hash any sensitive identifier (email, account ID, SSN, IP address) before recording it to span attributes or W3C 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.
2

Engineers MUST NOT propagate raw HTTP authentication headers, session cookies, or sensitive query parameters through W3C `baggage` or `tracestate` headers across service boundaries.

Engineers MUST NOT propagate raw HTTP authentication headers, session cookies, or sensitive query parameters through W3C `baggage` or `tracestate` headers across service boundaries.

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

Span processors MUST execute synchronously in memory before exporter dispatch to ensure zero raw PII is written to exporter network buffers or disk caches.

Span processors MUST execute synchronously in memory before exporter dispatch to ensure zero raw PII is written to exporter network buffers or disk caches.

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

Telemetry pipelines MUST use explicit allow-lists for W3C baggage keys permitted to traverse egress perimeter boundaries.

Telemetry pipelines MUST use explicit allow-lists for W3C baggage keys permitted to traverse egress perimeter boundaries.

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 log, trace, or export unredacted credit card data (PCI DSS), national identity numbers, or authentication secrets under any span event or exception recording.

Components NEVER log, trace, or export unredacted credit card data (PCI DSS), national identity numbers, or authentication secrets under any span event or exception recording.

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 W3C Trace Context Zero-Retention PII Redaction Standard critical for AI coding assistants?

Enforces deterministic, automated sanitization and cryptographically keyed tokenization of sensitive payload attributes within OpenTelemetry context envelopes and W3C trace propagation headers. Guarantees that personal identifiable information (PII), credentials, and regulated data are redacted in-memory before spans and baggage egress trust boundaries. 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 (Unredacted Egress of Regulated PII and Auth Tokens via W3C Baggage and Span Attributes) 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