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

OpenTelemetry Tail-Based Exemplar Metric Reservoir Quota and Memory Bounding Guardrail

Enforces strict memory-bounding and reservoir quota limits on OpenTelemetry trace-to-metric exemplar retention. Prevents catastrophic distributed collector and agent out-of-memory (OOM) crashes by constraining exemplar allocation under high-cardinality traffic bursts.

Prohibited Anti-Pattern: Unbounded Exemplar Allocation in Metric Aggregators Triggering Collector OOMs

Export Ready-to-Drop Configuration

Select format below to copy code or download file directly.

---
description: OpenTelemetry Tail-Based Exemplar Metric Reservoir Quota and Memory Bounding Guardrail - Enforces strict memory-bounding and reservoir quota limits on OpenTelemetry trace-to-metric exemplar retention. Prevents catastrophic distributed collector and agent out-of-memory (OOM) crashes by constraining exemplar allocation under high-cardinality traffic bursts.
globs: **/telemetry/**/*.{ts,js,go,py}, **/instrumentation/**/*.{ts,js,go,py}, **/otel-collector*.{yaml,yml}, src/observability/**/*.{ts,js}
alwaysApply: true
verified_by: "agentrules.org"
license: "CC-BY-4.0"
source: "https://agentrules.org/rules/opentelemetry-exemplar-reservoir-quota-guardrail"
---

# OpenTelemetry Tail-Based Exemplar Metric Reservoir Quota and Memory Bounding Guardrail

> **Severity**: CRITICAL | **Category**: devops
> **Anti-Pattern Warning**: Unbounded Exemplar Allocation in Metric Aggregators Triggering Collector OOMs

## System Constraints
You are a Principal Software Architect enforcing production reliability standards for telemetry collection pipelines. You must mandate strict memory bounding, size-limited reservoirs, and deterministic sampling policies on all OpenTelemetry exemplar configurations to prevent collector and application OOM crashes.

## Strict Guidelines
- Services MUST ALWAYS configure an explicit, bounded ExemplarReservoir factory (such as FixedSizeExemplarReservoir or bucket-aligned reservoirs with strict max capacity) on all custom meter providers.
- Engineers MUST NOT rely on default exemplar allocation or unbounded TraceBasedExemplarFilter implementations under high-frequency distributed tracing environments.
- Services MUST enforce strict byte and entry limits in OpenTelemetry Collector processor pipelines (e.g., memory_limiter combined with batch processor) upstream of metric exporters.
- Components NEVER attach high-cardinality span attributes (such as user IDs, raw request payloads, or full URLs) directly to metric exemplar label sets.
- Code SHOULD enforce sample-rate decay or tail-based filtering (such as AlwaysSample with probabilistic reservoirs) to prevent biased metric exemplar starvation and heap saturation.

## Bad vs Good Implementations
### Configuring Bounded Exemplar Reservoir in OpenTelemetry SDK

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: Omitting explicit exemplar reservoir sizing allows every sampled trace context to be retained within metric aggregations, exhausting process memory under sustained high-throughput conditions.
```typescript
import { MeterProvider } from '@opentelemetry/sdk-metrics';
import { AlwaysOnSampler } from '@opentelemetry/sdk-trace-base';

// ANTI-PATTERN: Default or unconstrained exemplar filters capture every sampled span,
// quickly causing unconstrained heap growth and collector crashes under high throughput.
export const meterProvider = new MeterProvider({
  // No exemplar reservoir limits defined
  // Unbounded trace context attachments lead to memory leaks in metrics pipelines
});
```

#### Production Standard (Correct)
> **Standard**: Constrains exemplar allocation using a FixedSizeExemplarReservoir with a strict upper-bound quota (100 samples), preventing memory bloat while preserving representative trace exemplars.
```typescript
import { MeterProvider, PeriodicExportingMetricReader } from '@opentelemetry/sdk-metrics';
import {
  ExemplarFilter,
  ExemplarReservoirFactory,
  FixedSizeExemplarReservoir
} from '@opentelemetry/sdk-metrics';

const MAX_EXEMPLAR_RESERVOIR_SIZE = 100;

// PRODUCTION INVARIANT: Explicitly bound exemplar storage to a deterministic quota
const boundedReservoirFactory: ExemplarReservoirFactory = {
  create: () => new FixedSizeExemplarReservoir(MAX_EXEMPLAR_RESERVOIR_SIZE),
};

export const meterProvider = new MeterProvider({
  exemplarFilter: ExemplarFilter.traceBased(),
  readers: [
    new PeriodicExportingMetricReader({
      exporter: metricExporter,
      exportIntervalMillis: 15000,
    }),
  ],
  // Guarantees strictly bounded exemplar retention per metric stream
  exemplarReservoirFactory: boundedReservoirFactory,
});
```

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-Based Exemplar Metric Reservoir Quota and Memory Bounding Guardrail

OpenTelemetry Tail-Based Exemplar Metric Reservoir Quota and Memory Bounding Guardrail defines an industrial-grade behavioral standard for devops engineering. Enforces strict memory-bounding and reservoir quota limits on OpenTelemetry trace-to-metric exemplar retention. Prevents catastrophic distributed collector and agent out-of-memory (OOM) crashes by constraining exemplar allocation under high-cardinality traffic bursts. 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 Exemplar Allocation in Metric Aggregators Triggering Collector OOMs 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 Exemplar Allocation in Metric Aggregators Triggering Collector OOMsCritical
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

Services MUST ALWAYS configure an explicit, bounded ExemplarReservoir factory (such as FixedSizeExemplarReservoir or bucket-aligned reservoirs with strict max capacity) on all custom meter providers.

Services MUST ALWAYS configure an explicit, bounded ExemplarReservoir factory (such as FixedSizeExemplarReservoir or bucket-aligned reservoirs with strict max capacity) on all custom meter providers.

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 rely on default exemplar allocation or unbounded TraceBasedExemplarFilter implementations under high-frequency distributed tracing environments.

Engineers MUST NOT rely on default exemplar allocation or unbounded TraceBasedExemplarFilter implementations under high-frequency distributed tracing environments.

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

Services MUST enforce strict byte and entry limits in OpenTelemetry Collector processor pipelines (e.g., memory_limiter combined with batch processor) upstream of metric exporters.

Services MUST enforce strict byte and entry limits in OpenTelemetry Collector processor pipelines (e.g., memory_limiter combined with batch processor) upstream of metric exporters.

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

Components NEVER attach high-cardinality span attributes (such as user IDs, raw request payloads, or full URLs) directly to metric exemplar label sets.

Components NEVER attach high-cardinality span attributes (such as user IDs, raw request payloads, or full URLs) directly to metric exemplar label sets.

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

Code SHOULD enforce sample-rate decay or tail-based filtering (such as AlwaysSample with probabilistic reservoirs) to prevent biased metric exemplar starvation and heap saturation.

Code SHOULD enforce sample-rate decay or tail-based filtering (such as AlwaysSample with probabilistic reservoirs) to prevent biased metric exemplar starvation and heap saturation.

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-Based Exemplar Metric Reservoir Quota and Memory Bounding Guardrail critical for AI coding assistants?

Enforces strict memory-bounding and reservoir quota limits on OpenTelemetry trace-to-metric exemplar retention. Prevents catastrophic distributed collector and agent out-of-memory (OOM) crashes by constraining exemplar allocation under high-cardinality traffic bursts. 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 Exemplar Allocation in Metric Aggregators Triggering Collector OOMs) 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