This specification is maintained by the AgentRules Working Group. Have enhancements or want to claim maintainership?Submit Specification →
devopscritical PriorityID: otel-baggage-pii-stripping-bloom-fencing-standard

OpenTelemetry W3C Baggage PII Stripping and Header Bloom Fencing Standard

Enforces deterministic redaction of regulated personally identifiable information (PII) and strict byte-budget fencing on OpenTelemetry W3C baggage prior to egress serialization. Prevents upstream cascading memory bloat, HTTP 431 header overflow failures, and GDPR/HIPAA compliance violations across distributed perimeter boundaries.

Prohibited Anti-Pattern: Unbounded PII Propagation and Giant Header Bloat in Distributed Trace Baggage

Export Ready-to-Drop Configuration

Select format below to copy code or download file directly.

---
description: OpenTelemetry W3C Baggage PII Stripping and Header Bloom Fencing Standard - Enforces deterministic redaction of regulated personally identifiable information (PII) and strict byte-budget fencing on OpenTelemetry W3C baggage prior to egress serialization. Prevents upstream cascading memory bloat, HTTP 431 header overflow failures, and GDPR/HIPAA compliance violations across distributed perimeter boundaries.
globs: src/telemetry/**/*.ts, src/infrastructure/tracing/**/*.ts, src/middleware/tracing/**/*.ts, src/common/telemetry/**/*.ts
alwaysApply: true
verified_by: "agentrules.org"
license: "CC-BY-4.0"
source: "https://agentrules.org/rules/otel-baggage-pii-stripping-bloom-fencing-standard"
---

# OpenTelemetry W3C Baggage PII Stripping and Header Bloom Fencing Standard

> **Severity**: CRITICAL | **Category**: devops
> **Anti-Pattern Warning**: Unbounded PII Propagation and Giant Header Bloat in Distributed Trace Baggage

## System Constraints
You are a Principal Software Architect enforcing production invariants for OpenTelemetry baggage propagation. You must ensure all outbound W3C baggage entries are strictly validated against an explicit allowlist, purged of PII/PHI (e.g., email, account numbers, tokens), and bounded to a strict aggregate byte budget to prevent RFC 7230 header-size overflow and compliance breaches.

## Strict Guidelines
- Engineers MUST ALWAYS enforce an explicit allowlist for baggage keys before context serialization at network egress perimeters.
- Engineers MUST NOT allow unverified user identifiers, JWT claims, email addresses, or unencrypted tenant secrets into W3C baggage entries.
- Services MUST enforce an aggregate byte limit (maximum 8192 bytes total, maximum 64 entries) for serialized W3C baggage to eliminate HTTP 431 Request Header Fields Too Large exceptions.
- Components NEVER rely on downstream microservices to clean or filter inherited inbound baggage; egress sanitization must occur at the active hop.
- Engineers MUST configure custom TextMapPropagators to drop rejected keys silently or log aggregated sanitization telemetry under a structured security audit event.

## Bad vs Good Implementations
### Unbounded Egress Baggage Injection vs Allowlisted Bounded Propagator

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: Directly serializing arbitrary baggage items without filtering leaks sensitive PII (emails, customer IDs, session tokens) across network boundaries and creates unbounded HTTP request headers that trigger reverse-proxy HTTP 431 drops.
```typescript
import { Context, defaultTextMapSetter, TextMapPropagator } from '@opentelemetry/api';
import { baggageWatcher } from '@opentelemetry/core';

// ANTI-PATTERN: Blindly attaching inbound payload attributes and unconstrained headers into baggage
export class PassThroughBaggagePropagator implements TextMapPropagator {
  inject(context: Context, carrier: Record<string, string>): void {
    const activeBaggage = baggageWatcher.getBaggage(context);
    if (!activeBaggage) return;

    const baggagePairs = activeBaggage.getAllEntries().map(([key, entry]) => `${key}=${entry.value}`);
    // Blindly joins keys without PII scanning, key allowlisting, or payload byte-length fencing
    carrier['baggage'] = baggagePairs.join(',');
  }

  extract(context: Context, carrier: Record<string, string>): Context {
    return context;
  }
  fields(): string[] { return ['baggage']; }
}
```

