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

OpenTelemetry Collector Tail-Based Sampling and Exemplar Retention Standard

Architects a two-tier OpenTelemetry Collector topology utilizing trace-ID routing via loadbalancingexporter and tail_sampling processors to deterministically retain 100% of traces with errors, P99 latency spikes, and explicit business anomalies while reducing healthy trace volume by over 80%. Guarantees continuous Prometheus and OpenTelemetry metric correlation by enforcing Span-to-Metric Exemplar propagation across service boundaries.

Prohibited Anti-Pattern: Head-based probabilistic SDK sampling and stateless uncoordinated Collector load balancing that fragment traces and discard root-cause error diagnostics.

Export Ready-to-Drop Configuration

Select format below to copy code or download file directly.

---
description: OpenTelemetry Collector Tail-Based Sampling and Exemplar Retention Standard - Architects a two-tier OpenTelemetry Collector topology utilizing trace-ID routing via loadbalancingexporter and tail_sampling processors to deterministically retain 100% of traces with errors, P99 latency spikes, and explicit business anomalies while reducing healthy trace volume by over 80%. Guarantees continuous Prometheus and OpenTelemetry metric correlation by enforcing Span-to-Metric Exemplar propagation across service boundaries.
globs: **/otel-collector*.{yaml,yml}, **/collector*.{yaml,yml}, **/k8s/**/otel*.{yaml,yml}, **/helm/**/otel*.{yaml,yml}, **/infrastructure/**/telemetry*.{yaml,yml}
alwaysApply: true
verified_by: "agentrules.org"
license: "CC-BY-4.0"
source: "https://agentrules.org/rules/opentelemetry-collector-tail-sampling-exemplar-standard"
---

# OpenTelemetry Collector Tail-Based Sampling and Exemplar Retention Standard

> **Severity**: CRITICAL | **Category**: devops
> **Anti-Pattern Warning**: Head-based probabilistic SDK sampling and stateless uncoordinated Collector load balancing that fragment traces and discard root-cause error diagnostics.

## System Constraints
You are a Principal Observability and Infrastructure Architect enforcing deterministic telemetry capture and cost optimization. You mandate that OpenTelemetry Collector deployments implement trace-aware hash routing, robust tail-based sampling policies, and metric exemplar preservation to capture all P99 regressions and errors without exceeding storage budgets.

## Strict Guidelines
- Engineers MUST ALWAYS deploy a two-tier collector topology where Tier-1 (agent/gateway) uses 'loadbalancingexporter' routing by 'trace_id' to Tier-2 stateful collectors running 'tail_sampling'.
- Engineers MUST NOT run 'tail_sampling' processors behind round-robin L4/L7 load balancers, as spans for a single trace will be partitioned across replicas, resulting in fractured trace retention and incorrect decisions.
- Collector tail-sampling policies MUST ALWAYS explicitly evaluate and capture 100% of traces containing 'status_code: ERROR', HTTP 5xx codes, gRPC non-zero codes, or downstream span exceptions before applying probabilistic rules.
- Collector pipelines MUST define latency-based sampling thresholds tuned to the service P95/P99 baseline (e.g., latency > 1500ms) to ensure anomalous performance regressions are never dropped.
- Engineers MUST configure Prometheus and OTel metric pipelines to preserve OpenTelemetry Exemplars, linking trace IDs directly to histogram bucket observations across both sampled-in and dropped trace paths.
- Collector instances running 'tail_sampling' MUST dimension memory buffers to accommodate the maximum 'decision_wait' window (minimum 10s-30s) alongside P99 burst trace volume to prevent premature cache eviction.

## Bad vs Good Implementations
### Tail-Based Sampling Configuration with Trace-Aware Routing and Metric Exemplars

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: Head-based probabilistic sampling randomly discards 95% of traces regardless of whether they contain critical 5xx errors, P99 latency spikes, or unhandled panics, crippling incident response.
```yaml
# Anti-Pattern: Flawed architecture using head-based sampling or uncoordinated tail sampling
receivers:
  otlp:
    protocols:
      grpc: { endpoint: 0.0.0.0:4317 }

processors:
  # Broken: Naive head-probabilistic sampling drops 95% of critical error traces
  probabilistic_sampler:
    sampling_percentage: 5

exporters:
  otlp/storage:
    endpoint: tempo:4317
    tls:
      insecure: true

service:
  pipelines:
    traces:
      receivers: [otlp]
      processors: [probabilistic_sampler]
      exporters: [otlp/storage]
```

