Architectural Invariant Design: OpenTelemetry GenAI Semantic Conventions for Heterogeneous LLM Observability
OpenTelemetry GenAI Semantic Conventions for Heterogeneous LLM Observability defines an industrial-grade behavioral standard for devops engineering. Enforces strict adherence to OpenTelemetry GenAI Semantic Conventions across all LLM inference call sites, agent frameworks, and streaming gateways. Guarantees uniform telemetry capture for token consumption, streaming Time-To-First-Token (TTFT), and agent execution traces to enable accurate cost accounting, auditability, and SLA attribution without leaking unmasked PII. 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 Span Names, Proprietary Token Metric Keys, and Missing Streaming TTFT Telemetry | 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 name LLM client spans using the format `{gen_ai.operation.name} {gen_ai.request.model}` (e.g., 'chat gpt-4o' or 'generate_content claude-3-5-sonnet') and set SpanKind to SpanKind.CLIENT.
Engineers MUST ALWAYS name LLM client spans using the format `{gen_ai.operation.name} {gen_ai.request.model}` (e.g., 'chat gpt-4o' or 'generate_content claude-3-5-sonnet') and set SpanKind to SpanKind.CLIENT.
Engineers MUST ALWAYS set required base attributes
Engineers MUST ALWAYS set required base attributes: `gen_ai.system` (e.g., 'openai', 'anthropic', 'aws.bedrock'), `gen_ai.operation.name` ('chat', 'text_completion', 'embeddings'), and `gen_ai.request.model`.
Engineers MUST ALWAYS record token usage attributes upon completion
Engineers MUST ALWAYS record token usage attributes upon completion: `gen_ai.usage.input_tokens` and `gen_ai.usage.output_tokens`. If the provider supports cached tokens, capture `gen_ai.usage.cache_read_input_tokens` and `gen_ai.usage.cache_creation_input_tokens`.
Engineers MUST measure and record streaming Time-To-First-Token (TTFT) on the arrival of the initial stream chunk, attaching the duration in milliseconds to `gen_ai.client.token.time_to_first_token` or emitting a dedicated `gen_ai.client.first_token` event.
Engineers MUST measure and record streaming Time-To-First-Token (TTFT) on the arrival of the initial stream chunk, attaching the duration in milliseconds to `gen_ai.client.token.time_to_first_token` or emitting a dedicated `gen_ai.client.first_token` event.
Engineers MUST NOT store raw unmasked prompt inputs or model outputs in span attributes unless explicitly enabled by privacy-compliant data redaction flags under `gen_ai.prompt` / `gen_ai.completion` events.
Engineers MUST NOT store raw unmasked prompt inputs or model outputs in span attributes unless explicitly enabled by privacy-compliant data redaction flags under `gen_ai.prompt` / `gen_ai.completion` events.
Engineers MUST ALWAYS record `gen_ai.response.finish_reasons` as an array of strings (e.g., ['stop', 'tool_calls', 'length']) and appropriately set span status to `StatusCode.ERROR` on failed responses or provider timeouts.
Engineers MUST ALWAYS record `gen_ai.response.finish_reasons` as an array of strings (e.g., ['stop', 'tool_calls', 'length']) and appropriately set span status to `StatusCode.ERROR` on failed responses or provider timeouts.
Services MUST link child agent tool calls or multi-turn reasoning steps to the parent GenAI span via standardized OpenTelemetry trace context propagation.
Services MUST link child agent tool calls or multi-turn reasoning steps to the parent GenAI span via standardized OpenTelemetry trace context propagation.
Frequently Asked Technical Questions
Common questions developers face when configuring AI coding assistants for this stack:
Q:Why is OpenTelemetry GenAI Semantic Conventions for Heterogeneous LLM Observability critical for AI coding assistants?
Enforces strict adherence to OpenTelemetry GenAI Semantic Conventions across all LLM inference call sites, agent frameworks, and streaming gateways. Guarantees uniform telemetry capture for token consumption, streaming Time-To-First-Token (TTFT), and agent execution traces to enable accurate cost accounting, auditability, and SLA attribution without leaking unmasked PII. 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 Span Names, Proprietary Token Metric Keys, and Missing Streaming TTFT Telemetry) 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.