Where a run spent its time: each step in a tree beside a bar on one time axis, with the chosen step's tokens, attributes, input and output.
- 9.5 kB JS 4.7 kB CSS gzipped
- No serious axe issues
- Server-rendered, hydrates
- 44px touch targets
- Right-to-left, arrows swap
- 8 tests
7.42 s in all9 steps6,658 tokens2 errors
- answer_ticket #4821, Agent, 7.42 s, starts at 0 ms
- plan, Model, 1.18 s, starts at 40 ms
- get_jobs, Tool, 2.31 s, starts at 1.26 s, failed
- SELECT export_jobs, Database, 2.01 s, starts at 1.29 s, failed
- SELECT export_jobs (retry), Database, 220 ms, starts at 3.33 s
- search_docs, Search, 640 ms, starts at 1.27 s
- POST /v1/search, HTTP, 560 ms, starts at 1.3 s
- draft_reply, Model, 3.72 s, starts at 3.6 s
- post_internal_note, Tool, 60 ms, starts at 7.34 s
import type { Html } from "effect/ui/html"import * as stylex from "@stylexjs/stylex"import { sx } from "./ui/uicontext/components/Sx.ts"import { type Span, TraceView } from "./ui/uicontext/components/TraceView.ts"const styles = stylex.create({ wrap: { inlineSize: "100%" } })// a support agent answering "Why did my export fail?": it plans, searches the docs, looks up the// customer's jobs, retries a slow call, and writes the replyconst spans: ReadonlyArray<Span> = [ { id: "run", parent: null, name: "answer_ticket #4821", kind: "agent", start: 0, duration: 7420, attributes: { ticket: "4821", customer: "Harborview Supply" } }, { id: "plan", parent: "run", name: "plan", kind: "llm", start: 40, duration: 1180, tokens: { input: 1840, output: 212 }, attributes: { model: "large-2", temperature: "0.2" }, input: "Ticket: Every CSV export since Monday comes back empty.\nTools: search_docs, get_jobs, draft_reply", output: "1. Look up the customer's recent export jobs.\n2. Search the docs for empty exports.\n3. Draft a reply." }, { id: "jobs", parent: "run", name: "get_jobs", kind: "tool", start: 1260, duration: 2310, status: "error", error: "Timed out after 2000 ms; retried once", attributes: { customer_id: "cus_N8x", limit: "20" } }, { id: "jobs-q1", parent: "jobs", name: "SELECT export_jobs", kind: "db", start: 1290, duration: 2010, status: "error", error: "statement timeout", attributes: { rows: "0", index: "none" } }, { id: "jobs-q2", parent: "jobs", name: "SELECT export_jobs (retry)", kind: "db", start: 3330, duration: 220, attributes: { rows: "14", index: "export_jobs_customer_idx" } }, { id: "docs", parent: "run", name: "search_docs", kind: "retrieval", start: 1270, duration: 640, attributes: { query: "csv export empty", hits: "6" }, output: "Exports skip rows the viewer can't see.\nA filter saved on the view applies to exports too." }, { id: "docs-http", parent: "docs", name: "POST /v1/search", kind: "http", start: 1300, duration: 560, attributes: { status: "200" } }, { id: "reply", parent: "run", name: "draft_reply", kind: "llm", start: 3600, duration: 3720, tokens: { input: 4120, output: 486 }, attributes: { model: "large-2", stream: "true" }, output: "Hi Ada, your exports are empty because the Invoices view has a saved filter (Status is Draft). Clear it under Filters, or export from All invoices. Sorry for the trouble." }, { id: "send", parent: "run", name: "post_internal_note", kind: "tool", start: 7340, duration: 60, attributes: { visibility: "team" } },]export const AgentRunTrace = <M>(h: Html.H<M>) => h.div.attrs(sx(styles.wrap)).children(TraceView(h, { key: "run", props: { label: "Run for ticket 4821", spans } }))When to use
Where a run spent its time: each step in a tree beside a bar on one time axis, with the chosen step's tokens, attributes, input and output. Use Run Summary instead when people need the run's outcome and cost, not where its time went.
Usage
import { type Span, TraceView } from "./ui/uicontext/components/TraceView.ts"export const RunTrace = <M>(h: Html.H<M>, spans: ReadonlyArray<Span>) => TraceView(h, { props: { label: "Run trace", spans } })Examples
A slow request, opened one level
depth sets how many levels start open. Open load board to see twelve queries, one after another.
1.84 s in all16 steps
- GET /projects/ENG/board, HTTP, 1.84 s, starts at 0 ms
- check session, Database, 12 ms, starts at 4 ms
- load board, Tool, 1.61 s, starts at 20 ms
- render, Tool, 190 ms, starts at 1.64 s
import type { Html } from "effect/ui/html"import * as stylex from "@stylexjs/stylex"import { sx } from "./ui/uicontext/components/Sx.ts"import { type Span, TraceView } from "./ui/uicontext/components/TraceView.ts"const styles = stylex.create({ wrap: { inlineSize: "100%" } })// one slow page load on the server, opened only to the first level: the N+1 queries hide insideconst spans: ReadonlyArray<Span> = [ { id: "req", parent: null, name: "GET /projects/ENG/board", kind: "http", start: 0, duration: 1840, attributes: { status: "200", user: "u_291" } }, { id: "auth", parent: "req", name: "check session", kind: "db", start: 4, duration: 12 }, { id: "board", parent: "req", name: "load board", kind: "tool", start: 20, duration: 1610 }, ...Array.from({ length: 12 }, (_, i): Span => ({ id: `q${i}`, parent: "board", name: `SELECT issues WHERE column = ${i + 1}`, kind: "db", start: 30 + i * 132, duration: 118 + (i % 3) * 9, attributes: { rows: String(8 + i) } })), { id: "render", parent: "req", name: "render", kind: "tool", start: 1640, duration: 190 },]export const SlowRequest = <M>(h: Html.H<M>) => h.div.attrs(sx(styles.wrap)).children(TraceView(h, { key: "req", props: { label: "Board request", spans, depth: 1 } }))API reference
Props
| Name | Type | Description |
|---|---|---|
labelrequired | string | What the trace is, for screen readers: "Run 4821". |
spansrequired | Span[] | — |
depth | number | How many levels start open; all by default. |
locale | string | For the numbers; the browser's by default. |
Installation
pnpm dlx shadcn@latest add checkfu/uicontext/trace-view