Architectural Invariant Design: OpenTelemetry GenAI Semantic Conventions Redaction & Truncation Invariant
OpenTelemetry GenAI Semantic Conventions Redaction & Truncation Invariant defines an industrial-grade behavioral standard for devops engineering. Mandates strict deterministic token-level PII/secrets redaction and bounded context-window byte/token truncation prior to mutating OpenTelemetry GenAI spans. All spans implementing gen_ai.prompt and gen_ai.completion attributes must execute sanitization pipelines locally in-process before delegating to span processors, batch exporters, or downstream telemetry aggregators. Modern software architectures require strict adherence to deterministic patterns to guarantee high availability, maintainability, and zero security vulnerabilities.
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 Mode | AI Symptom (The Anti-Pattern) | Severity | Production Impact & Remedy |
|---|---|---|---|
| AI Hallucination & Deprecation Drift | Exporting raw prompts and completions directly into gen_ai.* attributes without pre-export redaction and bound checks | Critical | 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 Inconsistency | AI 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. |
Step-by-Step Production Directives
Each rule constraint below is injected into the AI agent's system prompt to establish deterministic boundaries:
Engineers MUST ALWAYS sanitize gen_ai.prompt.* and gen_ai.completion.* attributes via an in-memory redaction engine (e.g., regex/masking rules for API keys, SSNs, credit cards, emails) BEFORE invoking span.setAttribute().
Engineers MUST ALWAYS sanitize gen_ai.prompt.* and gen_ai.completion.* attributes via an in-memory redaction engine (e.g., regex/masking rules for API keys, SSNs, credit cards, emails) BEFORE invoking span.setAttribute().
Engineers MUST enforce strict context-window byte/character truncation limits (default 4096 bytes or explicit token boundary) with an appended '[TRUNCATED]' marker to prevent trace memory exhaustion.
Engineers MUST enforce strict context-window byte/character truncation limits (default 4096 bytes or explicit token boundary) with an appended '[TRUNCATED]' marker to prevent trace memory exhaustion.
Engineers MUST NOT disable redaction conditionally based on process.env.NODE_ENV unless explicitly executing in an isolated local mock environment without actual telemetry exports.
Engineers MUST NOT disable redaction conditionally based on process.env.NODE_ENV unless explicitly executing in an isolated local mock environment without actual telemetry exports.
Custom SpanProcessors SHOULD serve as a secondary defensive fail-safe to drop or scrub accidentally leaked raw attributes prior to BatchSpanProcessor export.
Custom SpanProcessors SHOULD serve as a secondary defensive fail-safe to drop or scrub accidentally leaked raw attributes prior to BatchSpanProcessor export.
Services MUST emit a metric counter (e.g., gen_ai.client.redacted_entities_total) whenever sensitive tokens are caught and neutralized within a trace.
Services MUST emit a metric counter (e.g., gen_ai.client.redacted_entities_total) whenever sensitive tokens are caught and neutralized within a trace.
Frequently Asked Technical Questions
Common questions developers face when configuring AI coding assistants for this stack:
Q:Why is OpenTelemetry GenAI Semantic Conventions Redaction & Truncation Invariant critical for AI coding assistants?
Mandates strict deterministic token-level PII/secrets redaction and bounded context-window byte/token truncation prior to mutating OpenTelemetry GenAI spans. All spans implementing gen_ai.prompt and gen_ai.completion attributes must execute sanitization pipelines locally in-process before delegating to span processors, batch exporters, or downstream telemetry aggregators. 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 (Exporting raw prompts and completions directly into gen_ai.* attributes without pre-export redaction and bound checks) 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.