This specification is maintained by the AgentRules Working Group. Have enhancements or want to claim maintainership?Submit Specification →
devopscritical PriorityID: opentelemetry-ebpf-profiling-span-association-standard

OpenTelemetry eBPF Continuous Profiling Span Trace Association Standard

Kernel-level eBPF continuous wall-clock and CPU profiling agents must correlate raw stack traces with active OpenTelemetry TraceID and SpanID contexts. Applications must maintain deterministic thread-level or fiber-level span markers in memory-accessible registers or thread-local storage to guarantee sub-millisecond CPU and lock-contention hot-path attribution.

Prohibited Anti-Pattern: Decoupled Statistical eBPF Profiling Without Correlated Active Span Identifiers

Export Ready-to-Drop Configuration

Select format below to copy code or download file directly.

---
description: OpenTelemetry eBPF Continuous Profiling Span Trace Association Standard - Kernel-level eBPF continuous wall-clock and CPU profiling agents must correlate raw stack traces with active OpenTelemetry TraceID and SpanID contexts. Applications must maintain deterministic thread-level or fiber-level span markers in memory-accessible registers or thread-local storage to guarantee sub-millisecond CPU and lock-contention hot-path attribution.
globs: src/**/*.{ts,js,go,rs,cpp,c}, deploy/**/*.{yaml,json}, k8s/**/*.{yaml,json}
alwaysApply: true
verified_by: "agentrules.org"
license: "CC-BY-4.0"
source: "https://agentrules.org/rules/opentelemetry-ebpf-profiling-span-association-standard"
---

# OpenTelemetry eBPF Continuous Profiling Span Trace Association Standard

> **Severity**: CRITICAL | **Category**: devops
> **Anti-Pattern Warning**: Decoupled Statistical eBPF Profiling Without Correlated Active Span Identifiers

## System Constraints
You are a Principal Observability and Systems Architect enforcing OpenTelemetry Continuous Profiling eBPF Stack Trace Association Standards. You must mandate that all application runtimes expose synchronized span contexts to kernel-space eBPF profilers and prohibit uncoordinated statistical profiling.

## Strict Guidelines
- Engineers MUST ALWAYS expose active OpenTelemetry TraceID and SpanID contexts to runtime thread-local storage (TLS) or user-space statically defined tracing (USDT) probe points accessible by eBPF maps.
- Engineers MUST NOT rely on coarse temporal alignment (heuristic timestamp range overlap) between APM spans and pprof-style CPU profiles, as it fails in concurrent sub-millisecond execution.
- Code SHOULD propagate span contexts across asynchronous task boundaries using context managers to prevent eBPF samplers from attributing stack frames to stale or parent span IDs.
- Services MUST preserve frame pointers (-fno-omit-frame-pointer) or publish accessible DWARF/symbol tables so the eBPF unwinder can map raw instruction pointers to symbolized application functions.
- Deployments MUST mount required kernel subsystems (/sys/kernel/debug, /sys/fs/cgroup) and restrict eBPF collector privileges strictly to CAP_BPF, CAP_PERFMON, and CAP_SYS_PTRACE rather than root privileged mode.

## Bad vs Good Implementations
### Thread-Level Span Context Propagation for eBPF Profiler Inspection

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: The span runs asynchronously in user space without projecting its TraceID and SpanID into a native memory segment or runtime hook. The eBPF profiler captures kernel/native CPU samples without span association, requiring probabilistic timestamp post-processing that fails for sub-millisecond hot paths.
```typescript
import { trace } from '@opentelemetry/api';

// ANTI-PATTERN: Executing compute-intensive hot paths inside spans without
// synchronizing the active Span ID to native thread-local storage (TLS)
// or an eBPF-accessible USDT probe buffer.
export async function processBatch(items: Array<Buffer>): Promise<void> {
  const tracer = trace.getTracer('worker');
  return tracer.startActiveSpan('processBatch', async (span) => {
    try {
      for (const item of items) {
        // eBPF perf_event_open CPU interrupts sample this frame,
        // but the kernel profiler has zero visibility into the Node.js V8
        // heap context, leading to orphaned, unassociated stack traces.
        cryptoIntensiveHash(item);
      }
    } finally {
      span.end();
    }
  });
}

function cryptoIntensiveHash(data: Buffer): void {
  // Intensive computation detached from kernel trace awareness
}
```

