Coding Agent Observability: A Practical Runtime Tracing Architecture
Learn how to build runtime tracing for coding agents using a five-level call tree, plugin-based event collection, and asynchronous batch delivery. This article covers dynamic parent–child relationships, out-of-order events, restart continuity, and the trade-offs needed to analyze latency, failures, and costs across sessions and machines.
Coding Agent Observability: A Practical Runtime Tracing Architecture
1. From Session Logs to Execution Traces
When an AI agent runs only occasional debugging tasks, reading its session logs may be enough to find a problem. But as agents become part of everyday development—generating code, fixing bugs, and performing batch refactoring—the volume of work grows, and the questions change:
- Where does the time go? Is model inference slow, or is a tool call stalled?
- Which types of tasks fail most often, and at which stage?
- What drives costs: expanding context or unproductive retry loops?
Manually reviewing conversations cannot reliably answer these questions at scale. What you need is a call tree for every task, with parent–child relationships and timing information, backed by data that can be aggregated across sessions and machines and retained over time.
That is the role of an observability architecture.
2. Understand the System Before Instrumenting It
A useful observability design starts with the structure of the system being observed. Three characteristics of a typical coding agent framework directly shape the architecture.
A Microkernel with Pluggable Capabilities
The kernel contains no business capabilities of its own. It assembles plugins from configuration and manages their lifecycles. Model adapters, toolsets, sandbox policies, and session persistence are all plugins. Command-line, graphical, and headless interfaces share the same kernel.
This means observability can also be implemented as a plugin, without modifying the framework itself. That is the architectural prerequisite for collecting telemetry without changes to framework business logic.
A ReAct Execution Model with a Dynamic Structure
A user task is a turn. Within a turn, each cycle of reasoning, tool use, and observation is a step.
The number of steps, the tools selected at each step, and any nested calls triggered by those tools are unknown when execution begins. The model determines them dynamically from intermediate results.
As a result, the call tree cannot be defined statically. The observability system must establish parent–child relationships at runtime and accommodate arbitrary nesting and branching.
Concurrent Execution Across Processes and Sessions
At scale, multiple tasks may run concurrently across multiple machines. Their telemetry is naturally distributed. Without cross-session aggregation, the observability system provides only fragments of the execution picture.
3. A Five-Level Call Tree: Turning Events into Structure
The core data model is a five-level call tree:
- Session: A complete interaction that may contain multiple tasks.
- Turn: A single user task—the basic unit for cost accounting and success-rate analysis.
- Step: One reasoning–tool use–observation cycle, corresponding to a model call and the tool calls it produces.
- Tool Call: A single tool execution, including an input summary, duration, result summary, and status.
- IO/Event: The most granular events, such as streamed model output chunks, file reads and writes, and command
stdoutorstderr.
Each node carries a trace_id shared by the tree, a parent_id linking it to its parent, a unique span_id, and start and end timestamps. These fields allow incoming events to be attached to the appropriate location in the tree.
Two reconstruction details matter:
- Events may arrive out of order. The aggregation layer should buffer and merge records by
span_id, rather than rely on arrival order. - Long-running tasks may span process restarts. Identifiers must be persisted in session storage so that the call tree can continue after a restart.
4. Non-Intrusive Collection: Observability as a Plugin
With a plugin-based kernel, integration is straightforward: enable the observability plugin in configuration, and the kernel loads it at startup. No changes to framework business code are required.
The key mechanism is event bus subscription. The kernel publishes standardized events at lifecycle boundaries, including session creation, task start, model request start and completion, and tool invocation start and completion. The plugin subscribes to those events and asynchronously converts them into call-tree nodes.
class ObservabilityPlugin:def on_kernel_ready(self, bus, sink):bus.subscribe("turn.started", self.on_turn_start)bus.subscribe("step.finished", self.on_step_end)bus.subscribe("tool.invoked", self.on_tool_call)self.sink = sink # Batch delivery channeldef on_tool_call(self, evt):node = Span(span_id=evt.id, parent_id=evt.step_id,name=evt.tool, start=evt.ts, attrs=evt.args_digest)self.sink.enqueue(node)
Two engineering rules are essential.
First, telemetry collection must never block the main execution path. Serialization and network delivery belong in asynchronous queue processing.
Second, sensitive fields must be redacted or reduced to summaries before enqueueing. Code snippets, credentials, and similar data should not be collected indiscriminately. Retain only the minimum information required for troubleshooting.
5. The Trade-Offs of Batched Delivery
There are two common delivery patterns: send each event as it is produced, or buffer events locally and send them in batches. At scale, batching is generally preferable for three reasons:
- Lower network overhead: Per-event delivery magnifies connection and protocol overhead at high event rates. Batching can reduce request counts by one to two orders of magnitude.
- Backpressure isolation: Local buffering can absorb traffic spikes when the observability backend is unstable or unavailable, keeping backend problems off the agent’s main execution path.
- Controlled bandwidth costs: Compressing batches before transmission significantly reduces bandwidth usage.
The trade-offs are higher delivery latency and a risk of data loss. Three settings typically govern the balance:
- Maximum buffered record count
- Maximum buffer residence time
- Local disk spill policy
Flush when either threshold is reached: send when the buffer contains N records or the oldest buffered data has waited T seconds.
Unsent data should be persisted locally for replay after a restart, including recovery from abnormal process termination. The local persistence policy therefore needs to account for that failure case.
If the team already uses a general-purpose logging service or monitoring and alerting platform, the aggregation layer can feed that existing infrastructure. Reusing its storage, search, and alerting capabilities avoids building an entire observability backend from scratch.
6. What Tracing Enables—and Where to Start
Once execution traces are available, the original questions become measurable:
- Find performance bottlenecks by aggregating duration distributions by node type.
- Identify failure patterns by grouping errors according to the nodes where they occur, then use those findings to improve prompts and tool design.
- Understand costs by tracking model and tool usage per turn to support capacity and budget planning.
For teams implementing this architecture, three principles matter most:
- Model first, collect second. A clearly defined call-tree model makes downstream analysis much more effective.
- Keep collection asynchronous. Observability must not slow down the system it observes.
- Collect the minimum necessary data. Retain only the fields needed for troubleshooting and analysis to reduce costs and support compliance.
Observability is not a patch to add after agents reach scale. It is infrastructure that should be in place before they do.
