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

Deterministic Backpressure and Load Shedding in OpenTelemetry Collector Tail-Based Sampling

Enforces deterministic load shedding and explicit memory isolation within OpenTelemetry Collector tail-sampling pipelines during traffic spikes and incident cascades. Prevents OOM kills by mandating memory_limiter placement before stateful buffers and configuring finite memory-bounded trace reserves with priority-tiered drop rules.

Prohibited Anti-Pattern: Unbounded State Buffering in Tail Sampler Preceding Memory Limiter Inducing Pipeline OOM Kills

Export Ready-to-Drop Configuration

Select format below to copy code or download file directly.

---
description: Deterministic Backpressure and Load Shedding in OpenTelemetry Collector Tail-Based Sampling - Enforces deterministic load shedding and explicit memory isolation within OpenTelemetry Collector tail-sampling pipelines during traffic spikes and incident cascades. Prevents OOM kills by mandating memory_limiter placement before stateful buffers and configuring finite memory-bounded trace reserves with priority-tiered drop rules.
globs: **/otel-collector*.yaml, **/otel-collector*.yml, **/collector/*.yaml, **/collector/*.yml, deploy/k8s/**/*.yaml
alwaysApply: true
verified_by: "agentrules.org"
license: "CC-BY-4.0"
source: "https://agentrules.org/rules/otel-collector-tail-sampling-backpressure-invariant"
---

# Deterministic Backpressure and Load Shedding in OpenTelemetry Collector Tail-Based Sampling

> **Severity**: CRITICAL | **Category**: devops
> **Anti-Pattern Warning**: Unbounded State Buffering in Tail Sampler Preceding Memory Limiter Inducing Pipeline OOM Kills

## System Constraints
You are a Principal Observability Infrastructure Architect enforcing strict tail-based sampling backpressure invariants on OpenTelemetry Collector configurations. Mandate that stateful trace aggregation buffers never exceed predictable memory ceilings during telemetry storms. Ensure that memory_limiter processors strictly precede tail_sampling processors in trace pipelines, explicit maximum trace counts are set, and lower-tier telemetry (e.g., polling, non-error GET requests, health checks) is aggressively shed before degrading anomalous or error traces.

## Strict Guidelines
- Pipelines MUST ALWAYS position the `memory_limiter` processor as the very first processor in any traces pipeline utilizing `tail_sampling`.
- The `tail_sampling` processor MUST ALWAYS define `num_traces` and `expected_new_traces_per_sec` tuned strictly below container memory allocations.
- Engineers MUST NOT configure unbounded decision waits (`decision_wait`) exceeding 30s without deterministic routing to tiered fallback storage.
- Configurations MUST define prioritized policy ordering where deterministic high-frequency non-critical spans (health checks, liveness probes) are dropped or downsampled before stateful evaluation of business spans.
- Components NEVER rely on downstream exporter queues (`batch` processor or exporter retry queues) to apply backpressure to `tail_sampling` memory tables; explicit drop behavior MUST be declared at the collector ingress.

## Bad vs Good Implementations
### Collector Tail Sampling Pipeline Configuration

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: Placing tail_sampling before memory_limiter allows the tail sampler to accumulate trace state in memory uninhibited. During an incident, unbounded trace tree accumulation exhausts heap space before the memory_limiter can reject incoming batches, resulting in Linux OOM kills and zero telemetry egress.
```yaml
processors:
  tail_sampling:
    decision_wait: 30s
    # ANTI-PATTERN: Missing num_traces and expected_new_traces_per_sec
    # Buffer will grow unbounded during traffic spikes
    policies:
      - name: sample-errors
        type: status_code
        status_code: { status_codes: [ ERROR ] }
  memory_limiter:
    # ANTI-PATTERN: Placed after tail_sampling or omitted entirely
    check_interval: 1s
    limit_percentage: 80
    spike_limit_percentage: 20

service:
  pipelines:
    traces:
      receivers: [otlp]
      # ANTI-PATTERN: tail_sampling evaluated before memory_limiter enforcement
      processors: [tail_sampling, memory_limiter, batch]
      exporters: [otlp]
```

