Skip to documentation content

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.

trace-waterfall-demo

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

TraceWaterfall
  • 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.

KeyAction
ArrowDown and ArrowUpMove to the next or previous visible span
ArrowRightOpen a closed span, or move into an open one
ArrowLeftClose an open span, or move to the parent
Home and EndMove to the first or last visible span
Enter and SpaceChoose the span, or clear the choice
EscapeHide the details
*Open every span beside the focused one

In right-to-left layouts, the left and right arrows swap.

Installation

npx honestui@latest add trace-waterfall

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.

trace-waterfall-live

API reference

TraceWaterfall

Accepts native div props beyond those listed.

PropTypeDefaultDescription
spansTraceSpan[]RequiredThe top-level spans, nested through children.
titleReactNode"Trace"The heading, which also names the tree.
nownumberNoneThe current time on the spans' clock. Running spans reach it.
expandedstring[]NoneThe ids of open spans, controlled.
defaultExpandedstring[]Every span with childrenThe spans open at first.
onExpandedChange(expanded: string[]) => voidNoneRuns when a span opens or closes.
selectedIdstring | nullNoneThe chosen span, controlled.
defaultSelectedIdstring | nullnullThe span chosen at first.
onSelectedIdChange(id: string | null, span: TraceSpan | null) => voidNoneRuns when a span is chosen or the choice is cleared.
renderDetail(span: TraceSpan) => ReactNodeNoneReplaces the detail panel.
labelsPartial<TraceWaterfallLabels>EnglishEvery word, plus formatDuration, formatTick, formatTokens, formatCost, and tokensDescription.

TraceSpan

FieldTypeDescription
idstringA stable id.
namestringThe step's name, such as a tool's name.
kind"run" | "llm" | "tool" | "retrieval" | "agent" | "chain"Chooses the icon and the word read after the name. Defaults to "chain".
status"running" | "ok" | "error"Defaults to "running" without end, else "ok".
startnumberWhen the span started, in milliseconds.
endnumberWhen it ended. Leave it out while it runs.
modelstringThe model an LLM span called.
tokens{ input?: number; output?: number }The span's tokens.
costnumberWhat the span cost.
input and outputReactNodeWhat went in and came out. Strings are shown as preformatted text.
errorstringWhy the span failed.
attributesRecord<string, string | number | boolean>Extra facts shown in the details.
childrenTraceSpan[]Spans inside this one.

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.