This specification is maintained by the AgentRules Working Group. Have enhancements or want to claim maintainership?Submit Specification →
devopscritical PriorityID: opentelemetry-otlp-exporter-nonblocking-ring-buffer-backpressure-dropping-standard

OpenTelemetry OTLP Exporter Non-Blocking Ring Buffer and Backpressure Dropping Standard

Enforces strict bounding on OpenTelemetry BatchSpanProcessor and BatchLogRecordProcessor queues to eliminate memory leaks and event loop starvation during upstream collector latency or outages. Invariants require explicit bounded queue size ceilings, strict export timeouts, non-blocking telemetry generation, and observable drop counters. Telemetry generation must never degrade primary business logic availability or latency.

Prohibited Anti-Pattern: Unbounded or Blocking Telemetry Export Causing Host Out-Of-Memory Crashes and Event Loop Starvation

Export Ready-to-Drop Configuration

Select format below to copy code or download file directly.

---
description: OpenTelemetry OTLP Exporter Non-Blocking Ring Buffer and Backpressure Dropping Standard - Enforces strict bounding on OpenTelemetry BatchSpanProcessor and BatchLogRecordProcessor queues to eliminate memory leaks and event loop starvation during upstream collector latency or outages. Invariants require explicit bounded queue size ceilings, strict export timeouts, non-blocking telemetry generation, and observable drop counters. Telemetry generation must never degrade primary business logic availability or latency.
globs: src/**/tracing.{ts,js}, src/**/telemetry.{ts,js}, src/**/instrumentation.{ts,js}, src/**/otel.{ts,js}, src/**/logger.{ts,js}
alwaysApply: true
verified_by: "agentrules.org"
license: "CC-BY-4.0"
source: "https://agentrules.org/rules/opentelemetry-otlp-exporter-nonblocking-ring-buffer-backpressure-dropping-standard"
---

# OpenTelemetry OTLP Exporter Non-Blocking Ring Buffer and Backpressure Dropping Standard

> **Severity**: CRITICAL | **Category**: devops
> **Anti-Pattern Warning**: Unbounded or Blocking Telemetry Export Causing Host Out-Of-Memory Crashes and Event Loop Starvation

## System Constraints
You are a Principal Software Architect enforcing production-grade resilience standards for OpenTelemetry exports. You must prevent telemetry infrastructure from exhausting application memory or blocking asynchronous event loops when upstream OTLP endpoints become unresponsive. Ensure all BatchSpanProcessor and BatchLogRecordProcessor instances configure explicit maxQueueSize, maxExportBatchSize, exportTimeoutMillis, and scheduledDelayMillis invariants. Prohibit blocking I/O calls within telemetry generation pipelines, reject unbounded internal buffering, and mandate counter instrumentation for dropped spans and logs.

## Strict Guidelines
- Services MUST ALWAYS configure explicit limits for `maxQueueSize` and `maxExportBatchSize` on `BatchSpanProcessor` and `BatchLogRecordProcessor`; relying on unbounded or excessively large default queues is strictly prohibited.
- Engineers MUST set `exportTimeoutMillis` to a finite duration strictly lower than the upstream collector timeout (typically 3000ms–5000ms) to prevent lingering HTTP/gRPC sockets and heap bloat.
- Engineers MUST NEVER await telemetry export directly in application request lifecycles; telemetry submission to internal buffers MUST remain entirely non-blocking.
- Batch processors MUST be configured to drop spans or log records deterministically using circular ring buffers when queue capacities are exceeded, rather than allocating additional memory or throttling application threads.
- Services MUST register diagnostic metric callbacks or export failure counters (e.g., `otel.spans.dropped`) to alert operators when upstream ingestion failure forces client-side drops.
- Telemetry SDK shutdowns (`shutdown()`) during SIGTERM MUST be bounded by an uncompromising timeout (e.g., 5000ms) and MUST NOT delay graceful container drainage indefinitely.

## Bad vs Good Implementations
### Configuring Resilient Bounded Non-Blocking Batch Processors for OTLP

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: Using default BatchSpanProcessor parameters can retain tens of thousands of span references and unclosed TCP sockets during network degradation, resulting in Heap Out-Of-Memory (OOM) fatal errors and hanging process termination signals.
```typescript
import { NodeSDK } from '@opentelemetry/sdk-node';
import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-grpc';
import { BatchSpanProcessor } from '@opentelemetry/sdk-trace-base';

// ANTI-PATTERN: Default configurations allow huge unbounded memory queues,
// default long timeouts (30s), and can starve the Node.js event loop
// during sustained upstream collector downtime.
const traceExporter = new OTLPTraceExporter({
  url: process.env.OTEL_EXPORTER_OTLP_ENDPOINT || 'http://collector:4317',
});

const sdk = new NodeSDK({
  // Default BatchSpanProcessor allows up to 2048 spans in memory
  // and defaults to 30000ms export timeout, leading to massive socket retention.
  spanProcessor: new BatchSpanProcessor(traceExporter),
});

sdk.start();

process.on('SIGTERM', () => {
  // Anti-pattern: Unbounded shutdown promise can hang container eviction
  sdk.shutdown().then(() => process.exit(0));
});
```

