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

OpenTelemetry Spanmetrics Exemplar Reservoir and Bucket Anchoring Standard

Enforces deterministic latency histogram binning with OpenTelemetry exemplar reservoir sampling instead of promoting trace identifiers to metric labels. This guarantees high-percentile (p95/p99) latency spike trace root-cause attribution without risking downstream TSDB (Prometheus, Mimir, Cortex) time-series cardinality collapse.

Prohibited Anti-Pattern: Promoting Trace and Span IDs to Metric Dimensions Causing TSDB OOM and Cardinality Explosion

Export Ready-to-Drop Configuration

Select format below to copy code or download file directly.

---
description: OpenTelemetry Spanmetrics Exemplar Reservoir and Bucket Anchoring Standard - Enforces deterministic latency histogram binning with OpenTelemetry exemplar reservoir sampling instead of promoting trace identifiers to metric labels. This guarantees high-percentile (p95/p99) latency spike trace root-cause attribution without risking downstream TSDB (Prometheus, Mimir, Cortex) time-series cardinality collapse.
globs: **/otel-collector*.yaml, **/otel-collector*.yml, **/collector-config*.yaml, deployments/**/otel-*.yaml, k8s/**/otel-*.yaml
alwaysApply: true
verified_by: "agentrules.org"
license: "CC-BY-4.0"
source: "https://agentrules.org/rules/otel-spanmetrics-exemplar-reservoir-sampling-standard"
---

# OpenTelemetry Spanmetrics Exemplar Reservoir and Bucket Anchoring Standard

> **Severity**: CRITICAL | **Category**: devops
> **Anti-Pattern Warning**: Promoting Trace and Span IDs to Metric Dimensions Causing TSDB OOM and Cardinality Explosion

## System Constraints
You are a Principal Observability Infrastructure Architect enforcing OpenTelemetry Collector standards. You mandate that span-to-metric conversions must strictly isolate trace and span metadata inside OpenTelemetry Exemplars attached to explicit histogram buckets, completely forbidding high-cardinality attributes in metric labels.

## Strict Guidelines
- Engineers MUST ALWAYS isolate trace identifiers (`trace_id`, `span_id`) exclusively to OpenTelemetry Exemplars and NEVER include them in metric `dimensions`.
- Engineers MUST ALWAYS configure explicit, bounded latency histogram buckets in the `spanmetrics` connector/processor tailored to application SLA boundaries.
- Engineers MUST configure exemplar reservoir sampling on metric points to preserve high-percentile tail latency traces without memory exhaustion.
- Engineers MUST NOT add unbound attributes (such as `user_id`, `customer_id`, `session_id`, `raw_url`, or UUIDs) to `dimensions` within `spanmetrics` configurations.
- Pipelines MUST route traces through the `spanmetrics` connector and emit histogram data directly to metric pipelines carrying trace-anchored exemplars.
- Prometheus exporters MUST enable OpenTelemetry exemplar ingestion and export with appropriate OpenMetrics (`application/openmetrics-text; version=1.0.0`) compatibility headers.

## Bad vs Good Implementations
### Spanmetrics Pipeline Configuration

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: Promoting trace_id, span_id, and user.id as dimensions creates a distinct time-series for every single distributed transaction. This leads to instantaneous TSDB cardinality explosions, scraping timeouts, and database node memory exhaustion.
```yaml
# ANTI-PATTERN: Embedding trace and user identifiers into spanmetrics dimensions
connectors:
  spanmetrics:
    histogram:
      explicit:
        buckets: [10ms, 100ms, 1s]
    dimensions:
      - name: http.status_code
      - name: trace_id         # CRITICAL FAILURE: Generates unbounded time-series per request
      - name: span_id          # CRITICAL FAILURE: Triggers TSDB OOM
      - name: user.id          # CRITICAL FAILURE: High cardinality metric explosion

service:
  pipelines:
    traces:
      receivers: [otlp]
      processors: [batch]
      exporters: [spanmetrics, otlp]
    metrics:
      receivers: [spanmetrics]
      processors: [batch]
      exporters: [prometheus]
```

