🪢 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: use singular unit in clickhouse datediff for 23.x support (#4894)
Steffen Schmitz1c980c78dd9b
diff --git a/packages/shared/src/server/repositories/dashboards.ts b/packages/shared/src/server/repositories/dashboards.tsindex 8cbc57fe5c..cd4f5b6812 100644--- a/packages/shared/src/server/repositories/dashboards.ts+++ b/packages/shared/src/server/repositories/dashboards.ts@@ -418,7 +418,7 @@ export const getObservationLatencies = async (// Skipping FINAL here, as the quantiles are approximate to begin with.const query = `SELECT- quantiles(0.5, 0.9, 0.95, 0.99)(date_diff('milliseconds', o.start_time, o.end_time)) as quantiles,+ quantiles(0.5, 0.9, 0.95, 0.99)(date_diff('millisecond', o.start_time, o.end_time)) as quantiles,nameFROM observations o${chFilter.find((f) => f.clickhouseTable === "traces") ? "LEFT JOIN traces t ON o.trace_id = t.id AND o.project_id = t.project_id" : ""}@@ -465,7 +465,7 @@ export const getTracesLatencies = async (select o.trace_id,t.name,o.project_id,- date_diff('milliseconds', min(o.start_time), coalesce(max(o.end_time), max(o.start_time))) as duration+ date_diff('millisecond', min(o.start_time), coalesce(max(o.end_time), max(o.start_time))) as durationFROM traces tJOIN observations oON o.trace_id = t.id AND o.project_id = t.project_id@@ -521,7 +521,7 @@ export const getModelLatenciesOverTime = async (SELECT${selectTimeseriesColumn(groupBy, "o.start_time", "start_time_bucket")},provided_model_name,- quantiles(0.5, 0.75, 0.9, 0.95, 0.99)(date_diff('milliseconds', o.start_time, o.end_time)) as quantiles+ quantiles(0.5, 0.75, 0.9, 0.95, 0.99)(date_diff('millisecond', o.start_time, o.end_time)) as quantilesFROM observations o${traceFilter ? "JOIN traces t ON o.trace_id = t.id AND o.project_id = t.project_id" : ""}WHERE project_id = {projectId: String}diff --git a/packages/shared/src/server/repositories/observations.ts b/packages/shared/src/server/repositories/observations.tsindex 41fa2eccb7..68f2b92e7e 100644--- a/packages/shared/src/server/repositories/observations.ts+++ b/packages/shared/src/server/repositories/observations.ts@@ -540,8 +540,8 @@ const getObservationsTableInternal = async <T>(o.prompt_name as "prompt_name",o.prompt_version as "prompt_version",internal_model_id as "internal_model_id",- if(isNull(end_time), NULL, date_diff('milliseconds', start_time, end_time)) as latency,- if(isNull(completion_start_time), NULL, date_diff('milliseconds', start_time, completion_start_time)) as "time_to_first_token"`;+ if(isNull(end_time), NULL, date_diff('millisecond', start_time, end_time)) as latency,+ if(isNull(completion_start_time), NULL, date_diff('millisecond', start_time, completion_start_time)) as "time_to_first_token"`;const { projectId, filter, selectIOAndMetadata, limit, offset, orderBy } =opts;@@ -1010,7 +1010,7 @@ export const getObservationMetricsForPrompts = async (end_time,usage_details,cost_details,- dateDiff('milliseconds', start_time, end_time) AS latency_ms+ dateDiff('millisecond', start_time, end_time) AS latency_msFROM observationsFINALWHERE (type = 'GENERATION')@@ -1073,7 +1073,7 @@ export const getLatencyAndTotalCostForObservations = async (SELECTid,cost_details['total'] AS total_cost,- dateDiff('milliseconds', start_time, end_time) AS latency_ms+ dateDiff('millisecond', start_time, end_time) AS latency_msFROM observations FINALWHERE project_id = {projectId: String}AND id IN ({observationIds: Array(String)})@@ -1105,7 +1105,7 @@ export const getLatencyAndTotalCostForObservationsByTraces = async (SELECTtrace_id,sumMap(cost_details)['total'] AS total_cost,- dateDiff('milliseconds', min(start_time), max(end_time)) AS latency_ms+ dateDiff('millisecond', min(start_time), max(end_time)) AS latency_msFROM observations FINALWHERE project_id = {projectId: String}AND trace_id IN ({traceIds: Array(String)})@@ -1225,12 +1225,12 @@ export const getGenerationsForPostHog = async (o.start_time as start_time,o.id as id,o.total_cost as total_cost,- if(isNull(completion_start_time), NULL, date_diff('milliseconds', start_time, completion_start_time)) as time_to_first_token,+ if(isNull(completion_start_time), NULL, date_diff('millisecond', start_time, completion_start_time)) as time_to_first_token,o.usage_details['total'] as input_tokens,o.usage_details['output'] as output_tokens,o.cost_details['total'] as total_tokens,o.project_id as project_id,- if(isNull(end_time), NULL, date_diff('milliseconds', start_time, end_time) / 1000) as latency,+ if(isNull(end_time), NULL, date_diff('millisecond', start_time, end_time) / 1000) as latency,o.provided_model_name as model,o.level as level,o.version as version,diff --git a/packages/shared/src/server/repositories/traces.ts b/packages/shared/src/server/repositories/traces.tsindex f81348c400..5b9c40a310 100644--- a/packages/shared/src/server/repositories/traces.ts+++ b/packages/shared/src/server/repositories/traces.ts@@ -526,7 +526,7 @@ const getSessionsTableGeneric = async <T>(props: FetchSessionsTableProps) => {groupUniqArrayArray(t.tags) as trace_tags,-- Aggregate observations data at session levelsum(o.obs_count) as total_observations,- date_diff('milliseconds', min(min_start_time), max(max_end_time)) as duration,+ date_diff('millisecond', min(min_start_time), max(max_end_time)) as duration,sumMap(o.sum_usage_details) as session_usage_details,sumMap(o.sum_cost_details) as session_cost_details,arraySum(mapValues(mapFilter(x -> positionCaseInsensitive(x.1, 'input') > 0, sumMap(o.sum_cost_details)))) as session_input_cost,@@ -831,7 +831,7 @@ export const getTracesForPostHog = async (o.trace_id,sum(total_cost) as total_cost,count(*) as observation_count,- date_diff('milliseconds', least(min(start_time), min(end_time)), greatest(max(start_time), max(end_time))) as latency_milliseconds+ date_diff('millisecond', least(min(start_time), min(end_time)), greatest(max(start_time), max(end_time))) as latency_millisecondsFROM observations o FINALWHERE o.project_id = {projectId: String}AND o.start_time >= {minTimestamp: DateTime64(3)} - ${TRACE_TO_OBSERVATIONS_INTERVAL}diff --git a/packages/shared/src/server/services/traces-ui-table-service.ts b/packages/shared/src/server/services/traces-ui-table-service.tsindex 9d3546181a..b200f812ed 100644--- a/packages/shared/src/server/services/traces-ui-table-service.ts+++ b/packages/shared/src/server/services/traces-ui-table-service.ts@@ -351,7 +351,7 @@ const getTracesTableGeneric = async <T>(props: FetchTracesTableProps) => {COUNT(*) AS observation_count,sumMap(usage_details) as usage_details,SUM(total_cost) AS total_cost,- date_diff('milliseconds', least(min(start_time), min(end_time)), greatest(max(start_time), max(end_time))) as latency_milliseconds,+ date_diff('millisecond', least(min(start_time), min(end_time)), greatest(max(start_time), max(end_time))) as latency_milliseconds,multiIf(arrayExists(x -> x = 'ERROR', groupArray(level)), 'ERROR',arrayExists(x -> x = 'WARNING', groupArray(level)), 'WARNING',diff --git a/packages/shared/src/tableDefinitions/mapObservationsTable.ts b/packages/shared/src/tableDefinitions/mapObservationsTable.tsindex d95dfcad5c..6a8cac83f8 100644--- a/packages/shared/src/tableDefinitions/mapObservationsTable.ts+++ b/packages/shared/src/tableDefinitions/mapObservationsTable.ts@@ -68,7 +68,7 @@ export const observationsTableUiColumnDefinitions: UiColumnMapping[] = [uiTableId: "timeToFirstToken",clickhouseTableName: "observations",clickhouseSelect:- "if(isNull(completion_start_time), NULL, date_diff('milliseconds', start_time, completion_start_time) / 1000)",+ "if(isNull(completion_start_time), NULL, date_diff('millisecond', start_time, completion_start_time) / 1000)",// If we use the default of Decimal64(12), we cannot filter for more than ~40min due to an overflowclickhouseTypeOverwrite: "Decimal64(3)",},@@ -77,7 +77,7 @@ export const observationsTableUiColumnDefinitions: UiColumnMapping[] = [uiTableId: "latency",clickhouseTableName: "observations",clickhouseSelect:- "if(isNull(end_time), NULL, date_diff('milliseconds', start_time, end_time) / 1000)",+ "if(isNull(end_time), NULL, date_diff('millisecond', start_time, end_time) / 1000)",// If we use the default of Decimal64(12), we cannot filter for more than ~40min due to an overflowclickhouseTypeOverwrite: "Decimal64(3)",},@@ -86,7 +86,7 @@ export const observationsTableUiColumnDefinitions: UiColumnMapping[] = [uiTableId: "tokensPerSecond",clickhouseTableName: "observations",clickhouseSelect:- "(arraySum(mapValues(mapFilter(x -> positionCaseInsensitive(x.1, 'output') > 0, usage_details))) / (date_diff('milliseconds', start_time, end_time) / 1000))",+ "(arraySum(mapValues(mapFilter(x -> positionCaseInsensitive(x.1, 'output') > 0, usage_details))) / (date_diff('millisecond', start_time, end_time) / 1000))",},{uiTableName: "Input Cost ($)",diff --git a/web/src/features/datasets/server/service.ts b/web/src/features/datasets/server/service.tsindex 2657f3dfe7..e99fa65091 100644--- a/web/src/features/datasets/server/service.ts+++ b/web/src/features/datasets/server/service.ts@@ -289,7 +289,7 @@ const getObservationLatencyAndCostForDataset = async (const query = `WITH agg AS (SELECT- dateDiff('milliseconds', start_time, end_time) AS latency_ms,+ dateDiff('millisecond', start_time, end_time) AS latency_ms,total_cost AS cost,run_idFROM observations AS o@@ -342,7 +342,7 @@ const getTraceLatencyAndCostForDataset = async (SELECTo.trace_id,run_id,- dateDiff('milliseconds', min(start_time), max(end_time)) AS latency_ms,+ dateDiff('millisecond', min(start_time), max(end_time)) AS latency_ms,sum(total_cost) AS costFROM observations o JOIN ${tableName} tmpON tmp.project_id = o.project_iddiff --git a/web/src/features/public-api/server/traces.ts b/web/src/features/public-api/server/traces.tsindex 2710c0a32f..ec60aeb24b 100644--- a/web/src/features/public-api/server/traces.ts+++ b/web/src/features/public-api/server/traces.ts@@ -58,7 +58,7 @@ export const generateTracesForPublicApi = async (trace_id,project_id,sum(total_cost) as total_cost,- date_diff('milliseconds', least(min(start_time), min(end_time)), greatest(max(start_time), max(end_time))) as latency_milliseconds,+ date_diff('millisecond', least(min(start_time), min(end_time)), greatest(max(start_time), max(end_time))) as latency_milliseconds,groupArray(id) as observation_idsFROM observations FINALWHERE project_id = {projectId: String}