#### Production Standard (Correct)
> **Standard**: Explicit limits on maxQueueSize (512) and exportTimeoutMillis (3000ms) guarantee a predictable, finite memory footprint. When collector endpoints fail, the ring buffer drops excess spans without blocking thread execution or consuming unbounded heap. The shutdown hook uses a strict timeout fallback.
```typescript
import { NodeSDK } from '@opentelemetry/sdk-node';
import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-grpc';
import { BatchSpanProcessor } from '@opentelemetry/sdk-trace-base';
import { diag, DiagConsoleLogger, DiagLogLevel } from '@opentelemetry/api';

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

const traceExporter = new OTLPTraceExporter({
  url: process.env.OTEL_EXPORTER_OTLP_ENDPOINT || 'http://collector:4317',
  timeoutMillis: 4000,
});

// PRODUCTION INVARIANT: Bounded queue size, small export batch size, fast flush timeout,
// and tight timeout constraints prevent memory bloat and event-loop lag.
const boundedSpanProcessor = new BatchSpanProcessor(traceExporter, {
  maxQueueSize: 512,          // Ring buffer ceiling: immediately drops when full
  maxExportBatchSize: 128,    // Limits payload serialization strain
  scheduledDelayMillis: 1000, // Regular flush cadence
  exportTimeoutMillis: 3000,  // Bound latency to reject slow upstream sinks
});

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

sdk.start();

const handleGracefulShutdown = async (signal: string) => {
  const SHUTDOWN_TIMEOUT_MS = 5000;
  const timer = setTimeout(() => {
    process.exit(1);
  }, SHUTDOWN_TIMEOUT_MS);
  timer.unref();

  try {
    await sdk.shutdown();
    process.exit(0);
  } catch (error) {
    diag.error(`Error shutting down telemetry on ${signal}`, error);
    process.exit(1);
  }
};

process.on('SIGTERM', () => void handleGracefulShutdown('SIGTERM'));
process.on('SIGINT', () => void handleGracefulShutdown('SIGINT'));
```

Architectural Specification & Invariant Rationale

Architectural Invariant Design: OpenTelemetry OTLP Exporter Non-Blocking Ring Buffer and Backpressure Dropping Standard

OpenTelemetry OTLP Exporter Non-Blocking Ring Buffer and Backpressure Dropping Standard defines an industrial-grade behavioral standard for devops engineering. Enforces strict bounding on OpenTelemetry BatchSpanProcessor and BatchLogRecordProcessor queues to eliminate memory leaks and event loop starvation during upstream collector latency or outages. Invariants require explicit bounded queue size ceilings, strict export timeouts, non-blocking telemetry generation, and observable drop counters. Telemetry generation must never degrade primary business logic availability or latency. 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: Unbounded or Blocking Telemetry Export Causing Host Out-Of-Memory Crashes and Event Loop Starvation 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 DriftUnbounded or Blocking Telemetry Export Causing Host Out-Of-Memory Crashes and Event Loop StarvationCritical
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

Services MUST ALWAYS configure explicit limits for `maxQueueSize` and `maxExportBatchSize` on `BatchSpanProcessor` and `BatchLogRecordProcessor`

Services MUST ALWAYS configure explicit limits for `maxQueueSize` and `maxExportBatchSize` on `BatchSpanProcessor` and `BatchLogRecordProcessor`; relying on unbounded or excessively large default queues is strictly prohibited.

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 set `exportTimeoutMillis` to a finite duration strictly lower than the upstream collector timeout (typically 3000ms–5000ms) to prevent lingering HTTP/gRPC sockets and heap bloat.

Engineers MUST set `exportTimeoutMillis` to a finite duration strictly lower than the upstream collector timeout (typically 3000ms–5000ms) to prevent lingering HTTP/gRPC sockets and heap bloat.

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

Engineers MUST NEVER await telemetry export directly in application request lifecycles

Engineers MUST NEVER await telemetry export directly in application request lifecycles; telemetry submission to internal buffers MUST remain entirely non-blocking.

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

Batch processors MUST be configured to drop spans or log records deterministically using circular ring buffers when queue capacities are exceeded, rather than allocating additional memory or throttling application threads.

Batch processors MUST be configured to drop spans or log records deterministically using circular ring buffers when queue capacities are exceeded, rather than allocating additional memory or throttling application threads.

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

Services MUST register diagnostic metric callbacks or export failure counters (e.g., `otel.spans.dropped`) to alert operators when upstream ingestion failure forces client-side drops.

Services MUST register diagnostic metric callbacks or export failure counters (e.g., `otel.spans.dropped`) to alert operators when upstream ingestion failure forces client-side drops.

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

Telemetry SDK shutdowns (`shutdown()`) during SIGTERM MUST be bounded by an uncompromising timeout (e.g., 5000ms) and MUST NOT delay graceful container drainage indefinitely.

Telemetry SDK shutdowns (`shutdown()`) during SIGTERM MUST be bounded by an uncompromising timeout (e.g., 5000ms) and MUST NOT delay graceful container drainage indefinitely.

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 OTLP Exporter Non-Blocking Ring Buffer and Backpressure Dropping Standard critical for AI coding assistants?

Enforces strict bounding on OpenTelemetry BatchSpanProcessor and BatchLogRecordProcessor queues to eliminate memory leaks and event loop starvation during upstream collector latency or outages. Invariants require explicit bounded queue size ceilings, strict export timeouts, non-blocking telemetry generation, and observable drop counters. Telemetry generation must never degrade primary business logic availability or latency. 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 (Unbounded or Blocking Telemetry Export Causing Host Out-Of-Memory Crashes and Event Loop Starvation) 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