This specification is maintained by the AgentRules Working Group. Have enhancements or want to claim maintainership?Submit Specification →
devopscritical PriorityID: otel-ingest-dynamic-cardinality-guardrail

OpenTelemetry Ingest Attribute Dynamic Cardinality and Redaction Guardrail

Protects distributed telemetry storage backends (e.g., Prometheus, Mimir, ClickHouse, Tempo) from catastrophic cardinality explosions and out-of-memory (OOM) outages. Enforces collector-level regex normalization, key quotas, and runtime masking on high-entropy dimensions (UUIDs, raw URLs, user emails) before ingestion. Eliminates multi-thousand dollar telemetry cloud billing overages by shedding unbounded labels deterministically at ingress.

Prohibited Anti-Pattern: Attaching Unbounded High-Entropy Dimensions Directly to Metrics and Distributed Spans

Export Ready-to-Drop Configuration

Select format below to copy code or download file directly.

---
description: OpenTelemetry Ingest Attribute Dynamic Cardinality and Redaction Guardrail - Protects distributed telemetry storage backends (e.g., Prometheus, Mimir, ClickHouse, Tempo) from catastrophic cardinality explosions and out-of-memory (OOM) outages. Enforces collector-level regex normalization, key quotas, and runtime masking on high-entropy dimensions (UUIDs, raw URLs, user emails) before ingestion. Eliminates multi-thousand dollar telemetry cloud billing overages by shedding unbounded labels deterministically at ingress.
globs: **/otel-collector*.yaml, **/otel-collector*.yml, deploy/k8s/**/*.yaml, src/telemetry/**/*.{ts,js,py,go}
alwaysApply: true
verified_by: "agentrules.org"
license: "CC-BY-4.0"
source: "https://agentrules.org/rules/otel-ingest-dynamic-cardinality-guardrail"
---

# OpenTelemetry Ingest Attribute Dynamic Cardinality and Redaction Guardrail

> **Severity**: CRITICAL | **Category**: devops
> **Anti-Pattern Warning**: Attaching Unbounded High-Entropy Dimensions Directly to Metrics and Distributed Spans

## System Constraints
You are a Principal Observability and SRE Architect enforcing strict dynamic cardinality guardrails across OpenTelemetry instrumentations and collector pipelines. You must prevent catastrophic metric cardinality explosions and span index exhaustion caused by dynamic identifiers (UUIDs, emails, query parameters, hex hashes) being injected into metric labels or indexed span attributes. Enforce strict collector transform/filter/attributes processor pipelines and client-side sanitization invariants.

## Strict Guidelines
- Engineers MUST ALWAYS sanitize, mask, or route dynamic identifiers (e.g., UUIDs, user IDs, raw URLs) to span events, unindexed attributes, or logs, NEVER into metric label dimensions.
- Engineers MUST NOT concatenate raw, unparameterized HTTP path strings containing IDs (e.g., `/api/v1/orders/550e8400-e29b-41d4-a716-446655440000`) into `http.route` or metric dimensions; parameterized templates (e.g., `/api/v1/orders/{orderId}`) MUST be used.
- OpenTelemetry Collector pipelines MUST implement `transform` or `attributes` processors with strict regex matching to strip or replace high-entropy values like UUIDs (`[0-9a-fA-F-]{36}`) and emails with redaction placeholders (`[REDACTED_UUID]`).
- Services MUST configure the `metricstransform` or `filter` processor in collector pipelines to enforce strict label allowlists and drop unknown or ephemeral metric labels before forwarding to time-series backends.
- Collector pipelines MUST define a hard limit on attribute counts (e.g., `limit` processor or OTTL `keep_keys` directive) to prevent memory allocation attacks and collector container OOM kills.

## Bad vs Good Implementations
### Collector OTTL Processor vs Raw Unbounded Collector Ingress

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: Directly passing raw telemetry data to time-series and trace backends allows arbitrary dynamic labels (UUIDs, transaction IDs, raw URLs) to trigger immediate Prometheus OOM crashes and astronomical storage bills.
```yaml
# otel-collector-config.yaml - ANTI-PATTERN: Passes unbounded high-cardinality attributes directly to Prometheus and Tempo
processors:
  batch:
    timeout: 1s
    send_batch_size: 1024

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

#### Production Standard (Correct)
> **Standard**: OTTL statements actively normalize dynamic UUIDs to static tokens ({id}) and prune hazardous identity keys from metric dimensions before ingestion, bounding time-series growth.
```yaml
# otel-collector-config.yaml - PRODUCTION STANDARD: Enforces regex masking, route normalization, and label cardinality bounds via OTTL
processors:
  batch:
    timeout: 1s
    send_batch_size: 1024

  transform/cardinality_guard:
    error_mode: ignore
    metric_statements:
      - context: datapoint
        statements:
          # Mask UUIDs in metric attributes
          - replace_pattern(attributes["http.target"], "[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}", "{id}")
          # Strip high-risk unbounded dimensions
          - delete_key(attributes, "user.email")
          - delete_key(attributes, "account.id")
    trace_statements:
      - context: span
        statements:
          - replace_pattern(attributes["http.url"], "[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}", "{id}")

  filter/metric_labels:
    metrics:
      datapoint:
        - 'metric.name == "http.server.duration" and attributes["customer_tier"] == nil'

