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

OpenTelemetry WasmEdge Distributed Baggage Propagation Standard

Enforces deterministic extraction, propagation, and mutation of W3C TraceContext and Baggage across ephemeral WebAssembly (WasmEdge) runtime boundaries. Prevents telemetry dropping and eliminates cold-start latency amplification caused by heavy in-guest SDK initialization.

Prohibited Anti-Pattern: Instantiating Full In-Memory OTel SDKs and Dropping Baggage Across Ephemeral WASI Host-Guest Boundaries

Export Ready-to-Drop Configuration

Select format below to copy code or download file directly.

---
description: OpenTelemetry WasmEdge Distributed Baggage Propagation Standard - Enforces deterministic extraction, propagation, and mutation of W3C TraceContext and Baggage across ephemeral WebAssembly (WasmEdge) runtime boundaries. Prevents telemetry dropping and eliminates cold-start latency amplification caused by heavy in-guest SDK initialization.
globs: src/**/*.{ts,tsx,js,mjs}, edge/**/*.{ts,js}, runtime/**/*.{ts,js}
alwaysApply: true
verified_by: "agentrules.org"
license: "CC-BY-4.0"
source: "https://agentrules.org/rules/opentelemetry-wasmedge-baggage-propagation-standard"
---

# OpenTelemetry WasmEdge Distributed Baggage Propagation Standard

> **Severity**: CRITICAL | **Category**: devops
> **Anti-Pattern Warning**: Instantiating Full In-Memory OTel SDKs and Dropping Baggage Across Ephemeral WASI Host-Guest Boundaries

## System Constraints
You are a Principal Engineer and Telemetry Architect enforcing the OpenTelemetry WasmEdge Baggage Propagation Standard. Ephemeral WebAssembly instances must not instantiate full-blown OpenTelemetry SDKs, dynamic span processors, or blocking network exporters on the guest side. Instead, edge modules MUST parse and inject W3C traceparent and baggage headers via zero-allocation fast-path utilities, and offload span processing to the WasmEdge host runtime using native ABI bindings.

## Strict Guidelines
- Engineers MUST ALWAYS extract incoming 'traceparent', 'tracestate', and 'baggage' headers immediately upon entry into the WasmEdge guest environment.
- Engineers MUST NOT initialize heavy OpenTelemetry SDK components (e.g., NodeSDK, BatchSpanProcessor with HTTP/gRPC exporters) inside guest WASM modules.
- Code SHOULD mutate distributed baggage using immutable record structures that serialize strictly according to RFC 7230 and W3C Baggage specifications.
- Services MUST forward both 'traceparent' and 'baggage' headers down all outbound HTTP/gRPC egress calls made through the WasmEdge host networking interface.
- Components NEVER drop unknown baggage key-value properties or strip metadata qualifiers during guest-to-host execution transitions.

## Bad vs Good Implementations
### WasmEdge Edge Function Trace Context & Baggage Handling

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: Initializing full NodeSDK instances inside ephemeral WasmEdge invocations introduces massive cold-start penalties and memory bloat. Furthermore, explicitly filtering only 'traceparent' strips the W3C 'baggage' header, severing distributed context and tenant correlation across the edge boundary.
```typescript
// BAD: Instantiating full OTel SDK inside ephemeral WASM guest and dropping baggage during downstream fetch
import { NodeSDK } from '@opentelemetry/sdk-node';
import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-http';

export async function handleRequest(request: Request): Promise<Response> {
  // Anti-Pattern: Re-initializing SDK inside ephemeral WasmEdge guest incurs 100ms+ cold start
  const sdk = new NodeSDK({
    traceExporter: new OTLPTraceExporter({ url: 'http://collector:4318/v1/traces' }),
  });
  await sdk.start();

  // Anti-Pattern: Only copying traceparent while dropping distributed baggage metadata
  const traceparent = request.headers.get('traceparent');
  
  const outboundHeaders = new Headers();
  if (traceparent) {
    outboundHeaders.set('traceparent', traceparent);
  }
  
  // Baggage is omitted; context propagation broken across edge hop
  const response = await fetch('https://downstream-service/api', {
    headers: outboundHeaders
  });
  
  await sdk.shutdown();
  return response;
}
```