#### Production Standard (Correct)
> **Standard**: The memory_limiter processor is strictly first, proactively shedding new connections if heap thresholds are breached. The tail_sampling processor specifies explicit bounds (`num_traces: 50000`), drops non-diagnostic traffic first via explicit filter policies, and protects against trace accumulation leaks during massive cascading failures.
```yaml
processors:
  memory_limiter:
    check_interval: 500ms
    limit_percentage: 75
    spike_limit_percentage: 15
  tail_sampling:
    decision_wait: 10s
    num_traces: 50000
    expected_new_traces_per_sec: 2000
    policies:
      # 1. Deterministic drop of low-priority telemetry before deep inspection
      - name: drop-health-checks
        type: string_attribute
        string_attribute:
          key: http.route
          values: ["/healthz", "/livez", "/readyz", "/metrics"]
          enabled_regex_matching: false
          invert_match: false
      # 2. Retain 100% of errors
      - name: retain-errors
        type: status_code
        status_code: { status_codes: [ ERROR ] }
      # 3. Retain slow traces
      - name: retain-high-latency
        type: latency
        latency: { threshold_ms: 1500 }
      # 4. Probabilistic tail-drop fallback for benign traffic
      - name: sample-normal-traffic
        type: probabilistic
        probabilistic: { sampling_percentage: 5.0 }
  batch:
    send_batch_max_size: 2048
    timeout: 1s

service:
  pipelines:
    traces:
      receivers: [otlp]
      # Correct invariant: memory limits enforced first, followed by bounded 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.

Architectural Specification & Invariant Rationale

Architectural Invariant Design: Deterministic Backpressure and Load Shedding in OpenTelemetry Collector Tail-Based Sampling

Deterministic Backpressure and Load Shedding in OpenTelemetry Collector Tail-Based Sampling defines an industrial-grade behavioral standard for devops engineering. Enforces deterministic load shedding and explicit memory isolation within OpenTelemetry Collector tail-sampling pipelines during traffic spikes and incident cascades. Prevents OOM kills by mandating memory_limiter placement before stateful buffers and configuring finite memory-bounded trace reserves with priority-tiered drop rules. 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 State Buffering in Tail Sampler Preceding Memory Limiter Inducing Pipeline OOM Kills 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 State Buffering in Tail Sampler Preceding Memory Limiter Inducing Pipeline OOM KillsCritical
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

Pipelines MUST ALWAYS position the `memory_limiter` processor as the very first processor in any traces pipeline utilizing `tail_sampling`.

Pipelines MUST ALWAYS position the `memory_limiter` processor as the very first processor in any traces pipeline utilizing `tail_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.
2

The `tail_sampling` processor MUST ALWAYS define `num_traces` and `expected_new_traces_per_sec` tuned strictly below container memory allocations.

The `tail_sampling` processor MUST ALWAYS define `num_traces` and `expected_new_traces_per_sec` tuned strictly below container memory 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.
3

Engineers MUST NOT configure unbounded decision waits (`decision_wait`) exceeding 30s without deterministic routing to tiered fallback storage.

Engineers MUST NOT configure unbounded decision waits (`decision_wait`) exceeding 30s without deterministic routing to tiered fallback storage.

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

Configurations MUST define prioritized policy ordering where deterministic high-frequency non-critical spans (health checks, liveness probes) are dropped or downsampled before stateful evaluation of business spans.

Configurations MUST define prioritized policy ordering where deterministic high-frequency non-critical spans (health checks, liveness probes) are dropped or downsampled before stateful evaluation of business spans.

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

Components NEVER rely on downstream exporter queues (`batch` processor or exporter retry queues) to apply backpressure to `tail_sampling` memory tables

Components NEVER rely on downstream exporter queues (`batch` processor or exporter retry queues) to apply backpressure to `tail_sampling` memory tables; explicit drop behavior MUST be declared at the collector ingress.

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 Deterministic Backpressure and Load Shedding in OpenTelemetry Collector Tail-Based Sampling critical for AI coding assistants?

Enforces deterministic load shedding and explicit memory isolation within OpenTelemetry Collector tail-sampling pipelines during traffic spikes and incident cascades. Prevents OOM kills by mandating memory_limiter placement before stateful buffers and configuring finite memory-bounded trace reserves with priority-tiered drop rules. 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 State Buffering in Tail Sampler Preceding Memory Limiter Inducing Pipeline OOM Kills) 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

Deterministic