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

OpenTelemetry Tail-Sampling Exemplar and Error Retention Invariant

Enforces deterministic retention of all distributed traces associated with high-percentile latency (p99+) and HTTP 5xx/gRPC errors within OpenTelemetry Collector tail-sampling pipelines. Prevents broken metric-to-trace exemplar correlation in observability backends caused by premature probabilistic drop policies.

Prohibited Anti-Pattern: Dropping p99 and 5xx traces through downstream probabilistic tail-sampling, creating orphan metric exemplars

Export Ready-to-Drop Configuration

Select format below to copy code or download file directly.

---
description: OpenTelemetry Tail-Sampling Exemplar and Error Retention Invariant - Enforces deterministic retention of all distributed traces associated with high-percentile latency (p99+) and HTTP 5xx/gRPC errors within OpenTelemetry Collector tail-sampling pipelines. Prevents broken metric-to-trace exemplar correlation in observability backends caused by premature probabilistic drop policies.
globs: **/otel-collector*.{yaml,yml}, **/collector*.{yaml,yml}, **/otel/*.{yaml,yml}, deployments/**/otel*.{yaml,yml}, helm/**/values*.{yaml,yml}
alwaysApply: true
verified_by: "agentrules.org"
license: "CC-BY-4.0"
source: "https://agentrules.org/rules/otel-collector-tail-sampling-exemplar-retention"
---

# OpenTelemetry Tail-Sampling Exemplar and Error Retention Invariant

> **Severity**: CRITICAL | **Category**: devops
> **Anti-Pattern Warning**: Dropping p99 and 5xx traces through downstream probabilistic tail-sampling, creating orphan metric exemplars

## System Constraints
You are a Principal Observability and Infrastructure Architect enforcing OpenTelemetry Collector tail-sampling guarantees. You mandate that any OpenTelemetry Collector configuration MUST guarantee 100% retention for spans matching error conditions (HTTP 5xx, gRPC != 0, span status error) and high-latency thresholds (p99 SLA violations) before any probabilistic sampling policy is evaluated. Traces linked to metric exemplars MUST NOT return 404 in storage backends like Jaeger or Tempo.

## Strict Guidelines
- Engineers MUST ALWAYS order tail-sampling policies such that deterministic error status rules and latency threshold rules appear BEFORE probabilistic or rate-limiting rules.
- Engineers MUST configure 'decision_wait' to at least 1.5x the maximum expected p99 trace duration (typically 10s-30s) to prevent premature partial trace sampling evaluations.
- Collector pipelines MUST define a 100% sample percentage for spans with 'status.code == STATUS_CODE_ERROR' or HTTP status >= 500.
- Services MUST NOT use head-based probabilistic sampling if Prometheus/OTel exemplars are recorded at client runtimes; trace sampling MUST be deferred to collector tail-sampling.
- Components NEVER drop traces with 'forced-sampling=true' or 'sampled=true' attributes injected by upstream debug or testing harnesses.

## Bad vs Good Implementations
### OpenTelemetry Collector Tail-Sampling Configuration

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: Evaluating probabilistic sampling first drops up to 95% of critical 5xx errors and p99 latency spikes before they reach error or latency policies. This causes Prometheus/Grafana metric exemplars to point to missing traces (404 errors in Tempo/Jaeger). Additionally, a 2s decision_wait truncates long-running traces.
```yaml
processors:
  tail_sampling:
    decision_wait: 2s
    num_traces: 10000
    expected_new_traces_per_sec: 2000
    # ANTI-PATTERN: Probabilistic sampling evaluated first drops
    # p99 anomalies and 5xx errors before specialized rules match
    policies:
      - name: probabilistic-sample
        type: probabilistic
        probabilistic:
          sampling_percentage: 5.0
      - name: error-conditions
        type: status_code
        status_code:
          status_codes: [ERROR]
      - name: latency-p99
        type: latency
        latency:
          threshold_ms: 2000
```

#### Production Standard (Correct)
> **Standard**: Error conditions and high-latency thresholds are prioritized at 100% retention. All traces containing span errors, HTTP 5xx responses, or >1500ms duration are guaranteed preservation. Only normal traces fall through to the 2% probabilistic sampler, ensuring all metric exemplars map directly to intact distributed traces.
```yaml
processors:
  tail_sampling:
    decision_wait: 15s
    num_traces: 50000
    expected_new_traces_per_sec: 5000
    # PRODUCTION FIX: Deterministic retention for errors and p99 latency
    # evaluated ahead of probabilistic baseline to guarantee exemplar correlation
    policies:
      - name: retain-status-errors
        type: status_code
        status_code:
          status_codes: [ERROR]
      - name: retain-http-5xx
        type: numeric_attribute
        numeric_attribute:
          key: http.response.status_code
          min_value: 500
          max_value: 599
      - name: retain-p99-latency
        type: latency
        latency:
          threshold_ms: 1500
      - name: fallback-probabilistic-sampling
        type: probabilistic
        probabilistic:
          sampling_percentage: 2.0
```

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 Tail-Sampling Exemplar and Error Retention Invariant

OpenTelemetry Tail-Sampling Exemplar and Error Retention Invariant defines an industrial-grade behavioral standard for devops engineering. Enforces deterministic retention of all distributed traces associated with high-percentile latency (p99+) and HTTP 5xx/gRPC errors within OpenTelemetry Collector tail-sampling pipelines. Prevents broken metric-to-trace exemplar correlation in observability backends caused by premature probabilistic drop policies. 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: Dropping p99 and 5xx traces through downstream probabilistic tail-sampling, creating orphan metric exemplars 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 DriftDropping p99 and 5xx traces through downstream probabilistic tail-sampling, creating orphan metric exemplarsCritical
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 order tail-sampling policies such that deterministic error status rules and latency threshold rules appear BEFORE probabilistic or rate-limiting rules.

Engineers MUST ALWAYS order tail-sampling policies such that deterministic error status rules and latency threshold rules appear BEFORE probabilistic or rate-limiting 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.
2

Engineers MUST configure 'decision_wait' to at least 1.5x the maximum expected p99 trace duration (typically 10s-30s) to prevent premature partial trace sampling evaluations.

Engineers MUST configure 'decision_wait' to at least 1.5x the maximum expected p99 trace duration (typically 10s-30s) to prevent premature partial trace sampling evaluations.

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 pipelines MUST define a 100% sample percentage for spans with 'status.code == STATUS_CODE_ERROR' or HTTP status >= 500.

Collector pipelines MUST define a 100% sample percentage for spans with 'status.code == STATUS_CODE_ERROR' or HTTP status >= 500.

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

Services MUST NOT use head-based probabilistic sampling if Prometheus/OTel exemplars are recorded at client runtimes

Services MUST NOT use head-based probabilistic sampling if Prometheus/OTel exemplars are recorded at client runtimes; trace sampling MUST be deferred to collector 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.
5

Components NEVER drop traces with 'forced-sampling=true' or 'sampled=true' attributes injected by upstream debug or testing harnesses.

Components NEVER drop traces with 'forced-sampling=true' or 'sampled=true' attributes injected by upstream debug or testing harnesses.

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 Tail-Sampling Exemplar and Error Retention Invariant critical for AI coding assistants?

Enforces deterministic retention of all distributed traces associated with high-percentile latency (p99+) and HTTP 5xx/gRPC errors within OpenTelemetry Collector tail-sampling pipelines. Prevents broken metric-to-trace exemplar correlation in observability backends caused by premature probabilistic drop policies. 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 (Dropping p99 and 5xx traces through downstream probabilistic tail-sampling, creating orphan metric exemplars) 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