Trace Waterfall
Show an agent run's spans on one time axis, with the latency, tokens, and cost of each step and the details of the one you choose.
Overview
Trace Waterfall shows how an agent run spent its time. Each row is a span: a model call, a tool call, a retrieval, a sub-agent, or a step that groups others. Its bar starts when the span started and is as long as the span took, so slow steps, retries, and work that ran in parallel are visible at a glance. Choosing a span shows what went in, what came out, and why it failed.
It shows the spans you pass. Send it the spans your tracing backend records, nested through children, or pass flat spans with a parentId through buildTraceTree.
Anatomy
- HeaderThe run's title, its status, and totals for duration, tokens, cost, and spans
- AxisColumn names and time ticks from the first span's start
- SpanA chevron, the kind's icon, the name, a bar on the time axis, the duration, and input and output tokens
- DetailThe chosen span's timing, model, tokens, cost, error, input, output, and attributes
Behavior
Time
Times are milliseconds on any clock, as long as every span uses the same one. The axis runs from the earliest start to the latest end. A span without end is running: its bar reaches now, or the latest end when now is not passed, and it pulses. Pass a new now as time passes to grow running spans live.
Totals
The header adds up the tokens and cost of spans without children, because a parent span usually reports the sum of its children already. The duration is the length of the axis. The status is Running while any span runs, Failed when any span failed, and Completed otherwise.
Spans
Every span with children starts open. Clicking the chevron opens or closes it; clicking the row chooses it. A failed span shows a red icon and a red bar, so a failure is never hidden in a closed parent's row: the parent keeps its own status, and the header says Failed. Kinds are told apart by icon, not color.
Details
Choosing a span shows its details under the tree. Strings in input and output are shown as preformatted text in a scrolling box; pass a React node to render them yourself, such as with Code View. Choose the span again, press Escape, or use the close button to hide the details. Pass renderDetail to replace the panel.
Narrow layouts
The tokens column is hidden below about 34rem, and the time axis below about 28rem. Durations stay, and the detail panel still lists everything.
Accessibility
The spans follow the tree view pattern and are named by the title. Each span reports its level, its place among its siblings, whether it is chosen, and whether it is open. Its name is followed by its kind, its status when it is not completed, its duration, and its tokens, written out as "812 input tokens, 96 output tokens". The bars and tick marks are hidden from assistive technology, since the duration says the same in words.
In right-to-left layouts, the left and right arrows swap.
Installation
Usage
import { TraceWaterfall, buildTraceTree } from "@/components/ai/trace-waterfall"
<TraceWaterfall
title={run.name}
spans={buildTraceTree(run.spans)}
onSelectedIdChange={(id) => setInspected(id)}
/>While the run is going, pass the current time so running spans grow:
<TraceWaterfall spans={spans} now={Date.now()} />Examples
Live
Spans arrive as the run goes, and running spans grow toward now.
API reference
TraceWaterfall
Accepts native div props beyond those listed.
TraceSpan
buildTraceTree
buildTraceTree(spans: FlatTraceSpan[]): TraceSpan[] nests spans that carry a parentId under their parents and sorts each level by start. A span whose parent is not in the list becomes a top-level span.