🪢 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
fix(filters): allow restoring saved views with metdata (#9938)
Nimarf3d4ae7bbac1
diff --git a/packages/shared/src/observationsTable.ts b/packages/shared/src/observationsTable.tsindex 94a983569a..28b9226f27 100644--- a/packages/shared/src/observationsTable.ts+++ b/packages/shared/src/observationsTable.ts@@ -45,6 +45,14 @@ export const observationsTableCols: ColumnDefinition[] = [internal: 't."user_id"',nullable: true,},+ {+ name: "Environment",+ id: "environment",+ type: "stringOptions",+ internal: 'o."environment"',+ options: [], // to be added at runtime+ nullable: true,+ },{name: "Start Time",id: "startTime",@@ -219,6 +227,7 @@ export type ObservationOptions = {modelId: Array<SingleValueOption>;name: Array<SingleValueOption>;traceName: Array<SingleValueOption>;+ environment: Array<SingleValueOption>;scores_avg: Array<string>;score_categories: Array<MultiValueOption>;promptName: Array<SingleValueOption>;@@ -242,6 +251,9 @@ export function observationsTableColsWithOptions(if (col.id === "traceName") {return formatColumnOptions(col, options?.traceName ?? []);}+ if (col.id === "environment") {+ return formatColumnOptions(col, options?.environment ?? []);+ }if (col.id === "scores_avg") {return formatColumnOptions(col, options?.scores_avg ?? []);}diff --git a/web/src/features/filters/config/traces-config.ts b/web/src/features/filters/config/traces-config.tsindex 084d5a833a..47c3756a48 100644--- a/web/src/features/filters/config/traces-config.ts+++ b/web/src/features/filters/config/traces-config.ts@@ -20,9 +20,9 @@ const TRACE_COLUMN_TO_QUERY_KEY: ColumnToQueryKeyMap = {inputCost: "inputCost",outputCost: "outputCost",totalCost: "totalCost",- "Scores (categorical)": "score_categories",- "Scores (numeric)": "scores_avg",- Metadata: "metadata",+ score_categories: "score_categories",+ scores_avg: "scores_avg",+ metadata: "metadata",};export const traceFilterConfig: FilterConfig = {@@ -62,7 +62,7 @@ export const traceFilterConfig: FilterConfig = {},{type: "stringKeyValue" as const,- column: "Metadata",+ column: "metadata",label: "Metadata",},{@@ -147,12 +147,12 @@ export const traceFilterConfig: FilterConfig = {},{type: "keyValue" as const,- column: "Scores (categorical)",+ column: "score_categories",label: "Categorical Scores",},{type: "numericKeyValue" as const,- column: "Scores (numeric)",+ column: "scores_avg",label: "Numeric Scores",},],diff --git a/web/src/features/filters/filter-integration.clienttest.ts b/web/src/features/filters/filter-integration.clienttest.tsindex ccae80ad95..ca0993b0cb 100644--- a/web/src/features/filters/filter-integration.clienttest.ts+++ b/web/src/features/filters/filter-integration.clienttest.ts@@ -4,7 +4,11 @@* using browser URLSearchParams APIs to simulate real-world usage.*/-import { type FilterState, tracesTableCols } from "@langfuse/shared";+import {+ type FilterState,+ tracesTableCols,+ observationsTableCols,+} from "@langfuse/shared";import {encodeFiltersGeneric,decodeFiltersGeneric,@@ -12,6 +16,8 @@ import {type GenericFilterOptions,} from "./lib/filter-query-encoding";import { validateFilters } from "@/src/components/table/table-view-presets/validation";+import { traceFilterConfig } from "./config/traces-config";+import { observationFilterConfig } from "./config/observations-config";const mockColumnMap: ColumnToQueryKeyMap = {name: "name",@@ -416,4 +422,148 @@ describe("Saved View Validation (Backward & Forward Compatibility)", () => {expect(validated[0]?.column).toBe("userId"); // Normalized!expect(validated[1]?.column).toBe("name"); // Already correct});++ it("should handle old saved view metadata filter with column name metadata key", () => {+ const savedFilter: FilterState = [+ {+ key: "projectName",+ type: "stringObject",+ value: "myproject",+ column: "Metadata", // Display name (capital M)+ operator: "contains",+ },+ ];++ // 1. Validate: normalizes "Metadata" → "metadata"+ const validated = validateFilters(savedFilter, tracesTableCols);+ expect(validated).toHaveLength(1);+ expect(validated[0]?.column).toBe("metadata"); // Normalized to lowercase ID++ // 2. Encode: should find "metadata" in columnToQueryKey+ const encoded = encodeFiltersGeneric(+ validated,+ {+ metadata: "metadata",+ name: "name",+ userId: "userId",+ },+ {},+ );++ // Should successfully encode (not drop the filter!)+ expect(encoded).toBeTruthy();+ expect(encoded).toContain(+ "metadata;stringObject;projectName;contains;myproject",+ );++ // 3. Decode: should restore correctly+ const decoded = decodeFiltersGeneric(+ encoded,+ {+ metadata: "metadata",+ name: "name",+ userId: "userId",+ },+ {},+ );++ expect(decoded).toHaveLength(1);+ expect(decoded[0]).toEqual({+ column: "metadata",+ type: "stringObject",+ key: "projectName",+ operator: "contains",+ value: "myproject",+ });+ });++ it("should handle saved score filters with display names", () => {+ // Real saved filters for scores+ const savedFilters: FilterState = [+ {+ key: "hallucination",+ type: "categoryOptions",+ value: ["high"],+ column: "Scores (categorical)", // Display name+ operator: "any of",+ },+ {+ key: "accuracy",+ type: "numberObject",+ value: 0.8,+ column: "Scores (numeric)", // Display name+ operator: ">=",+ },+ ];++ // 1. Validate: normalizes display names → IDs+ const validated = validateFilters(savedFilters, tracesTableCols);+ expect(validated).toHaveLength(2);+ expect(validated[0]?.column).toBe("score_categories");+ expect(validated[1]?.column).toBe("scores_avg");++ // 2. Encode: should find column IDs in columnToQueryKey+ const encoded = encodeFiltersGeneric(+ validated,+ {+ score_categories: "score_categories",+ scores_avg: "scores_avg",+ },+ {},+ );++ expect(encoded).toBeTruthy();+ expect(encoded).toContain(+ "score_categories;categoryOptions;hallucination;any of;high",+ );+ expect(encoded).toContain("scores_avg;numberObject;accuracy");++ // 3. Round-trip: decode should restore+ const decoded = decodeFiltersGeneric(+ encoded,+ {+ score_categories: "score_categories",+ scores_avg: "scores_avg",+ },+ {},+ );++ expect(decoded).toHaveLength(2);+ expect(decoded[0]?.column).toBe("score_categories");+ expect(decoded[1]?.column).toBe("scores_avg");+ });+});++describe("Config Validation of old saved views", () => {+ it("should validate traces config uses column IDs not display names", () => {+ // Validate all keys in columnToQueryKey exist as column IDs+ const columnIds = new Set(tracesTableCols.map((col) => col.id));+ const invalidKeys = Object.keys(traceFilterConfig.columnToQueryKey).filter(+ (key) => !columnIds.has(key),+ );++ expect(invalidKeys).toEqual([]);++ // Validate all facet columns exist as column IDs+ const invalidFacets = traceFilterConfig.facets.filter(+ (facet) => !columnIds.has(facet.column),+ );++ expect(invalidFacets).toEqual([]);+ });++ it("should validate observations config uses column IDs not display names", () => {+ const columnIds = new Set(observationsTableCols.map((col) => col.id));+ const invalidKeys = Object.keys(+ observationFilterConfig.columnToQueryKey,+ ).filter((key) => !columnIds.has(key));++ expect(invalidKeys).toEqual([]);++ const invalidFacets = observationFilterConfig.facets.filter(+ (facet) => !columnIds.has(facet.column),+ );++ expect(invalidFacets).toEqual([]);+ });});diff --git a/web/src/server/api/routers/generations/filterOptionsQuery.ts b/web/src/server/api/routers/generations/filterOptionsQuery.tsindex 0f21f54ff1..493f5c3a8d 100644--- a/web/src/server/api/routers/generations/filterOptionsQuery.ts+++ b/web/src/server/api/routers/generations/filterOptionsQuery.ts@@ -171,6 +171,7 @@ export const filterOptionsQuery = protectedProjectProcedure].map((i) => ({value: i,})),+ environment: [], // Environment is fetched separately via api.projects.environmentFilterOptions};return res;