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

OpenTelemetry W3C Baggage Bounded Propagation & Trace-State Guardrail

Enforces strict payload bounding, key allowlisting, and sanitization for W3C Baggage and tracestate headers across distributed RPC boundaries. Prevents HTTP 431 header bloat outages, distributed denial-of-service vectors, and tenant credential leaks in multi-hop microservice topologies.

Prohibited Anti-Pattern: Unbounded, Unfiltered Baggage Propagation Leading to Header Bloat and Sensitive Data Exfiltration

Export Ready-to-Drop Configuration

Select format below to copy code or download file directly.

---
description: OpenTelemetry W3C Baggage Bounded Propagation & Trace-State Guardrail - Enforces strict payload bounding, key allowlisting, and sanitization for W3C Baggage and tracestate headers across distributed RPC boundaries. Prevents HTTP 431 header bloat outages, distributed denial-of-service vectors, and tenant credential leaks in multi-hop microservice topologies.
globs: src/telemetry/**/*.{ts,js}, src/middleware/**/*.{ts,js}, src/instrumentation/**/*.{ts,js}, src/transport/**/*.{ts,js}
alwaysApply: true
verified_by: "agentrules.org"
license: "CC-BY-4.0"
source: "https://agentrules.org/rules/opentelemetry-w3c-baggage-bounded-propagation-guardrail"
---

# OpenTelemetry W3C Baggage Bounded Propagation & Trace-State Guardrail

> **Severity**: CRITICAL | **Category**: devops
> **Anti-Pattern Warning**: Unbounded, Unfiltered Baggage Propagation Leading to Header Bloat and Sensitive Data Exfiltration

## System Constraints
You are a Principal Software Architect enforcing OpenTelemetry W3C Baggage and tracestate boundary guardrails. You must mandate bounded context propagation, explicit allowlisting of metadata keys, strict byte-size budget enforcement (max 8192 bytes total, max 1024 bytes per entry), and the absolute exclusion of PII, tokens, and ephemeral payload state from inter-service transport headers.

## Strict Guidelines
- Engineers MUST ALWAYS enforce an explicit key allowlist before injecting baggage into outgoing carrier headers.
- Engineers MUST NOT propagate raw request query parameters, authorization tokens, or unsanitized user context via W3C Baggage.
- Services MUST enforce strict byte budgets: maximum 8192 total bytes for the baggage header and 1024 bytes per individual key-value pair.
- Services MUST drop or redact baggage entries exceeding budget limits rather than allowing HTTP 431 (Request Header Fields Too Large) downstream.
- Components NEVER mutate or forward unknown tracestate tenant keys across non-trusted perimeter boundaries.

## Bad vs Good Implementations
### Bounded and Allowlisted Baggage Propagator Middleware

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: Arbitrary request headers and query parameters are copied directly into OpenTelemetry baggage without bounds, key allowlisting, or size checks. This exposes downstream services to HTTP 431 denial-of-service failures and exfiltrates sensitive authorization headers across service boundaries.
```typescript
import { propagation, context, Baggage } from '@opentelemetry/api';
import { Request, Response, NextFunction } from 'express';

export function badPropagationMiddleware(req: Request, res: Response, next: NextFunction): void {
  // Anti-pattern: Forwarding arbitrary incoming headers and client query parameters into baggage without limits
  let activeBaggage = propagation.getBaggage(context.active()) || propagation.createBaggage();
  
  for (const [key, value] of Object.entries(req.headers)) {
    if (typeof value === 'string') {
      activeBaggage = activeBaggage.setEntry(key, { value });
    }
  }
  
  // Propagating unbounded tenant metadata and potential auth tokens downstream
  if (req.query.tenantData) {
    activeBaggage = activeBaggage.setEntry('tenant.metadata', { value: String(req.query.tenantData) });
  }
  
  context.with(propagation.setBaggage(context.active(), activeBaggage), () => next());
}
```

