🪢 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
perf(dashboard): read v4 home trace latencies from root observations (#18857)
Steffen Reuther52fe65fcd8bf
diff --git a/web/src/features/dashboard/components/LatencyTables.tsx b/web/src/features/dashboard/components/LatencyTables.tsxindex e09ceb385f..089900ffe1 100644--- a/web/src/features/dashboard/components/LatencyTables.tsx+++ b/web/src/features/dashboard/components/LatencyTables.tsx@@ -21,28 +21,63 @@ export type LatencyTableKind = "traces" | "generations" | "observations";const LATENCY_TABLE_KINDS: Record<LatencyTableKind,{- title: string;+ title: (metricsVersion: ViewVersion) => string;nameHeader: string;+ /** Result field that carries the row label. */+ nameField: (metricsVersion: ViewVersion) => string;buildQuery: (globalFilterState: FilterState,fromTimestamp: Date,toTimestamp: Date,+ metricsVersion: ViewVersion,) => QueryType;}> = {traces: {- title: "Trace latency percentiles",+ title: (metricsVersion) =>+ metricsVersion === "v2"+ ? "Root observation latency percentiles"+ : "Trace latency percentiles",nameHeader: "Trace Name",- buildQuery: (globalFilterState, fromTimestamp, toTimestamp) => ({- view: "traces",- dimensions: [{ field: "name" }],+ nameField: (metricsVersion) =>+ metricsVersion === "v2" ? "traceName" : "name",+ buildQuery: (+ globalFilterState,+ fromTimestamp,+ toTimestamp,+ metricsVersion,+ ) => ({+ // v2 reads each trace's latency from its root observation instead of+ // grouping every event in the window by trace. A trace whose only root+ // is the synthetic trace span (no end time) has no root latency.+ ...(metricsVersion === "v2"+ ? {+ view: "observations",+ dimensions: [{ field: "traceName" }],+ filters: [+ ...mapLegacyUiTableFilterToView(+ "observations",+ globalFilterState,+ ),+ {+ column: "isRootObservation",+ operator: "=",+ value: true,+ type: "boolean",+ },+ ],+ }+ : {+ view: "traces",+ dimensions: [{ field: "name" }],+ filters: mapLegacyUiTableFilterToView("traces", globalFilterState),+ }),metrics: [{ measure: "latency", aggregation: "p50" },{ measure: "latency", aggregation: "p90" },{ measure: "latency", aggregation: "p95" },{ measure: "latency", aggregation: "p99" },],- filters: mapLegacyUiTableFilterToView("traces", globalFilterState),timeDimension: null,fromTimestamp: fromTimestamp.toISOString(),toTimestamp: toTimestamp.toISOString(),@@ -51,8 +86,9 @@ const LATENCY_TABLE_KINDS: Record<}),},generations: {- title: "Generation latency percentiles",+ title: () => "Generation latency percentiles",nameHeader: "Generation Name",+ nameField: () => "name",buildQuery: (globalFilterState, fromTimestamp, toTimestamp) => ({view: "observations",dimensions: [{ field: "name" }],@@ -79,8 +115,9 @@ const LATENCY_TABLE_KINDS: Record<}),},observations: {- title: "Observation latency percentiles",+ title: () => "Observation latency percentiles",nameHeader: "Observation",+ nameField: () => "name",buildQuery: (globalFilterState, fromTimestamp, toTimestamp) => ({view: "observations",dimensions: [{ field: "type" }, { field: "name" }],@@ -108,12 +145,15 @@ const LATENCY_TABLE_KINDS: Record<},};-const generateLatencyData = (data?: Record<string, unknown>[]) => {+const generateLatencyData = (+ nameField: string,+ data?: Record<string, unknown>[],+) => {return data? data- .filter((item) => item.name !== null)+ .filter((item) => item[nameField] !== null).map((item, i) => [- <div key={`${item.name as string}-${i}`}>+ <div key={`${item[nameField] as string}-${i}`}><PopuptriggerContent={item.type ? (@@ -121,16 +161,16 @@ const generateLatencyData = (data?: Record<string, unknown>[]) => {<span className="text-muted-foreground text-[10px] font-bold tracking-wide uppercase">{String(item.type)}</span>- <span>{truncate(item.name as string)}</span>+ <span>{truncate(item[nameField] as string)}</span></div>) : (- truncate(item.name as string)+ truncate(item[nameField] as string))}description={item.type- ? `${String(item.type)} · ${item.name as string}`- : (item.name as string)+ ? `${String(item.type)} · ${item[nameField] as string}`+ : (item[nameField] as string)}/></div>,@@ -179,12 +219,18 @@ export const LatencyTable = ({metricsVersion: ViewVersion;schedulerId?: string;}) => {- const { title, nameHeader, buildQuery } = LATENCY_TABLE_KINDS[kind];+ const { title, nameHeader, nameField, buildQuery } =+ LATENCY_TABLE_KINDS[kind];const latencies = useScheduledDashboardExecuteQuery({projectId,- query: buildQuery(globalFilterState, fromTimestamp, toTimestamp),+ query: buildQuery(+ globalFilterState,+ fromTimestamp,+ toTimestamp,+ metricsVersion,+ ),version: metricsVersion,},{@@ -205,7 +251,7 @@ export const LatencyTable = ({// shrink so the row area scrolls internally. (LFE-11035)className={cn(className, "h-full")}cardContentClassName="min-h-0"- title={title}+ title={title(metricsVersion)}isLoading={isLoading || latencies.isPending}><DashboardTable@@ -218,7 +264,7 @@ export const LatencyTable = ({</RightAlignedCell>,<RightAlignedCell key="p99">p99</RightAlignedCell>,]}- rows={generateLatencyData(latencies.data)}+ rows={generateLatencyData(nameField(metricsVersion), latencies.data)}isLoading={isLoading || latencies.isPending}collapse={{ collapsed: 5, expanded: 20 }}/>diff --git a/web/src/features/dashboard/components/home-preset-registry.tsx b/web/src/features/dashboard/components/home-preset-registry.tsxindex a82d01c46d..4af132ab77 100644--- a/web/src/features/dashboard/components/home-preset-registry.tsx+++ b/web/src/features/dashboard/components/home-preset-registry.tsx@@ -1,9 +1,5 @@import { type ReactNode } from "react";-import {- HOME_DASHBOARD_PRESET_IDS,- type FilterState,- type HomeDashboardPresetId,-} from "@langfuse/shared";+import { type FilterState, type HomeDashboardPresetId } from "@langfuse/shared";import { type ViewVersion } from "@langfuse/shared/query";import { type DashboardDateRangeAggregationOption } from "@/src/utils/date-range-utils";import { TracesBarListChart } from "@/src/features/dashboard/components/TracesBarListChart";@@ -216,20 +212,21 @@ const HOME_PRESETS: Record<),};+type HomePresetMetadata = {+ name: string;+ description: string;+ illustration: string;+};+/*** Display metadata for the preset picker (Add Widget dialog). `illustration`- * keys into ChartTypeIllustration. `queriesTracesView` marks a preset whose- * query still targets the legacy `traces` view under v2, so it is not- * suggested to v4 users (LFE-14444) — every other card branches to the events- * model on its own.+ * keys into ChartTypeIllustration. `v2` overrides the label for a card that+ * measures something else on the v2 read path.*/-export const HOME_PRESET_METADATA: Record<+const HOME_PRESET_METADATA: Record<HomeDashboardPresetId,- {- name: string;- description: string;- illustration: string;- queriesTracesView?: true;+ HomePresetMetadata & {+ v2?: Pick<HomePresetMetadata, "name" | "description">;}> = {"home-traces": {@@ -271,8 +268,10 @@ export const HOME_PRESET_METADATA: Record<name: "Trace Latency Percentiles",description: "p50–p99 latencies per trace name",illustration: "PIVOT_TABLE",- // LatencyTable kind="traces" has no v2 branch: always `view: "traces"`.- queriesTracesView: true,+ v2: {+ name: "Root Observation Latency Percentiles",+ description: "p50–p99 root observation latencies per trace name",+ },},"home-latency-table-generations": {name: "Generation Latency Percentiles",@@ -296,14 +295,12 @@ export const HOME_PRESET_METADATA: Record<},};-/** Home cards offered in the Add Widget dialog for a metrics version. */-export function getSuggestedHomePresetIds(+export function getHomePresetMetadata(+ presetId: HomeDashboardPresetId,version: ViewVersion,-): HomeDashboardPresetId[] {- return HOME_DASHBOARD_PRESET_IDS.filter(- (presetId) =>- version !== "v2" || !HOME_PRESET_METADATA[presetId].queriesTracesView,- );+): HomePresetMetadata {+ const { v2, ...metadata } = HOME_PRESET_METADATA[presetId];+ return version === "v2" && v2 ? { ...metadata, ...v2 } : metadata;}export function getHomePreset(diff --git a/web/src/features/dashboard/components/homePresetSuggestions.clienttest.ts b/web/src/features/dashboard/components/homePresetSuggestions.clienttest.tsdeleted file mode 100644index 678a8e4d27..0000000000--- a/web/src/features/dashboard/components/homePresetSuggestions.clienttest.ts+++ /dev/null@@ -1,14 +0,0 @@-// @vitest-environment node--import { describe, expect, it } from "vitest";-import { HOME_DASHBOARD_PRESET_IDS } from "@langfuse/shared";-import { getSuggestedHomePresetIds } from "@/src/features/dashboard/components/home-preset-registry";--describe("Add Widget home-card suggestions", () => {- it("drops presets that still query the legacy traces view on v4", () => {- expect(getSuggestedHomePresetIds("v2")).not.toContain(- "home-latency-table-traces",- );- expect(getSuggestedHomePresetIds("v1")).toEqual(HOME_DASHBOARD_PRESET_IDS);- });-});diff --git a/web/src/features/widgets/components/SelectWidgetDialog.tsx b/web/src/features/widgets/components/SelectWidgetDialog.tsxindex 88f146e844..2ff8b566d6 100644--- a/web/src/features/widgets/components/SelectWidgetDialog.tsx+++ b/web/src/features/widgets/components/SelectWidgetDialog.tsx@@ -16,15 +16,15 @@ import { Tabs } from "@/src/components/design-system/Tabs/Tabs";import startCase from "lodash/startCase";import { getChartTypeDisplayName } from "@/src/features/widgets/chart-library/utils";import { ChartTypeIllustration } from "@/src/features/widgets/components/ChartTypeIllustration";-import { type HomeDashboardPresetId } from "@langfuse/shared";+import {+ HOME_DASHBOARD_PRESET_IDS,+ type HomeDashboardPresetId,+} from "@langfuse/shared";import {isSuggestedWidgetView,type ViewVersion,} from "@langfuse/shared/query";-import {- getSuggestedHomePresetIds,- HOME_PRESET_METADATA,-} from "@/src/features/dashboard/components/home-preset-registry";+import { getHomePresetMetadata } from "@/src/features/dashboard/components/home-preset-registry";import { useReadPath } from "@/src/features/events";import { type DashboardWidgetChartType } from "@langfuse/shared/src/db";import {@@ -145,7 +145,6 @@ export function SelectWidgetDialog({isSuggestedWidgetView(widget.view, suggestedVersion),);const hiddenWidgetCount = allProjectWidgets.length - projectWidgets.length;- const suggestedPresetIds = getSuggestedHomePresetIds(suggestedVersion);// Replaces the generic empty state when it hid every widget, so the two can// never contradict each other.const hiddenWidgetsNote =@@ -232,7 +231,7 @@ export function SelectWidgetDialog({{onSelectPreset && (<Tabs.Triggervalue="home-cards"- label={`Home cards (${suggestedPresetIds.length})`}+ label={`Home cards (${HOME_DASHBOARD_PRESET_IDS.length})`}/>)}</Tabs.List>@@ -263,8 +262,11 @@ export function SelectWidgetDialog({<div className="mt-2"><Tabs.Content value="home-cards"><div className="flex max-h-[360px] flex-col gap-2 overflow-y-auto p-1">- {suggestedPresetIds.map((presetId) => {- const meta = HOME_PRESET_METADATA[presetId];+ {HOME_DASHBOARD_PRESET_IDS.map((presetId) => {+ const meta = getHomePresetMetadata(+ presetId,+ suggestedVersion,+ );return (<buttonkey={presetId}