#### Production Standard (Correct)
> **Standard**: Implements an explicit key allowlist to drop PII dynamically while enforcing aggregate byte fencing (8192 bytes max) and entry count limits (64 entries max) to guarantee RFC conformance and prevent downstream buffer bloat.
```typescript
import { Context, TextMapPropagator, TextMapSetter, defaultTextMapSetter } from '@opentelemetry/api';
import { baggageWatcher } from '@opentelemetry/core';

const BAGGAGE_MAX_TOTAL_BYTES = 8192;
const BAGGAGE_MAX_KEY_COUNT = 64;

// Deterministic allowlist: only operational context is allowed in W3C Baggage
const ALLOWED_BAGGAGE_KEYS = new Set<string>([
  'deployment.environment',
  'service.version',
  'tenant.tier',
  'request.priority'
]);

export class FencedSanitizingBaggagePropagator implements TextMapPropagator {
  inject(context: Context, carrier: unknown, setter: TextMapSetter = defaultTextMapSetter): void {
    const activeBaggage = baggageWatcher.getBaggage(context);
    if (!activeBaggage) return;

    const sanitizedEntries: string[] = [];
    let accumulatedBytes = 0;
    let entryCount = 0;

    for (const [key, entry] of activeBaggage.getAllEntries()) {
      if (!ALLOWED_BAGGAGE_KEYS.has(key)) {
        continue; // Deterministic PII / Unbounded property strip
      }
      if (entryCount >= BAGGAGE_MAX_KEY_COUNT) {
        break;
      }

      const encodedKey = encodeURIComponent(key.trim());
      const encodedVal = encodeURIComponent(entry.value.trim());
      const serialized = `${encodedKey}=${encodedVal}`;
      const cost = serialized.length + (sanitizedEntries.length > 0 ? 1 : 0); // Account for comma delimiter

      if (accumulatedBytes + cost > BAGGAGE_MAX_TOTAL_BYTES) {
        break; // Guard against header bloom attacks and proxy limits
      }

      sanitizedEntries.push(serialized);
      accumulatedBytes += cost;
      entryCount++;
    }

    if (sanitizedEntries.length > 0) {
      setter.set(carrier, 'baggage', sanitizedEntries.join(','));
    }
  }

  extract(context: Context, carrier: unknown): Context {
    return context;
  }

  fields(): string[] {
    return ['baggage'];
  }
}
```

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 Baggage PII Stripping and Header Bloom Fencing Standard

OpenTelemetry W3C Baggage PII Stripping and Header Bloom Fencing Standard defines an industrial-grade behavioral standard for devops engineering. Enforces deterministic redaction of regulated personally identifiable information (PII) and strict byte-budget fencing on OpenTelemetry W3C baggage prior to egress serialization. Prevents upstream cascading memory bloat, HTTP 431 header overflow failures, and GDPR/HIPAA compliance violations across distributed perimeter 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: Unbounded PII Propagation and Giant Header Bloat in Distributed Trace Baggage 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 DriftUnbounded PII Propagation and Giant Header Bloat in Distributed Trace BaggageCritical
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 enforce an explicit allowlist for baggage keys before context serialization at network egress perimeters.

Engineers MUST ALWAYS enforce an explicit allowlist for baggage keys before context serialization at network egress perimeters.

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 allow unverified user identifiers, JWT claims, email addresses, or unencrypted tenant secrets into W3C baggage entries.

Engineers MUST NOT allow unverified user identifiers, JWT claims, email addresses, or unencrypted tenant secrets into W3C baggage entries.

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 an aggregate byte limit (maximum 8192 bytes total, maximum 64 entries) for serialized W3C baggage to eliminate HTTP 431 Request Header Fields Too Large exceptions.

Services MUST enforce an aggregate byte limit (maximum 8192 bytes total, maximum 64 entries) for serialized W3C baggage to eliminate HTTP 431 Request Header Fields Too Large exceptions.

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

Components NEVER rely on downstream microservices to clean or filter inherited inbound baggage

Components NEVER rely on downstream microservices to clean or filter inherited inbound baggage; egress sanitization must occur at the active hop.

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

Engineers MUST configure custom TextMapPropagators to drop rejected keys silently or log aggregated sanitization telemetry under a structured security audit event.

Engineers MUST configure custom TextMapPropagators to drop rejected keys silently or log aggregated sanitization telemetry under a structured security audit event.

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 Baggage PII Stripping and Header Bloom Fencing Standard critical for AI coding assistants?

Enforces deterministic redaction of regulated personally identifiable information (PII) and strict byte-budget fencing on OpenTelemetry W3C baggage prior to egress serialization. Prevents upstream cascading memory bloat, HTTP 431 header overflow failures, and GDPR/HIPAA compliance violations across distributed perimeter 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 (Unbounded PII Propagation and Giant Header Bloat in Distributed Trace Baggage) 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