#### Production Standard (Correct)
> **Standard**: Restricts dimensions to low-cardinality control attributes (status code, normalized route), while enabling exemplars to automatically sample and bind trace/span IDs directly to matching latency histogram buckets without creating extra time-series.
```yaml
# PRODUCTION FIX: Constrained dimensions with exemplar-anchored trace correlation
connectors:
  spanmetrics:
    histogram:
      explicit:
        # Tailored buckets capturing typical distribution and SLA boundaries
        buckets: [2ms, 5ms, 10ms, 25ms, 50ms, 100ms, 250ms, 500ms, 1s, 2.5s, 5s, 10s]
      unit: ms
    dimensions:
      - name: http.status_code
      - name: http.route
        default: "unknown_route"
      - name: rpc.method
    exemplars:
      enabled: true
      max_per_data_point: 1
    dimensions_cache_size: 1000
    aggregation_temporality: "AGGREGATION_TEMPORALITY_CUMULATIVE"

exporters:
  prometheus:
    endpoint: "0.0.0.0:8889"
    enable_open_metrics: true
    send_timestamps: true

service:
  pipelines:
    traces:
      receivers: [otlp]
      processors: [batch]
      exporters: [spanmetrics, otlp]
    metrics:
      receivers: [spanmetrics]
      processors: [batch]
      exporters: [prometheus]
```

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 Spanmetrics Exemplar Reservoir and Bucket Anchoring Standard

OpenTelemetry Spanmetrics Exemplar Reservoir and Bucket Anchoring Standard defines an industrial-grade behavioral standard for devops engineering. Enforces deterministic latency histogram binning with OpenTelemetry exemplar reservoir sampling instead of promoting trace identifiers to metric labels. This guarantees high-percentile (p95/p99) latency spike trace root-cause attribution without risking downstream TSDB (Prometheus, Mimir, Cortex) time-series cardinality collapse. 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: Promoting Trace and Span IDs to Metric Dimensions Causing TSDB OOM and Cardinality Explosion 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 DriftPromoting Trace and Span IDs to Metric Dimensions Causing TSDB OOM and Cardinality ExplosionCritical
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 isolate trace identifiers (`trace_id`, `span_id`) exclusively to OpenTelemetry Exemplars and NEVER include them in metric `dimensions`.

Engineers MUST ALWAYS isolate trace identifiers (`trace_id`, `span_id`) exclusively to OpenTelemetry Exemplars and NEVER include them in metric `dimensions`.

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 ALWAYS configure explicit, bounded latency histogram buckets in the `spanmetrics` connector/processor tailored to application SLA boundaries.

Engineers MUST ALWAYS configure explicit, bounded latency histogram buckets in the `spanmetrics` connector/processor tailored to application SLA boundaries.

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 configure exemplar reservoir sampling on metric points to preserve high-percentile tail latency traces without memory exhaustion.

Engineers MUST configure exemplar reservoir sampling on metric points to preserve high-percentile tail latency traces without memory exhaustion.

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

Engineers MUST NOT add unbound attributes (such as `user_id`, `customer_id`, `session_id`, `raw_url`, or UUIDs) to `dimensions` within `spanmetrics` configurations.

Engineers MUST NOT add unbound attributes (such as `user_id`, `customer_id`, `session_id`, `raw_url`, or UUIDs) to `dimensions` within `spanmetrics` configurations.

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

Pipelines MUST route traces through the `spanmetrics` connector and emit histogram data directly to metric pipelines carrying trace-anchored exemplars.

Pipelines MUST route traces through the `spanmetrics` connector and emit histogram data directly to metric pipelines carrying trace-anchored exemplars.

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

Prometheus exporters MUST enable OpenTelemetry exemplar ingestion and export with appropriate OpenMetrics (`application/openmetrics-text

Prometheus exporters MUST enable OpenTelemetry exemplar ingestion and export with appropriate OpenMetrics (`application/openmetrics-text; version=1.0.0`) compatibility headers.

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 Spanmetrics Exemplar Reservoir and Bucket Anchoring Standard critical for AI coding assistants?

Enforces deterministic latency histogram binning with OpenTelemetry exemplar reservoir sampling instead of promoting trace identifiers to metric labels. This guarantees high-percentile (p95/p99) latency spike trace root-cause attribution without risking downstream TSDB (Prometheus, Mimir, Cortex) time-series cardinality collapse. 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 (Promoting Trace and Span IDs to Metric Dimensions Causing TSDB OOM and Cardinality Explosion) 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