This specification is maintained by the AgentRules Working Group. Have enhancements or want to claim maintainership?Submit Specification →
devopscritical PriorityID: otel-collector-tail-sampling-memory-buffer-guardrail

OpenTelemetry Collector Tail-Based Sampling Bounded Memory & Backpressure Guardrail

Tail-based sampling requires buffering trace segments across a sliding evaluation window, creating extreme vulnerability to OOM termination during traffic spikes. Collector configurations must enforce hard byte-level thresholds via the memory_limiter processor preceding tail_sampling, explicitly bound trace buffer allocations, and align GOMEMLIMIT with container resource limits to prevent pod eviction.

Prohibited Anti-Pattern: Unbounded tail-sampling buffers without memory-limiter placement causing fatal OOMKills during trace spikes

Export Ready-to-Drop Configuration

Select format below to copy code or download file directly.

---
description: OpenTelemetry Collector Tail-Based Sampling Bounded Memory & Backpressure Guardrail - Tail-based sampling requires buffering trace segments across a sliding evaluation window, creating extreme vulnerability to OOM termination during traffic spikes. Collector configurations must enforce hard byte-level thresholds via the memory_limiter processor preceding tail_sampling, explicitly bound trace buffer allocations, and align GOMEMLIMIT with container resource limits to prevent pod eviction.
globs: **/otel-collector*.{yaml,yml}, **/collector*.{yaml,yml}, **/helm/**/values*.{yaml,yml}, **/k8s/**/*.yaml
alwaysApply: true
verified_by: "agentrules.org"
license: "CC-BY-4.0"
source: "https://agentrules.org/rules/otel-collector-tail-sampling-memory-buffer-guardrail"
---

# OpenTelemetry Collector Tail-Based Sampling Bounded Memory & Backpressure Guardrail

> **Severity**: CRITICAL | **Category**: devops
> **Anti-Pattern Warning**: Unbounded tail-sampling buffers without memory-limiter placement causing fatal OOMKills during trace spikes

## System Constraints
You are a Principal Observability Infrastructure Engineer enforcing OpenTelemetry Collector resilience invariants. Mandate that all tail-based sampling configurations enforce deterministic memory bounds, strict processor execution ordering, and explicit backpressure limits to prevent OOM kills under burst workloads.

## Strict Guidelines
- Engineers MUST ALWAYS place the `memory_limiter` processor BEFORE `tail_sampling` in the traces pipeline definition.
- Engineers MUST set `check_interval` to 1s or less and define explicit `limit_percentage` (max 75-80%) or `limit_mib` alongside a `spike_limit_percentage` (max 15-20%) or `spike_limit_mib`.
- Engineers MUST define explicit `num_traces` limits within the `tail_sampling` processor to bound the in-memory trace map size.
- Engineers MUST calibrate `decision_wait` to the minimum viable window (typically 5s-30s) required to assemble distributed traces, avoiding over-retention in volatile heap.
- Kubernetes deployments MUST define `GOMEMLIMIT` matching 80-85% of the pod's `resources.limits.memory` and set `GOCACHEPROG` or standard GC target `GOGC=80` to trigger GC before container cgroup limits trip.
- Pipelines MUST NOT use `tail_sampling` without an upstream rate limiting or queue-dropping strategy when operating under untrusted or variable ingestion volumes.

## Bad vs Good Implementations
### Unbounded Tail-Based Sampling Pipeline (Vulnerable to OOMKill)

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: The tail_sampling processor retains all trace spans in heap memory for 30 seconds without an upstream memory limiter. A spike in traffic or deep trace trees will exhaust container memory, triggering the Linux kernel OOM killer (Exit Code 137).
```yaml
processors:
  tail_sampling:
    decision_wait: 30s
    # ANTI-PATTERN: Default num_traces is unbounded/too high, no memory_limiter preceding it
    expected_new_traces_per_sec: 2000
    policies:
      - name: errors-policy
        type: status_code
        status_code: { status_codes: [ ERROR ] }

service:
  pipelines:
    traces:
      receivers: [otlp]
      processors: [tail_sampling, batch] # Missing memory_limiter; OOM occurs here under burst
      exporters: [otlp]
```

