This specification is maintained by the AgentRules Working Group. Have enhancements or want to claim maintainership?Submit Specification →
devopscritical PriorityID: otel-spanprocessor-nonblocking-ringbuffer-standard

OpenTelemetry Non-Blocking Drop-Tail SpanProcessor Invariant

Enforces strict lock-free, drop-tail batch processing invariants across OpenTelemetry tracing pipelines. Ensures tracing overhead and collector backpressure can never cascade into critical execution paths, block worker event loops, or degrade primary request throughput.

Prohibited Anti-Pattern: Synchronous Backpressure Propagation and Unbounded Buffering in Observability Exporters

Export Ready-to-Drop Configuration

Select format below to copy code or download file directly.

---
description: OpenTelemetry Non-Blocking Drop-Tail SpanProcessor Invariant - Enforces strict lock-free, drop-tail batch processing invariants across OpenTelemetry tracing pipelines. Ensures tracing overhead and collector backpressure can never cascade into critical execution paths, block worker event loops, or degrade primary request throughput.
globs: src/**/tracing.{ts,js}, src/**/telemetry.{ts,js}, src/**/instrumentation.{ts,js}, src/**/*span-processor*.{ts,js}
alwaysApply: true
verified_by: "agentrules.org"
license: "CC-BY-4.0"
source: "https://agentrules.org/rules/otel-spanprocessor-nonblocking-ringbuffer-standard"
---

# OpenTelemetry Non-Blocking Drop-Tail SpanProcessor Invariant

> **Severity**: CRITICAL | **Category**: devops
> **Anti-Pattern Warning**: Synchronous Backpressure Propagation and Unbounded Buffering in Observability Exporters

## System Constraints
You are a Principal Software Architect enforcing production reliability standards for distributed observability. You must mandate that all OpenTelemetry SpanProcessor configurations use bounded, non-blocking ring buffers with explicit drop-tail or drop-oldest policies. Tracing pipeline saturation must never block the application event loop, exhaust memory, or introduce latency into customer-facing transactions.

## Strict Guidelines
- Engineers MUST ALWAYS configure BatchSpanProcessor with explicit bounded capacity (`maxQueueSize`) and batch export thresholds (`maxExportBatchSize`).
- Engineers MUST NOT use synchronous `SimpleSpanProcessor` in production environments or any processor that blocks the execution thread during span export.
- Services MUST implement non-blocking drop-tail or drop-oldest semantics when span queue limits are reached, immediately shedding telemetry under downstream load.
- Engineers MUST configure Prometheus or OpenTelemetry runtime counters to track dropped span counts (`telemetry.spans.dropped`) whenever buffer overruns occur.
- Code MUST export telemetry asynchronously on an unblocked schedule and enforce strict timeout boundaries (`exportTimeoutMillis`) on collector calls.
- Components NEVER await telemetry export operations within primary request handler paths or middleware lifecycles.

## Bad vs Good Implementations
### Unbounded / Blocking Span Processor vs Non-Blocking RingBuffer Configuration

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: SimpleSpanProcessor exports synchronously upon span end, causing network round-trips to execute in-band with critical customer request paths. Under network degradation or collector outages, application threads become blocked.
```typescript
import { NodeSDK } from '@opentelemetry/sdk-node';
import { SimpleSpanProcessor, ConsoleSpanExporter } from '@opentelemetry/sdk-trace-base';
import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-http';

// ANTI-PATTERN: SimpleSpanProcessor blocks the event loop on each span export.
// If the OTLP trace collector encounters latency, customer requests will stall.
const sdk = new NodeSDK({
  spanProcessor: new SimpleSpanProcessor(new OTLPTraceExporter({
    url: 'http://collector.monitoring.svc:4318/v1/traces',
    // No timeout configured; defaults can lead to socket hangs
  })),
});

sdk.start();
```

