This specification is maintained by the AgentRules Working Group. Have enhancements or want to claim maintainership?Submit Specification →
devopscritical PriorityID: otel-baggage-mutation-memory-quarantine

OpenTelemetry 1.35 W3C Baggage Mutation & Memory Quarantine Standard

Enforces strict bounds, allowlists, and memory quarantine on OpenTelemetry W3C Baggage propagation to eliminate distributed telemetry egress amplification and span memory exhaustion. Prevents unbounded downstream header cascade by enforcing key-length ceilings, total byte budgets, and non-mutating context propagation invariants across distributed spans.

Prohibited Anti-Pattern: Unconstrained baggage mutation and forwarding causing W3C header bloat, trace context exhaustion, and downstream egress amplification attacks.

Export Ready-to-Drop Configuration

Select format below to copy code or download file directly.

---
description: OpenTelemetry 1.35 W3C Baggage Mutation & Memory Quarantine Standard - Enforces strict bounds, allowlists, and memory quarantine on OpenTelemetry W3C Baggage propagation to eliminate distributed telemetry egress amplification and span memory exhaustion. Prevents unbounded downstream header cascade by enforcing key-length ceilings, total byte budgets, and non-mutating context propagation invariants across distributed spans.
globs: src/**/telemetry/**/*.{ts,js}, src/**/tracing/**/*.{ts,js}, src/**/middleware/**/*.{ts,js}, src/**/http/**/*.{ts,js}
alwaysApply: true
verified_by: "agentrules.org"
license: "CC-BY-4.0"
source: "https://agentrules.org/rules/otel-baggage-mutation-memory-quarantine"
---

# OpenTelemetry 1.35 W3C Baggage Mutation & Memory Quarantine Standard

> **Severity**: CRITICAL | **Category**: devops
> **Anti-Pattern Warning**: Unconstrained baggage mutation and forwarding causing W3C header bloat, trace context exhaustion, and downstream egress amplification attacks.

## System Constraints
You are a Principal Observability Architect enforcing the OpenTelemetry 1.35 W3C Baggage Mutation & Memory Quarantine Standard. You must reject any code that directly mutates baggage without sanitization, attaches arbitrary runtime metadata to active propagation baggage, or relays inbound baggage headers downstream without strict allowlisting and byte-budget validation.

## Strict Guidelines
- Engineers MUST ALWAYS enforce strict allowlists for W3C Baggage keys before propagation across service boundaries.
- Engineers MUST NOT copy raw HTTP request headers or unsanitized payloads directly into OpenTelemetry Baggage entries.
- Code SHOULD enforce an absolute ceiling of 8192 bytes for total baggage payload and reject entries exceeding 256 bytes per key or 2048 bytes per value.
- Services MUST quarantine incoming baggage by creating an immutable, filtered Baggage instance prior to binding it to the active trace context.
- Components NEVER re-export unverified, externally supplied baggage to downstream HTTP, gRPC, or messaging clients.

## Bad vs Good Implementations
### Unbounded Inbound Baggage Relaying vs. Quarantined Allowlist Propagation

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: Directly attaching arbitrary inbound headers to baggage causes unbounded header growth across microservices. This leads to HTTP 431 (Request Header Fields Too Large) downstream errors, memory exhaustion in span context tracking, and opens egress amplification vectors.
```typescript
import { propagation, context, BaggageEntry } from '@opentelemetry/api';
import { Request, Response, NextFunction } from 'express';

export function telemetryMiddleware(req: Request, res: Response, next: NextFunction): void {
  // Anti-pattern: Extracts arbitrary upstream baggage and binds it directly without limits
  const extractedContext = propagation.extract(context.active(), req.headers);
  let currentBaggage = propagation.getBaggage(extractedContext) ?? propagation.createBaggage();

  // Unbounded mutation: dynamically appends request payloads and user-agent into baggage
  for (const [key, value] of Object.entries(req.headers)) {
    if (typeof value === 'string') {
      currentBaggage = currentBaggage.setEntry(key, { value });
    }
  }

  // Propagates bloated, unvalidated baggage down the entire distributed call chain
  const mutatedContext = propagation.setBaggage(extractedContext, currentBaggage);
  context.with(mutatedContext, () => {
    next();
  });
}
```

