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

OpenTelemetry OTLP/gRPC Bounded Ring Buffer & Tail-Drop Guardrail

Enforces deterministic in-memory bounded ring buffering with error-prioritizing shedding policies for OpenTelemetry OTLP/gRPC exporters. Prevents service-level heap exhaustion (OOM) during downstream collector failures by dropping low-entropy telemetry while guaranteeing error trace retention up to strict memory limits.

Prohibited Anti-Pattern: Unbounded Telemetry Queueing and Indiscriminate FIFO Spans Purging During Collector Outages

Export Ready-to-Drop Configuration

Select format below to copy code or download file directly.

---
description: OpenTelemetry OTLP/gRPC Bounded Ring Buffer & Tail-Drop Guardrail - Enforces deterministic in-memory bounded ring buffering with error-prioritizing shedding policies for OpenTelemetry OTLP/gRPC exporters. Prevents service-level heap exhaustion (OOM) during downstream collector failures by dropping low-entropy telemetry while guaranteeing error trace retention up to strict memory limits.
globs: src/**/telemetry/**/*.{ts,js}, src/**/tracing/**/*.{ts,js}, src/**/instrumentation/**/*.{ts,js}, src/**/observability/**/*.{ts,js}
alwaysApply: true
verified_by: "agentrules.org"
license: "CC-BY-4.0"
source: "https://agentrules.org/rules/otel-otlp-ring-buffer-backpressure-policy"
---

# OpenTelemetry OTLP/gRPC Bounded Ring Buffer & Tail-Drop Guardrail

> **Severity**: CRITICAL | **Category**: devops
> **Anti-Pattern Warning**: Unbounded Telemetry Queueing and Indiscriminate FIFO Spans Purging During Collector Outages

## System Constraints
You are a Principal Observability and Infrastructure Architect enforcing deterministic telemetry backpressure under the OpenTelemetry OTLP/gRPC In-Memory Ring Buffer Backpressure Dropping Policy. You must eliminate node-level OOM vulnerabilities caused by unbounded batch processors and collector connection degradation. Enforce bounded circular buffers, selective tail-dropping of low-entropy telemetry (e.g., successful health checks, synthetic transactions), prioritized retention of high-entropy error spans (status code ERROR, exceptions), and strict exponential-backoff gRPC retry ceilings.

## Strict Guidelines
- Engineers MUST ALWAYS configure bounded memory queues for OpenTelemetry span processors using strict buffer limits (`maxQueueSize` and `maxExportBatchSize`) based on runtime heap allocations.
- Engineers MUST NOT use the standard BatchSpanProcessor with unbounded retry policies or default drop-oldest FIFO behaviors when export failures can trigger process-level OOM.
- Custom SpanProcessors MUST implement selective priority shedding: when the buffer capacity crosses the high-water mark (e.g., 80%), low-entropy spans (SpanStatusCode.UNSET, SpanStatusCode.OK, route /healthz) MUST be shed before error traces.
- High-entropy spans (containing SpanStatusCode.ERROR or recorded exceptions) MUST be preserved within an internal priority ring buffer until a hard maximum memory ceiling is reached.
- The OTLP gRPC client MUST configure backoff limits (`exportTimeoutMillis`, `concurrencyLimit`, explicit deadline intervals) to prevent in-flight buffer leaks during network partitions.
- Services MUST emit runtime metrics (e.g., `telemetry.spans.dropped{reason="backpressure", entropy="low|high"}`) whenever backpressure truncation occurs.

## Bad vs Good Implementations
### Naive BatchSpanProcessor with Default Queue causing OOM during Collector Disconnect

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: Allocates a dangerously large in-memory queue that grows unchecked during downstream collector outages. It sheds spans randomly or in plain FIFO order, meaning catastrophic HTTP 500 exceptions are purged while routine HTTP 200/health-check spans consume remaining buffer slots, eventually causing memory exhaustion and process termination.
```typescript
import { NodeSDK } from '@opentelemetry/sdk-node';
import { BatchSpanProcessor } from '@opentelemetry/sdk-trace-base';
import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-grpc';

// ANTI-PATTERN: Default BatchSpanProcessor with large/unbounded queue and naive FIFO drops.
// Collector outages cause spans to accumulate in V8 heap, causing OOM-killer invocations.
// When queue drops occur, critical 500 error spans are dropped indiscriminately alongside /healthz checks.
const exporter = new OTLPTraceExporter({
  url: 'grpc://otel-collector:4317',
});

const sdk = new NodeSDK({
  spanProcessor: new BatchSpanProcessor(exporter, {
    maxQueueSize: 204800, // Excessive buffer holding raw spans in memory without entropy awareness
    maxExportBatchSize: 2048,
    scheduledDelayMillis: 5000,
    exportTimeoutMillis: 30000,
  }),
});

sdk.start();
```

