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-fencing

OpenTelemetry Collector Tail-Based Sampling & Memory Limiter Fencing Standard

Enforces deterministic pipeline ordering and memory fencing within the OpenTelemetry Collector to prevent OOM panics during high-ingestion spikes while preserving trace completeness for anomalous transactions. Mandates the memory_limiter processor as the first processor in all trace pipelines and sizes buffer windows against container cgroup limits.

Prohibited Anti-Pattern: Placing tail_sampling before memory_limiter or omitting spike boundaries, triggering kernel OOM kills under burst traffic.

Export Ready-to-Drop Configuration

Select format below to copy code or download file directly.

---
description: OpenTelemetry Collector Tail-Based Sampling & Memory Limiter Fencing Standard - Enforces deterministic pipeline ordering and memory fencing within the OpenTelemetry Collector to prevent OOM panics during high-ingestion spikes while preserving trace completeness for anomalous transactions. Mandates the memory_limiter processor as the first processor in all trace pipelines and sizes buffer windows against container cgroup limits.
globs: **/otel-collector*.{yaml,yml}, **/collector*.{yaml,yml}, **/opentelemetry*.{yaml,yml}, deploy/k8s/**/*.{yaml,yml}, charts/**/templates/*.{yaml,yml}
alwaysApply: true
verified_by: "agentrules.org"
license: "CC-BY-4.0"
source: "https://agentrules.org/rules/otel-collector-tail-sampling-memory-fencing"
---

# OpenTelemetry Collector Tail-Based Sampling & Memory Limiter Fencing Standard

> **Severity**: CRITICAL | **Category**: devops
> **Anti-Pattern Warning**: Placing tail_sampling before memory_limiter or omitting spike boundaries, triggering kernel OOM kills under burst traffic.

## System Constraints
You are a Principal Engineer enforcing OpenTelemetry Collector Dynamic Tail-Based Sampling & Memory Fencing. Mandate strict pipeline order (memory_limiter must precede tail_sampling), calibrate memory bounds relative to container cgroup allocations, and enforce trace-routing consistency to ensure complete error traces without collector panics.

## Strict Guidelines
- Engineers MUST ALWAYS configure `memory_limiter` as the very first processor in any OpenTelemetry Collector traces pipeline to reject/shed traffic before buffers fill.
- Engineers MUST calibrate `memory_limiter.limit_percentage` to at most 75-80% of the container hard memory limit, with a `spike_limit_percentage` of at least 15-20% to absorb micro-bursts.
- Engineers MUST NOT place `tail_sampling` or `batch` processors before `memory_limiter`, as buffered traces will exhaust heap space before eviction triggers.
- Pipeline configurations MUST pair tail-based sampling collectors with an upstream `loadbalancingexporter` routed by `trace_id` to guarantee trace completeness across distributed collector pools.
- Tail-sampling policies MUST prioritize non-200 HTTP statuses, gRPC error codes, explicit error attributes, and high-latency percentiles (p95/p99) over probabilistic uniform sampling.
- Engineers MUST calculate `expected_new_traces_per_sec` and `decision_wait` in `tail_sampling` based on measured ingress throughput and available heap headroom to eliminate unconstrained buffer growth.

## Bad vs Good Implementations
### OpenTelemetry Collector Pipeline Configuration

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: The memory_limiter is placed at the end of the processor chain, allowing tail_sampling and batch processors to hoard unconstrained trace data in memory during traffic spikes. The 95% limit with no spike buffer guarantees Linux cgroup OOM panics.
```yaml
processors:
  batch:
    timeout: 10s
    send_batch_size: 10000
  tail_sampling:
    decision_wait: 30s # Holds traces for 30s in unconstrained memory
    expected_new_traces_per_sec: 20000
    policies:
      [ { name: sample_errors, type: status_code, status_code: { status_codes: [ ERROR ] } } ]
  memory_limiter:
    check_interval: 5s # Checked too late; batch and tail_sampling consume memory first
    limit_percentage: 95 # Dangerously close to 100%, kernel OOM killer fires first

service:
  pipelines:
    traces:
      receivers: [otlp]
      processors: [tail_sampling, batch, memory_limiter] # ANTI-PATTERN: tail_sampling is first
      exporters: [otlp]
```

#### Production Standard (Correct)
> **Standard**: The memory_limiter sits at the entry point of the pipeline, actively monitoring heap every 1s. It sets a 75% baseline and a 20% spike buffer, dropping new spans gracefully when memory spikes before they can be buffered by tail_sampling. Tail sampling evaluates errors and latencies deterministically.
```yaml
processors:
  # FENCE: memory_limiter must be first to shed load before any allocation
  memory_limiter:
    check_interval: 1s
    limit_percentage: 75
    spike_limit_percentage: 20
  tail_sampling:
    decision_wait: 10s
    expected_new_traces_per_sec: 5000
    policies:
      - name: drop_health_checks
        type: filter
        filter: { attribute: http.target, regex: ^/(healthz|readyz|metrics)$ }
      - name: retain_errors
        type: status_code
        status_code: { status_codes: [ ERROR ] }
      - name: retain_high_latency
        type: latency
        latency: { threshold_ms: 1500 }
      - name: probabilistic_fallback
        type: probabilistic
        probabilistic: { sampling_percentage: 5.0 }
  batch:
    timeout: 1s
    send_batch_size: 2048
    send_batch_max_size: 4096

service:
  pipelines:
    traces:
      receivers: [otlp]
      processors: [memory_limiter, tail_sampling, batch] # PRODUCTION STANDARD: memory_limiter first
      exporters: [otlp]
```

Architectural Specification & Invariant Rationale

Architectural Invariant Design: OpenTelemetry Collector Tail-Based Sampling & Memory Limiter Fencing Standard

OpenTelemetry Collector Tail-Based Sampling & Memory Limiter Fencing Standard defines an industrial-grade behavioral standard for devops engineering. Enforces deterministic pipeline ordering and memory fencing within the OpenTelemetry Collector to prevent OOM panics during high-ingestion spikes while preserving trace completeness for anomalous transactions. Mandates the memory_limiter processor as the first processor in all trace pipelines and sizes buffer windows against container cgroup 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: Placing tail_sampling before memory_limiter or omitting spike boundaries, triggering kernel OOM kills under burst traffic. 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 DriftPlacing tail_sampling before memory_limiter or omitting spike boundaries, triggering kernel OOM kills under burst traffic.Critical
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 `memory_limiter` as the very first processor in any OpenTelemetry Collector traces pipeline to reject/shed traffic before buffers fill.

Engineers MUST ALWAYS configure `memory_limiter` as the very first processor in any OpenTelemetry Collector traces pipeline to reject/shed traffic before buffers fill.

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 calibrate `memory_limiter.limit_percentage` to at most 75-80% of the container hard memory limit, with a `spike_limit_percentage` of at least 15-20% to absorb micro-bursts.

Engineers MUST calibrate `memory_limiter.limit_percentage` to at most 75-80% of the container hard memory limit, with a `spike_limit_percentage` of at least 15-20% to absorb micro-bursts.

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 NOT place `tail_sampling` or `batch` processors before `memory_limiter`, as buffered traces will exhaust heap space before eviction triggers.

Engineers MUST NOT place `tail_sampling` or `batch` processors before `memory_limiter`, as buffered traces will exhaust heap space before eviction triggers.

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

Pipeline configurations MUST pair tail-based sampling collectors with an upstream `loadbalancingexporter` routed by `trace_id` to guarantee trace completeness across distributed collector pools.

Pipeline configurations MUST pair tail-based sampling collectors with an upstream `loadbalancingexporter` routed by `trace_id` to guarantee trace completeness across distributed collector pools.

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

Tail-sampling policies MUST prioritize non-200 HTTP statuses, gRPC error codes, explicit error attributes, and high-latency percentiles (p95/p99) over probabilistic uniform sampling.

Tail-sampling policies MUST prioritize non-200 HTTP statuses, gRPC error codes, explicit error attributes, and high-latency percentiles (p95/p99) over probabilistic uniform sampling.

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

Engineers MUST calculate `expected_new_traces_per_sec` and `decision_wait` in `tail_sampling` based on measured ingress throughput and available heap headroom to eliminate unconstrained buffer growth.

Engineers MUST calculate `expected_new_traces_per_sec` and `decision_wait` in `tail_sampling` based on measured ingress throughput and available heap headroom to eliminate unconstrained buffer growth.

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 & Memory Limiter Fencing Standard critical for AI coding assistants?

Enforces deterministic pipeline ordering and memory fencing within the OpenTelemetry Collector to prevent OOM panics during high-ingestion spikes while preserving trace completeness for anomalous transactions. Mandates the memory_limiter processor as the first processor in all trace pipelines and sizes buffer windows against container cgroup 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 (Placing tail_sampling before memory_limiter or omitting spike boundaries, triggering kernel OOM kills under burst traffic.) 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