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

OpenTelemetry Collector Dynamic Memory Shedding & Adaptive Tail Sampling Invariant

Enforces survival invariants on OpenTelemetry Collector pipelines by prioritizing critical error traces and shedding non-erroneous telemetry under downstream backpressure. Prevents OOM kills through strict processor ordering, memory_limiter thresholds, and composite tail-sampling policies with prioritized fallback tiers.

Prohibited Anti-Pattern: Unbounded Trace Buffering and Indiscriminate In-Memory Tail Sampling Inducing Outage Cascades and OOM Kills

Export Ready-to-Drop Configuration

Select format below to copy code or download file directly.

---
description: OpenTelemetry Collector Dynamic Memory Shedding & Adaptive Tail Sampling Invariant - Enforces survival invariants on OpenTelemetry Collector pipelines by prioritizing critical error traces and shedding non-erroneous telemetry under downstream backpressure. Prevents OOM kills through strict processor ordering, memory_limiter thresholds, and composite tail-sampling policies with prioritized fallback tiers.
globs: **/otel-collector*.yaml, **/otel-collector*.yml, **/collector-config*.yaml, k8s/**/otel*.yaml, deploy/observability/**/*.yaml
alwaysApply: true
verified_by: "agentrules.org"
license: "CC-BY-4.0"
source: "https://agentrules.org/rules/otel-tail-sampling-dynamic-memory-shedding"
---

# OpenTelemetry Collector Dynamic Memory Shedding & Adaptive Tail Sampling Invariant

> **Severity**: CRITICAL | **Category**: devops
> **Anti-Pattern Warning**: Unbounded Trace Buffering and Indiscriminate In-Memory Tail Sampling Inducing Outage Cascades and OOM Kills

## System Constraints
You are a Principal Observability Infrastructure Engineer enforcing OpenTelemetry Collector resilience invariants. You must mandate dynamic memory shedding and backpressure handling so collectors survive total downstream outages while preserving error traces.

## Strict Guidelines
- Engineers MUST ALWAYS declare the `memory_limiter` processor as the FIRST processor in every trace pipeline.
- Engineers MUST configure `check_interval` to at most `1s` with `limit_percentage` set between 75% and 80%, and `spike_limit_percentage` set to 20% to prevent heap runaway before garbage collection cycles execute.
- Engineers MUST NOT place `tail_sampling` ahead of `memory_limiter` or omit hard limits on `num_traces` in the tail sampling memory buffer.
- Pipelines MUST implement prioritized composite sampling where HTTP 5xx errors and gRPC status code exceptions are evaluated with 100% retention before applying probabilistic or rate-limiting filters to healthy traces.
- Exporters MUST configure bounded retry queues (`sending_queue` with explicit `queue_size` and non-infinite `retry_on_failure`) to prevent exporter buffers from cannibalizing the tail sampler's memory allocation.
- Collectors MUST emit and alert on `otelcol_processor_tail_sampling_early_drops` and `otelcol_processor_refused_spans` to indicate active memory shedding.

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

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: Omits the memory_limiter processor and buffers traces for 30s unconditionally without trace count ceilings. When downstream stalls, the buffer continuously accumulates spans until the OS kernel OOM-kills the collector container, destroying 100% of telemetry data.
```yaml
processors:
  tail_sampling:
    decision_wait: 30s
    expected_new_traces_per_sec: 2000
    policies:
      - name: sample-everything
        type: always_sample

exporters:
  otlp:
    endpoint: downstream-tempo:4317
    # Missing memory_limiter, unbounded wait, no error prioritization

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

#### Production Standard (Correct)
> **Standard**: Orders memory_limiter first to enforce hard caps on heap usage, bounds tail-sampling buffer size and retention window, and implements hierarchical policies that retain errors and high latencies while aggressively shedding non-erroneous telemetry under saturation.
```yaml
processors:
  memory_limiter:
    check_interval: 1s
    limit_percentage: 75
    spike_limit_percentage: 20

  tail_sampling:
    decision_wait: 10s
    num_traces: 50000
    expected_new_traces_per_sec: 5000
    policies:
      # Tier 1: Keep 100% of error traces unconditionally
      - name: drop-errors-first-inverse
        type: status_code
        status_code: { status_codes: [ ERROR ] }
      # Tier 2: Retain high-latency anomalies
      - name: latency-tier
        type: latency
        latency: { threshold_ms: 2000 }
      # Tier 3: Dynamically rate-limit or shed healthy traces
      - name: rate-limit-healthy
        type: probabilistic
        probabilistic: { sampling_percentage: 5.0 }

