This specification is maintained by the AgentRules Working Group. Have enhancements or want to claim maintainership?Submit Specification →
devopscritical PriorityID: opentelemetry-otlp-backpressure-adaptive-tail-drop-invariant

OpenTelemetry OTLP Backpressure and Adaptive Tail-Drop Buffer Invariant

Enforces deterministic, non-blocking telemetry pipelines in high-throughput applications and collectors to prevent Out-Of-Memory (OOM) failures under sudden load spikes. Mandates strict queue size limits, adaptive tail-drop or reservoir-based head sampling, and non-blocking export behavior that prioritizes application execution over telemetry preservation. Prohibits unbounded in-memory queues and synchronous blocking calls during trace or metric dispatch.

Prohibited Anti-Pattern: Unbounded Batch Span Processors and Blocking Export Queues Causing Process OOM Crashes

Export Ready-to-Drop Configuration

Select format below to copy code or download file directly.

---
description: OpenTelemetry OTLP Backpressure and Adaptive Tail-Drop Buffer Invariant - Enforces deterministic, non-blocking telemetry pipelines in high-throughput applications and collectors to prevent Out-Of-Memory (OOM) failures under sudden load spikes. Mandates strict queue size limits, adaptive tail-drop or reservoir-based head sampling, and non-blocking export behavior that prioritizes application execution over telemetry preservation. Prohibits unbounded in-memory queues and synchronous blocking calls during trace or metric dispatch.
globs: src/**/telemetry/**/*.{ts,js,py,go}, src/**/tracing/**/*.{ts,js,py,go}, src/**/instrumentation/**/*.{ts,js,py,go}, deploy/**/otel-collector*.{yaml,yml}, k8s/**/collector*.{yaml,yml}
alwaysApply: true
verified_by: "agentrules.org"
license: "CC-BY-4.0"
source: "https://agentrules.org/rules/opentelemetry-otlp-backpressure-adaptive-tail-drop-invariant"
---

# OpenTelemetry OTLP Backpressure and Adaptive Tail-Drop Buffer Invariant

> **Severity**: CRITICAL | **Category**: devops
> **Anti-Pattern Warning**: Unbounded Batch Span Processors and Blocking Export Queues Causing Process OOM Crashes

## System Constraints
You are a Principal Software Architect enforcing production-grade OpenTelemetry OTLP Backpressure & Adaptive Tail-Drop Buffer Invariants. Under catastrophic traffic bursts, client applications and intermediate collectors must fail soft: telemetry must be discarded deterministically via bounded circular buffers or tail-drop mechanisms rather than blocking application threads or consuming memory until OOM termination. You must reject any telemetry configuration lacking strict memory limits, timeouts, and bounded export queues.

## Strict Guidelines
- Engineers MUST ALWAYS configure explicit `maxQueueSize` and `maxExportBatchSize` parameters on `BatchSpanProcessor` instances, ensuring `maxQueueSize` does not exceed memory allocation budgets.
- Engineers MUST NOT use default unbounded in-memory queues or allow telemetry exporters to block the critical execution thread when downstream OTLP endpoints become unresponsive.
- Pipelines MUST enforce a deterministic drop policy (tail-drop or ring-buffer overwrite) and record internal telemetry metric counters (e.g., `otel.dropped_spans_total`) when buffers exceed threshold capacity.
- Exporters MUST define aggressive request timeouts (e.g., 5000ms max) and bounded retry attempts with exponential backoff and jitter to mitigate thundering herds against the OTLP collector.
- Telemetry Collector configurations MUST implement `memory_limiter` as the primary processor in all active pipelines, placed ahead of any batching or routing logic.

## Bad vs Good Implementations
### Node.js/TypeScript OpenTelemetry SDK Bounded Batch Configuration

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: The default BatchSpanProcessor configuration does not account for burst spikes or downstream collector latency. If the collector stalls, spans accumulate in memory until Node.js encounters an unrecoverable process OOM, taking down the host service.
```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 BatchSpanProcessor configuration uses unbounded or excessively
// large in-memory buffers (2048 default items with long export timeouts). Under sudden
// traffic bursts or OTLP collector unavailability, spans accumulate indefinitely, exhausting Node heap.
const exporter = new OTLPTraceExporter({
  url: 'http://otel-collector:4317',
});

const sdk = new NodeSDK({
  traceExporter: exporter,
  spanProcessor: new BatchSpanProcessor(exporter),
});

sdk.start();
```

#### Production Standard (Correct)
> **Standard**: Configures finite queue limits (4096 items), an aggressive 3-second export timeout, batch boundaries, and ratio sampling. When buffer capacity is exceeded during an outage, subsequent spans are dropped immediately without blocking execution or exhausting memory.
```typescript
import { NodeSDK } from '@opentelemetry/sdk-node';
import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-grpc';
import { BatchSpanProcessor, ParentBasedSampler, TraceIdRatioBasedSampler } from '@opentelemetry/sdk-trace-base';

// PRODUCTION INVARIANT: Bounded buffer with deterministic memory caps, aggressive timeouts,
// and head/adaptive ratio sampling to absorb upstream traffic surges safely.
const MAX_QUEUE_SIZE = 4096;
const MAX_EXPORT_BATCH_SIZE = 512;
const EXPORT_TIMEOUT_MS = 3000;

const exporter = new OTLPTraceExporter({
  url: process.env.OTEL_EXPORTER_OTLP_ENDPOINT || 'http://otel-collector:4317',
  timeoutMillis: EXPORT_TIMEOUT_MS,
});

const sdk = new NodeSDK({
  sampler: new ParentBasedSampler({
    root: new TraceIdRatioBasedSampler(0.2), // Downsample root transactions under high concurrency
  }),
  spanProcessor: new BatchSpanProcessor(exporter, {
    maxQueueSize: MAX_QUEUE_SIZE,
    maxExportBatchSize: MAX_EXPORT_BATCH_SIZE,
    scheduledDelayMillis: 1000,
    exportTimeoutMillis: EXPORT_TIMEOUT_MS,
  }),
});

sdk.start();
```