#### Production Standard (Correct)
> **Standard**: Implements an explicit key allowlist, strictly validates individual key-value sizes against a 1024-byte ceiling, and caps total baggage payload to 8192 bytes. Prevents header explosion and data exfiltration across RPC boundaries.
```typescript
import { propagation, context, Baggage, BaggageEntry } from '@opentelemetry/api';
import { Request, Response, NextFunction } from 'express';

const ALLOWED_BAGGAGE_KEYS = new Set(['tenant.id', 'routing.region', 'client.type']);
const MAX_TOTAL_BYTES = 8192;
const MAX_ENTRY_BYTES = 1024;

function sanitizeAndBoundBaggage(incoming: Baggage): Baggage {
  let totalSize = 0;
  let sanitized = propagation.createBaggage();

  for (const [key, entry] of incoming.getAllEntries()) {
    if (!ALLOWED_BAGGAGE_KEYS.has(key)) {
      continue;
    }

    const serializedSize = Buffer.byteLength(key, 'utf8') + Buffer.byteLength(entry.value, 'utf8');
    if (serializedSize > MAX_ENTRY_BYTES || totalSize + serializedSize > MAX_TOTAL_BYTES) {
      continue;
    }

    sanitized = sanitized.setEntry(key, entry);
    totalSize += serializedSize;
  }

  return sanitized;
}

export function safePropagationMiddleware(req: Request, res: Response, next: NextFunction): void {
  const activeCtx = context.active();
  const rawBaggage = propagation.getBaggage(activeCtx);
  
  if (!rawBaggage) {
    return next();
  }

  const boundedBaggage = sanitizeAndBoundBaggage(rawBaggage);
  context.with(propagation.setBaggage(activeCtx, boundedBaggage), () => next());
}
```

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 Bounded Propagation & Trace-State Guardrail

OpenTelemetry W3C Baggage Bounded Propagation & Trace-State Guardrail defines an industrial-grade behavioral standard for devops engineering. Enforces strict payload bounding, key allowlisting, and sanitization for W3C Baggage and tracestate headers across distributed RPC boundaries. Prevents HTTP 431 header bloat outages, distributed denial-of-service vectors, and tenant credential leaks in multi-hop microservice topologies. 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, Unfiltered Baggage Propagation Leading to Header Bloat and Sensitive Data Exfiltration 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, Unfiltered Baggage Propagation Leading to Header Bloat and Sensitive Data ExfiltrationCritical
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 key allowlist before injecting baggage into outgoing carrier headers.

Engineers MUST ALWAYS enforce an explicit key allowlist before injecting baggage into outgoing carrier headers.

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 request query parameters, authorization tokens, or unsanitized user context via W3C Baggage.

Engineers MUST NOT propagate raw request query parameters, authorization tokens, or unsanitized user context via 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.
3

Services MUST enforce strict byte budgets

Services MUST enforce strict byte budgets: maximum 8192 total bytes for the baggage header and 1024 bytes per individual key-value pair.

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

Services MUST drop or redact baggage entries exceeding budget limits rather than allowing HTTP 431 (Request Header Fields Too Large) downstream.

Services MUST drop or redact baggage entries exceeding budget limits rather than allowing HTTP 431 (Request Header Fields Too Large) downstream.

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 mutate or forward unknown tracestate tenant keys across non-trusted perimeter boundaries.

Components NEVER mutate or forward unknown tracestate tenant keys across non-trusted 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.
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 Bounded Propagation & Trace-State Guardrail critical for AI coding assistants?

Enforces strict payload bounding, key allowlisting, and sanitization for W3C Baggage and tracestate headers across distributed RPC boundaries. Prevents HTTP 431 header bloat outages, distributed denial-of-service vectors, and tenant credential leaks in multi-hop microservice topologies. 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, Unfiltered Baggage Propagation Leading to Header Bloat and Sensitive Data Exfiltration) 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