🪢 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(dashboarding): support experiment dimensions and filters in observations view (#13602)
marliessophie8cbad17b5663
diff --git a/packages/shared/src/features/query/dataModel.ts b/packages/shared/src/features/query/dataModel.tsindex b3bbd07a87..01633374c7 100644--- a/packages/shared/src/features/query/dataModel.ts+++ b/packages/shared/src/features/query/dataModel.ts@@ -1147,6 +1147,29 @@ export const eventsObservationsView: ViewDeclarationType = {valueAlias: "usage_value",},},+ // Experiment dimensions (v2 only - experiment data only exists in events table)+ experimentName: {+ sql: "nullIf(events_observations.experiment_name, '')",+ alias: "experimentName",+ type: "string",+ description: "Name of the experiment this observation belongs to.",+ highCardinality: true,+ },+ experimentDatasetId: {+ sql: "nullIf(events_observations.experiment_dataset_id, '')",+ alias: "experimentDatasetId",+ type: "string",+ description: "Dataset used in the experiment.",+ highCardinality: true,+ },+ experimentId: {+ sql: "nullIf(events_observations.experiment_id, '')",+ alias: "experimentId",+ type: "string",+ description: "ID of the experiment this observation belongs to.",+ highCardinality: true,+ uiHidden: true, // Only available as filter, not as breakdown dimension+ },},measures: {count: {diff --git a/web/src/__tests__/server/dashboard-widget-version.servertest.ts b/web/src/__tests__/server/dashboard-widget-version.servertest.tsindex 99e2766f5c..3e73ef78ef 100644--- a/web/src/__tests__/server/dashboard-widget-version.servertest.ts+++ b/web/src/__tests__/server/dashboard-widget-version.servertest.ts@@ -113,6 +113,28 @@ describe("dashboard widget minVersion", () => {[{ column: "release" }],true,],+ // v2-only experiment filters+ [+ "observations",+ [],+ [{ measure: "count" }],+ [{ column: "experimentId" }],+ true,+ ],+ [+ "observations",+ [],+ [{ measure: "count" }],+ [{ column: "experimentName" }],+ true,+ ],+ [+ "observations",+ [],+ [{ measure: "count" }],+ [{ column: "experimentDatasetId" }],+ true,+ ],// v1-compatible fields["observations",diff --git a/web/src/features/dashboard/lib/dashboardUiTableToViewMapping.ts b/web/src/features/dashboard/lib/dashboardUiTableToViewMapping.tsindex d0ebee8ab5..f5790fc68c 100644--- a/web/src/features/dashboard/lib/dashboardUiTableToViewMapping.ts+++ b/web/src/features/dashboard/lib/dashboardUiTableToViewMapping.ts@@ -153,6 +153,19 @@ const viewFilterDefinitions: Record<sourceSpec("Observation Release", { uiTableId: "release" }),),defineField("version", sourceSpec("Version", { uiTableId: "version" })),+ // Experiment fields (v2 only - experiment data only exists in events table)+ defineField(+ "experimentName",+ sourceSpec("Experiment Name", { uiTableId: "experimentName" }),+ ),+ defineField(+ "experimentDatasetId",+ sourceSpec("Experiment Dataset", { uiTableId: "experimentDatasetId" }),+ ),+ defineField(+ "experimentId",+ sourceSpec("Experiment ID", { uiTableId: "experimentId" }),+ ),],"scores-numeric": [defineField("name", sourceSpec("Score Name", { uiTableId: "scoreName" })),diff --git a/web/src/features/widgets/components/WidgetForm.tsx b/web/src/features/widgets/components/WidgetForm.tsxindex baee6c52c2..0e0b807156 100644--- a/web/src/features/widgets/components/WidgetForm.tsx+++ b/web/src/features/widgets/components/WidgetForm.tsx@@ -75,7 +75,14 @@ import {Plus,X,AlertCircle,+ Sparkles,} from "lucide-react";+import {+ Popover,+ PopoverContent,+ PopoverTrigger,+ PopoverClose,+} from "@/src/components/ui/popover";import {buildWidgetName,buildWidgetDescription,@@ -97,6 +104,7 @@ import {getWidgetColumnsWithCustomSelect,getWidgetFilterColumns,} from "./widgetFilterColumns";+import { WIDGET_FILTER_PRESETS } from "@/src/features/widgets/constants/widgetFilterPresets";type ChartType = {group: "time-series" | "total-value";@@ -627,6 +635,7 @@ export function WidgetForm({}};+ // v1: Use traces/generations filter options (old normalized tables)const traceFilterOptions = api.traces.filterOptions.useQuery({projectId,@@ -641,6 +650,7 @@ export function WidgetForm({refetchOnWindowFocus: false,refetchOnReconnect: false,staleTime: Infinity,+ enabled: viewVersion === "v1",},);@@ -658,9 +668,29 @@ export function WidgetForm({refetchOnWindowFocus: false,refetchOnReconnect: false,staleTime: Infinity,+ enabled: viewVersion === "v1",+ },+ );++ const eventsFilterOptions = api.events.filterOptions.useQuery(+ {+ projectId,+ },+ {+ trpc: {+ context: {+ skipBatch: true,+ },+ },+ refetchOnMount: false,+ refetchOnWindowFocus: false,+ refetchOnReconnect: false,+ staleTime: Infinity,+ enabled: viewVersion === "v2",},);+ // v1: Use project environment filter options (queries from Postgres)const environmentFilterOptions =api.projects.environmentFilterOptions.useQuery({@@ -677,20 +707,59 @@ export function WidgetForm({refetchOnWindowFocus: false,refetchOnReconnect: false,staleTime: Infinity,+ enabled: viewVersion === "v1",},);- const environmentOptions =- environmentFilterOptions.data?.map((value) => ({- value: value.environment,- })) || [];- const nameOptions = normalizeSingleValueOptions(- traceFilterOptions.data?.name,++ const datasets = api.datasets.allDatasetMeta.useQuery(+ {+ projectId,+ },+ { enabled: viewVersion === "v2" },);- const tagsOptions = traceFilterOptions.data?.tags || [];- const modelOptions = generationsFilterOptions.data?.model || [];- const toolNamesOptions = generationsFilterOptions.data?.toolNames || [];++ // Resolve filter options based on viewVersion+ const environmentOptions =+ viewVersion === "v2"+ ? eventsFilterOptions.data?.environment || []+ : environmentFilterOptions.data?.map((value) => ({+ value: value.environment,+ })) || [];+ const nameOptions =+ viewVersion === "v2"+ ? normalizeSingleValueOptions(eventsFilterOptions.data?.traceName)+ : normalizeSingleValueOptions(traceFilterOptions.data?.name);+ const tagsOptions =+ viewVersion === "v2"+ ? eventsFilterOptions.data?.traceTags || []+ : traceFilterOptions.data?.tags || [];+ const modelOptions =+ viewVersion === "v2"+ ? eventsFilterOptions.data?.providedModelName || []+ : generationsFilterOptions.data?.model || [];+ const toolNamesOptions =+ viewVersion === "v2"+ ? eventsFilterOptions.data?.toolNames || []+ : generationsFilterOptions.data?.toolNames || [];const calledToolNamesOptions =- generationsFilterOptions.data?.calledToolNames || [];+ viewVersion === "v2"+ ? eventsFilterOptions.data?.calledToolNames || []+ : generationsFilterOptions.data?.calledToolNames || [];++ // Experiment options only available in v2 (from events table)+ const experimentNameOptions =+ viewVersion === "v2" ? eventsFilterOptions.data?.experimentName || [] : [];+ const experimentDatasetIdSet = new Set(+ eventsFilterOptions.data?.experimentDatasetId?.map((e) => e.value),+ );+ const experimentDatasetIdOptions =+ datasets.data+ ?.filter((d) => experimentDatasetIdSet.has(d.id))+ .map((d) => ({+ value: d.id,+ displayValue: d.name,+ })) ?? [];+const filterColumns = getWidgetFilterColumns({selectedView,viewVersion,@@ -701,6 +770,8 @@ export function WidgetForm({toolNamesOptions,calledToolNamesOptions,observationLevelOptions,+ experimentNameOptions,+ experimentDatasetOptions: experimentDatasetIdOptions,observationTypeOptions,});const columnsWithCustomSelect = getWidgetColumnsWithCustomSelect({@@ -713,9 +784,33 @@ export function WidgetForm({toolNamesOptions,calledToolNamesOptions,observationLevelOptions,+ experimentNameOptions,+ experimentDatasetOptions: experimentDatasetIdOptions,observationTypeOptions,});+ // Helper to get valid filter column identifiers for a given view+ const getValidFilterColumnIds = (+ view: z.infer<typeof views>,+ ): Set<string> => {+ const columns = getWidgetFilterColumns({+ selectedView: view,+ viewVersion,+ environmentOptions,+ nameOptions,+ tagsOptions,+ modelOptions,+ toolNamesOptions,+ calledToolNamesOptions,+ observationLevelOptions,+ observationTypeOptions,+ experimentNameOptions,+ experimentDatasetOptions: experimentDatasetIdOptions,+ });+ // Include both column id and name since filters may use either+ return new Set(columns.flatMap((col) => [col.id, col.name]));+ };+// When chart type does not support breakdown, wipe the breakdown dimensionuseEffect(() => {if (@@ -1098,6 +1193,43 @@ export function WidgetForm({viewVersion,]);+ // Resets chart fields and pivot table state when switching views+ const resetChartFieldsForView = (newView: z.infer<typeof views>) => {+ const newViewDeclaration = viewDeclarations[viewVersion][newView];++ // Reset regular chart fields+ setSelectedMeasure("count");+ setSelectedAggregation("count");+ setSelectedDimension("none");++ // Handle pivot table cleanup+ if (selectedChartType === "PIVOT_TABLE") {+ const validMetrics = selectedMetrics.filter(+ (metric) => metric.measure in newViewDeclaration.measures,+ );+ if (validMetrics.length === 0) {+ validMetrics.push({+ id: "count_count",+ measure: "count",+ aggregation: "count" as z.infer<typeof metricAggregations>,+ label: "Count Count",+ });+ }+ setSelectedMetrics(validMetrics);++ const validDimensions = pivotDimensions.filter(+ (dimension) => dimension in newViewDeclaration.dimensions,+ );+ setPivotDimensions(validDimensions);+ }++ // Remove filters that are not valid for the new view+ const validColumns = getValidFilterColumnIds(newView);+ setUserFilterState((prev) =>+ prev.filter((filter) => validColumns.has(filter.column)),+ );+ };+const handleSaveWidget = () => {if (!queryValidation.valid) {showErrorToast("Invalid query", queryValidation.reason);@@ -1299,7 +1431,41 @@ export function WidgetForm({)}{/* Data Selection Section */}<div className="space-y-4">- <h3 className="text-lg font-bold">Data Selection</h3>+ <div className="flex items-center justify-between">+ <h3 className="text-lg font-bold">Data Selection</h3>+ {viewVersion === "v2" && (+ <Popover>+ <PopoverTrigger asChild>+ <Button variant="outline" size="sm">+ <Sparkles className="mr-2 h-4 w-4" />+ Presets+ </Button>+ </PopoverTrigger>+ <PopoverContent className="w-64 p-1" align="end">+ {Object.entries(WIDGET_FILTER_PRESETS).map(+ ([key, preset]) => (+ <PopoverClose key={key} asChild>+ <Button+ className="w-full justify-start"+ variant="ghost"+ onClick={() => {+ if (preset.view !== selectedView) {+ resetChartFieldsForView(preset.view);+ setSelectedView(preset.view);+ }+ setUserFilterState([...preset.filters]);+ }}+ >+ <preset.icon className="mr-2 h-4 w-4" />+ {preset.label}+ </Button>+ </PopoverClose>+ ),+ )}+ </PopoverContent>+ </Popover>+ )}+ </div>{/* View Selection */}<div className="space-y-2">@@ -1307,74 +1473,11 @@ export function WidgetForm({<Selectvalue={selectedView}onValueChange={(value) => {- if (value !== selectedView) {- const newView = value as z.infer<typeof views>;- const newViewDeclaration =- viewDeclarations[viewVersion][newView];-- // Reset regular chart fields- setSelectedMeasure("count");- setSelectedAggregation("count");- setSelectedDimension("none");-- // Handle pivot table metrics - filter out invalid measures for the new view- if (selectedChartType === "PIVOT_TABLE") {- const validMetrics = selectedMetrics.filter(- (metric) =>- metric.measure in newViewDeclaration.measures,- );-- // Ensure we have at least one valid metric (count is always available)- if (validMetrics.length === 0) {- validMetrics.push({- id: "count_count",- measure: "count",- aggregation: "count" as z.infer<- typeof metricAggregations- >,- label: "Count Count",- });- }-- setSelectedMetrics(validMetrics);-- // Handle pivot table dimensions - filter out invalid dimensions for the new view- const validDimensions = pivotDimensions.filter(- (dimension) =>- dimension in newViewDeclaration.dimensions,- );- setPivotDimensions(validDimensions);- }-- // Remove score-only filters when switching away from- // scores-categorical or scores-numeric. The widget editor- // state stores current UI labels such as "Score Value",- // but older/canonical filters can still surface as ids- // during transitions, so we need to clean up both- // representations here.- setUserFilterState((prev) =>- prev.filter((filter) => {- if (- newView !== "scores-categorical" &&- (filter.column === "stringValue" ||- filter.column === "Score String Value")- ) {- return false;- }-- if (- newView !== "scores-numeric" &&- (filter.column === "value" ||- filter.column === "Score Value")- ) {- return false;- }-- return true;- }),- );+ const newView = value as z.infer<typeof views>;+ if (newView !== selectedView) {+ resetChartFieldsForView(newView);}- setSelectedView(value as z.infer<typeof views>);+ setSelectedView(newView);}}><SelectTrigger id="view-select">diff --git a/web/src/features/widgets/components/widgetFilterColumns.ts b/web/src/features/widgets/components/widgetFilterColumns.tsindex e5f3c3adcd..d2827f0790 100644--- a/web/src/features/widgets/components/widgetFilterColumns.ts+++ b/web/src/features/widgets/components/widgetFilterColumns.ts@@ -16,6 +16,8 @@ type GetWidgetFilterColumnsParams = {toolNamesOptions: SingleValueOption[];calledToolNamesOptions: SingleValueOption[];observationLevelOptions: SingleValueOption[];+ experimentNameOptions: SingleValueOption[];+ experimentDatasetOptions: SingleValueOption[];observationTypeOptions: SingleValueOption[];};@@ -34,6 +36,8 @@ const getWidgetFilterColumnSpecs = ({toolNamesOptions,calledToolNamesOptions,observationLevelOptions,+ experimentNameOptions,+ experimentDatasetOptions,observationTypeOptions,}: GetWidgetFilterColumnsParams): WidgetFilterColumnSpec[] => {const filterColumns: WidgetFilterColumnSpec[] = [@@ -130,6 +134,7 @@ const getWidgetFilterColumnSpecs = ({if (selectedView === "observations") {filterColumns.push(+ // v2-only filter columns (experiment data only exists in events table)...(viewVersion === "v2"? [{@@ -140,6 +145,34 @@ const getWidgetFilterColumnSpecs = ({internal: "internalValue",},} satisfies WidgetFilterColumnSpec,+ {+ column: {+ name: "Experiment Name",+ id: "experimentName",+ type: "stringOptions",+ options: experimentNameOptions,+ internal: "internalValue",+ },+ customSelect: true,+ } satisfies WidgetFilterColumnSpec,+ {+ column: {+ name: "Experiment Dataset",+ id: "experimentDatasetId",+ type: "stringOptions",+ options: experimentDatasetOptions,+ internal: "internalValue",+ },+ customSelect: true,+ } satisfies WidgetFilterColumnSpec,+ {+ column: {+ name: "Experiment ID",+ id: "experimentId",+ type: "null",+ internal: "internalValue",+ },+ } satisfies WidgetFilterColumnSpec,]: []),{diff --git a/web/src/features/widgets/constants/widgetFilterPresets.ts b/web/src/features/widgets/constants/widgetFilterPresets.tsnew file mode 100644index 0000000000..c4ae3f7691--- /dev/null+++ b/web/src/features/widgets/constants/widgetFilterPresets.ts@@ -0,0 +1,45 @@+import { type views } from "@langfuse/shared/query";+import { type z } from "zod";+import { BeakerIcon, type LucideIcon } from "lucide-react";+import { type FilterState } from "@langfuse/shared";++/**+ * Widget filter preset definition.+ */+type WidgetFilterPreset = {+ label: string;+ description: string;+ icon: LucideIcon;+ /** The view this preset applies to */+ view: z.infer<typeof views>;+ /** Filters to apply - must be complete, valid filters */+ filters: FilterState;+};++/**+ * Predefined filter presets for common widget configurations.+ *+ * To add a new preset:+ * 1. Add a new key to this object+ * 2. TypeScript will validate that filters match FilterState schema+ * 3. If a filter column is renamed/removed, TypeScript won't catch it directly,+ * but the filter will fail at runtime when applied+ */+export const WIDGET_FILTER_PRESETS = {+ allExperimentData: {+ label: "Experiment Data",+ description: "All experiment-items linked to experiments",+ icon: BeakerIcon,+ view: "observations",+ filters: [+ {+ column: "experimentId",+ type: "null",+ operator: "is not null",+ value: "",+ },+ ],+ },+} as const satisfies Record<string, WidgetFilterPreset>;++export type WidgetFilterPresetKey = keyof typeof WIDGET_FILTER_PRESETS;