exporters:
  otlp:
    endpoint: downstream-tempo:4317
    sending_queue:
      enabled: true
      num_consumers: 8
      queue_size: 1000
    retry_on_failure:
      enabled: true
      initial_interval: 5s
      max_interval: 30s
      max_elapsed_time: 5m

service:
  pipelines:
    traces:
      receivers: [otlp]
      processors: [memory_limiter, tail_sampling]
      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 Dynamic Memory Shedding & Adaptive Tail Sampling Invariant

OpenTelemetry Collector Dynamic Memory Shedding & Adaptive Tail Sampling Invariant defines an industrial-grade behavioral standard for devops engineering. Enforces survival invariants on OpenTelemetry Collector pipelines by prioritizing critical error traces and shedding non-erroneous telemetry under downstream backpressure. Prevents OOM kills through strict processor ordering, memory_limiter thresholds, and composite tail-sampling policies with prioritized fallback tiers. 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 Trace Buffering and Indiscriminate In-Memory Tail Sampling Inducing Outage Cascades and 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 Trace Buffering and Indiscriminate In-Memory Tail Sampling Inducing Outage Cascades and 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

Engineers MUST ALWAYS declare the `memory_limiter` processor as the FIRST processor in every trace pipeline.

Engineers MUST ALWAYS declare the `memory_limiter` processor as the FIRST processor in every trace pipeline.

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 configure `check_interval` to at most `1s` with `limit_percentage` set between 75% and 80%, and `spike_limit_percentage` set to 20% to prevent heap runaway before garbage collection cycles execute.

Engineers MUST configure `check_interval` to at most `1s` with `limit_percentage` set between 75% and 80%, and `spike_limit_percentage` set to 20% to prevent heap runaway before garbage collection cycles execute.

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` ahead of `memory_limiter` or omit hard limits on `num_traces` in the tail sampling memory buffer.

Engineers MUST NOT place `tail_sampling` ahead of `memory_limiter` or omit hard limits on `num_traces` in the tail sampling memory buffer.

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

Pipelines MUST implement prioritized composite sampling where HTTP 5xx errors and gRPC status code exceptions are evaluated with 100% retention before applying probabilistic or rate-limiting filters to healthy traces.

Pipelines MUST implement prioritized composite sampling where HTTP 5xx errors and gRPC status code exceptions are evaluated with 100% retention before applying probabilistic or rate-limiting filters to healthy 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.
5

Exporters MUST configure bounded retry queues (`sending_queue` with explicit `queue_size` and non-infinite `retry_on_failure`) to prevent exporter buffers from cannibalizing the tail sampler's memory allocation.

Exporters MUST configure bounded retry queues (`sending_queue` with explicit `queue_size` and non-infinite `retry_on_failure`) to prevent exporter buffers from cannibalizing the tail sampler's memory allocation.

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

Collectors MUST emit and alert on `otelcol_processor_tail_sampling_early_drops` and `otelcol_processor_refused_spans` to indicate active memory shedding.

Collectors MUST emit and alert on `otelcol_processor_tail_sampling_early_drops` and `otelcol_processor_refused_spans` to indicate active memory shedding.

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 Dynamic Memory Shedding & Adaptive Tail Sampling Invariant critical for AI coding assistants?

Enforces survival invariants on OpenTelemetry Collector pipelines by prioritizing critical error traces and shedding non-erroneous telemetry under downstream backpressure. Prevents OOM kills through strict processor ordering, memory_limiter thresholds, and composite tail-sampling policies with prioritized fallback tiers. 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 Trace Buffering and Indiscriminate In-Memory Tail Sampling Inducing Outage Cascades and 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

OpenTelemetry