#### Production Standard (Correct)
> **Standard**: Implements an explicit quarantine step that validates inbound baggage against an allowlist, strictly restricts per-entry byte boundaries, and caps total payload size at 8KB, preventing egress amplification and span memory bloat.
```typescript
import { propagation, context, Baggage, BaggageEntry } from '@opentelemetry/api';
import { Request, Response, NextFunction } from 'express';

const ALLOWED_BAGGAGE_KEYS = new Set(['tenant.id', 'routing.tier', 'feature_flag.cohort']);
const MAX_TOTAL_BYTES = 8192;
const MAX_KEY_BYTES = 256;
const MAX_VALUE_BYTES = 2048;

function sanitizeBaggage(incoming: Baggage | undefined): Baggage {
  let cleanBaggage = propagation.createBaggage();
  if (!incoming) return cleanBaggage;

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

    const keyBytes = Buffer.byteLength(key, 'utf8');
    const valBytes = Buffer.byteLength(entry.value, 'utf8');

    if (keyBytes > MAX_KEY_BYTES || valBytes > MAX_VALUE_BYTES) continue;
    if (totalBytes + keyBytes + valBytes > MAX_TOTAL_BYTES) break;

    cleanBaggage = cleanBaggage.setEntry(key, { value: entry.value });
    totalBytes += keyBytes + valBytes;
  }

  return cleanBaggage;
}

export function telemetryMiddleware(req: Request, res: Response, next: NextFunction): void {
  const extractedContext = propagation.extract(context.active(), req.headers);
  const rawBaggage = propagation.getBaggage(extractedContext);
  const quarantinedBaggage = sanitizeBaggage(rawBaggage);

  const safeContext = propagation.setBaggage(extractedContext, quarantinedBaggage);
  context.with(safeContext, () => {
    next();
  });
}
```

Recommended Agent Skills (askills.dev)

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

Architectural Specification & Invariant Rationale

Architectural Invariant Design: OpenTelemetry 1.35 W3C Baggage Mutation & Memory Quarantine Standard

OpenTelemetry 1.35 W3C Baggage Mutation & Memory Quarantine Standard defines an industrial-grade behavioral standard for devops engineering. Enforces strict bounds, allowlists, and memory quarantine on OpenTelemetry W3C Baggage propagation to eliminate distributed telemetry egress amplification and span memory exhaustion. Prevents unbounded downstream header cascade by enforcing key-length ceilings, total byte budgets, and non-mutating context propagation invariants across distributed spans. 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: Unconstrained baggage mutation and forwarding causing W3C header bloat, trace context exhaustion, and downstream egress amplification attacks. 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 DriftUnconstrained baggage mutation and forwarding causing W3C header bloat, trace context exhaustion, and downstream egress amplification attacks.Critical
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 strict allowlists for W3C Baggage keys before propagation across service boundaries.

Engineers MUST ALWAYS enforce strict allowlists for W3C Baggage keys before propagation 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.
2

Engineers MUST NOT copy raw HTTP request headers or unsanitized payloads directly into OpenTelemetry Baggage entries.

Engineers MUST NOT copy raw HTTP request headers or unsanitized payloads directly into OpenTelemetry 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

Code SHOULD enforce an absolute ceiling of 8192 bytes for total baggage payload and reject entries exceeding 256 bytes per key or 2048 bytes per value.

Code SHOULD enforce an absolute ceiling of 8192 bytes for total baggage payload and reject entries exceeding 256 bytes per key or 2048 bytes per value.

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 quarantine incoming baggage by creating an immutable, filtered Baggage instance prior to binding it to the active trace context.

Services MUST quarantine incoming baggage by creating an immutable, filtered Baggage instance prior to binding it to the active trace context.

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 re-export unverified, externally supplied baggage to downstream HTTP, gRPC, or messaging clients.

Components NEVER re-export unverified, externally supplied baggage to downstream HTTP, gRPC, or messaging clients.

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 1.35 W3C Baggage Mutation & Memory Quarantine Standard critical for AI coding assistants?

Enforces strict bounds, allowlists, and memory quarantine on OpenTelemetry W3C Baggage propagation to eliminate distributed telemetry egress amplification and span memory exhaustion. Prevents unbounded downstream header cascade by enforcing key-length ceilings, total byte budgets, and non-mutating context propagation invariants across distributed spans. 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 (Unconstrained baggage mutation and forwarding causing W3C header bloat, trace context exhaustion, and downstream egress amplification attacks.) 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