#### Production Standard (Correct)
> **Standard**: memory_limiter is placed first in the pipeline to drop or refuse incoming spans when heap utilization exceeds 75%, absorbing sudden spikes. tail_sampling enforces a hard ceiling of 50,000 active traces with a bounded 10-second decision window, keeping heap footprint predictable.
```yaml
processors:
  memory_limiter:
    check_interval: 1s
    limit_percentage: 75
    spike_limit_percentage: 15

  tail_sampling:
    decision_wait: 10s
    num_traces: 50000 # Strict ceiling on in-memory trace buffer
    expected_new_traces_per_sec: 5000
    policies:
      - name: drop-health-checks
        type: filter
        filter: { tag: http.target, value: '/healthz', invert: true }
      - name: errors-policy
        type: status_code
        status_code: { status_codes: [ ERROR ] }

  batch:
    send_batch_max_size: 1024
    send_batch_size: 512
    timeout: 1s

service:
  pipelines:
    traces:
      receivers: [otlp]
      # Order is critical: memory_limiter MUST precede tail_sampling
      processors: [memory_limiter, tail_sampling, batch]
      exporters: [otlp]
```

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 Collector Tail-Based Sampling Bounded Memory & Backpressure Guardrail

OpenTelemetry Collector Tail-Based Sampling Bounded Memory & Backpressure Guardrail defines an industrial-grade behavioral standard for devops engineering. Tail-based sampling requires buffering trace segments across a sliding evaluation window, creating extreme vulnerability to OOM termination during traffic spikes. Collector configurations must enforce hard byte-level thresholds via the memory_limiter processor preceding tail_sampling, explicitly bound trace buffer allocations, and align GOMEMLIMIT with container resource limits to prevent pod eviction. 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 tail-sampling buffers without memory-limiter placement causing fatal OOMKills during trace spikes 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 tail-sampling buffers without memory-limiter placement causing fatal OOMKills during trace spikesCritical
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 place the `memory_limiter` processor BEFORE `tail_sampling` in the traces pipeline definition.

Engineers MUST ALWAYS place the `memory_limiter` processor BEFORE `tail_sampling` in the traces pipeline definition.

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 `check_interval` to 1s or less and define explicit `limit_percentage` (max 75-80%) or `limit_mib` alongside a `spike_limit_percentage` (max 15-20%) or `spike_limit_mib`.

Engineers MUST set `check_interval` to 1s or less and define explicit `limit_percentage` (max 75-80%) or `limit_mib` alongside a `spike_limit_percentage` (max 15-20%) or `spike_limit_mib`.

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 define explicit `num_traces` limits within the `tail_sampling` processor to bound the in-memory trace map size.

Engineers MUST define explicit `num_traces` limits within the `tail_sampling` processor to bound the in-memory trace map size.

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 calibrate `decision_wait` to the minimum viable window (typically 5s-30s) required to assemble distributed traces, avoiding over-retention in volatile heap.

Engineers MUST calibrate `decision_wait` to the minimum viable window (typically 5s-30s) required to assemble distributed traces, avoiding over-retention in volatile heap.

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

Kubernetes deployments MUST define `GOMEMLIMIT` matching 80-85% of the pod's `resources.limits.memory` and set `GOCACHEPROG` or standard GC target `GOGC=80` to trigger GC before container cgroup limits trip.

Kubernetes deployments MUST define `GOMEMLIMIT` matching 80-85% of the pod's `resources.limits.memory` and set `GOCACHEPROG` or standard GC target `GOGC=80` to trigger GC before container cgroup limits trip.

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

Pipelines MUST NOT use `tail_sampling` without an upstream rate limiting or queue-dropping strategy when operating under untrusted or variable ingestion volumes.

Pipelines MUST NOT use `tail_sampling` without an upstream rate limiting or queue-dropping strategy when operating under untrusted or variable ingestion volumes.

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 Collector Tail-Based Sampling Bounded Memory & Backpressure Guardrail critical for AI coding assistants?

Tail-based sampling requires buffering trace segments across a sliding evaluation window, creating extreme vulnerability to OOM termination during traffic spikes. Collector configurations must enforce hard byte-level thresholds via the memory_limiter processor preceding tail_sampling, explicitly bound trace buffer allocations, and align GOMEMLIMIT with container resource limits to prevent pod eviction. 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 tail-sampling buffers without memory-limiter placement causing fatal OOMKills during trace spikes) 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