Instrumenting Tool Calls and Diffs as First-Class Observability Events
Tool calls and diffs need separate observability spans to reconstruct failures and enforce policy.

Full observability for AI coding agent sessions requires logs of LLM responses and linked records of tool calls, file diffs, intermediate state, and token attribution. Instrumenting tool calls and diffs as first-class observability events makes external changes attributable, failures reconstructable, and policy enforceable before an action completes. These events belong inside the session’s execution trace, with separate audit records to keep the evidence for the long term.
Why tool calls and diffs require a different observability model than LLM responses
A fired API call cannot be taken back. An LLM response can be reviewed and ignored, but a committed database write has already changed an external system. Coding agents therefore need records of what they changed.
Traditional application performance monitoring detects HTTP errors and timeouts, but it cannot establish whether an agent selected the wrong tool, supplied the wrong arguments, or drifted from its plan. A call can return HTTP 200 with an empty, null, or malformed payload. The request succeeded, but the agent could no longer trust its context. Across dozens of model calls and tool invocations, that bad result can poison subsequent steps, while an unrecorded file diff leaves the resulting regression disconnected from its originating session.
What “first-class observability event” actually means for a tool call
Diagnosing the wrong-tool or wrong-arguments failure requires more than a call count. A first-class tool-call span records the tool name, arguments passed, raw output, duration, retry count, and error state. Arguments show what the agent requested, while raw output preserves the evidence available for its next decision. Retry count and error state show repeated attempts that would otherwise look like healthy traffic.
The call also needs an address within the run. Spans that are typed and timestamped and have parent-child links put each invocation in a single trace that shows the execution graph for one request. That structure connects a failed call to the step that prompted it and the steps that depended on it.
Tool calls alone are necessary but insufficient. The broader schema includes four span types, namely tool-call spans, reasoning spans for the plan-act-observe cycle, state-transition spans for working memory before and after each step, and memory-operation spans for reads, writes, and retrieval scores. These distinguish a bad invocation from a bad plan, a corrupted state transition, or an unsuitable retrieval. Each failure becomes visible at the layer where it needs correction.
Why diffs deserve their own span type, separate from tool-call output
A tool’s return value is not a codebase delta. Tool-call spans record arguments and results, but they do not automatically preserve what files contained before and after execution. Coding agents need to record that change in a separate diff event. Otherwise, code review may identify a regression without connecting it to the agent run that introduced it.
The diff event must record the files changed, before-and-after state, session or run ID, triggering tool call, and timestamp. Those fields make it joinable to both the execution trace and version control history. The tool span explains the invocation, while the diff establishes its effect on the codebase. Keeping them separate also prevents attribution from depending on whether a tool happens to return a useful description of its edits.
Audit use imposes a further requirement on that record. Hash-chaining and signing make later alteration detectable, so an editable event is not mistaken for tamper-evident evidence. Completeness and integrity answer different questions. A diff can describe the right change yet remain unsuitable for audit if someone can silently rewrite its history.
The OpenTelemetry GenAI semantic conventions as the connective tissue for agent instrumentation
The OpenTelemetry GenAI semantic conventions provide a common vocabulary for portable instrumentation through gen_ai.* span attributes, metric instruments, and events. This separates the instrumentation design from the backend that stores it. Adopting that vocabulary lets teams change observability platforms without rebuilding the agent’s instrumentation.
The conventions make several boundaries explicit for agent execution. An execute_tool span represents a single tool or function call, with tool name required and arguments and result marked opt-in because they are sensitive. MCP instrumentation enriches that span in place. An invoke_workflow span can parent multiple invoke_agent children, making handoffs readable within one trace.
The practical choice is in-process SDK instrumentation for agents a team owns, because it provides semantic context, and eBPF-based monitoring for third-party or closed-source components, where code modification is unavailable. The latter captures less semantic detail. Native framework adapters can normalize mixed stacks into a common schema, with OTel providing the fallback for unsupported frameworks.
How silent tool failures cascade through multi-step agent runs
An empty result becomes dangerous when the next step trusts it. If a tool returns malformed data and the agent incorporates it into working memory, later decisions operate on corrupted context. The eventual answer may remain confident and superficially coherent. Output logging captures that answer but not the point where the run departed from valid evidence.
Intermediate state is not automatically preserved between steps. Reconstructing the failure therefore depends on deliberately recording the plan-act-observe cycle, state transitions, and memory operations around the tool call. The trace must distinguish the tool’s bad output from the agent’s subsequent use of it. Without that distinction, a fix may remove the final symptom and leave the cause of the failure in place.
The same gap also weakens accountability across delegated work. Agent handoffs can fragment the record of who acted on which information, even when each service appears healthy. The NIST AI RMF and EU AI Act make this audit gap a compliance concern, even though neither has its own category for agentic systems. Output logs alone do not explain a chain of external actions.
Structuring tool-call and diff events for debugging versus audit: two different schemas for two different uses
Debugging needs full context, recorded reasoning steps, intermediate state, retry chains, and raw outputs so an engineer can reconstruct a failure. These records are high-volume and short-retention. Their value lies in the detail around a particular decision, including unsuccessful attempts that never changed external state.
Audit records prioritize attribution and detectable alteration over diagnostic breadth. Their schema needs session ID, agent identity, tool name, arguments, result, timestamp, and a hash or signature. These records are lower-volume and long-retention, intended for reviewers whose questions may not be known when capture occurs. Shared identifiers connect the two schemas without forcing identical payloads or retention rules.
aGiTrack demonstrates a version-control-native way to connect execution and diffs. It commits each agent turn to git and records the prompt, backend, model, and per-turn token counts in the commit message. That places execution metadata directly beside the diff history. Bifrost Enterprise illustrates a different separation, with administrative audit logs that can be cryptographically authenticated, while request logs and OpenTelemetry traces cover runtime tool execution.
Implementing per-session cost instrumentation alongside tool-call tracing
A budget overrun is difficult to diagnose from an account total. A silent retry loop can consume resources while aggregate traffic still appears healthy, just as a malformed result can propagate through apparently successful steps. Cost therefore belongs in the execution trace. Per-step attribution shows which model invocations and tool calls ran up the cost, so teams can see why they spent it before a billing report arrives.
The span schema needs to record token consumption and compute cost for each tool call as well as for the whole run. Budget controls then operate at the run, step, and tool levels. At defined thresholds, dynamic rules can route work to a less expensive model, compress context, or gate non-critical tool calls. These controls depend on cost data being available at decision time.
Cost and latency data for each task can help teams route most tasks to smaller models, fewer to mid-tier models, and only a small fraction to frontier models. Token records for each step show where context repeats and prompt caching may help. Anthropic’s cache_control offers such a caching mechanism, but the trace identifies which repeated contexts are worth targeting.
Sandbox isolation as the precondition for trustworthy tool-call and diff records
If sessions share credentials or can interfere with one another’s filesystems, the record may faithfully capture an action without establishing which session controlled the affected state. Isolation sets the limits of what an audit record can claim. Credentials must be minted for each session and revoked on completion so attribution of an action identifies a specific run and trigger for “the agent.
The propose/dispose pattern separates execution from authority to write. The job running the agent has read-only access and no deploy secrets, while its output is a reviewable patch artifact. A downstream job makes the writes after a human approves them. The diff event belongs to the propose phase, and the audit trail covers both phases so the proposed change remains connected to its approved application.
NVIDIA’s OpenShell demonstrates the infrastructure pattern through an open-source sandbox runtime with kernel-level isolation governed by declarative YAML security policies. Isolation gives those policies an execution boundary beyond their statements in a log. The Docker sandbox pattern adds reproducibility by defining tools, credentials, network rules, and configuration in one YAML file. Comparable environments make trace differences interpretable, while inconsistent environments leave uncertainty about whether behavior changed because of the agent or its surroundings.
Policy enforcement at the tool-call boundary: acting on events in real time, not after review
A structured tool-call event can do more than describe completed work. When it exists in the execution path, its tool name, arguments, identity, and context become inputs to a policy decision. Enforcement attaches to the same boundary that produces the trace. This is the transition from observing an action to governing whether it may complete.
A call that would drop a database table or force-push to main should be pausable for human approval before execution. Recording it afterward preserves evidence but cannot provide that control. Proofpane implements execution-path decisions that allow, deny, redact, or pause for a human, and produces a hash-chained audit with an offline-verifiable, digitally signed evidence pack.
The boundary also applies to what comes back. The OWASP Agentic AI threat model identifies prompt injection through untrusted tool output as a primary attack vector. Policy inspection checks the content at that point, before the agent uses it to make later decisions. The tool-call event links invocation control, output inspection, and the evidence of the decision across the systems that handle them.
Agents-as-code and YAML configuration as the governance layer for what gets instrumented
The rules for producing evidence need their own review history. Decisions about which tool calls to log, which diffs to capture, what budgets to enforce, and where approval is required belong in version control with the agent configuration. Otherwise, an audit trail may describe execution without explaining the capture policy in force at the time. Configuration is part of the evidence boundary.
A YAML-defined agent makes tool permissions, budget caps, and logging policy reviewable in a pull request, platforms such as Ellipsis, a managed cloud runtime for Claude Code and Codex agents where every session's credentials, budget caps, and audit logs are defined as YAML config files in the repo, are built around exactly this model. Scoped credentials and audit-trail settings can be governed through the same repo-native process. Repository history then preserves the intended configuration for each revision, giving reviewers a basis for understanding changes in instrumentation. This makes the decision to omit an event as reviewable as the decision to permit a tool.
Governance therefore asks what the agent did and who approved the rules under which that action was permitted, measured, and recorded.


