Skip to content

🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.

perf: skip observations deduplication for additional routes for otel projects (#10734)

Steffen Schmitz88ebf2045331
diff --git a/.gitignore b/.gitignore
index 4b485b7199..f4f56d73d2 100644
--- a/.gitignore
+++ b/.gitignore
@@ -57,7 +57,7 @@ yarn-error.log*
/public/openapi*.yml
# claude meta files
-./claude/tsc-cache/*
+.claude/tsc-cache
# vscode
node_modules
diff --git a/packages/shared/src/server/repositories/observations.ts b/packages/shared/src/server/repositories/observations.ts
index a495f2a60c..7234cf5bb2 100644
--- a/packages/shared/src/server/repositories/observations.ts
+++ b/packages/shared/src/server/repositories/observations.ts
@@ -45,6 +45,7 @@ import type { AnalyticsGenerationEvent } from "../analytics-integrations/types";
import { ObservationType } from "../../domain";
import { recordDistribution } from "../instrumentation";
import { DEFAULT_RENDERING_PROPS, RenderingProps } from "../utils/rendering";
+import { shouldSkipObservationsFinal } from "../queries/clickhouse-sql/query-options";
/**
* Checks if observation exists in clickhouse.
@@ -141,6 +142,9 @@ export const getObservationsForTrace = async <IncludeIO extends boolean>(
preferredClickhouseService,
} = opts;
+ // OTel projects use immutable spans - no need for deduplication
+ const skipDedup = await shouldSkipObservationsFinal(projectId);
+
const query = `
SELECT
id,
@@ -177,8 +181,8 @@ export const getObservationsForTrace = async <IncludeIO extends boolean>(
WHERE trace_id = {traceId: String}
AND project_id = {projectId: String}
${timestamp ? `AND start_time >= {traceTimestamp: DateTime64(3)} - ${TRACE_TO_OBSERVATIONS_INTERVAL}` : ""}
- ORDER BY event_ts DESC
- LIMIT 1 BY id, project_id`;
+ ${skipDedup ? "" : "ORDER BY event_ts DESC"}
+ ${skipDedup ? "" : "LIMIT 1 BY id, project_id"}`;
const records = await queryClickhouse<ObservationRecordReadType>({
query,
params: {
@@ -652,6 +656,9 @@ const getObservationsTableInternal = async <T>(
clickhouseConfigs,
} = opts;
+ // OTel projects use immutable spans - no need for deduplication
+ const skipDedup = await shouldSkipObservationsFinal(projectId);
+
const selectString = selectIOAndMetadata
? `${select}, o.input, o.output, o.metadata`
: select;
@@ -798,7 +805,7 @@ const getObservationsTableInternal = async <T>(
${timeFilter && (traceTableFilter.length > 0 || orderByTraces) ? `AND t.timestamp > {tracesTimestampFilter: DateTime64(3)} - ${OBSERVATIONS_TO_TRACE_INTERVAL}` : ""}
${search.query}
${chOrderBy}
- ${opts.select === "rows" ? "LIMIT 1 BY o.id, o.project_id" : ""}
+ ${opts.select === "rows" && !skipDedup ? "LIMIT 1 BY o.id, o.project_id" : ""}
${limit !== undefined && offset !== undefined ? `LIMIT ${limit} OFFSET ${offset}` : ""};`;
return measureAndReturn({
diff --git a/packages/shared/src/server/services/traces-ui-table-service.ts b/packages/shared/src/server/services/traces-ui-table-service.ts
index e75ae44cf1..a2f0f8b1f8 100644
--- a/packages/shared/src/server/services/traces-ui-table-service.ts
+++ b/packages/shared/src/server/services/traces-ui-table-service.ts
@@ -26,6 +26,7 @@ import { measureAndReturn } from "../clickhouse/measureAndReturn";
import { TracingSearchType } from "../../interfaces/search";
import { ObservationLevelType, TraceDomain } from "../../domain";
import { ClickHouseClientConfigOptions } from "@clickhouse/client";
+import { shouldSkipObservationsFinal } from "../queries/clickhouse-sql/query-options";
export type TracesTableReturnType = Pick<
TraceRecordReadType,
@@ -218,6 +219,9 @@ async function getTracesTableGeneric(props: FetchTracesTableProps) {
clickhouseConfigs,
} = props;
+ // OTel projects use immutable spans - no need for deduplication
+ const skipObservationsDedup = await shouldSkipObservationsFinal(projectId);
+
const { tracesFilter, scoresFilter, observationsFilter } =
getProjectIdDefaultFilter(projectId, { tracesPrefix: "t" });
@@ -302,7 +306,7 @@ async function getTracesTableGeneric(props: FetchTracesTableProps) {
sumMap(cost_details) as cost_details,
trace_id,
project_id
- FROM observations o FINAL
+ FROM observations o ${skipObservationsDedup ? "" : "FINAL"}
WHERE o.project_id = {projectId: String}
${timeStampFilter ? `AND o.start_time >= {traceTimestamp: DateTime64(3)} - ${OBSERVATIONS_TO_TRACE_INTERVAL}` : ""}
${observationsFilter ? `AND ${observationFilterRes.query}` : ""}