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

OpenTelemetry eBPF Kernel Tracing with W3C TraceContext Invariants

Correlating kernel-level eBPF socket telemetry with distributed W3C TraceContext headers requires strict payload parsing, deterministic tail-latency trace reconstruction, and rigorous synchronization between userspace OpenTelemetry context injection and kprobe/uprobe hooks. Failure to maintain traceparent integrity across TCP/HTTP stream boundaries produces broken distributed traces, unmonitored drop rates, and kernel memory leaks in BPF ring buffers.

Prohibited Anti-Pattern: Blind kernel packet snooping without W3C traceparent protocol boundaries or socket lifecycle correlation

Export Ready-to-Drop Configuration

Select format below to copy code or download file directly.

---
description: OpenTelemetry eBPF Kernel Tracing with W3C TraceContext Invariants - Correlating kernel-level eBPF socket telemetry with distributed W3C TraceContext headers requires strict payload parsing, deterministic tail-latency trace reconstruction, and rigorous synchronization between userspace OpenTelemetry context injection and kprobe/uprobe hooks. Failure to maintain traceparent integrity across TCP/HTTP stream boundaries produces broken distributed traces, unmonitored drop rates, and kernel memory leaks in BPF ring buffers.
globs: src/**/*.{c,h,bpf.c}, pkg/**/*.{go,rs}, services/**/*.{ts,js,py}, k8s/**/*.yaml
alwaysApply: true
verified_by: "agentrules.org"
license: "CC-BY-4.0"
source: "https://agentrules.org/rules/opentelemetry-ebpf-w3c-tracecontext-propagation"
---

# OpenTelemetry eBPF Kernel Tracing with W3C TraceContext Invariants

> **Severity**: CRITICAL | **Category**: devops
> **Anti-Pattern Warning**: Blind kernel packet snooping without W3C traceparent protocol boundaries or socket lifecycle correlation

## System Constraints
You are a Principal Observability and Kernel Systems Architect enforcing industrial-grade OpenTelemetry eBPF auto-instrumentation and W3C TraceContext propagation. Ensure that all socket-level network egress/ingress hooks strictly validate W3C `traceparent` and `tracestate` headers, correlate socket file descriptors with process namespace identifiers (pid/tgid), and guarantee zero-overhead lockless ring buffer streaming without dropping trace linkages or leaking kernel memory.

## Strict Guidelines
- Engineers MUST ALWAYS validate W3C `traceparent` version bytes (version 00: 4-part hex `00-${trace_id}-${span_id}-${trace_flags}`) before correlating kernel socket buffers with user-space telemetry spans.
- Engineers MUST NOT rely solely on raw TCP packet payloads without handling TCP segmentation, streaming reassembly, or TLS uprobe boundaries (e.g., OpenSSL `SSL_write` / `SSL_read` hooks) for HTTPS traffic.
- Code SHOULD maintain bidirectional BPF hash maps keyed by socket cookie (`bpf_get_socket_cookie`) or 5-tuple + PID namespace to prevent thread migration context poisoning.
- Services MUST emit explicit dropped-span telemetry metrics whenever the BPF perf ring buffer or ringbuf returns `-ENOBUFS` or exceeds high-water mark thresholds.
- Components NEVER overwrite active span context or inject synthetic trace IDs inside kernel probes if a valid upstream W3C `traceparent` header already exists in the ingress payload.

## Bad vs Good Implementations
### Correlating W3C Traceparent Header via HTTP Egress and Kernel BPF Event Capture

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: Fails to propagate standard W3C `traceparent` headers. Relies on non-standard headers (`x-request-id`) which prevents the eBPF kernel agent (e.g., inspecting socket buffers at `sys_enter_write` or TLS uprobes) from mapping kernel-level network latency to the distributed trace graph.
```typescript
import { createServer } from 'http';
import axios from 'axios';

// ANTI-PATTERN: Emitting outbound requests without explicit W3C propagation headers
// and discarding socket correlation metadata, forcing eBPF to guess parentage or drop context.
const server = createServer(async (req, res) => {
  try {
    // Outbound HTTP call lacks validated traceparent extraction or propagation
    const upstreamRes = await axios.get('http://inventory-service/items', {
      headers: {
        'x-request-id': req.headers['x-request-id'] || 'fallback-id'
      }
    });
    res.writeHead(200, { 'Content-Type': 'application/json' });
    res.end(JSON.stringify(upstreamRes.data));
  } catch (err) {
    res.writeHead(500);
    res.end(JSON.stringify({ error: (err as Error).message }));
  }
});
server.listen(8080);
```

