🪢 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: further tighten the difference between v1 views and their v2 implementations (#12065)
Valery Meleshkindcb10ffc5ac4
diff --git a/packages/shared/src/server/clickhouse/schema.ts b/packages/shared/src/server/clickhouse/schema.tsindex 576c2d7c2f..0db7a142b9 100644--- a/packages/shared/src/server/clickhouse/schema.ts+++ b/packages/shared/src/server/clickhouse/schema.ts@@ -9,6 +9,8 @@ export const ClickhouseTableNames = {// TODO: Check if we can do this more elegantlyscores_numeric: "scores_numeric",scores_categorical: "scores_categorical",+ events_traces: "events_traces",+ events_observations: "events_observations",} as const;export type ClickhouseTableName = keyof typeof ClickhouseTableNames;diff --git a/web/src/features/query/dataModel.ts b/web/src/features/query/dataModel.tsindex 0494a0ff2e..7a84f2c120 100644--- a/web/src/features/query/dataModel.ts+++ b/web/src/features/query/dataModel.ts@@ -237,14 +237,14 @@ export const eventsTracesView: ViewDeclarationType = {},measures: {count: {- sql: "count(*)",+ sql: "countIf(events_traces.parent_span_id = '')",alias: "count",type: "integer",description: "Total number of traces.",unit: "traces",},observationsCount: {- sql: "uniq(events_traces.span_id)",+ sql: "uniqIf(events_traces.span_id, events_traces.parent_span_id != '')",alias: "observationsCount",type: "integer",description: "Unique observations linked to the trace.",@@ -273,7 +273,7 @@ export const eventsTracesView: ViewDeclarationType = {unit: "sessions",},latency: {- sql: "date_diff('millisecond', min(events_traces.start_time), max(events_traces.end_time))",+ sql: "date_diff('millisecond', minIf(events_traces.start_time, events_traces.parent_span_id != ''), maxIf(events_traces.end_time, events_traces.parent_span_id != ''))",alias: "latency",type: "integer",description:@@ -281,14 +281,14 @@ export const eventsTracesView: ViewDeclarationType = {unit: "millisecond",},totalTokens: {- sql: "sumMap(events_traces.usage_details)['total']",+ sql: "sumMapIf(events_traces.usage_details, events_traces.parent_span_id != '')['total']",alias: "totalTokens",type: "integer",description: "Sum of tokens consumed by all observations in the trace.",unit: "tokens",},totalCost: {- sql: "sum(events_traces.total_cost)",+ sql: "sumIf(toNullable(events_traces.total_cost), events_traces.parent_span_id != '')",alias: "totalCost",type: "decimal",description: "Total cost accumulated across observations in the trace.",@@ -305,6 +305,7 @@ export const eventsTracesView: ViewDeclarationType = {},segments: [],timeDimension: "start_time",+ timeDimensionAggregation: "min",baseCte: `events events_traces`,};@@ -1187,7 +1188,7 @@ export const eventsObservationsView: ViewDeclarationType = {unit: "USD",},totalCost: {- sql: "@@AGG1@@(total_cost)",+ sql: "@@AGG1@@(toNullable(total_cost))",aggs: { agg1: "sum" },alias: "totalCost",type: "decimal",diff --git a/web/src/features/query/server/queryBuilder.ts b/web/src/features/query/server/queryBuilder.tsindex 2110893ea7..f95e302182 100644--- a/web/src/features/query/server/queryBuilder.ts+++ b/web/src/features/query/server/queryBuilder.ts@@ -446,7 +446,7 @@ export class QueryBuilder {uiTableId: relation.timeDimension,clickhouseTableName: relation.name,clickhouseSelect: relation.timeDimension,- queryPrefix: relation.name,+ queryPrefix: relationTableName,type: "datetime",};@@ -571,9 +571,10 @@ export class QueryBuilder {);// Optionally wrap in aggregation function (e.g., "any" for two-level inner SELECT)- const wrappedSql = wrapInAgg- ? `${wrapInAgg}(${timeDimensionSql})`- : timeDimensionSql;+ const agg = wrapInAgg+ ? (view.timeDimensionAggregation ?? wrapInAgg)+ : undefined;+ const wrappedSql = agg ? `${agg}(${timeDimensionSql})` : timeDimensionSql;return `${wrappedSql} as time_dimension`;}diff --git a/web/src/features/query/types.ts b/web/src/features/query/types.tsindex bc338d6469..54edf415cf 100644--- a/web/src/features/query/types.ts+++ b/web/src/features/query/types.ts@@ -48,6 +48,7 @@ export const viewDeclaration = z.object({// Segments are used to apply "constant" filters to the query. For example, if we only want one type of observations.segments: z.array(singleFilter),timeDimension: z.string(),+ timeDimensionAggregation: z.string().optional(),});export const stringDateTime = z.string().datetime({ offset: true });