πͺ’ Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.
TypeScript analyticsautogenevaluationlangchainlarge-language-modelsllama-indexllmllm-evaluationllm-observabilityllmopsmonitoringobservabilityopen-sourceopenaiplaygroundprompt-engineeringprompt-managementself-hostedycombinator
feat(events): add a y axis to the Pulse outlier strip (#15572)
Trang Nguyendffc16900945
diff --git a/web/src/features/events/components/outlier-strip/OutlierBarStrip.stories.tsx b/web/src/features/events/components/outlier-strip/OutlierBarStrip.stories.tsxindex a49b97319d..06fc1fcd88 100644--- a/web/src/features/events/components/outlier-strip/OutlierBarStrip.stories.tsx+++ b/web/src/features/events/components/outlier-strip/OutlierBarStrip.stories.tsx@@ -7,9 +7,9 @@ import { makeFixtureSeries } from "./lib/fixtures";* Design surface for the outlier strip above the trace table (LFE-14451).* Each bar aggregates its time bucket (summed cost, p95/avg latency, event* count) β the strip exists to click into spikes, so the visual must read- * at a glance: compact, Firefox-devtools-inspired, values on hover only,- * sparse gridline ticks, a baseline that keeps the plot boundary visible- * where data is absent.+ * at a glance: compact, Firefox-devtools-inspired, exact values on hover,+ * horizontal value gridlines with left sans labels (no vertical lines), a+ * baseline that keeps the plot boundary visible where data is absent.** Locked defaults (design review 2026-07-27): sqrt scale, 40px height.*/diff --git a/web/src/features/events/components/outlier-strip/OutlierBarStrip.tsx b/web/src/features/events/components/outlier-strip/OutlierBarStrip.tsxindex e4088e0373..9ac5e6681a 100644--- a/web/src/features/events/components/outlier-strip/OutlierBarStrip.tsx+++ b/web/src/features/events/components/outlier-strip/OutlierBarStrip.tsx@@ -6,6 +6,7 @@ import { Layer } from "@/src/components/ui/layer";import {formatBucketRange,OUTLIER_STRIP_METRICS,+ prepareOutlierYTicks,type OutlierStripDenseBin,type OutlierStripMetricKey,type OutlierStripTick,@@ -19,8 +20,9 @@ import {* narrow the table's time window.** The strip always spans the full `widthPx` (fractional bar slots), with a- * baseline and sparse vertical gridline ticks so the chart's boundaries stay- * visible even where the range holds no data.+ * baseline and horizontal value gridlines so the chart's boundaries stay+ * visible even where the range holds no data; sparse time labels sit on the+ * tick grid without any vertical lines.*/const METRIC_COLOR: Record<OutlierStripMetricKey, string> = {@@ -185,16 +187,26 @@ export function OutlierBarStrip({const scaled = scale === "sqrt" ? Math.sqrt(fraction) : fraction;return Math.max(1.5, scaled * plotHeight);};+ // Y axis: nice-value gridlines + labels, scale-mapped by the preparer so+ // they sit exactly where a bar of that value would top out.+ const yTicks = prepareOutlierYTicks({+ maxValue,+ metric,+ plotHeightPx: plotHeight,+ scale,+ });return (<>- {/* Sparse vertical gridline ticks (Firefox-devtools style) */}- {ticks.map((tick) => (+ {/* Horizontal value gridlines (behind the bars). No vertical chrome+ at all β the time grid carries its sparse labels alone, and the+ horizontal lines mark the y axis (design 2026-07-29). */}+ {yTicks.map((tick) => (<line- key={`tick-${tick.index}`}- x1={tick.index * slotPx}- y1={0}- x2={tick.index * slotPx}- y2={plotHeight}+ key={`y-tick-${tick.value}`}+ x1={0}+ y1={plotHeight - tick.offsetPx}+ x2={widthPx}+ y2={plotHeight - tick.offsetPx}className="stroke-foreground"strokeWidth={1}opacity={0.07}@@ -249,12 +261,36 @@ export function OutlierBarStrip({key={`label-${tick.index}`}x={tick.index * slotPx + 3}y={heightPx + 9}- className="fill-muted-foreground/80 font-mono"+ className="fill-muted-foreground/80 font-sans"fontSize={9}>{tick.label}</text>))}++ {/* Y-axis labels β after the bars so they stay legible on top; the+ background-colored stroke (paint-order) keeps them readable where+ they overlap a bar. Every label hangs BELOW its gridline: the top+ gridline can hug the plot's top edge (no room above), and one+ consistent side means the preparer's line spacing is also the+ label spacing. */}+ {yTicks.map((tick) => {+ const lineY = plotHeight - tick.offsetPx;+ return (+ <text+ key={`y-label-${tick.value}`}+ x={3}+ y={lineY + 9}+ textAnchor="start"+ className="fill-muted-foreground stroke-background font-sans"+ fontSize={9}+ strokeWidth={2.5}+ style={{ paintOrder: "stroke" }}+ >+ {tick.label}+ </text>+ );+ })}</>);}, [@@ -267,6 +303,7 @@ export function OutlierBarStrip({color,ticks,maxValue,+ metric,scale,hasData,showActivityTicks,diff --git a/web/src/features/events/components/outlier-strip/lib/binning.clienttest.ts b/web/src/features/events/components/outlier-strip/lib/binning.clienttest.tsindex a43c1f6323..6fcef9a475 100644--- a/web/src/features/events/components/outlier-strip/lib/binning.clienttest.ts+++ b/web/src/features/events/components/outlier-strip/lib/binning.clienttest.ts@@ -1,11 +1,13 @@import { describe, it, expect } from "vitest";import {canReuseOutlierPlaceholder,+ formatCompoundDuration,OUTLIER_STRIP_METRICS,outlierStripQueryMetrics,outlierStripResultColumn,pickChartGranularity,prepareOutlierSeries,+ prepareOutlierYTicks,rowsToOutlierBins,type OutlierStripBin,} from "./binning";@@ -234,6 +236,206 @@ describe("prepareOutlierSeries", () => {});});+describe("prepareOutlierYTicks", () => {+ it("returns no ticks when the range has no data", () => {+ expect(+ prepareOutlierYTicks({+ maxValue: 0,+ metric: "cost",+ plotHeightPx: 49,+ scale: "sqrt",+ }),+ ).toEqual([]);+ });++ it("returns no ticks for a non-finite max instead of walking forever", () => {+ // An Infinity cost (corrupt data surviving superjson) must not hang the+ // 1-2-5 walk: Infinity candidates never drop below the baseline guard.+ for (const maxValue of [Number.POSITIVE_INFINITY, Number.NaN]) {+ expect(+ prepareOutlierYTicks({+ maxValue,+ metric: "cost",+ plotHeightPx: 49,+ scale: "sqrt",+ }),+ ).toEqual([]);+ }+ });++ it("walks nice values top-down and drops sqrt-compressed ones", () => {+ // max 7.3s on a 49px sqrt plot: 5 β 40.5px, 2 β 25.7px (gap 14.9, fits);+ // 1 β 18.1px and 0.5 β 12.8px are within 14px of the last tick (skipped);+ // 0.2 β 8.1px is inside the 10px baseline guard (walk ends).+ const ticks = prepareOutlierYTicks({+ maxValue: 7.3,+ metric: "latency",+ plotHeightPx: 49,+ scale: "sqrt",+ });+ expect(ticks.map((t) => t.value)).toEqual([5, 2]);+ });++ it("maps offsets through the same scale as the bars", () => {+ const [top] = prepareOutlierYTicks({+ maxValue: 7.3,+ metric: "latency",+ plotHeightPx: 49,+ scale: "sqrt",+ });+ expect(top.offsetPx).toBeCloseTo(Math.sqrt(5 / 7.3) * 49, 6);+ });++ it("keeps a tick exactly at the max when the max is a nice value", () => {+ // Cost has no ladder β plain 1-2-5. Linear 49px plot, max 100:+ // 100 β 49px, 50 β 24.5px, 20 β 9.8px is inside the baseline guard.+ const ticks = prepareOutlierYTicks({+ maxValue: 100,+ metric: "cost",+ plotHeightPx: 49,+ scale: "linear",+ });+ expect(ticks.map((t) => t.value)).toEqual([100, 50]);+ expect(ticks[0].offsetPx).toBeCloseTo(49, 6);+ });++ it("ticks latency on time-native ladder steps, labeled compound", () => {+ // Duration ladder, not 1-2-5: max 100s picks 60 ("1m") and 30 ("30s"),+ // never 100/50. Linear 49px: 60 β 29.4px, 30 β 14.7px (gap 14.7, fits),+ // 15 β 7.35px is inside the baseline guard.+ const ticks = prepareOutlierYTicks({+ maxValue: 100,+ metric: "latency",+ plotHeightPx: 49,+ scale: "linear",+ });+ expect(ticks.map((t) => t.value)).toEqual([60, 30]);+ expect(ticks.map((t) => t.label)).toEqual(["1m", "30s"]);+ });++ it("caps the tick count", () => {+ // Sqrt spreads the ladder's 900/300/60 far enough apart for three labels.+ const ticks = prepareOutlierYTicks({+ maxValue: 1000,+ metric: "latency",+ plotHeightPx: 49,+ scale: "sqrt",+ });+ expect(ticks.map((t) => t.value)).toEqual([900, 300, 60]);+ expect(ticks.map((t) => t.label)).toEqual(["15m", "5m", "1m"]);+ });++ it("falls through to 1-2-5 decades below the ladder floor", () => {+ // All-sub-second latencies: the 1s ladder floor yields nothing, so the+ // walk continues on 1-2-5. Max 0.4s sqrt: 0.2 β 34.6px, 0.1 β 24.5px+ // (gap 10.2, skipped), 0.05 β 17.3px (gap 17.3, fits).+ const ticks = prepareOutlierYTicks({+ maxValue: 0.4,+ metric: "latency",+ plotHeightPx: 49,+ scale: "sqrt",+ });+ expect(ticks.map((t) => t.value)).toEqual([0.2, 0.05]);+ expect(ticks.map((t) => t.label)).toEqual(["200ms", "50ms"]);+ });++ it("labels cost ticks without trailing zeros", () => {+ const ticks = prepareOutlierYTicks({+ maxValue: 0.8,+ metric: "cost",+ plotHeightPx: 49,+ scale: "sqrt",+ });+ expect(ticks.map((t) => t.value)).toEqual([0.5, 0.2]);+ expect(ticks.map((t) => t.label)).toEqual(["$0.5", "$0.2"]);+ });++ it("labels micro-dollar ticks with enough digits, never as $0", () => {+ // Total range cost under a micro-dollar: the 6-digit tier would label+ // the 2e-7 gridline "$0" and 5e-7 as a doubled "$0.000001".+ const ticks = prepareOutlierYTicks({+ maxValue: 8e-7,+ metric: "cost",+ plotHeightPx: 49,+ scale: "sqrt",+ });+ expect(ticks.map((t) => t.value)).toEqual([5e-7, 2e-7]);+ expect(ticks.map((t) => t.label)).toEqual(["$0.0000005", "$0.0000002"]);+ });++ it("labels whole-dollar cost ticks bare", () => {+ // Max $23 sqrt 49px: $20 β 45.7px, $10 β 32.3px (gap 13.4, skipped),+ // $5 β 22.9px (gap 22.8, fits), $2 β 14.5px (gap 8.4, skipped),+ // $1 β 10.2px (gap 12.7, skipped), $0.5 β 7.2px ends the walk.+ const ticks = prepareOutlierYTicks({+ maxValue: 23,+ metric: "cost",+ plotHeightPx: 49,+ scale: "sqrt",+ });+ expect(ticks.map((t) => t.label)).toEqual(["$20", "$5"]);+ });++ it("returns nothing on a plot too short for a label", () => {+ expect(+ prepareOutlierYTicks({+ maxValue: 7.3,+ metric: "latency",+ plotHeightPx: 8,+ scale: "sqrt",+ }),+ ).toEqual([]);+ });+});++describe("formatCompoundDuration", () => {+ it("splits minute-plus durations into two units", () => {+ expect(formatCompoundDuration(90_600)).toBe("1m 31s");+ expect(formatCompoundDuration(5_400_000)).toBe("1h 30m");+ expect(formatCompoundDuration(93_600_000)).toBe("1d 2h");+ });++ it("drops a zero sub-unit", () => {+ expect(formatCompoundDuration(120_000)).toBe("2m");+ expect(formatCompoundDuration(3_600_000)).toBe("1h");+ });++ it("carries a sub-unit that rounds up to a full primary", () => {+ // 1m 59.7s must not render "1m 60s".+ expect(formatCompoundDuration(119_700)).toBe("2m");+ });++ it("promotes a carry that lands on a full larger unit", () => {+ // 59m 59.6s must render "1h", not the denormalized "60m".+ expect(formatCompoundDuration(3_599_600)).toBe("1h");+ // 23h 59m 59.5s β "1d", not "24h".+ expect(formatCompoundDuration(86_399_499)).toBe("1d");+ });++ it("routes values that round up to a minute into the compound path", () => {+ // 59.998s falls under the raw 60s threshold, but the single-unit+ // formatter's own rounding would print "60s" β it must read "1m".+ expect(formatCompoundDuration(59_998)).toBe("1m");+ // Below the rounding window the single-unit format stays.+ expect(formatCompoundDuration(59_400)).toBe("59.4s");+ });++ it("keeps the shared single-unit format below a minute", () => {+ expect(formatCompoundDuration(30_000)).toBe("30s");+ expect(formatCompoundDuration(450)).toBe("450ms");+ });++ it("delegates non-finite input instead of rendering 'Infinityd'", () => {+ // Corrupt latency data: keep the shared formatter's "βd", pre-PR.+ expect(formatCompoundDuration(Number.POSITIVE_INFINITY)).toBe("βd");+ });++ it("is the latency metric's registry format", () => {+ // Plotted unit is seconds.+ expect(OUTLIER_STRIP_METRICS.latency.format(90.6)).toBe("1m 31s");+ });+});+describe("outlierStripResultColumn", () => {it("matches executeQuery's `${aggregation}_${measure}` naming", () => {expect(outlierStripResultColumn("totalCost", "sum")).toBe("sum_totalCost");diff --git a/web/src/features/events/components/outlier-strip/lib/binning.ts b/web/src/features/events/components/outlier-strip/lib/binning.tsindex bed40012aa..afa4a753aa 100644--- a/web/src/features/events/components/outlier-strip/lib/binning.ts+++ b/web/src/features/events/components/outlier-strip/lib/binning.ts@@ -125,6 +125,53 @@ export type OutlierStripMetricDef = {/** Raw result value β plotted unit (e.g. latency ms β s). */fromRaw: (raw: number) => number;format: (value: number) => string;+ /** Ascending "nice" y-tick values in the plotted unit. Metrics without a+ * ladder (plain numbers like cost) tick on 1-2-5 decades; durations need+ * time-native steps so ticks read "1m", not "1m 40s" (100). */+ yTickLadder?: readonly number[];+};++/**+ * Durations β₯ 1 minute as two units ("1m 31s", "1h 30m"), zero sub-unit+ * dropped ("2m"); below a minute the shared single-unit formatter already+ * reads naturally ("450ms", "7.3s"). The shared latencyFormatter can't do+ * this itself β Intl.NumberFormat formats exactly one unit, so it renders+ * decimal minutes ("1.51m").+ */+const COMPOUND_DURATION_UNITS = [+ { label: "d", ms: 86_400_000 },+ { label: "h", ms: 3_600_000 },+ { label: "m", ms: 60_000 },+ { label: "s", ms: 1_000 },+] as const;++export const formatCompoundDuration = (ms: number): string => {+ // Threshold on the SECOND-ROUNDED value: 59,998ms must take the compound+ // path ("1m") β the single-unit formatter's own rounding would print+ // "60s". Non-finite corrupt data keeps the shared formatter's "βd", not+ // "Infinityd" from the arithmetic below.+ const secondRounded = Math.round(ms / 1_000) * 1_000;+ if (!Number.isFinite(ms) || secondRounded < 60_000) {+ return latencyFormatter(ms);+ }+ const index = COMPOUND_DURATION_UNITS.findIndex(+ (unit) => secondRounded >= unit.ms,+ );+ const unit = COMPOUND_DURATION_UNITS[index];+ // Always defined: ms >= 60_000 selects "m" or coarser, never "s".+ const sub = COMPOUND_DURATION_UNITS[index + 1];+ // Round to the sub-unit FIRST: a value that rounds up across its unit+ // boundary ("59m 59.6s" β 60 minutes) must re-select the larger unit+ // ("1h"), not denormalize β the recursion strictly promotes, so it ends.+ const rounded = Math.round(ms / sub.ms) * sub.ms;+ const larger = COMPOUND_DURATION_UNITS[index - 1];+ if (larger && rounded >= larger.ms) return formatCompoundDuration(rounded);+ const primary = Math.floor(rounded / unit.ms);+ // Exact: `rounded` and unit.ms are both multiples of sub.ms.+ const rest = (rounded - primary * unit.ms) / sub.ms;+ return rest > 0+ ? `${primary}${unit.label} ${rest}${sub.label}`+ : `${primary}${unit.label}`;};export const OUTLIER_STRIP_METRICS: Record<@@ -136,8 +183,25 @@ export const OUTLIER_STRIP_METRICS: Record<measure: "totalCost",aggregations: [{ key: "sum", queryAggregation: "sum" }],fromRaw: (raw) => raw,+ // Zero minimum fraction digits: round values render bare ("$2", "$0.5"),+ // on ticks and tooltips alike; the adaptive maximum still gives small+ // values the precision they need ("$0.0042"). Deeper tiers keep+ // micro-dollar Y TICKS honest β a 6-digit cap would label a 2e-7+ // gridline "$0".format: (value) =>- usdFormatter(value, 2, value < 0.001 ? 6 : value < 0.1 ? 4 : 2),+ usdFormatter(+ value,+ 0,+ value < 1e-9+ ? 12+ : value < 1e-6+ ? 9+ : value < 0.001+ ? 6+ : value < 0.1+ ? 4+ : 2,+ ),},latency: {shortLabel: "Latency",@@ -147,7 +211,10 @@ export const OUTLIER_STRIP_METRICS: Record<{ key: "p50", queryAggregation: "p50" },],fromRaw: (raw) => raw / 1000, // executeQuery latency is in ms- format: (value) => latencyFormatter(value * 1000),+ format: (value) => formatCompoundDuration(value * 1000),+ // Same duration steps as the time grid: y ticks land on "30s"/"1m"/"5m",+ // not on decimal-decade values like 100s.+ yTickLadder: OUTLIER_STRIP_STEP_LADDER_SECONDS,},};@@ -363,6 +430,100 @@ export function prepareOutlierSeries(params: {return { dense, maxValue, ticks };}+// ---------------------------------------------------------------------------+// Y axis (value gridlines)+// ---------------------------------------------------------------------------++/** A prepared value gridline: metric value, registry-formatted label, and its+ * scale-mapped distance above the baseline. */+export type OutlierStripYTick = {+ value: number;+ label: string;+ /** px above the baseline, already mapped through the bar-height scale. */+ offsetPx: number;+};++/** Vertical room a 9px axis label needs between accepted gridlines. */+const Y_TICK_MIN_SPACING_PX = 14;+/** Ticks closer to the baseline than this collide with activity ticks. */+const Y_TICK_MIN_OFFSET_PX = 10;+const Y_TICK_MAX_COUNT = 3;++/**+ * Descending "nice" tick candidates β€ maxValue: the metric's ladder first+ * (largest fitting step down to its floor), then 1-2-5 decades below the+ * floor (sub-second latencies); ladderless metrics walk 1-2-5 decades from+ * the max. Values strictly decrease, so the consumer's baseline guard always+ * terminates the (infinite) walk.+ */+function* descendNiceValues(+ maxValue: number,+ ladder?: readonly number[],+): Generator<number> {+ const ladderFloor = ladder?.length ? ladder[0] : Number.POSITIVE_INFINITY;+ if (ladder?.length) {+ for (let i = ladder.length - 1; i >= 0; i--) {+ if (ladder[i] <= maxValue) yield ladder[i];+ }+ }+ const below125Start = Math.min(maxValue, ladderFloor);+ for (let exp = Math.ceil(Math.log10(below125Start)); ; exp--) {+ for (const mantissa of [5, 2, 1]) {+ const value = mantissa * 10 ** exp;+ if (value <= maxValue && value < ladderFloor) yield value;+ }+ }+}++/**+ * Places horizontal value gridlines for the strip: nice values below the max+ * ({@link descendNiceValues}), walked top-down and accepted only where the+ * label fits β the sqrt scale compresses lower values toward the baseline,+ * so spacing must be checked in SCALED pixel space, not value space. The+ * bars scale against the true max (tallest bar always hits the top), so+ * ticks land at their exact scaled positions rather than the domain being+ * rounded up to a nice number.+ */+export function prepareOutlierYTicks(params: {+ /** Max metric value across buckets (the bar scale's domain). */+ maxValue: number;+ metric: OutlierStripMetricKey;+ /** Bar canvas height above the baseline. */+ plotHeightPx: number;+ /** Must match the visualiser's bar-height scale. */+ scale: "linear" | "sqrt";+}): OutlierStripYTick[] {+ const { maxValue, plotHeightPx } = params;+ // Number.isFinite: an Infinity max (corrupt data surviving the wire) would+ // walk descendNiceValues forever β Infinity candidates never drop below+ // the baseline guard.+ if (+ !Number.isFinite(maxValue) ||+ maxValue <= 0 ||+ plotHeightPx <= Y_TICK_MIN_OFFSET_PX+ ) {+ return [];+ }+ const def = OUTLIER_STRIP_METRICS[params.metric];+ const toOffsetPx = (value: number) => {+ const fraction = value / maxValue;+ const scaled = params.scale === "sqrt" ? Math.sqrt(fraction) : fraction;+ return scaled * plotHeightPx;+ };++ const ticks: OutlierStripYTick[] = [];+ let lastOffsetPx = Number.POSITIVE_INFINITY;+ for (const value of descendNiceValues(maxValue, def.yTickLadder)) {+ const offsetPx = toOffsetPx(value);+ if (offsetPx < Y_TICK_MIN_OFFSET_PX) break;+ if (lastOffsetPx - offsetPx < Y_TICK_MIN_SPACING_PX) continue;+ ticks.push({ value, label: def.format(value), offsetPx });+ if (ticks.length >= Y_TICK_MAX_COUNT) break;+ lastOffsetPx = offsetPx;+ }+ return ticks;+}+/*** Whether bins fetched for a previous query window may stand in for the next* one while it loads (LFE-14575). The bucket grid is epoch-aligned, so bins