Observability

Run Trace

Flame graph of an agent run with click-to-zoom spans, plus a breakdown of where time, tokens and cost went.

3 variantsMIT

Preview

Installation

Copies the component into components/ui and installs its dependencies and theme tokens.

pnpm dlx shadcn@latest add https://uilab.tmih06.com/r/run-trace.json

Usage

Pass your own data and wire the callbacks to your agent runtime.

import { RunTrace, type TraceSpan } from "@/components/ui/run-trace";

// Map your tracer's spans (OpenTelemetry, Langfuse, agent SDK events) to TraceSpan.
export function Trace({ spans, elapsedMs }: { spans: TraceSpan[]; elapsedMs: number }) {
  return (
    <RunTrace
      data={{ spans, elapsedMs }}
      onZoom={(span) => analytics.track("trace_zoom", { span: span?.name })}
    />
  );
}

// While the run is live, leave endMs undefined on open spans and
// re-render with a growing elapsedMs (e.g. from requestAnimationFrame).

// Pass null while the first trace payload is in flight. When refetching,
// keep the stale payload for shape hints and set loading.
export function TraceState({ query }: { query: TraceQuery }) {
  return (
    <RunTrace
      data={query.data ? toTraceData(query.data) : null}
      loading={query.isRefetching}
      skeleton={{ count: 8, rows: 4 }}
    />
  );
}

Props

PropTypeDefaultDescription
data*{ spans: TraceSpan[]; elapsedMs: number } | null—Spans of one run with offsets from its start. elapsedMs drives running spans and the time axis. Pass null while the first payload loads.
loadingbooleanfalseForce the layout-preserving skeleton while refetching, even when stale data is available.
skeleton{ count?: number; rows?: number }—Shape hints for the loading state; count is the number of span or breakdown-row placeholders and rows reserves flame lanes.
view"flame" | "breakdown""flame"Flame is a zoomable flame graph: click a span to fill the width with it, Esc or the breadcrumb to zoom out. Breakdown totals time, tokens or cost per tool and model.
onZoom(span: TraceSpan | null) => void—Called when the flame graph zooms into a span, or back to the whole run.
localestring"en-US"BCP 47 locale for costs and percentages.
labelsPartial<RunTraceLabels>—Your own UI strings (loading announcement, span kinds, hints, footer, screen-reader text), for translating. Right-to-left works under `dir="rtl"`; the time axis still runs left to right.
classNamestring—Extra classes for the root section.
type TraceSpan = {
  id: string;
  parentId?: string;       // nests the span under another one
  name: string;
  kind: "llm" | "tool" | "agent" | "retrieval";
  startMs: number;         // offset from the start of the run
  endMs?: number;          // undefined while running
  model?: string;
  tokens?: { input: number; output: number };
  costUsd?: number;
  status?: "ok" | "error";
};