🪢 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
chore: migrate latency charts to new query builder (#6284)
Steffen Schmitze4594db953de
diff --git a/web/src/__tests__/queryBuilderDashboards.servertest.ts b/web/src/__tests__/queryBuilderDashboards.servertest.tsindex 42f6e6cd9b..4d5bff4a52 100644--- a/web/src/__tests__/queryBuilderDashboards.servertest.ts+++ b/web/src/__tests__/queryBuilderDashboards.servertest.ts@@ -12,6 +12,9 @@ import {getTotalObservationUsageByTimeByModel,getModelUsageByUser,getTracesGroupedByUsers,+ getObservationLatencies,+ getTracesLatencies,+ getModelLatenciesOverTime,} from "@langfuse/shared/src/server";import { type FilterState } from "@langfuse/shared";import { type QueryType } from "@/src/features/query/types";@@ -1169,4 +1172,247 @@ describe("selfServeDashboards", () => {});});});++ describe("observation-latencies-aggregated query", () => {+ it("should return the same result with query builder as with legacy function", async () => {+ // 1. Get result using the legacy function+ const legacyResult = await getObservationLatencies(projectId, [+ {+ type: "datetime",+ operator: ">=",+ column: "timestamp",+ value: new Date(defaultFromTime),+ },+ {+ type: "datetime",+ operator: "<=",+ column: "timestamp",+ value: new Date(defaultToTime),+ },+ ]);++ // 2. Define the equivalent query for the query builder+ const queryBuilderQuery: QueryType = {+ view: "observations",+ dimensions: [{ field: "name" }],+ metrics: [+ { measure: "latency", aggregation: "p50" },+ { measure: "latency", aggregation: "p90" },+ { measure: "latency", aggregation: "p95" },+ { measure: "latency", aggregation: "p99" },+ ],+ filters: [],+ timeDimension: null,+ fromTimestamp: defaultFromTime,+ toTimestamp: defaultToTime,+ orderBy: [{ field: "p95_latency", direction: "desc" }],+ };++ // 3. Get result using the query builder+ const queryBuilderResult = await executeQuery(+ projectId,+ queryBuilderQuery,+ );++ // 4. Verify both results+ expect(queryBuilderResult).toBeDefined();+ expect(legacyResult).toBeDefined();++ // Verify both result sets have the same number of rows+ expect(legacyResult.length).toBe(queryBuilderResult.length);++ // Create maps for easier comparison+ const legacyResultMap = new Map(+ legacyResult.map((item) => [item.name, item]),+ );++ // Verify each observation's latency metrics match+ queryBuilderResult.forEach((row: any) => {+ const name = row.name;+ const legacyData = legacyResultMap.get(name);++ expect(legacyData).toBeDefined();+ expect(Number(row.p50_latency) / 1000).toBeCloseTo(+ Number(legacyData?.p50),+ );+ expect(Number(row.p90_latency) / 1000).toBeCloseTo(+ Number(legacyData?.p90),+ );+ expect(Number(row.p95_latency) / 1000).toBeCloseTo(+ Number(legacyData?.p95),+ );+ expect(Number(row.p99_latency) / 1000).toBeCloseTo(+ Number(legacyData?.p99),+ );+ });+ });+ });++ describe("traces-latencies-aggregated query", () => {+ it("should return the same result with query builder as with legacy function", async () => {+ // 1. Get result using the legacy function+ const legacyResult = await getTracesLatencies(projectId, [+ {+ type: "datetime",+ operator: ">=",+ column: "timestamp",+ value: new Date(defaultFromTime),+ },+ {+ type: "datetime",+ operator: "<=",+ column: "timestamp",+ value: new Date(defaultToTime),+ },+ ]);++ // 2. Define the equivalent query for the query builder+ const queryBuilderQuery: QueryType = {+ view: "traces",+ dimensions: [{ field: "name" }],+ metrics: [+ { measure: "latency", aggregation: "p50" },+ { measure: "latency", aggregation: "p90" },+ { measure: "latency", aggregation: "p95" },+ { measure: "latency", aggregation: "p99" },+ ],+ filters: [],+ timeDimension: null,+ fromTimestamp: defaultFromTime,+ toTimestamp: defaultToTime,+ orderBy: [{ field: "p95_latency", direction: "desc" }],+ };++ // 3. Get result using the query builder+ const queryBuilderResult = await executeQuery(+ projectId,+ queryBuilderQuery,+ );++ // 4. Verify both results+ expect(queryBuilderResult).toBeDefined();+ expect(legacyResult).toBeDefined();++ // Verify both result sets have the same number of rows+ expect(legacyResult.length).toBe(queryBuilderResult.length);++ // Create maps for easier comparison+ const legacyResultMap = new Map(+ legacyResult.map((item) => [item.name, item]),+ );++ // Verify each trace's latency metrics match+ queryBuilderResult.forEach((row: any) => {+ const name = row.name;+ const legacyData = legacyResultMap.get(name);++ expect(legacyData).toBeDefined();+ expect(Number(row.p50_latency) / 1000).toBeCloseTo(+ Number(legacyData?.p50),+ );+ expect(Number(row.p90_latency) / 1000).toBeCloseTo(+ Number(legacyData?.p90),+ );+ expect(Number(row.p95_latency) / 1000).toBeCloseTo(+ Number(legacyData?.p95),+ );+ expect(Number(row.p99_latency) / 1000).toBeCloseTo(+ Number(legacyData?.p99),+ );+ });+ });+ });++ describe("model-latencies-over-time query", () => {+ it("should return the same result with query builder as with legacy function", async () => {+ // 1. Get result using the legacy function+ const legacyResult = await getModelLatenciesOverTime(projectId, [+ {+ type: "datetime",+ operator: ">=",+ column: "timestamp",+ value: new Date(defaultFromTime),+ },+ {+ type: "datetime",+ operator: "<=",+ column: "timestamp",+ value: new Date(defaultToTime),+ },+ ]);++ // 2. Define the equivalent query for the query builder+ const queryBuilderQuery: QueryType = {+ view: "observations",+ dimensions: [{ field: "providedModelName" }],+ metrics: [+ { measure: "latency", aggregation: "p50" },+ { measure: "latency", aggregation: "p75" },+ { measure: "latency", aggregation: "p90" },+ { measure: "latency", aggregation: "p95" },+ { measure: "latency", aggregation: "p99" },+ ],+ filters: [],+ timeDimension: {+ granularity: "hour",+ },+ fromTimestamp: defaultFromTime,+ toTimestamp: defaultToTime,+ orderBy: null,+ };++ // 3. Get result using the query builder+ const queryBuilderResult = await executeQuery(+ projectId,+ queryBuilderQuery,+ );++ // 4. Verify both results+ expect(queryBuilderResult).toBeDefined();+ expect(legacyResult).toBeDefined();++ // Verify both result sets have a similar number of rows+ // The exact number might differ due to time granularity differences+ expect(queryBuilderResult.length).toBeGreaterThan(0);+ expect(legacyResult.length).toBeGreaterThan(0);++ // Create maps for easier comparison+ const legacyResultMap = new Map(+ legacyResult.map((item) => [+ `${item.model}-${new Date(item.start_time).getTime()}`,+ item,+ ]),+ );++ // Verify model latency metrics match for some samples+ // Note: We can't check all rows as the time granularity might differ+ let matchCount = 0;+ queryBuilderResult.forEach((row: any) => {+ const key = `${row.provided_model_name}-${new Date(row.time_dimension).getTime()}`;+ const legacyData = legacyResultMap.get(key);++ if (legacyData && !isNaN(legacyData?.p50)) {+ matchCount++;+ expect(Number(row.p50_latency) / 1000).toBeCloseTo(+ Number(legacyData.p50),+ );+ expect(Number(row.p75_latency) / 1000).toBeCloseTo(+ Number(legacyData.p75),+ );+ expect(Number(row.p90_latency) / 1000).toBeCloseTo(+ Number(legacyData.p90),+ );+ expect(Number(row.p95_latency) / 1000).toBeCloseTo(+ Number(legacyData.p95),+ );+ expect(Number(row.p99_latency) / 1000).toBeCloseTo(+ Number(legacyData.p99),+ );+ }+ });++ // Ensure we found at least some matches+ expect(matchCount).toBeGreaterThan(0);+ });+ });});diff --git a/web/src/features/dashboard/components/LatencyChart.tsx b/web/src/features/dashboard/components/LatencyChart.tsxindex 9932d61397..bc79b141a5 100644--- a/web/src/features/dashboard/components/LatencyChart.tsx+++ b/web/src/features/dashboard/components/LatencyChart.tsx@@ -9,27 +9,33 @@ import { DashboardCard } from "@/src/features/dashboard/components/cards/Dashboaimport { BaseTimeSeriesChart } from "@/src/features/dashboard/components/BaseTimeSeriesChart";import { TabComponent } from "@/src/features/dashboard/components/TabsComponent";import { latencyFormatter } from "@/src/utils/numbers";-import {- dashboardDateRangeAggregationSettings,- type DashboardDateRangeAggregationOption,-} from "@/src/utils/date-range-utils";+import { type DashboardDateRangeAggregationOption } from "@/src/utils/date-range-utils";import { NoDataOrLoading } from "@/src/components/NoDataOrLoading";import {ModelSelectorPopover,useModelSelection,} from "@/src/features/dashboard/components/ModelSelector";+import {+ type QueryType,+ mapLegacyUiTableFilterToView,+} from "@/src/features/query";+import type { DatabaseRow } from "@/src/server/api/services/sqlInterface";export const GenerationLatencyChart = ({className,projectId,globalFilterState,agg,+ fromTimestamp,+ toTimestamp,isLoading = false,}: {className?: string;projectId: string;globalFilterState: FilterState;agg: DashboardDateRangeAggregationOption;+ fromTimestamp: Date;+ toTimestamp: Date;isLoading?: boolean;}) => {const {@@ -39,44 +45,52 @@ export const GenerationLatencyChart = ({isAllSelected,buttonText,handleSelectAll,- } = useModelSelection(projectId, globalFilterState);+ } = useModelSelection(+ projectId,+ globalFilterState,+ fromTimestamp,+ toTimestamp,+ );++ // Define the query for model latencies using the new QueryType structure+ const latenciesQuery: QueryType = {+ view: "observations",+ dimensions: [{ field: "providedModelName" }],+ metrics: [+ { measure: "latency", aggregation: "p50" },+ { measure: "latency", aggregation: "p75" },+ { measure: "latency", aggregation: "p90" },+ { measure: "latency", aggregation: "p95" },+ { measure: "latency", aggregation: "p99" },+ ],+ filters: [+ ...mapLegacyUiTableFilterToView("observations", globalFilterState),+ {+ column: "type",+ operator: "=",+ value: "GENERATION",+ type: "string",+ },+ {+ column: "providedModelName",+ operator: "any of",+ value: selectedModels,+ type: "stringOptions",+ },+ ],+ timeDimension: {+ granularity: "auto",+ },+ fromTimestamp: fromTimestamp.toISOString(),+ toTimestamp: toTimestamp.toISOString(),+ orderBy: null,+ };- const latencies = api.dashboard.chart.useQuery(+ // Execute the query using the new dashboard.executeQuery functionality+ const latencies = api.dashboard.executeQuery.useQuery({projectId,- from: "traces_observations",- select: [- { column: "duration", agg: "50thPercentile" },- { column: "duration", agg: "75thPercentile" },- { column: "duration", agg: "90thPercentile" },- { column: "duration", agg: "95thPercentile" },- { column: "duration", agg: "99thPercentile" },- { column: "model" },- ],- filter: [- ...globalFilterState,- {- type: "string",- column: "type",- operator: "=",- value: "GENERATION",- },- {- type: "stringOptions",- column: "model",- operator: "any of",- value: selectedModels,- } as const,- ],- groupBy: [- {- type: "datetime",- column: "startTime",- temporalUnit: dashboardDateRangeAggregationSettings[agg].date_trunc,- },- { type: "string", column: "model" },- ],- queryName: "model-latencies-over-time",+ query: latenciesQuery,},{enabled: !isLoading && selectedModels.length > 0 && allModels.length > 0,@@ -91,12 +105,16 @@ export const GenerationLatencyChart = ({const getData = (valueColumn: string) => {return latencies.data && selectedModels.length > 0? fillMissingValuesAndTransform(- extractTimeSeriesData(latencies.data, "startTime", [- {- uniqueIdentifierColumns: [{ accessor: "model" }],- valueColumn: valueColumn,- },- ]),+ extractTimeSeriesData(+ latencies.data as DatabaseRow[],+ "time_dimension",+ [+ {+ uniqueIdentifierColumns: [{ accessor: "provided_model_name" }],+ valueColumn: valueColumn,+ },+ ],+ ),selectedModels,): [];@@ -105,23 +123,23 @@ export const GenerationLatencyChart = ({const data = [{tabTitle: "50th Percentile",- data: getData("percentile50Duration"),+ data: getData("p50_latency"),},{tabTitle: "75th Percentile",- data: getData("percentile75Duration"),+ data: getData("p75_latency"),},{tabTitle: "90th Percentile",- data: getData("percentile90Duration"),+ data: getData("p90_latency"),},{tabTitle: "95th Percentile",- data: getData("percentile95Duration"),+ data: getData("p95_latency"),},{tabTitle: "99th Percentile",- data: getData("percentile99Duration"),+ data: getData("p99_latency"),},];@@ -130,7 +148,9 @@ export const GenerationLatencyChart = ({className={className}title="Model latencies"description="Latencies (seconds) per LLM generation"- isLoading={isLoading || (latencies.isLoading && selectedModels.length > 0)}+ isLoading={+ isLoading || (latencies.isLoading && selectedModels.length > 0)+ }headerRight={<div className="flex items-center justify-end"><ModelSelectorPopover@@ -158,7 +178,9 @@ export const GenerationLatencyChart = ({valueFormatter={latencyFormatter}/>) : (- <NoDataOrLoading isLoading={isLoading || latencies.isLoading} />+ <NoDataOrLoading+ isLoading={isLoading || latencies.isLoading}+ />)}</>),diff --git a/web/src/features/dashboard/components/LatencyTables.tsx b/web/src/features/dashboard/components/LatencyTables.tsxindex d54f1355f6..4e1d2b054e 100644--- a/web/src/features/dashboard/components/LatencyTables.tsx+++ b/web/src/features/dashboard/components/LatencyTables.tsx@@ -4,46 +4,57 @@ import { DashboardTable } from "@/src/features/dashboard/components/cards/Dashboimport { type FilterState } from "@langfuse/shared";import { api } from "@/src/utils/api";-import { type DatabaseRow } from "@/src/server/api/services/sqlInterface";import { formatIntervalSeconds } from "@/src/utils/dates";-import { createTracesTimeFilter } from "@/src/features/dashboard/lib/dashboard-utils";import { truncate } from "@/src/utils/string";import { Popup } from "@/src/components/layouts/doc-popup";+import {+ type QueryType,+ mapLegacyUiTableFilterToView,+} from "@/src/features/query";export const LatencyTables = ({projectId,globalFilterState,+ fromTimestamp,+ toTimestamp,isLoading = false,}: {projectId: string;globalFilterState: FilterState;+ fromTimestamp: Date;+ toTimestamp: Date;isLoading?: boolean;}) => {- const generationsLatencies = api.dashboard.chart.useQuery(+ // Define the query for generation latencies using the new QueryType structure+ const generationsLatenciesQuery: QueryType = {+ view: "observations",+ dimensions: [{ field: "name" }],+ metrics: [+ { measure: "latency", aggregation: "p50" },+ { measure: "latency", aggregation: "p90" },+ { measure: "latency", aggregation: "p95" },+ { measure: "latency", aggregation: "p99" },+ ],+ filters: [+ ...mapLegacyUiTableFilterToView("observations", globalFilterState),+ {+ column: "type",+ operator: "=",+ value: "GENERATION",+ type: "string",+ },+ ],+ timeDimension: null,+ fromTimestamp: fromTimestamp.toISOString(),+ toTimestamp: toTimestamp.toISOString(),+ orderBy: [{ field: "p95_latency", direction: "desc" }],+ };++ // Execute the query using the new dashboard.executeQuery functionality+ const generationsLatencies = api.dashboard.executeQuery.useQuery({projectId,- from: "traces_observations",- select: [- { column: "duration", agg: "50thPercentile" },- { column: "duration", agg: "90thPercentile" },- { column: "duration", agg: "95thPercentile" },- { column: "duration", agg: "99thPercentile" },- { column: "name" },- ],- filter: [- ...globalFilterState,- {- type: "string",- column: "type",- operator: "=",- value: "GENERATION",- },- ],- groupBy: [{ type: "string", column: "name" }],- orderBy: [- { column: "duration", agg: "95thPercentile", direction: "DESC" },- ],- queryName: "observation-latencies-aggregated",+ query: generationsLatenciesQuery,},{trpc: {@@ -55,31 +66,36 @@ export const LatencyTables = ({},);- const spansLatencies = api.dashboard.chart.useQuery(+ // Define the query for span latencies using the new QueryType structure+ const spansLatenciesQuery: QueryType = {+ view: "observations",+ dimensions: [{ field: "name" }],+ metrics: [+ { measure: "latency", aggregation: "p50" },+ { measure: "latency", aggregation: "p90" },+ { measure: "latency", aggregation: "p95" },+ { measure: "latency", aggregation: "p99" },+ ],+ filters: [+ ...mapLegacyUiTableFilterToView("observations", globalFilterState),+ {+ column: "type",+ operator: "=",+ value: "SPAN",+ type: "string",+ },+ ],+ timeDimension: null,+ fromTimestamp: fromTimestamp.toISOString(),+ toTimestamp: toTimestamp.toISOString(),+ orderBy: [{ field: "p95_latency", direction: "desc" }],+ };++ // Execute the query using the new dashboard.executeQuery functionality+ const spansLatencies = api.dashboard.executeQuery.useQuery({projectId,- from: "traces_observations",- select: [- { column: "duration", agg: "50thPercentile" },- { column: "duration", agg: "90thPercentile" },- { column: "duration", agg: "95thPercentile" },- { column: "duration", agg: "99thPercentile" },- { column: "name" },- ],- filter: [- ...globalFilterState,- {- type: "string",- column: "type",- operator: "=",- value: "SPAN",- },- ],- groupBy: [{ type: "string", column: "name" }],- orderBy: [- { column: "duration", agg: "95thPercentile", direction: "DESC" },- ],- queryName: "observation-latencies-aggregated",+ query: spansLatenciesQuery,},{trpc: {@@ -91,23 +107,28 @@ export const LatencyTables = ({},);- const tracesLatencies = api.dashboard.chart.useQuery(+ // Define the query for trace latencies using the new QueryType structure+ const tracesLatenciesQuery: QueryType = {+ view: "traces",+ dimensions: [{ field: "name" }],+ 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(),+ orderBy: [{ field: "p95_latency", direction: "desc" }],+ };++ // Execute the query using the new dashboard.executeQuery functionality+ const tracesLatencies = api.dashboard.executeQuery.useQuery({projectId,- from: "traces_metrics",- select: [- { column: "duration", agg: "50thPercentile" },- { column: "duration", agg: "90thPercentile" },- { column: "duration", agg: "95thPercentile" },- { column: "duration", agg: "99thPercentile" },- { column: "traceName" },- ],- filter: [...createTracesTimeFilter(globalFilterState)],- groupBy: [{ type: "string", column: "traceName" }],- orderBy: [- { column: "duration", agg: "95thPercentile", direction: "DESC" },- ],- queryName: "traces-latencies-aggregated",+ query: tracesLatenciesQuery,},{trpc: {@@ -119,7 +140,7 @@ export const LatencyTables = ({},);- const generateLatencyData = (data?: DatabaseRow[]) => {+ const generateLatencyData = (data?: Record<string, unknown>[]) => {return data? data.filter((item) => item.name !== null)@@ -130,18 +151,26 @@ export const LatencyTables = ({description={item.name as string}/></div>,- ...[- "percentile50Duration",- "percentile90Duration",- "percentile95Duration",- "percentile99Duration",- ].map((percentile) => (- <RightAlignedCell key={`${i}-${percentile}`}>- {item[percentile]- ? formatIntervalSeconds(item[percentile] as number, 3)- : "-"}- </RightAlignedCell>- )),+ <RightAlignedCell key={`${i}-p50`}>+ {item.p50_latency+ ? formatIntervalSeconds(Number(item.p50_latency) / 1000, 3)+ : "-"}+ </RightAlignedCell>,+ <RightAlignedCell key={`${i}-p90`}>+ {item.p90_latency+ ? formatIntervalSeconds(Number(item.p90_latency) / 1000, 3)+ : "-"}+ </RightAlignedCell>,+ <RightAlignedCell key={`${i}-p95`}>+ {item.p95_latency+ ? formatIntervalSeconds(Number(item.p95_latency) / 1000, 3)+ : "-"}+ </RightAlignedCell>,+ <RightAlignedCell key={`${i}-p99`}>+ {item.p99_latency+ ? formatIntervalSeconds(Number(item.p99_latency) / 1000, 3)+ : "-"}+ </RightAlignedCell>,]): [];};@@ -163,13 +192,7 @@ export const LatencyTables = ({</RightAlignedCell>,<RightAlignedCell key="99th">99th</RightAlignedCell>,]}- rows={generateLatencyData(- tracesLatencies.data- ?.filter((item) => item.traceName !== null)- .map((item) => {- return { ...item, name: item.traceName as string };- }),- )}+ rows={generateLatencyData(tracesLatencies.data)}isLoading={isLoading || tracesLatencies.isLoading}collapse={{ collapsed: 5, expanded: 20 }}/>diff --git a/web/src/features/dashboard/components/ModelSelector.tsx b/web/src/features/dashboard/components/ModelSelector.tsxindex 3ceb66e576..c22f0cee3c 100644--- a/web/src/features/dashboard/components/ModelSelector.tsx+++ b/web/src/features/dashboard/components/ModelSelector.tsx@@ -104,8 +104,15 @@ export const ModelSelectorPopover = ({export const useModelSelection = (projectId: string,globalFilterState: FilterState,+ fromTimestamp: Date,+ toTimestamp: Date,) => {- const allModels = getAllModels(projectId, globalFilterState);+ const allModels = getAllModels(+ projectId,+ globalFilterState,+ fromTimestamp,+ toTimestamp,+ );const [selectedModels, setSelectedModels] = useState<string[]>([]);const [firstAllModelUpdate, setFirstAllModelUpdate] = useState(true);diff --git a/web/src/features/dashboard/components/ModelUsageChart.tsx b/web/src/features/dashboard/components/ModelUsageChart.tsxindex 0f6e023b71..7c9d17aae3 100644--- a/web/src/features/dashboard/components/ModelUsageChart.tsx+++ b/web/src/features/dashboard/components/ModelUsageChart.tsx@@ -52,7 +52,12 @@ export const ModelUsageChart = ({isAllSelected,buttonText,handleSelectAll,- } = useModelSelection(projectId, globalFilterState);+ } = useModelSelection(+ projectId,+ userAndEnvFilterState,+ fromTimestamp,+ toTimestamp,+ );// Define the query for model usage data using the new QueryType structureconst modelUsageQuery: QueryType = {diff --git a/web/src/features/dashboard/components/hooks.ts b/web/src/features/dashboard/components/hooks.tsindex f4ddab0b74..dbccf09459 100644--- a/web/src/features/dashboard/components/hooks.ts+++ b/web/src/features/dashboard/components/hooks.ts@@ -2,27 +2,35 @@ import { type TimeSeriesChartDataPoint } from "@/src/features/dashboard/componenimport { type FilterState } from "@langfuse/shared";import { type DatabaseRow } from "@/src/server/api/services/sqlInterface";import { api } from "@/src/utils/api";+import { mapLegacyUiTableFilterToView } from "@/src/features/query";export const getAllModels = (projectId: string,globalFilterState: FilterState,+ fromTimestamp: Date,+ toTimestamp: Date,) => {- const allModels = api.dashboard.chart.useQuery(+ const allModels = api.dashboard.executeQuery.useQuery({projectId,- from: "traces_observations",- select: [{ column: "model" }],- filter: [- ...globalFilterState,- {- type: "string",- column: "type",- operator: "=",- value: "GENERATION",- },- ],- groupBy: [{ type: "string", column: "model" }],- queryName: "distinct-models",+ query: {+ view: "observations",+ dimensions: [{ field: "providedModelName" }],+ metrics: [],+ filters: [+ ...mapLegacyUiTableFilterToView("observations", globalFilterState),+ {+ column: "type",+ operator: "=",+ value: "GENERATION",+ type: "string",+ },+ ],+ timeDimension: null,+ fromTimestamp: fromTimestamp.toISOString(),+ toTimestamp: toTimestamp.toISOString(),+ orderBy: null,+ },},{trpc: {@@ -37,12 +45,12 @@ export const getAllModels = (};const extractAllModels = (- data: DatabaseRow[],+ data: Record<string, unknown>[],): { model: string; count: number }[] => {return data- .filter((item) => item.model !== null)+ .filter((item) => item.provided_model_name !== null).map((item) => ({- model: item.model as string,+ model: item.provided_model_name as string,count: item.count as number,}));};diff --git a/web/src/features/dashboard/server/dashboard-router.ts b/web/src/features/dashboard/server/dashboard-router.tsindex a2575890d4..bdbfb6074b 100644--- a/web/src/features/dashboard/server/dashboard-router.ts+++ b/web/src/features/dashboard/server/dashboard-router.ts@@ -12,11 +12,7 @@ import { createHistogramData } from "@/src/features/dashboard/lib/score-analyticimport { TRPCError } from "@trpc/server";import {getScoreAggregate,- getDistinctModels,getScoresAggregateOverTime,- getModelLatenciesOverTime,- getObservationLatencies,- getTracesLatencies,getNumericScoreHistogram,getNumericScoreTimeSeries,getCategoricalScoreTimeSeries,@@ -50,13 +46,13 @@ export const dashboardRouter = createTRPCRouter({// Cost by type and usage by type are currently not supported in the new data model"observations-usage-by-type-timeseries","observations-cost-by-type-timeseries",- "distinct-models",+ // "distinct-models","scores-aggregate-timeseries",// "observations-usage-by-users",// "traces-grouped-by-user",- "observation-latencies-aggregated",- "traces-latencies-aggregated",- "model-latencies-over-time",+ // "observation-latencies-aggregated",+ // "traces-latencies-aggregated",+ // "model-latencies-over-time","numeric-score-time-series","categorical-score-chart",// "observations-status-timeseries",@@ -150,13 +146,12 @@ export const dashboardRouter = createTRPCRouter({);return rowsObsCostByType as DatabaseRow[];- case "distinct-models":- const models = await getDistinctModels(- input.projectId,- input.filter ?? [],- );- return models as DatabaseRow[];-+ // case "distinct-models":+ // const models = await getDistinctModels(+ // input.projectId,+ // input.filter ?? [],+ // );+ // return models as DatabaseRow[];case "scores-aggregate-timeseries":const aggregatedScores = await getScoresAggregateOverTime(input.projectId,@@ -189,47 +184,47 @@ export const dashboardRouter = createTRPCRouter({// user: row.user,// countTraceId: Number(row.count),// })) as DatabaseRow[];- case "observation-latencies-aggregated":- const latencies = await getObservationLatencies(- input.projectId,- input.filter ?? [],- );-- return latencies.map((row) => ({- name: row.name,- percentile50Duration: row.p50,- percentile90Duration: row.p90,- percentile95Duration: row.p95,- percentile99Duration: row.p99,- })) as DatabaseRow[];- case "model-latencies-over-time":- const modelLatencies = await getModelLatenciesOverTime(- input.projectId,- input.filter ?? [],- );-- return modelLatencies.map((row) => ({- model: row.model,- startTime: row.start_time,- percentile50Duration: row.p50,- percentile75Duration: row.p75,- percentile90Duration: row.p90,- percentile95Duration: row.p95,- percentile99Duration: row.p99,- })) as DatabaseRow[];- case "traces-latencies-aggregated":- const traceLatencies = await getTracesLatencies(- input.projectId,- input.filter ?? [],- );-- return traceLatencies.map((row) => ({- traceName: row.name,- percentile50Duration: row.p50,- percentile90Duration: row.p90,- percentile95Duration: row.p95,- percentile99Duration: row.p99,- })) as DatabaseRow[];+ // case "observation-latencies-aggregated":+ // const latencies = await getObservationLatencies(+ // input.projectId,+ // input.filter ?? [],+ // );+ //+ // return latencies.map((row) => ({+ // name: row.name,+ // percentile50Duration: row.p50,+ // percentile90Duration: row.p90,+ // percentile95Duration: row.p95,+ // percentile99Duration: row.p99,+ // })) as DatabaseRow[];+ // case "model-latencies-over-time":+ // const modelLatencies = await getModelLatenciesOverTime(+ // input.projectId,+ // input.filter ?? [],+ // );+ //+ // return modelLatencies.map((row) => ({+ // model: row.model,+ // startTime: row.start_time,+ // percentile50Duration: row.p50,+ // percentile75Duration: row.p75,+ // percentile90Duration: row.p90,+ // percentile95Duration: row.p95,+ // percentile99Duration: row.p99,+ // })) as DatabaseRow[];+ // case "traces-latencies-aggregated":+ // const traceLatencies = await getTracesLatencies(+ // input.projectId,+ // input.filter ?? [],+ // );+ //+ // return traceLatencies.map((row) => ({+ // traceName: row.name,+ // percentile50Duration: row.p50,+ // percentile90Duration: row.p90,+ // percentile95Duration: row.p95,+ // percentile99Duration: row.p99,+ // })) as DatabaseRow[];case "numeric-score-time-series":const dateTruncNumericScoreTimeSeries = extractTimeSeries(input.groupBy,diff --git a/web/src/features/query/server/queryBuilder.ts b/web/src/features/query/server/queryBuilder.tsindex 2532eca03b..2314d3c6f1 100644--- a/web/src/features/query/server/queryBuilder.ts+++ b/web/src/features/query/server/queryBuilder.ts@@ -78,7 +78,7 @@ export class QueryBuilder {return dimensions.map((dimension) => {if (!(dimension.field in view.dimensions)) {throw new Error(- `Invalid dimension. Must be one of ${Object.keys(view.dimensions)}`,+ `Invalid dimension ${dimension.field}. Must be one of ${Object.keys(view.dimensions)}`,);}const dim = view.dimensions[dimension.field];@@ -96,7 +96,7 @@ export class QueryBuilder {return metrics.map((metric) => {if (!(metric.measure in view.measures)) {throw new Error(- `Invalid metric. Must be one of ${Object.keys(view.measures)}`,+ `Invalid metric ${metric.measure}. Must be one of ${Object.keys(view.measures)}`,);}return {diff --git a/web/src/pages/project/[projectId]/index.tsx b/web/src/pages/project/[projectId]/index.tsxindex b2b8be8c5d..2d736c48e7 100644--- a/web/src/pages/project/[projectId]/index.tsx+++ b/web/src/pages/project/[projectId]/index.tsx@@ -287,14 +287,18 @@ export default function Dashboard() {/><LatencyTablesprojectId={projectId}- globalFilterState={mergedFilterState}+ globalFilterState={[...userFilterState, ...environmentFilter]}+ fromTimestamp={fromTimestamp}+ toTimestamp={toTimestamp}isLoading={environmentFilterOptions.isLoading}/><GenerationLatencyChartclassName="col-span-1 flex-auto justify-between lg:col-span-full"projectId={projectId}agg={agg}- globalFilterState={mergedFilterState}+ globalFilterState={[...userFilterState, ...environmentFilter]}+ fromTimestamp={fromTimestamp}+ toTimestamp={toTimestamp}isLoading={environmentFilterOptions.isLoading}/><ScoreAnalyticsdiff --git a/web/src/utils/numbers.ts b/web/src/utils/numbers.tsindex c2c0955f5c..aad3cf3b36 100644--- a/web/src/utils/numbers.ts+++ b/web/src/utils/numbers.ts@@ -19,7 +19,7 @@ export const numberFormatter = (}).format(number ?? 0);};-export const latencyFormatter = (number?: number | bigint) => {+export const latencyFormatter = (milliseconds?: number) => {return Intl.NumberFormat("en-US", {style: "unit",unit: "second",@@ -27,7 +27,7 @@ export const latencyFormatter = (number?: number | bigint) => {notation: "compact",minimumFractionDigits: 2,maximumFractionDigits: 2,- }).format(number ?? 0);+ }).format((milliseconds ?? 0) / 1000);};export const usdFormatter = (