trace
ui · paidone request's spans as a waterfall: who called whom, how long each took, what failed
npx shadcn add @ag/traceA paid item: its source installs with a licence key, kept in .env.local as AG_LICENCE_KEY and sent from components.json. The source stays in your project and out of any public repository. The licence
{
"registries": {
"@ag": {
"url": "https://ui.adriangalilea.com/r/{name}.json",
"headers": { "Authorization": "Bearer ${AG_LICENCE_KEY}" }
}
}
}Already installed? Preview an update
npx shadcn add @ag/trace --dry-runYour installed source stays unchanged until you update it. How updates work
- The details region scrolls in
ScrollArea, the one capped scroller, andtracenow depends onscroll-area. It looks and scrolls as before.
also called waterfall, spans, distributed tracing, flame graph
shelf data & status
uses span, timeline-view, tree, readout, button, key-router, card, scroll-area, scroll-thumb, scrims, material, telemetry
used by deployment
the demo above, verbatim
"use client"
import { Sample } from "@/app/samples"
import type { TraceSpan } from "@/registry/base-nova/lib/telemetry"
import { MaterialProvider } from "@/registry/base-nova/ui/material"
import { Trace } from "@/registry/base-nova/ui/trace"
// #region checkout
/** One checkout as four services traced it, in ms from the request's arrival. The
* first charge times out at the acquirer and the retry goes through; the receipt is
* a queued job the request never waits for, so it runs past its parent and says so. */
const checkout: TraceSpan[] = [
{
id: "a1",
name: "POST /checkout",
service: "frontend",
from: 0,
to: 412.6,
status: "ok",
attributes: {
"http.method": "POST",
"http.route": "/checkout",
"http.status_code": 200,
"user.tier": "plus",
},
},
{
id: "a2",
parentId: "a1",
name: "verify session",
service: "frontend",
from: 2.1,
to: 19.8,
status: "ok",
},
{
id: "a3",
parentId: "a2",
name: "redis GET session",
service: "frontend",
from: 3,
to: 5.4,
status: "ok",
attributes: { "db.system": "redis", "cache.hit": true },
},
{
id: "a4",
parentId: "a2",
name: "decode jwt",
service: "frontend",
from: 5.9,
to: 6.4,
status: "ok",
},
{
id: "b1",
parentId: "a1",
name: "PlaceOrder",
service: "checkout",
from: 22.4,
to: 404.9,
status: "ok",
attributes: { "rpc.system": "grpc", "rpc.method": "PlaceOrder" },
},
{
id: "b2",
parentId: "b1",
name: "load cart",
service: "checkout",
from: 24,
to: 61.3,
status: "ok",
},
{
id: "b3",
parentId: "b2",
name: "SELECT cart_items",
service: "checkout",
from: 25.2,
to: 46.8,
status: "ok",
attributes: { "db.system": "postgresql", "db.rows": 4 },
},
{
id: "b4",
parentId: "b2",
name: "SELECT products",
service: "checkout",
from: 47.5,
to: 59.9,
status: "ok",
attributes: { "db.system": "postgresql", "db.rows": 4 },
},
{
id: "b10",
parentId: "b1",
name: "validate address",
service: "checkout",
from: 61.5,
to: 62.8,
status: "ok",
},
{
id: "c1",
parentId: "b1",
name: "Reserve",
service: "inventory",
from: 63,
to: 148.2,
status: "ok",
attributes: { "rpc.system": "grpc", "inventory.skus": 4 },
},
{
id: "c2",
parentId: "c1",
name: "lock sku rows",
service: "inventory",
from: 65.1,
to: 81.7,
status: "ok",
},
{
id: "c3",
parentId: "c1",
name: "UPDATE stock",
service: "inventory",
from: 83,
to: 131.4,
status: "ok",
attributes: { "db.system": "postgresql", "db.rows": 4 },
},
{
id: "c4",
parentId: "c1",
name: "publish stock.reserved",
service: "inventory",
from: 132.9,
to: 145.5,
status: "ok",
attributes: { "messaging.system": "kafka" },
},
{
id: "b5",
parentId: "b1",
name: "price order",
service: "checkout",
from: 150.3,
to: 176,
status: "ok",
},
{
id: "b6",
parentId: "b5",
name: "tax quote",
service: "checkout",
from: 151.8,
to: 171.2,
status: "ok",
attributes: { "tax.region": "ES", "tax.rate": 0.21 },
},
{
id: "d1",
parentId: "b1",
name: "Charge",
service: "payments",
from: 179.6,
to: 371,
status: "ok",
attributes: { "payment.amount": 84.5, "payment.currency": "EUR" },
},
{
id: "d2",
parentId: "d1",
name: "fraud score",
service: "payments",
from: 182,
to: 213.7,
status: "ok",
attributes: { "fraud.score": 0.07 },
},
{
id: "d3",
parentId: "d1",
name: "POST /v1/charges",
service: "payments",
from: 215.2,
to: 316,
status: "error",
attributes: {
"http.status_code": 504,
"error.type": "timeout",
"retry.attempt": 1,
"net.peer.name": "api.acquirer.example",
},
},
{
id: "d4",
parentId: "d1",
name: "backoff",
service: "payments",
from: 316.1,
to: 328,
status: "ok",
},
{
id: "d5",
parentId: "d1",
name: "POST /v1/charges",
service: "payments",
from: 328.4,
to: 366.9,
status: "ok",
attributes: {
"http.status_code": 201,
"retry.attempt": 2,
"net.peer.name": "api.acquirer.example",
},
},
{
id: "b7",
parentId: "b1",
name: "INSERT orders",
service: "checkout",
from: 373,
to: 391.8,
status: "ok",
attributes: { "db.system": "postgresql", "db.rows": 1 },
},
{
id: "b8",
parentId: "b1",
name: "publish order.placed",
service: "checkout",
from: 392.5,
to: 401.3,
status: "ok",
attributes: { "messaging.system": "kafka" },
},
{
id: "b9",
parentId: "b8",
name: "send receipt",
service: "checkout",
from: 402,
to: 458.6,
status: "ok",
detached: "a queued job: the request does not wait for the email",
attributes: { "messaging.system": "kafka", "email.template": "receipt" },
},
{
id: "a6",
parentId: "a1",
name: "set cookie",
service: "frontend",
from: 405.1,
to: 405.9,
status: "ok",
},
{
id: "a5",
parentId: "a1",
name: "render confirmation",
service: "frontend",
from: 406.2,
to: 411.9,
status: "ok",
},
]
// #endregion
// #region search
/** A search fanned out over five services, five hundred spans, made the same every
* time (a seeded generator): each span's children share its time in order or fan
* out side by side, and a few of them fail. */
function searchTrace(count: number): TraceSpan[] {
let seed = 7
const random = () => {
seed = (seed * 1664525 + 1013904223) % 2 ** 32
return seed / 2 ** 32
}
const services = ["edge", "search", "ranker", "index", "cache"]
const verbs = [
"query",
"fetch",
"score",
"merge",
"lookup",
"decode",
"filter",
]
const root: TraceSpan = {
id: "s0",
name: "GET /search",
service: "edge",
from: 0,
to: 2400,
status: "ok",
}
const spans = [root]
const waiting = [root]
for (let parent = waiting.shift(); parent; parent = waiting.shift()) {
const room = parent.to - parent.from
const kids = 4 + Math.floor(random() * 6)
// A fan-out: the children run side by side, each most of the parent's time.
const fanOut = random() < 0.5
const slot = (room * 0.96) / kids
for (let k = 0; k < kids && spans.length < count; k++) {
const length = fanOut
? room * (0.4 + random() * 0.5)
: slot * (0.5 + random() * 0.4)
const from = fanOut
? parent.from + random() * (room - length)
: parent.from + room * 0.02 + k * slot + random() * slot * 0.1
const span: TraceSpan = {
id: `s${spans.length}`,
parentId: parent.id,
name: `${verbs[Math.floor(random() * verbs.length)]} ${spans.length}`,
service: services[Math.floor(random() * services.length)] as string,
from,
to: from + length,
status: random() < 0.01 ? "error" : "ok",
attributes: { shard: k },
}
spans.push(span)
waiting.push(span)
}
}
return spans
}
const search = searchTrace(500)
// #endregion
export default function TraceDemo() {
return (
<div className="space-y-8">
<Sample
name="capped"
glance="large"
title="a checkout, eight rows at a time"
with="checkout"
>
<Trace spans={checkout} label="POST /checkout" visibleRows={8} />
</Sample>
<Sample
name="checkout"
title="a checkout, its error chosen"
description="click a span or press Enter on it for its details; ← and → fold and open a parent, Esc lets the span go. ⌘ or ctrl with the wheel (or a pinch) zooms at the pointer, a sideways wheel pans, + − 0 from the keys; the details' magnifier zooms to the span. The charge's first attempt timed out; the receipt is a queued job that runs past the request, drawn hollow."
with="checkout"
>
<Trace spans={checkout} label="POST /checkout" defaultSelected="d3" />
</Sample>
<Sample
name="narrow"
title="narrow: the details below"
description="under 48 rem of its own width the details are a band of fixed height under the waterfall, there before anything is chosen, so a choice never moves what is below."
with="checkout"
>
<div className="max-w-xl">
<Trace spans={checkout} label="POST /checkout" visibleRows={10} />
</div>
</Sample>
<Sample
name="folded"
title="subtrees folded"
description="the inventory reservation and the charge start folded: their bars stay, their children wait behind the chevron."
with="checkout"
>
<Trace
spans={checkout}
label="POST /checkout"
defaultCollapsed={["c1", "d1"]}
/>
</Sample>
<Sample name="glass" title="on glass" with="checkout">
<MaterialProvider material="glass">
<div className="rounded-2xl bg-[url(/lightbox/peaks.jpg)] bg-cover bg-center p-4 sm:p-8">
<Trace
spans={checkout}
label="POST /checkout"
defaultSelected="b6"
visibleRows={10}
/>
</div>
</MaterialProvider>
</Sample>
<Sample
name="large"
title="five hundred spans"
description="only the rows in view are mounted; the thumb says where you are, the edges fade where there is more."
with="search"
>
<Trace spans={search} label="GET /search" visibleRows={20} />
</Sample>
</div>
)
}