This specification is maintained by the AgentRules Working Group. Have enhancements or want to claim maintainership?Submit Specification →
devopscritical PriorityID: opentelemetry-v128-exemplar-cardinality-budget-guardrail

OpenTelemetry v1.28 Exemplar Cardinality & Buffer Saturation Guardrail

Enforces deterministic bounded exemplar retention and probabilistic reservoir sampling across OpenTelemetry v1.28+ collectors and SDKs. Prevents uncontrolled memory bloat and collector crash loops caused by unbudgeted trace exemplar attachment during high-throughput tail-latency metric surges. Mandates explicit reservoir capacity caps, filtered exemplar attachment, and collector batch queue drop-on-overflow behaviors.

Prohibited Anti-Pattern: Unbounded Trace Exemplar Accumulation Saturating Telemetry Buffers During Latency Anomalies

Export Ready-to-Drop Configuration

Select format below to copy code or download file directly.

---
description: OpenTelemetry v1.28 Exemplar Cardinality & Buffer Saturation Guardrail - Enforces deterministic bounded exemplar retention and probabilistic reservoir sampling across OpenTelemetry v1.28+ collectors and SDKs. Prevents uncontrolled memory bloat and collector crash loops caused by unbudgeted trace exemplar attachment during high-throughput tail-latency metric surges. Mandates explicit reservoir capacity caps, filtered exemplar attachment, and collector batch queue drop-on-overflow behaviors.
globs: **/otel-collector*.{yaml,yml}, **/telemetry.{ts,js}, **/instrumentation.{ts,js}, **/monitoring/collector/**/*.yaml
alwaysApply: true
verified_by: "agentrules.org"
license: "CC-BY-4.0"
source: "https://agentrules.org/rules/opentelemetry-v128-exemplar-cardinality-budget-guardrail"
---

# OpenTelemetry v1.28 Exemplar Cardinality & Buffer Saturation Guardrail

> **Severity**: CRITICAL | **Category**: devops
> **Anti-Pattern Warning**: Unbounded Trace Exemplar Accumulation Saturating Telemetry Buffers During Latency Anomalies

## System Constraints
You are a Principal Observability and Infrastructure Architect enforcing deterministic telemetry bounds under OpenTelemetry v1.28+. You mandate strict exemplar budget controls in both SDK meter configurations and Collector telemetry pipelines to prevent OOM kills and downstream saturation under P99 latency bursts.

## Strict Guidelines
- Engineers MUST ALWAYS configure an explicit `ExemplarFilter` (e.g., `TraceBasedExemplarFilter`) and a bounded reservoir such as `FixedSizeExemplarReservoir` or `AlignedHistogramBucketExemplarReservoir` with an upper bound cap of 1 exemplar per bucket or explicit fixed budget.
- Engineers MUST NOT allow default unbounded exemplar attachment or `AlwaysSample` exemplar filters on high-throughput metric streams (e.g., HTTP request duration counters or histogram buckets receiving > 5,000 req/sec).
- Collector pipelines MUST configure `memory_limiter` processor preceding any batching or metric transforming processors with `check_interval: 1s`, `limit_percentage: 75`, and `spike_limit_percentage: 20` to prevent buffer starvation.
- Batch processors MUST explicitly configure bounded `send_batch_max_size` and a strict timeout (`timeout: 200ms` to `1s`) to flush exemplar-heavy metric points before heap exhaustion occurs.
- Prometheus exporters and OTLP exporters MUST specify an explicit exemplar maximum metric point threshold or metric metadata size budget to guard against downstream remote-write rejections (413 Payload Too Large).

## Bad vs Good Implementations
### Configuring OTel Node.js SDK Metric Reader with Bounded Exemplar Reservoir

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: Default configuration does not enforce an exemplar reservoir budget or explicit sampling strategy. Under latency surges, exemplar references accumulate in memory between 60s export intervals, overwhelming the Node.js V8 heap and ballooning OTLP payload sizes.
```typescript
import { MeterProvider, PeriodicExportingMetricReader } from '@opentelemetry/sdk-metrics';
import { OTLPMetricExporter } from '@opentelemetry/exporter-metrics-otlp-grpc';

// ANTI-PATTERN: Default meter provider with unconstrained exemplar allocation.
// Under tail latency spikes, every traced request attaches exemplars to histogram
// buckets without cardinality restrictions, leading to Node.js heap leaks.
export const meterProvider = new MeterProvider({
  readers: [
    new PeriodicExportingMetricReader({
      exporter: new OTLPMetricExporter({
        url: 'http://otel-collector:4317',
      }),
      exportIntervalMillis: 60000,
    }),
  ],
});
```

#### Production Standard (Correct)
> **Standard**: Predefines discrete histogram bounds to clamp exemplar reservoir slot multiplication, sets an aggressive 10s export interval to drain buffers, and limits concurrent in-flight metric requests to prevent memory runaway.
```typescript
import { MeterProvider, PeriodicExportingMetricReader, View, ExplicitBucketHistogramAggregation } from '@opentelemetry/sdk-metrics';
import { OTLPMetricExporter } from '@opentelemetry/exporter-metrics-otlp-grpc';

// PRODUCTION FIX: Explicitly constrain metric views, histogram aggregation boundaries,
// and enforce bounded batching intervals to limit memory footprint.
export const meterProvider = new MeterProvider({
  views: [
    new View({
      instrumentName: '*_duration_ms',
      aggregation: new ExplicitBucketHistogramAggregation([
        1, 5, 10, 25, 50, 100, 250, 500, 1000, 2500, 5000
      ]),
      // Exemplar reservoir bounds are strictly tied to defined histogram boundaries
    }),
  ],
  readers: [
    new PeriodicExportingMetricReader({
      exporter: new OTLPMetricExporter({
        url: 'http://otel-collector:4317',
        concurrencyLimit: 5,
      }),
      exportIntervalMillis: 10000,
      exportTimeoutMillis: 5000,
    }),
  ],
});
```

