Architectural Invariant Design: OpenTelemetry GenAI Semantic Conventions and Exemplar Trace Invariant
OpenTelemetry GenAI Semantic Conventions and Exemplar Trace Invariant defines an industrial-grade behavioral standard for devops engineering. Enforces strict compliance with OpenTelemetry GenAI Semantic Conventions across federated LLM routing gateways and proxy layers. Guarantees immutable propagation of W3C trace context, standardized gen_ai.* metric naming, and explicit exemplar linkage between financial token cost metrics and active spans for SLA audits. 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 | Fragmented Ad-Hoc Metric Payloads and Broken W3C Exemplar Linkage in Gateway Dispatchers | 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:
Services MUST emit spans matching `gen_ai.system`, `gen_ai.request.model`, `gen_ai.response.model`, `gen_ai.usage.input_tokens`, and `gen_ai.usage.output_tokens` adhering strictly to official OTel semantic conventions.
Services MUST emit spans matching `gen_ai.system`, `gen_ai.request.model`, `gen_ai.response.model`, `gen_ai.usage.input_tokens`, and `gen_ai.usage.output_tokens` adhering strictly to official OTel semantic conventions.
Engineers MUST ALWAYS extract and inject W3C Distributed Tracing headers (`traceparent`, `tracestate`) across federated upstream router boundaries before making downstream provider API calls.
Engineers MUST ALWAYS extract and inject W3C Distributed Tracing headers (`traceparent`, `tracestate`) across federated upstream router boundaries before making downstream provider API calls.
Engineers MUST NOT emit custom or unstandardized token counter metrics (e.g., `llm_cost_total` or `prompt_tokens_used`)
Engineers MUST NOT emit custom or unstandardized token counter metrics (e.g., `llm_cost_total` or `prompt_tokens_used`); all token recording MUST bind directly to `gen_ai.client.token.usage` histogram or counter instruments with explicit Exemplars containing the current `trace_id` and `span_id`.
Spans MUST transition to an `ERROR` status code and explicitly set `error.type` when model invocation fails or rate limits trigger, without swallowing stack traces or trace context.
Spans MUST transition to an `ERROR` status code and explicitly set `error.type` when model invocation fails or rate limits trigger, without swallowing stack traces or trace context.
Gateways NEVER record raw user prompts or generated model completions into trace attributes unless explicitly masked and gated behind an opt-in privacy flag (`gen_ai.capture_message_content=true`).
Gateways NEVER record raw user prompts or generated model completions into trace attributes unless explicitly masked and gated behind an opt-in privacy flag (`gen_ai.capture_message_content=true`).
Frequently Asked Technical Questions
Common questions developers face when configuring AI coding assistants for this stack:
Q:Why is OpenTelemetry GenAI Semantic Conventions and Exemplar Trace Invariant critical for AI coding assistants?
Enforces strict compliance with OpenTelemetry GenAI Semantic Conventions across federated LLM routing gateways and proxy layers. Guarantees immutable propagation of W3C trace context, standardized gen_ai.* metric naming, and explicit exemplar linkage between financial token cost metrics and active spans for SLA audits. 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 (Fragmented Ad-Hoc Metric Payloads and Broken W3C Exemplar Linkage in Gateway Dispatchers) 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.