#### Production Standard (Correct)
> **Standard**: Explicitly extracts and injects standard W3C TraceContext headers (`traceparent`). The kernel eBPF probe can inspect egress packets at the socket buffer layer, accurately read the 16-byte trace_id and 8-byte parent_id, and correlate kernel network performance metrics directly with the active span.
```typescript
import { createServer } from 'http';
import axios from 'axios';
import { trace, context, propagation } from '@opentelemetry/api';

// PRODUCTION FIX: Ensure standard W3C TraceContext is explicitly propagated
// and socket cookies/thread contexts remain deterministic for eBPF uprobe correlation.
const tracer = trace.getTracer('ebpf-compatible-ingress', '1.0.0');

const server = createServer((req, res) => {
  // Extract incoming W3C Context (traceparent / tracestate)
  const activeCtx = propagation.extract(context.active(), req.headers);

  context.with(activeCtx, async () => {
    const span = tracer.startSpan('handle-request');
    try {
      const outboundHeaders: Record<string, string> = {};
      // Inject W3C TraceContext into egress headers (00-{trace_id}-{span_id}-{flags})
      propagation.inject(trace.setSpan(context.active(), span), outboundHeaders);

      const upstreamRes = await axios.get('http://inventory-service/items', {
        headers: outboundHeaders
      });

      span.setStatus({ code: 1 }); // OK
      res.writeHead(200, { 'Content-Type': 'application/json' });
      res.end(JSON.stringify(upstreamRes.data));
    } catch (err) {
      span.recordException(err as Error);
      span.setStatus({ code: 2, message: (err as Error).message }); // ERROR
      res.writeHead(500);
      res.end(JSON.stringify({ error: 'Internal Server Error' }));
    } finally {
      span.end();
    }
  });
});
server.listen(8080);
```

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 eBPF Kernel Tracing with W3C TraceContext Invariants

OpenTelemetry eBPF Kernel Tracing with W3C TraceContext Invariants defines an industrial-grade behavioral standard for devops engineering. Correlating kernel-level eBPF socket telemetry with distributed W3C TraceContext headers requires strict payload parsing, deterministic tail-latency trace reconstruction, and rigorous synchronization between userspace OpenTelemetry context injection and kprobe/uprobe hooks. Failure to maintain traceparent integrity across TCP/HTTP stream boundaries produces broken distributed traces, unmonitored drop rates, and kernel memory leaks in BPF ring buffers. 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: Blind kernel packet snooping without W3C traceparent protocol boundaries or socket lifecycle correlation 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 DriftBlind kernel packet snooping without W3C traceparent protocol boundaries or socket lifecycle correlationCritical
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 validate W3C `traceparent` version bytes (version 00

Engineers MUST ALWAYS validate W3C `traceparent` version bytes (version 00: 4-part hex `00-${trace_id}-${span_id}-${trace_flags}`) before correlating kernel socket buffers with user-space telemetry spans.

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 rely solely on raw TCP packet payloads without handling TCP segmentation, streaming reassembly, or TLS uprobe boundaries (e.g., OpenSSL `SSL_write` / `SSL_read` hooks) for HTTPS traffic.

Engineers MUST NOT rely solely on raw TCP packet payloads without handling TCP segmentation, streaming reassembly, or TLS uprobe boundaries (e.g., OpenSSL `SSL_write` / `SSL_read` hooks) for HTTPS traffic.

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 maintain bidirectional BPF hash maps keyed by socket cookie (`bpf_get_socket_cookie`) or 5-tuple + PID namespace to prevent thread migration context poisoning.

Code SHOULD maintain bidirectional BPF hash maps keyed by socket cookie (`bpf_get_socket_cookie`) or 5-tuple + PID namespace to prevent thread migration context poisoning.

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 emit explicit dropped-span telemetry metrics whenever the BPF perf ring buffer or ringbuf returns `-ENOBUFS` or exceeds high-water mark thresholds.

Services MUST emit explicit dropped-span telemetry metrics whenever the BPF perf ring buffer or ringbuf returns `-ENOBUFS` or exceeds high-water mark thresholds.

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 overwrite active span context or inject synthetic trace IDs inside kernel probes if a valid upstream W3C `traceparent` header already exists in the ingress payload.

Components NEVER overwrite active span context or inject synthetic trace IDs inside kernel probes if a valid upstream W3C `traceparent` header already exists in the ingress payload.

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 eBPF Kernel Tracing with W3C TraceContext Invariants critical for AI coding assistants?

Correlating kernel-level eBPF socket telemetry with distributed W3C TraceContext headers requires strict payload parsing, deterministic tail-latency trace reconstruction, and rigorous synchronization between userspace OpenTelemetry context injection and kprobe/uprobe hooks. Failure to maintain traceparent integrity across TCP/HTTP stream boundaries produces broken distributed traces, unmonitored drop rates, and kernel memory leaks in BPF ring buffers. 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 (Blind kernel packet snooping without W3C traceparent protocol boundaries or socket lifecycle correlation) 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