#### Production Standard (Correct)
> **Standard**: BatchSpanProcessor decouples span creation from network transport using an internal bounded queue. When maxQueueSize is breached, incoming spans are dropped non-blocking, preserving application latency.
```typescript
import { NodeSDK } from '@opentelemetry/sdk-node';
import { BatchSpanProcessor } from '@opentelemetry/sdk-trace-base';
import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-http';
import { diag, DiagConsoleLogger, DiagLogLevel } from '@opentelemetry/api';

diag.setLogger(new DiagConsoleLogger(), DiagLogLevel.WARN);

const exporter = new OTLPTraceExporter({
  url: process.env.OTEL_EXPORTER_OTLP_ENDPOINT || 'http://collector.monitoring.svc:4318/v1/traces',
  timeoutMillis: 1500, // Hard ceiling prevents socket leaks
});

// PRODUCTION STANDARD: Bounded, non-blocking batch processor with drop-tail semantics
const spanProcessor = new BatchSpanProcessor(exporter, {
  maxQueueSize: 2048,          // Hard queue limit: excess spans are dropped (drop-tail)
  maxExportBatchSize: 512,      // Flush batch size
  scheduledDelayMillis: 1000,   // Flush frequency
  exportTimeoutMillis: 1500,    // Guard against downstream backpressure
});

const sdk = new NodeSDK({
  spanProcessor,
});

sdk.start();
```

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 Non-Blocking Drop-Tail SpanProcessor Invariant

OpenTelemetry Non-Blocking Drop-Tail SpanProcessor Invariant defines an industrial-grade behavioral standard for devops engineering. Enforces strict lock-free, drop-tail batch processing invariants across OpenTelemetry tracing pipelines. Ensures tracing overhead and collector backpressure can never cascade into critical execution paths, block worker event loops, or degrade primary request throughput. 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: Synchronous Backpressure Propagation and Unbounded Buffering in Observability Exporters 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 DriftSynchronous Backpressure Propagation and Unbounded Buffering in Observability ExportersCritical
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 configure BatchSpanProcessor with explicit bounded capacity (`maxQueueSize`) and batch export thresholds (`maxExportBatchSize`).

Engineers MUST ALWAYS configure BatchSpanProcessor with explicit bounded capacity (`maxQueueSize`) and batch export thresholds (`maxExportBatchSize`).

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 use synchronous `SimpleSpanProcessor` in production environments or any processor that blocks the execution thread during span export.

Engineers MUST NOT use synchronous `SimpleSpanProcessor` in production environments or any processor that blocks the execution thread during span export.

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 implement non-blocking drop-tail or drop-oldest semantics when span queue limits are reached, immediately shedding telemetry under downstream load.

Services MUST implement non-blocking drop-tail or drop-oldest semantics when span queue limits are reached, immediately shedding telemetry under downstream load.

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

Engineers MUST configure Prometheus or OpenTelemetry runtime counters to track dropped span counts (`telemetry.spans.dropped`) whenever buffer overruns occur.

Engineers MUST configure Prometheus or OpenTelemetry runtime counters to track dropped span counts (`telemetry.spans.dropped`) whenever buffer overruns occur.

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

Code MUST export telemetry asynchronously on an unblocked schedule and enforce strict timeout boundaries (`exportTimeoutMillis`) on collector calls.

Code MUST export telemetry asynchronously on an unblocked schedule and enforce strict timeout boundaries (`exportTimeoutMillis`) on collector calls.

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.
6

Components NEVER await telemetry export operations within primary request handler paths or middleware lifecycles.

Components NEVER await telemetry export operations within primary request handler paths or middleware lifecycles.

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 Non-Blocking Drop-Tail SpanProcessor Invariant critical for AI coding assistants?

Enforces strict lock-free, drop-tail batch processing invariants across OpenTelemetry tracing pipelines. Ensures tracing overhead and collector backpressure can never cascade into critical execution paths, block worker event loops, or degrade primary request throughput. 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 (Synchronous Backpressure Propagation and Unbounded Buffering in Observability Exporters) 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