Question-led guide · implementation
What belongs in an AI agent trace schema?
A field-level design for tracing agent runs across models, retrieval, tools, policy decisions, outcomes, cost, and privacy boundaries.
Direct answer
An agent trace schema should identify the run and operation, preserve parent and link relationships, pin every executable version, describe the requested task and policy context, record model and tool attempts, reference admitted evidence, distinguish attempted from confirmed side effects, allocate latency and cost, and state outcome plus stop reason. It also needs privacy classification, redaction status, schema version, and observation-quality fields. Put large or sensitive payloads behind controlled references instead of embedding them in spans.
Scope
This schema is for agent runtimes that combine model calls, retrieval, tools, policy checks, and evaluators. It is a logical contract, not a requirement to place every field on every OpenTelemetry span. Decide which data belongs in resource attributes, span attributes, events, metrics, logs, and protected evidence stores.
Why it happens
Instrumentation usually grows component by component. The model gateway records tokens, the retriever records query latency, the tool service logs HTTP requests, and the product database stores the final state. Each component may be healthy while the overall run is impossible to reconstruct. Common names such as request_id, session_id, and user_id also acquire incompatible meanings.
A trace schema should begin from the questions operators and evaluators must answer, then map those questions to stable fields and relationships.
Diagnosis
Review existing telemetry for four kinds of ambiguity:
- Identity ambiguity: a run, attempt, conversation, tool transaction, and external effect share or lack identifiers.
- Version ambiguity: the model alias, prompt, policy, tool schema, retrieval index, or evaluator changed without an immutable reference.
- State ambiguity: telemetry cannot distinguish requested, authorized, attempted, returned, confirmed, compensated, and unknown.
- meaning ambiguity:
success,cost,confidence, orresulthas no documented definition and unit.
If a field cannot be defined in one sentence with its unit, allowed values, owner, privacy class, and compatibility rule, it is not ready to become a production contract.
Solution
Organize the schema into nine groups:
| Group | Minimum fields |
|---|---|
| Envelope | schema_version, run_id, started_at, ended_at, environment |
| Relationships | trace_id, span_id, parent_span_id, typed links for retries or handoffs |
| Task | task_type, task_version, tenant_ref, requested_outcome, risk_class |
| Executable versions | agent, model, prompt, policy, tool-contract, retrieval-index, evaluator versions |
| Model operation | provider, operation, model, request settings, token counts, finish or error reason |
| Evidence | source reference, version or observed time, query reference, rank, admission decision |
| Tool operation | tool, action, authorization, idempotency key, attempt, response, effect confirmation |
| Economics | latency, provider units, currency, allocated cost, cache status, retry waste |
| Outcome and governance | execution state, evaluation state, business outcome, stop reason, privacy class, redaction |
Use OpenTelemetry trace context for distributed correlation and established semantic attributes where their definitions fit. Put local concepts under a documented namespace. Version the envelope and publish compatibility rules: additive optional fields, deprecated fields, semantic changes, and required migrations.
Do not put unbounded arrays or complete documents in span attributes. Emit bounded events or store a protected object and record its immutable reference, hash, classification, and retention policy.
Artifact
Start with the Agent Run Envelope JSON Schema. Validate envelopes at ingestion and maintain a representative compatibility fixture for every released schema version.
Common mistakes
- Calling every operation
agent.stepand placing meaning in free-form text. - Recording a mutable model or prompt alias without a resolved version.
- Mixing requested tool calls, provider responses, and confirmed external effects.
- Putting high-cardinality or sensitive payloads into metric labels.
- Using
success: truewhen only execution completion is known. - Adding fields without a data owner, privacy class, unit, or evolution rule.
Evidence
Trace context supplies interoperable identifiers for correlating operations across process boundaries.
The W3C Trace Context Recommendation defines traceparent and tracestate for propagating distributed trace context.
Primary source · standard · checked Aug 25, 2026
Limit: Propagation identifies related operations but does not define agent semantics, privacy controls, or business outcomes.
Generative AI attributes can form an interoperable base for model-operation telemetry.
OpenTelemetry maintains a registry for generative-AI attributes such as provider, operation, request, response, and token-related concepts.
Primary source · standard · checked Aug 25, 2026
Limit: Applications must check the stability level and cannot assume the registry covers tool effects, local policy, or outcome semantics.
Schema evolution must be explicit so stored telemetry remains interpretable after field definitions change.
OpenTelemetry schemas describe transformations between telemetry semantic versions.
Primary source · standard · checked Aug 25, 2026
Limit: A local agent envelope still needs its own compatibility policy and migration tests.
Limitations
Field names in emerging generative-AI semantic conventions can change. Verify the OpenTelemetry stability level before production rollout and document every local extension.
FAQ
- Should every agent step become a span?
- No. Create spans for operations that matter to latency, causality, ownership, effects, or diagnosis; keep low-value internal chatter as bounded events or attributes.
- Where should retrieved documents be stored?
- Store stable identifiers, versions, ranks, relevance decisions, and protected references in telemetry. Keep full documents in their governed source or a separately controlled evidence store.
Related guides
Continue within Agent observability, or use one of these adjacent diagnostics:
English editorial review: Codex native-English editorial review, .
