Chapter 5.3 — Semantic tracing¶
🎯 Objective¶
Define, at an operational level, the minimum content of a trace in AI systems. Without standardization, traces become illegible and incident investigation turns into prospecting.
🧠 Span types¶
| Type | Key attributes |
|---|---|
| LLM call | model.name, model.version, prompt.version, input/output tokens, cost, latency, ttft |
| Embedding | model.name, dimensions, batch_size, latency |
| Tool call | tool.name, tool.version, args (redacted), result_size, error |
| Retrieval | index, dimensions, top_k, filters, scores |
| Agent execution | agent.name, agent.version, total tokens, steps, decision_path |
| Handoff (multi-agent / A2A) | from, to, task_id, payload size |
| Human approval | requester, approver, decision, latency |
| Policy decision | policy.bundle, decision, reason |
| ML inference | model.name, model.version, features hashing, latency, output |
🧭 Mapping to OpenTelemetry GenAI¶
The names above are the book's. OpenTelemetry maintains GenAI semantic conventions (gen_ai.*) that cover the same ground; the mapping, for those exporting via OTel:
| Book field | gen_ai.* attribute |
Note |
|---|---|---|
model.name |
gen_ai.request.model (request) / gen_ai.response.model (response) |
The model actually served may differ from the one requested |
| provider | gen_ai.provider.name |
Replaced gen_ai.system in August 2025 (v1.37.0) |
| input/output tokens | gen_ai.usage.input_tokens / gen_ai.usage.output_tokens |
There are specific attributes for cache, audio, image and reasoning tokens |
| operation (chat, embeddings, retrieval) | gen_ai.operation.name |
Required; names the span ({operation} {model}) |
agent (agent.name, steps) |
invoke_agent / create_agent spans with gen_ai.agent.name; execute_tool with gen_ai.tool.name and gen_ai.tool.call.id |
invoke_agent is CLIENT for a remote agent and INTERNAL for an in-process agent |
| conversation / session | gen_ai.conversation.id |
Correlates turns of the same conversation |
| prompt and response content | gen_ai.input.messages / gen_ai.output.messages |
Opt-in: not captured by default, for privacy; the old per-message events were deprecated |
| tool call via MCP | mcp.method.name, mcp.session.id, mcp.protocol.version; tool calls with gen_ai.operation.name=execute_tool |
Trace context propagated in params._meta (traceparent, tracestate, baggage), aligned with the MCP 2026-07-28 spec |
Maturity (checked on 2026-10-25). Everything under
gen_ai.*is in Development status: it is not stable. In June 2026 (semantic conventions release v1.42.0) the GenAI conventions left the main repository and now live inopen-telemetry/semantic-conventions-genai, still without a versioned release; the old pages onopentelemetry.ioare "moved" notices. Before that, release v1.37.0 (August 2025) renamedgen_ai.systemtogen_ai.provider.nameand deprecated the per-message events. In practice, three generations of attributes emitted by different frameworks coexist, alongside parallel vocabularies. Recommendation: adoptgen_ai.*as an emerging standard, but keep your own normalization layer (the book's fields serve as the internal schema) between instrumentation libraries and the backend, and pin the convention version each instrumentation library emits.
📊 Suggested minimum fields¶
trace.id, span.id, parent.id,
agent.name, agent.version,
model.name, model.version, prompt.version,
tenant.id (hash), user.id (hash),
input.tokens, output.tokens, cached.tokens,
cost.usd, latency.ms, ttft.ms,
retriever.index, retriever.dimensions, retriever.scores,
tool.name, tool.version,
policy.bundle, policy.decision, policy.reason,
guardrail.triggered, guardrail.action,
error.code, error.kind (if any)
🧠 Conscious sampling¶
Tracing 100% at scale is expensive. Poorly done sampling hides exactly the interesting case. Useful strategies:
- Tiered sampling. High on errors, high on new cases, high on critical tenants; lower on routine traffic.
- Head sampling (decided at the start) is cheaper; tail sampling (decided later) captures tails with more fidelity.
- Force 100% during active incidents with an operational toggle.
🧠 Trace replay¶
Saving structured traces enables replay: re-running the same input against a candidate version and measuring the difference. Replay is the most honest form of "test in production" without affecting a real user.
For replay to work:
- Inputs must be captured in a reproducible form.
- PII must be redacted from capture onward.
- Tools with side effects must have a mock/replay mode.
🚨 Observability cost¶
Semantic tracing is not free. Typical costs:
- Span volume per task: dozens in complex agents.
- Retention: regulation may require 6–24 months for audit.
- Backend: storage + indexing + queries.
Cost-reduction decisions involve: sampling, payload compaction, tiered retention (hot/warm/cold) and separating operational traces (short-term) from audit traces (long-term).
📚 References¶
- OpenTelemetry — Semantic Conventions for Generative AI (
semantic-conventions-genairepository; Development status): https://github.com/open-telemetry/semantic-conventions-genai - OpenTelemetry — GenAI client inference span (
gen_ai.*, opt-in content): https://github.com/open-telemetry/semantic-conventions-genai/blob/main/docs/gen-ai/client-inference.md - OpenTelemetry — GenAI agent spans (
invoke_agent,execute_tool): https://github.com/open-telemetry/semantic-conventions-genai/blob/main/docs/gen-ai/gen-ai-agent-spans.md - OpenTelemetry — Semantic conventions for MCP (
mcp.*, trace context in_meta): https://github.com/open-telemetry/semantic-conventions-genai/blob/main/docs/gen-ai/mcp.md - OpenTelemetry — semantic-conventions v1.37.0 (
gen_ai.system→gen_ai.provider.name; per-message events deprecated; 2025): https://github.com/open-telemetry/semantic-conventions/releases/tag/v1.37.0 - OpenTelemetry — semantic-conventions v1.42.0 (migration of the GenAI conventions to their own repository; 2026): https://github.com/open-telemetry/semantic-conventions/releases/tag/v1.42.0