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

Deterministic Dynamic Wasm PII Masking and Tail-Based Sampling Pipeline Standard

Mandates inline WebAssembly (Wasm) bytecode execution for zero-allocation, linear-time PII tokenization and cryptographic pseudonymization at the OpenTelemetry Collector ingress edge before any trace egress. Enforces a multi-tiered collector architecture where stateless Wasm sanitation precedes trace-id consistent hash routing into isolated tail-based sampling clusters. Guarantees 100% capture of error/high-latency traces while neutralizing downstream compliance liabilities.

Prohibited Anti-Pattern: Egressing Raw PII in Distributed Spans via Naive Head Sampling and Greedy Regex Processors

Export Ready-to-Drop Configuration

Select format below to copy code or download file directly.

---
description: Deterministic Dynamic Wasm PII Masking and Tail-Based Sampling Pipeline Standard - Mandates inline WebAssembly (Wasm) bytecode execution for zero-allocation, linear-time PII tokenization and cryptographic pseudonymization at the OpenTelemetry Collector ingress edge before any trace egress. Enforces a multi-tiered collector architecture where stateless Wasm sanitation precedes trace-id consistent hash routing into isolated tail-based sampling clusters. Guarantees 100% capture of error/high-latency traces while neutralizing downstream compliance liabilities.
globs: **/otel-collector*.{yaml,yml}, **/collector/**/*.{yaml,yml}, **/k8s/otel*/*.{yaml,yml}, **/wasm/**/*.{rs,go,wasm}
alwaysApply: true
verified_by: "agentrules.org"
license: "CC-BY-4.0"
source: "https://agentrules.org/rules/otel-collector-wasm-pii-tail-sampling-standard"
---

# Deterministic Dynamic Wasm PII Masking and Tail-Based Sampling Pipeline Standard

> **Severity**: CRITICAL | **Category**: devops
> **Anti-Pattern Warning**: Egressing Raw PII in Distributed Spans via Naive Head Sampling and Greedy Regex Processors

## System Constraints
You are a Principal Observability and Infrastructure Security Architect enforcing the OpenTelemetry Collector Dynamic Wasm-Based Ephemeral PII Masking & Tail-Based Sampling Standard. Mandate that every telemetry pipeline sanitizes span attributes, event payloads, and log attributes at edge ingress via memory-safe Wasm filters before stateful persistence or export. Enforce two-tier collector topologies using traceID-based load-balancing exporters to dedicated tail-sampling nodes, prohibiting unmasked trace leakage, catastrophic regex backtracking, and uncoordinated head-drop data loss.

## Strict Guidelines
- Pipelines MUST sanitize all span attributes, resource attributes, and span events using deterministic, precompiled Wasm transforms prior to routing or tail-sampling stages.
- Engineers MUST NOT rely on unanchored or greedy regular expressions within standard transform processors across high-throughput paths (>5,000 spans/sec/core) due to ReDoS and CPU-saturation risks.
- Collector topologies MUST enforce a two-tier topology: Tier-1 Edge Agent (stateless, executes Wasm PII masking, routes via `loadbalancingexporter` keyed on `trace_id`), Tier-2 Cluster (stateful, executes `tail_sampling` with memory ballast and coordinated retention).
- Tail-sampling policies MUST enforce deterministic, non-probabilistic retention (100% sample rate) for spans bearing error status codes (`status.code == 2` / HTTP 5xx) or durations breaching P99 SLO thresholds.
- Wasm sanitization modules MUST be compiled to `wasm32-wasi` or native OTel Wasm targets with zero external network or filesystem system-call permissions, operating exclusively over linear host memory.
- Cryptographic pseudonymization in Wasm modules MUST use ephemeral or salted HMAC hashes (e.g., BLAKE3/SHA-256 with rotatable salt) rather than reversible encryption keys inside collector memory spaces.
- Tail-sampling nodes MUST configure the `decision_wait` parameter based on maximum upstream network latency and span clock drift (recommended: 10s-30s), accompanied by bounded `num_traces` in-memory queues.

## Bad vs Good Implementations
### Vulnerable Head-Sampling and Unbounded Regex Transform Configuration

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: Probabilistic sampling at the edge drops critical error spans while still allowing unmasked PII through for sampled traces. The `transform` processor uses expensive, non-deterministic regex patterns prone to ReDoS, lacks cryptographic one-way hashing, and does not evaluate full trace contexts before sampling.
```yaml
# CRITICAL FLAW: Inefficient regex masking running alongside naive probabilistic
# head-sampling directly exporting to third-party SaaS without distributed trace cohesion.
receivers:
  otlp:
    protocols:
      grpc: { endpoint: 0.0.0.0:4317 }

processors:
  # Flaw: Catastrophic backtracking regex, executes after span dropping,
  # leaves sensitive metadata exposed in logs and custom attributes.
  transform:
    error_mode: ignore
    trace_statements:
      - context: span
        statements:
          - replace_all_patterns(attributes, "value", ".*password.*", "REDACTED")
          - replace_all_patterns(attributes, "value", "\\b[0-9]{16}\\b", "REDACTED")

  probabilistic_sampler:
    sampling_percentage: 10.0 # Flaw: Drops 90% of error traces and context

exporters:
  otlp/vendor:
    endpoint: ingress.signoz-or-datadog-external.net:4317

service:
  pipelines:
    traces:
      receivers: [otlp]
      processors: [probabilistic_sampler, transform]
      exporters: [otlp/vendor]
```