### OpenTelemetry Collector Memory Limiter and Queued Retry Invariant

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: The collector configuration lacks a memory_limiter processor and places unbounded batches ahead of an exporter without backpressure guards. A traffic spike will cause the collector container to exceed its cgroup memory limit.
```yaml
# ANTI-PATTERN: OTLP pipeline accepts unbounded incoming traffic without memory guardrails.
# Under traffic spikes or backend slowdowns, the collector crashes with SIGKILL / OOMKilled.
receivers:
  otlp:
    protocols:
      grpc: { endpoint: 0.0.0.0:4317 }

processors:
  batch:
    send_batch_size: 8192
    timeout: 10s

exporters:
  otlp:
    endpoint: tracing-backend:4317

service:
  pipelines:
    traces:
      receivers: [otlp]
      processors: [batch]
      exporters: [otlp]
```

#### Production Standard (Correct)
> **Standard**: The memory_limiter processor forces proactive shedding of data before the container memory threshold is hit. The exporter defines a bounded sending queue and deterministic retry limits that protect both the collector and downstream storage.
```yaml
# PRODUCTION INVARIANT: memory_limiter sits as the first processor in all pipelines
# combined with bounded buffered retries and tail-drop backpressure.
receivers:
  otlp:
    protocols:
      grpc: { endpoint: 0.0.0.0:4317 }

processors:
  memory_limiter:
    check_interval: 250ms
    limit_percentage: 80
    spike_limit_percentage: 20
  batch:
    send_batch_size: 1024
    timeout: 1s
    send_batch_max_size: 2048

exporters:
  otlp:
    endpoint: tracing-backend:4317
    timeout: 5s
    sending_queue:
      enabled: true
      num_consumers: 4
      queue_size: 2000
    retry_on_failure:
      enabled: true
      initial_interval: 1s
      max_interval: 10s
      max_elapsed_time: 30s

service:
  pipelines:
    traces:
      receivers: [otlp]
      processors: [memory_limiter, batch]
      exporters: [otlp]
```

Recommended MCP Servers (mcp-serverlist.com)

Equip agent with system tools to verify code for this stack.

Architectural Specification & Invariant Rationale

Architectural Invariant Design: OpenTelemetry OTLP Backpressure and Adaptive Tail-Drop Buffer Invariant

OpenTelemetry OTLP Backpressure and Adaptive Tail-Drop Buffer Invariant defines an industrial-grade behavioral standard for devops engineering. Enforces deterministic, non-blocking telemetry pipelines in high-throughput applications and collectors to prevent Out-Of-Memory (OOM) failures under sudden load spikes. Mandates strict queue size limits, adaptive tail-drop or reservoir-based head sampling, and non-blocking export behavior that prioritizes application execution over telemetry preservation. Prohibits unbounded in-memory queues and synchronous blocking calls during trace or metric dispatch. 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 Batch Span Processors and Blocking Export Queues Causing Process OOM Crashes 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 Batch Span Processors and Blocking Export Queues Causing Process OOM CrashesCritical
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 explicit `maxQueueSize` and `maxExportBatchSize` parameters on `BatchSpanProcessor` instances, ensuring `maxQueueSize` does not exceed memory allocation budgets.

Engineers MUST ALWAYS configure explicit `maxQueueSize` and `maxExportBatchSize` parameters on `BatchSpanProcessor` instances, ensuring `maxQueueSize` does not exceed memory allocation budgets.

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 default unbounded in-memory queues or allow telemetry exporters to block the critical execution thread when downstream OTLP endpoints become unresponsive.

Engineers MUST NOT use default unbounded in-memory queues or allow telemetry exporters to block the critical execution thread when downstream OTLP endpoints become unresponsive.

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

Pipelines MUST enforce a deterministic drop policy (tail-drop or ring-buffer overwrite) and record internal telemetry metric counters (e.g., `otel.dropped_spans_total`) when buffers exceed threshold capacity.

Pipelines MUST enforce a deterministic drop policy (tail-drop or ring-buffer overwrite) and record internal telemetry metric counters (e.g., `otel.dropped_spans_total`) when buffers exceed threshold capacity.

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

Exporters MUST define aggressive request timeouts (e.g., 5000ms max) and bounded retry attempts with exponential backoff and jitter to mitigate thundering herds against the OTLP collector.

Exporters MUST define aggressive request timeouts (e.g., 5000ms max) and bounded retry attempts with exponential backoff and jitter to mitigate thundering herds against the OTLP collector.

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

Telemetry Collector configurations MUST implement `memory_limiter` as the primary processor in all active pipelines, placed ahead of any batching or routing logic.

Telemetry Collector configurations MUST implement `memory_limiter` as the primary processor in all active pipelines, placed ahead of any batching or routing logic.

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 Backpressure and Adaptive Tail-Drop Buffer Invariant critical for AI coding assistants?

Enforces deterministic, non-blocking telemetry pipelines in high-throughput applications and collectors to prevent Out-Of-Memory (OOM) failures under sudden load spikes. Mandates strict queue size limits, adaptive tail-drop or reservoir-based head sampling, and non-blocking export behavior that prioritizes application execution over telemetry preservation. Prohibits unbounded in-memory queues and synchronous blocking calls during trace or metric dispatch. 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 Batch Span Processors and Blocking Export Queues Causing Process OOM Crashes) 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