### OpenTelemetry Collector Memory Limiter and Batch Processor Invariant

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: Without the memory_limiter processor and explicit batch queue sizes, high exemplar volumes during request bursts cause collector buffers to balloon, triggering Linux OOM killer invocation.
```yaml
# ANTI-PATTERN: Collector config lacking memory_limiter guardrail and using infinite queues
processors:
  batch:
    timeout: 10s
    send_batch_size: 10000

pipelines:
  metrics:
    receivers: [otlp]
    processors: [batch]
    exporters: [prometheusremotewrite]
```

#### Production Standard (Correct)
> **Standard**: The memory_limiter processor runs as the initial stage in the pipeline to shed or throttle traffic before saturation. Batch sizes are capped at 4096 entries with a 1-second timeout to bound in-memory exemplar retention.
```yaml
# PRODUCTION FIX: memory_limiter placed first with hard capacity limits and bounded batch buffers
processors:
  memory_limiter:
    check_interval: 1s
    limit_percentage: 75
    spike_limit_percentage: 20

  batch:
    send_batch_size: 2048
    send_batch_max_size: 4096
    timeout: 1s

service:
  pipelines:
    metrics:
      receivers: [otlp]
      processors: [memory_limiter, batch]
      exporters: [prometheusremotewrite]
```

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 v1.28 Exemplar Cardinality & Buffer Saturation Guardrail

OpenTelemetry v1.28 Exemplar Cardinality & Buffer Saturation Guardrail defines an industrial-grade behavioral standard for devops engineering. Enforces deterministic bounded exemplar retention and probabilistic reservoir sampling across OpenTelemetry v1.28+ collectors and SDKs. Prevents uncontrolled memory bloat and collector crash loops caused by unbudgeted trace exemplar attachment during high-throughput tail-latency metric surges. Mandates explicit reservoir capacity caps, filtered exemplar attachment, and collector batch queue drop-on-overflow behaviors. 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 Exemplar Accumulation Saturating Telemetry Buffers During Latency Anomalies 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 Exemplar Accumulation Saturating Telemetry Buffers During Latency AnomaliesCritical
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 configure an explicit `ExemplarFilter` (e.g., `TraceBasedExemplarFilter`) and a bounded reservoir such as `FixedSizeExemplarReservoir` or `AlignedHistogramBucketExemplarReservoir` with an upper bound cap of 1 exemplar per bucket or explicit fixed budget.

Engineers MUST ALWAYS configure an explicit `ExemplarFilter` (e.g., `TraceBasedExemplarFilter`) and a bounded reservoir such as `FixedSizeExemplarReservoir` or `AlignedHistogramBucketExemplarReservoir` with an upper bound cap of 1 exemplar per bucket or explicit fixed budget.

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 allow default unbounded exemplar attachment or `AlwaysSample` exemplar filters on high-throughput metric streams (e.g., HTTP request duration counters or histogram buckets receiving > 5,000 req/sec).

Engineers MUST NOT allow default unbounded exemplar attachment or `AlwaysSample` exemplar filters on high-throughput metric streams (e.g., HTTP request duration counters or histogram buckets receiving > 5,000 req/sec).

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 configure `memory_limiter` processor preceding any batching or metric transforming processors with `check_interval

Collector pipelines MUST configure `memory_limiter` processor preceding any batching or metric transforming processors with `check_interval: 1s`, `limit_percentage: 75`, and `spike_limit_percentage: 20` to prevent buffer starvation.

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

Batch processors MUST explicitly configure bounded `send_batch_max_size` and a strict timeout (`timeout

Batch processors MUST explicitly configure bounded `send_batch_max_size` and a strict timeout (`timeout: 200ms` to `1s`) to flush exemplar-heavy metric points before heap exhaustion occurs.

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

Prometheus exporters and OTLP exporters MUST specify an explicit exemplar maximum metric point threshold or metric metadata size budget to guard against downstream remote-write rejections (413 Payload Too Large).

Prometheus exporters and OTLP exporters MUST specify an explicit exemplar maximum metric point threshold or metric metadata size budget to guard against downstream remote-write rejections (413 Payload Too Large).

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 v1.28 Exemplar Cardinality & Buffer Saturation Guardrail critical for AI coding assistants?

Enforces deterministic bounded exemplar retention and probabilistic reservoir sampling across OpenTelemetry v1.28+ collectors and SDKs. Prevents uncontrolled memory bloat and collector crash loops caused by unbudgeted trace exemplar attachment during high-throughput tail-latency metric surges. Mandates explicit reservoir capacity caps, filtered exemplar attachment, and collector batch queue drop-on-overflow behaviors. 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 Exemplar Accumulation Saturating Telemetry Buffers During Latency Anomalies) 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