#### Production Standard (Correct)
> **Standard**: Implements Tier-1 ingress isolation where zero-allocation Wasm bytecode scrubbers deterministically redact and pseudonymize PII using linear host memory buffers. Then, spans are consistently hashed across trace IDs via `loadbalancing` exporter to an upstream tail-sampling collector cluster, guaranteeing complete trace capture and zero raw PII leakage.
```yaml
# PRODUCTION STANDARD: Tier-1 Edge Ingress running Wasm Sanitization
# and Trace-ID Consistent Routing to Stateful Tail-Sampling Tier-2.
receivers:
  otlp:
    protocols:
      grpc:
        endpoint: 0.0.0.0:4317
        max_concurrent_streams: 1024

processors:
  memory_limiter:
    check_interval: 250ms
    limit_percentage: 80
    spike_limit_percentage: 20

  # Inline deterministic Wasm PII masking compiled to wasm32-wasi
  wasm/pii_scrubber:
    file: /etc/otel/modules/mask_pii_linear.wasm
    function: sanitize_span_payload
    request_headers:
      - "x-tenant-id"
    environment:
      SALT_ROTATION_EPOCH: "1710000000"

exporters:
  # Consistent hashing ensures all spans for a trace_id route to the same Tier-2 node
  loadbalancing:
    protocol:
      otlp:
        tls:
          insecure: false
          ca_file: /etc/ssl/certs/internal-ca.pem
    resolver:
      dns:
        hostname: otel-collector-tail-tier2.internal.net
        port: 4317
    routing_key: "trace_id"

service:
  telemetry:
    metrics:
      address: 0.0.0.0:8888
  pipelines:
    traces:
      receivers: [otlp]
      processors: [memory_limiter, wasm/pii_scrubber]
      exporters: [loadbalancing]
```

Architectural Specification & Invariant Rationale

Architectural Invariant Design: Deterministic Dynamic Wasm PII Masking and Tail-Based Sampling Pipeline Standard

Deterministic Dynamic Wasm PII Masking and Tail-Based Sampling Pipeline Standard defines an industrial-grade behavioral standard for devops engineering. Mandates inline WebAssembly (Wasm) bytecode execution for zero-allocation, linear-time PII tokenization and cryptographic pseudonymization at the OpenTelemetry Collector ingress edge before any trace egress. Enforces a multi-tiered collector architecture where stateless Wasm sanitation precedes trace-id consistent hash routing into isolated tail-based sampling clusters. Guarantees 100% capture of error/high-latency traces while neutralizing downstream compliance liabilities. 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: Egressing Raw PII in Distributed Spans via Naive Head Sampling and Greedy Regex Processors 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 DriftEgressing Raw PII in Distributed Spans via Naive Head Sampling and Greedy Regex ProcessorsCritical
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

Pipelines MUST sanitize all span attributes, resource attributes, and span events using deterministic, precompiled Wasm transforms prior to routing or tail-sampling stages.

Pipelines MUST sanitize all span attributes, resource attributes, and span events using deterministic, precompiled Wasm transforms prior to routing or tail-sampling stages.

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 unanchored or greedy regular expressions within standard transform processors across high-throughput paths (>5,000 spans/sec/core) due to ReDoS and CPU-saturation risks.

Engineers MUST NOT rely on unanchored or greedy regular expressions within standard transform processors across high-throughput paths (>5,000 spans/sec/core) due to ReDoS and CPU-saturation risks.

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 topologies MUST enforce a two-tier topology

Collector topologies MUST enforce a two-tier topology: Tier-1 Edge Agent (stateless, executes Wasm PII masking, routes via `loadbalancingexporter` keyed on `trace_id`), Tier-2 Cluster (stateful, executes `tail_sampling` with memory ballast and coordinated retention).

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

Tail-sampling policies MUST enforce deterministic, non-probabilistic retention (100% sample rate) for spans bearing error status codes (`status.code == 2` / HTTP 5xx) or durations breaching P99 SLO thresholds.

Tail-sampling policies MUST enforce deterministic, non-probabilistic retention (100% sample rate) for spans bearing error status codes (`status.code == 2` / HTTP 5xx) or durations breaching P99 SLO thresholds.

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

Wasm sanitization modules MUST be compiled to `wasm32-wasi` or native OTel Wasm targets with zero external network or filesystem system-call permissions, operating exclusively over linear host memory.

Wasm sanitization modules MUST be compiled to `wasm32-wasi` or native OTel Wasm targets with zero external network or filesystem system-call permissions, operating exclusively over linear host memory.

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

Cryptographic pseudonymization in Wasm modules MUST use ephemeral or salted HMAC hashes (e.g., BLAKE3/SHA-256 with rotatable salt) rather than reversible encryption keys inside collector memory spaces.

Cryptographic pseudonymization in Wasm modules MUST use ephemeral or salted HMAC hashes (e.g., BLAKE3/SHA-256 with rotatable salt) rather than reversible encryption keys inside collector memory spaces.

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.
7

Tail-sampling nodes MUST configure the `decision_wait` parameter based on maximum upstream network latency and span clock drift (recommended

Tail-sampling nodes MUST configure the `decision_wait` parameter based on maximum upstream network latency and span clock drift (recommended: 10s-30s), accompanied by bounded `num_traces` in-memory queues.

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 Deterministic Dynamic Wasm PII Masking and Tail-Based Sampling Pipeline Standard critical for AI coding assistants?

Mandates inline WebAssembly (Wasm) bytecode execution for zero-allocation, linear-time PII tokenization and cryptographic pseudonymization at the OpenTelemetry Collector ingress edge before any trace egress. Enforces a multi-tiered collector architecture where stateless Wasm sanitation precedes trace-id consistent hash routing into isolated tail-based sampling clusters. Guarantees 100% capture of error/high-latency traces while neutralizing downstream compliance liabilities. 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 (Egressing Raw PII in Distributed Spans via Naive Head Sampling and Greedy Regex Processors) 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

Deterministic