#### Production Standard (Correct)
> **Standard**: Avoids in-guest SDK initialization completely, eliminating cold-start latency. Correctly parses, preserves, and appends distributed baggage according to W3C specifications, guaranteeing seamless telemetry propagation through WasmEdge into downstream infrastructure.
```typescript
// GOOD: Zero-dependency W3C propagation leveraging immutable baggage and host-delegated telemetry
interface W3CTelemetryContext {
  traceparent: string | null;
  tracestate: string | null;
  baggage: Map<string, string>;
}

function parseBaggage(rawBaggage: string | null): Map<string, string> {
  const baggageMap = new Map<string, string>();
  if (!rawBaggage) return baggageMap;

  for (const pair of rawBaggage.split(',')) {
    const [entry] = pair.split(';'); // Strip baggage properties for mutation
    const eqIdx = entry.indexOf('=');
    if (eqIdx > 0) {
      const key = decodeURIComponent(entry.slice(0, eqIdx).trim());
      const value = decodeURIComponent(entry.slice(eqIdx + 1).trim());
      baggageMap.set(key, value);
    }
  }
  return baggageMap;
}

function serializeBaggage(baggageMap: Map<string, string>): string {
  const entries: string[] = [];
  for (const [key, value] of baggageMap.entries()) {
    entries.push(`${encodeURIComponent(key)}=${encodeURIComponent(value)}`);
  }
  return entries.join(',');
}

export async function handleRequest(request: Request): Promise<Response> {
  // Fast, zero-SDK extraction of W3C TraceContext and Baggage
  const context: W3CTelemetryContext = {
    traceparent: request.headers.get('traceparent'),
    tracestate: request.headers.get('tracestate'),
    baggage: parseBaggage(request.headers.get('baggage')),
  };

  // Mutate or append contextual edge metadata
  context.baggage.set('edge.node.runtime', 'wasmedge');

  const outboundHeaders = new Headers(request.headers);
  if (context.traceparent) {
    outboundHeaders.set('traceparent', context.traceparent);
  }
  if (context.tracestate) {
    outboundHeaders.set('tracestate', context.tracestate);
  }
  outboundHeaders.set('baggage', serializeBaggage(context.baggage));

  // Outbound call preserves full context chain without network overhead or cold-start penalties
  return await fetch('https://downstream-service/api', {
    headers: outboundHeaders
  });
}
```

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 WasmEdge Distributed Baggage Propagation Standard

OpenTelemetry WasmEdge Distributed Baggage Propagation Standard defines an industrial-grade behavioral standard for devops engineering. Enforces deterministic extraction, propagation, and mutation of W3C TraceContext and Baggage across ephemeral WebAssembly (WasmEdge) runtime boundaries. Prevents telemetry dropping and eliminates cold-start latency amplification caused by heavy in-guest SDK initialization. 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: Instantiating Full In-Memory OTel SDKs and Dropping Baggage Across Ephemeral WASI Host-Guest Boundaries 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 DriftInstantiating Full In-Memory OTel SDKs and Dropping Baggage Across Ephemeral WASI Host-Guest BoundariesCritical
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 extract incoming 'traceparent', 'tracestate', and 'baggage' headers immediately upon entry into the WasmEdge guest environment.

Engineers MUST ALWAYS extract incoming 'traceparent', 'tracestate', and 'baggage' headers immediately upon entry into the WasmEdge guest environment.

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 initialize heavy OpenTelemetry SDK components (e.g., NodeSDK, BatchSpanProcessor with HTTP/gRPC exporters) inside guest WASM modules.

Engineers MUST NOT initialize heavy OpenTelemetry SDK components (e.g., NodeSDK, BatchSpanProcessor with HTTP/gRPC exporters) inside guest WASM modules.

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 mutate distributed baggage using immutable record structures that serialize strictly according to RFC 7230 and W3C Baggage specifications.

Code SHOULD mutate distributed baggage using immutable record structures that serialize strictly according to RFC 7230 and W3C Baggage specifications.

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 forward both 'traceparent' and 'baggage' headers down all outbound HTTP/gRPC egress calls made through the WasmEdge host networking interface.

Services MUST forward both 'traceparent' and 'baggage' headers down all outbound HTTP/gRPC egress calls made through the WasmEdge host networking interface.

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 drop unknown baggage key-value properties or strip metadata qualifiers during guest-to-host execution transitions.

Components NEVER drop unknown baggage key-value properties or strip metadata qualifiers during guest-to-host execution transitions.

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 WasmEdge Distributed Baggage Propagation Standard critical for AI coding assistants?

Enforces deterministic extraction, propagation, and mutation of W3C TraceContext and Baggage across ephemeral WebAssembly (WasmEdge) runtime boundaries. Prevents telemetry dropping and eliminates cold-start latency amplification caused by heavy in-guest SDK initialization. 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 (Instantiating Full In-Memory OTel SDKs and Dropping Baggage Across Ephemeral WASI Host-Guest Boundaries) 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