#### Production Standard (Correct)
> **Standard**: By explicitly syncing the OpenTelemetry TraceID and SpanID to native thread-local storage via an optimized binding, the eBPF kernel sampler extracts the exact span identifier during perf interrupts, enabling deterministic sub-millisecond hot-path identification.
```typescript
import { trace, SpanContext } from '@opentelemetry/api';
import nativeProfilerHook from 'native-ebpf-otel-binding';

// PRODUCTION FIX: Register active span context into native thread memory
// where eBPF probe maps (uprobes/USDT) can atomically read TraceID/SpanID on every sample.
export async function processBatch(items: Array<Buffer>): Promise<void> {
  const tracer = trace.getTracer('worker');
  return tracer.startActiveSpan('processBatch', async (span) => {
    const context: SpanContext = span.spanContext();
    
    // Atomically write TraceID and SpanID to current OS Thread Local Storage (TLS)
    // readable by the eBPF perf_event handler on CPU schedule interrupts.
    nativeProfilerHook.setThreadSpanContext(context.traceId, context.spanId);
    
    try {
      for (const item of items) {
        cryptoIntensiveHash(item);
      }
    } finally {
      nativeProfilerHook.clearThreadSpanContext();
      span.end();
    }
  });
}

function cryptoIntensiveHash(data: Buffer): void {
  // Deterministically associated with the active span inside eBPF trace aggregations
}
```

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 Continuous Profiling Span Trace Association Standard

OpenTelemetry eBPF Continuous Profiling Span Trace Association Standard defines an industrial-grade behavioral standard for devops engineering. Kernel-level eBPF continuous wall-clock and CPU profiling agents must correlate raw stack traces with active OpenTelemetry TraceID and SpanID contexts. Applications must maintain deterministic thread-level or fiber-level span markers in memory-accessible registers or thread-local storage to guarantee sub-millisecond CPU and lock-contention hot-path attribution. 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: Decoupled Statistical eBPF Profiling Without Correlated Active Span Identifiers 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 DriftDecoupled Statistical eBPF Profiling Without Correlated Active Span IdentifiersCritical
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 expose active OpenTelemetry TraceID and SpanID contexts to runtime thread-local storage (TLS) or user-space statically defined tracing (USDT) probe points accessible by eBPF maps.

Engineers MUST ALWAYS expose active OpenTelemetry TraceID and SpanID contexts to runtime thread-local storage (TLS) or user-space statically defined tracing (USDT) probe points accessible by eBPF maps.

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 on coarse temporal alignment (heuristic timestamp range overlap) between APM spans and pprof-style CPU profiles, as it fails in concurrent sub-millisecond execution.

Engineers MUST NOT rely on coarse temporal alignment (heuristic timestamp range overlap) between APM spans and pprof-style CPU profiles, as it fails in concurrent sub-millisecond execution.

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 propagate span contexts across asynchronous task boundaries using context managers to prevent eBPF samplers from attributing stack frames to stale or parent span IDs.

Code SHOULD propagate span contexts across asynchronous task boundaries using context managers to prevent eBPF samplers from attributing stack frames to stale or parent span IDs.

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 preserve frame pointers (-fno-omit-frame-pointer) or publish accessible DWARF/symbol tables so the eBPF unwinder can map raw instruction pointers to symbolized application functions.

Services MUST preserve frame pointers (-fno-omit-frame-pointer) or publish accessible DWARF/symbol tables so the eBPF unwinder can map raw instruction pointers to symbolized application functions.

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

Deployments MUST mount required kernel subsystems (/sys/kernel/debug, /sys/fs/cgroup) and restrict eBPF collector privileges strictly to CAP_BPF, CAP_PERFMON, and CAP_SYS_PTRACE rather than root privileged mode.

Deployments MUST mount required kernel subsystems (/sys/kernel/debug, /sys/fs/cgroup) and restrict eBPF collector privileges strictly to CAP_BPF, CAP_PERFMON, and CAP_SYS_PTRACE rather than root privileged mode.

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 Continuous Profiling Span Trace Association Standard critical for AI coding assistants?

Kernel-level eBPF continuous wall-clock and CPU profiling agents must correlate raw stack traces with active OpenTelemetry TraceID and SpanID contexts. Applications must maintain deterministic thread-level or fiber-level span markers in memory-accessible registers or thread-local storage to guarantee sub-millisecond CPU and lock-contention hot-path attribution. 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 (Decoupled Statistical eBPF Profiling Without Correlated Active Span Identifiers) 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