#### Production Standard (Correct)
> **Standard**: Enforces a multi-stage tail-sampling evaluation that deterministically retains all errors, HTTP 5xx status codes, and latency outliers over 1500ms, while safely throttling baseline healthy traffic down to 5%.
```yaml
# Production Standard: Two-tier stateful collector configuration
# Tier 2 Collector: Stateful Tail-Based Sampling and Exemplar Propagation
receivers:
  otlp:
    protocols:
      grpc: { endpoint: 0.0.0.0:4317 }

processors:
  memory_limiter:
    check_interval: 1s
    limit_percentage: 75
    spike_limit_percentage: 20

  tail_sampling:
    decision_wait: 30s
    num_traces: 50000
    expected_new_traces_per_sec: 2000
    policies:
      # Invariant 1: Capture 100% of explicit error spans
      - name: drop-no-errors-policy
        type: status_code
        status_code: { status_codes: [ ERROR ] }
      # Invariant 2: Capture 100% of HTTP 5xx responses
      - name: http-server-errors
        type: numeric_attribute
        numeric_attribute: { key: "http.status_code", min_value: 500, max_value: 599 }
      # Invariant 3: Capture 100% of P99 latency outliers (>1500ms)
      - name: high-latency-p99
        type: latency
        latency: { threshold_ms: 1500 }
      # Invariant 4: Sample baseline successful traffic at 5%
      - name: baseline-probabilistic
        type: probabilistic
        probabilistic: { sampling_percentage: 5.0 }

  batch:
    send_batch_size: 8192
    timeout: 5s

exporters:
  otlp/tempo:
    endpoint: tempo-distributor.monitoring.svc.cluster.local:4317
    tls:
      insecure: false
      ca_file: /etc/ssl/certs/internal-ca.crt

service:
  pipelines:
    traces:
      receivers: [otlp]
      processors: [memory_limiter, tail_sampling, batch]
      exporters: [otlp/tempo]
```

Architectural Specification & Invariant Rationale

Architectural Invariant Design: OpenTelemetry Collector Tail-Based Sampling and Exemplar Retention Standard

OpenTelemetry Collector Tail-Based Sampling and Exemplar Retention Standard defines an industrial-grade behavioral standard for devops engineering. Architects a two-tier OpenTelemetry Collector topology utilizing trace-ID routing via loadbalancingexporter and tail_sampling processors to deterministically retain 100% of traces with errors, P99 latency spikes, and explicit business anomalies while reducing healthy trace volume by over 80%. Guarantees continuous Prometheus and OpenTelemetry metric correlation by enforcing Span-to-Metric Exemplar propagation across service boundaries. 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: Head-based probabilistic SDK sampling and stateless uncoordinated Collector load balancing that fragment traces and discard root-cause error diagnostics. 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 DriftHead-based probabilistic SDK sampling and stateless uncoordinated Collector load balancing that fragment traces and discard root-cause error diagnostics.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 deploy a two-tier collector topology where Tier-1 (agent/gateway) uses 'loadbalancingexporter' routing by 'trace_id' to Tier-2 stateful collectors running 'tail_sampling'.

Engineers MUST ALWAYS deploy a two-tier collector topology where Tier-1 (agent/gateway) uses 'loadbalancingexporter' routing by 'trace_id' to Tier-2 stateful collectors running '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

Engineers MUST NOT run 'tail_sampling' processors behind round-robin L4/L7 load balancers, as spans for a single trace will be partitioned across replicas, resulting in fractured trace retention and incorrect decisions.

Engineers MUST NOT run 'tail_sampling' processors behind round-robin L4/L7 load balancers, as spans for a single trace will be partitioned across replicas, resulting in fractured trace retention and incorrect decisions.

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

Collector tail-sampling policies MUST ALWAYS explicitly evaluate and capture 100% of traces containing 'status_code

Collector tail-sampling policies MUST ALWAYS explicitly evaluate and capture 100% of traces containing 'status_code: ERROR', HTTP 5xx codes, gRPC non-zero codes, or downstream span exceptions before applying probabilistic rules.

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

Collector pipelines MUST define latency-based sampling thresholds tuned to the service P95/P99 baseline (e.g., latency > 1500ms) to ensure anomalous performance regressions are never dropped.

Collector pipelines MUST define latency-based sampling thresholds tuned to the service P95/P99 baseline (e.g., latency > 1500ms) to ensure anomalous performance regressions are never dropped.

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

Engineers MUST configure Prometheus and OTel metric pipelines to preserve OpenTelemetry Exemplars, linking trace IDs directly to histogram bucket observations across both sampled-in and dropped trace paths.

Engineers MUST configure Prometheus and OTel metric pipelines to preserve OpenTelemetry Exemplars, linking trace IDs directly to histogram bucket observations across both sampled-in and dropped trace paths.

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

Collector instances running 'tail_sampling' MUST dimension memory buffers to accommodate the maximum 'decision_wait' window (minimum 10s-30s) alongside P99 burst trace volume to prevent premature cache eviction.

Collector instances running 'tail_sampling' MUST dimension memory buffers to accommodate the maximum 'decision_wait' window (minimum 10s-30s) alongside P99 burst trace volume to prevent premature cache eviction.

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 and Exemplar Retention Standard critical for AI coding assistants?

Architects a two-tier OpenTelemetry Collector topology utilizing trace-ID routing via loadbalancingexporter and tail_sampling processors to deterministically retain 100% of traces with errors, P99 latency spikes, and explicit business anomalies while reducing healthy trace volume by over 80%. Guarantees continuous Prometheus and OpenTelemetry metric correlation by enforcing Span-to-Metric Exemplar propagation across service boundaries. 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 (Head-based probabilistic SDK sampling and stateless uncoordinated Collector load balancing that fragment traces and discard root-cause error diagnostics.) 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