pipelines:
  metrics:
    receivers: [otlp]
    processors: [transform/cardinality_guard, filter/metric_labels, batch]
    exporters: [prometheusremotewrite]
  traces:
    receivers: [otlp]
    processors: [transform/cardinality_guard, batch]
    exporters: [otlp/tempo]
```

### Application Instrumentation: Dynamic URL String vs Parameterized Route Metric

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: Using unparameterized request URLs and user identifiers creates millions of distinct metric time-series streams, triggering severe memory leaks and backend storage throttling.
```typescript
import { metrics } from '@opentelemetry/api';
import { Request, Response } from 'express';

const meter = metrics.getMeter('billing-service');
const requestCounter = meter.createCounter('http.requests.total');

export function trackRequest(req: Request, res: Response) {
  // DANGEROUS: req.originalUrl contains dynamic path params (/users/123e4567-e89b.../cards/987)
  // Creates a brand new Prometheus time series per unique request URL
  requestCounter.add(1, {
    'http.url': req.originalUrl,
    'user.id': req.headers['x-user-id'] as string,
    'status_code': res.statusCode
  });
}
```

#### Production Standard (Correct)
> **Standard**: Using parameterized Express route definitions bounds cardinality to static application routes, preserving metric backend stability while trace contexts retain granular forensic data.
```typescript
import { metrics } from '@opentelemetry/api';
import { Request, Response } from 'express';

const meter = metrics.getMeter('billing-service');
const requestCounter = meter.createCounter('http.server.requests_total');

export function trackRequest(req: Request, res: Response) {
  // SAFE: Use parameterized route template; place user identifiers strictly in trace context/events
  const routeTemplate = req.baseUrl + (req.route?.path || '/unmatched');
  
  requestCounter.add(1, {
    'http.route': routeTemplate,
    'http.method': req.method,
    'http.status_code': res.statusCode
  });
}
```

Architectural Specification & Invariant Rationale

Architectural Invariant Design: OpenTelemetry Ingest Attribute Dynamic Cardinality and Redaction Guardrail

OpenTelemetry Ingest Attribute Dynamic Cardinality and Redaction Guardrail defines an industrial-grade behavioral standard for devops engineering. Protects distributed telemetry storage backends (e.g., Prometheus, Mimir, ClickHouse, Tempo) from catastrophic cardinality explosions and out-of-memory (OOM) outages. Enforces collector-level regex normalization, key quotas, and runtime masking on high-entropy dimensions (UUIDs, raw URLs, user emails) before ingestion. Eliminates multi-thousand dollar telemetry cloud billing overages by shedding unbounded labels deterministically at ingress. 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: Attaching Unbounded High-Entropy Dimensions Directly to Metrics and Distributed Spans 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 DriftAttaching Unbounded High-Entropy Dimensions Directly to Metrics and Distributed SpansCritical
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 sanitize, mask, or route dynamic identifiers (e.g., UUIDs, user IDs, raw URLs) to span events, unindexed attributes, or logs, NEVER into metric label dimensions.

Engineers MUST ALWAYS sanitize, mask, or route dynamic identifiers (e.g., UUIDs, user IDs, raw URLs) to span events, unindexed attributes, or logs, NEVER into metric label 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 NOT concatenate raw, unparameterized HTTP path strings containing IDs (e.g., `/api/v1/orders/550e8400-e29b-41d4-a716-446655440000`) into `http.route` or metric dimensions

Engineers MUST NOT concatenate raw, unparameterized HTTP path strings containing IDs (e.g., `/api/v1/orders/550e8400-e29b-41d4-a716-446655440000`) into `http.route` or metric dimensions; parameterized templates (e.g., `/api/v1/orders/{orderId}`) MUST be used.

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

OpenTelemetry Collector pipelines MUST implement `transform` or `attributes` processors with strict regex matching to strip or replace high-entropy values like UUIDs (`[0-9a-fA-F-]{36}`) and emails with redaction placeholders (`[REDACTED_UUID]`).

OpenTelemetry Collector pipelines MUST implement `transform` or `attributes` processors with strict regex matching to strip or replace high-entropy values like UUIDs (`[0-9a-fA-F-]{36}`) and emails with redaction placeholders (`[REDACTED_UUID]`).

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 configure the `metricstransform` or `filter` processor in collector pipelines to enforce strict label allowlists and drop unknown or ephemeral metric labels before forwarding to time-series backends.

Services MUST configure the `metricstransform` or `filter` processor in collector pipelines to enforce strict label allowlists and drop unknown or ephemeral metric labels before forwarding to time-series backends.

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

Collector pipelines MUST define a hard limit on attribute counts (e.g., `limit` processor or OTTL `keep_keys` directive) to prevent memory allocation attacks and collector container OOM kills.

Collector pipelines MUST define a hard limit on attribute counts (e.g., `limit` processor or OTTL `keep_keys` directive) to prevent memory allocation attacks and collector container OOM kills.

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 Ingest Attribute Dynamic Cardinality and Redaction Guardrail critical for AI coding assistants?

Protects distributed telemetry storage backends (e.g., Prometheus, Mimir, ClickHouse, Tempo) from catastrophic cardinality explosions and out-of-memory (OOM) outages. Enforces collector-level regex normalization, key quotas, and runtime masking on high-entropy dimensions (UUIDs, raw URLs, user emails) before ingestion. Eliminates multi-thousand dollar telemetry cloud billing overages by shedding unbounded labels deterministically at ingress. 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 (Attaching Unbounded High-Entropy Dimensions Directly to Metrics and Distributed Spans) 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