#### Production Standard (Correct)
> **Standard**: Implements an in-memory priority ring buffer with explicit high-water mark shedding. Drops non-essential low-entropy traces (HTTP 200s, health checks) when the queue reaches 80% capacity, guarantees heap safety by bounding total capacity to 4,096 elements, and preferentially retains and re-enqueues error traces during exporter failure scenarios.
```typescript
import { Span, SpanStatusCode } from '@opentelemetry/api';
import { ReadableSpan, SpanProcessor } from '@opentelemetry/sdk-trace-base';
import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-grpc';

export class PriorityRingBufferSpanProcessor implements SpanProcessor {
  private readonly maxCapacity = 4096;
  private readonly highWaterMark = 3276; // 80%
  private buffer: ReadableSpan[] = [];
  private isFlushing = false;

  constructor(private readonly exporter: OTLPTraceExporter) {}

  onStart(span: Span): void {}

  onEnd(span: ReadableSpan): void {
    const isError = span.status.code === SpanStatusCode.ERROR || (span.events && span.events.some(e => e.name === 'exception'));

    if (this.buffer.length >= this.maxCapacity) {
      if (!isError) {
        // Deterministically drop incoming low-entropy span
        return;
      }
      // Evict first available non-error span to prioritize high-entropy error span
      const evictIdx = this.buffer.findIndex(s => s.status.code !== SpanStatusCode.ERROR);
      if (evictIdx !== -1) {
        this.buffer.splice(evictIdx, 1);
      } else {
        this.buffer.shift(); // Evict oldest error span only when buffer is 100% errors
      }
    } else if (this.buffer.length >= this.highWaterMark && !isError) {
      // Selective tail-dropping for low-entropy traces under pressure
      return;
    }

    this.buffer.push(span);
  }

  async forceFlush(): Promise<void> {
    if (this.isFlushing || this.buffer.length === 0) return;
    this.isFlushing = true;
    const batch = this.buffer.splice(0, 1024);
    try {
      await new Promise<void>((resolve, reject) => {
        this.exporter.export(batch, (result) => {
          result.code === 0 ? resolve() : reject(result.error);
        });
      });
    } catch {
      // Retain only error spans during backpressure
      const salvagedErrors = batch.filter(s => s.status.code === SpanStatusCode.ERROR);
      this.buffer = [...salvagedErrors, ...this.buffer].slice(0, this.maxCapacity);
    } finally {
      this.isFlushing = false;
    }
  }

  async shutdown(): Promise<void> {
    await this.forceFlush();
    await this.exporter.shutdown();
  }
}
```

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 OTLP/gRPC Bounded Ring Buffer & Tail-Drop Guardrail

OpenTelemetry OTLP/gRPC Bounded Ring Buffer & Tail-Drop Guardrail defines an industrial-grade behavioral standard for devops engineering. Enforces deterministic in-memory bounded ring buffering with error-prioritizing shedding policies for OpenTelemetry OTLP/gRPC exporters. Prevents service-level heap exhaustion (OOM) during downstream collector failures by dropping low-entropy telemetry while guaranteeing error trace retention up to strict memory limits. 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 Telemetry Queueing and Indiscriminate FIFO Spans Purging During Collector Outages 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 Telemetry Queueing and Indiscriminate FIFO Spans Purging During Collector OutagesCritical
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 bounded memory queues for OpenTelemetry span processors using strict buffer limits (`maxQueueSize` and `maxExportBatchSize`) based on runtime heap allocations.

Engineers MUST ALWAYS configure bounded memory queues for OpenTelemetry span processors using strict buffer limits (`maxQueueSize` and `maxExportBatchSize`) based on runtime heap allocations.

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 the standard BatchSpanProcessor with unbounded retry policies or default drop-oldest FIFO behaviors when export failures can trigger process-level OOM.

Engineers MUST NOT use the standard BatchSpanProcessor with unbounded retry policies or default drop-oldest FIFO behaviors when export failures can trigger process-level OOM.

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

Custom SpanProcessors MUST implement selective priority shedding

Custom SpanProcessors MUST implement selective priority shedding: when the buffer capacity crosses the high-water mark (e.g., 80%), low-entropy spans (SpanStatusCode.UNSET, SpanStatusCode.OK, route /healthz) MUST be shed before error traces.

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

High-entropy spans (containing SpanStatusCode.ERROR or recorded exceptions) MUST be preserved within an internal priority ring buffer until a hard maximum memory ceiling is reached.

High-entropy spans (containing SpanStatusCode.ERROR or recorded exceptions) MUST be preserved within an internal priority ring buffer until a hard maximum memory ceiling is reached.

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

The OTLP gRPC client MUST configure backoff limits (`exportTimeoutMillis`, `concurrencyLimit`, explicit deadline intervals) to prevent in-flight buffer leaks during network partitions.

The OTLP gRPC client MUST configure backoff limits (`exportTimeoutMillis`, `concurrencyLimit`, explicit deadline intervals) to prevent in-flight buffer leaks during network partitions.

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

Services MUST emit runtime metrics (e.g., `telemetry.spans.dropped{reason="backpressure", entropy="low|high"}`) whenever backpressure truncation occurs.

Services MUST emit runtime metrics (e.g., `telemetry.spans.dropped{reason="backpressure", entropy="low|high"}`) whenever backpressure truncation occurs.

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/gRPC Bounded Ring Buffer & Tail-Drop Guardrail critical for AI coding assistants?

Enforces deterministic in-memory bounded ring buffering with error-prioritizing shedding policies for OpenTelemetry OTLP/gRPC exporters. Prevents service-level heap exhaustion (OOM) during downstream collector failures by dropping low-entropy telemetry while guaranteeing error trace retention up to strict memory limits. 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 Telemetry Queueing and Indiscriminate FIFO Spans Purging During Collector Outages) 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