🪢 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
refactor(v4): remove unused router procedures (#16066)
Max Deichmannc64fd4edfa9e
diff --git a/web/src/__tests__/server/unit/v4TransitionRouter.servertest.ts b/web/src/__tests__/server/unit/v4TransitionRouter.servertest.tsindex 1485de5a68..1a40f60845 100644--- a/web/src/__tests__/server/unit/v4TransitionRouter.servertest.ts+++ b/web/src/__tests__/server/unit/v4TransitionRouter.servertest.ts@@ -134,7 +134,6 @@ const mockedQueryClickhouse = vi.mocked(queryClickhouse);const projectId = "project-v4-transition";const orgId = "org-v4-transition";const secondProjectId = "project-v4-transition-second";-const outsideProjectId = "project-v4-transition-outside";// Mocked Prisma delegates only implement the methods a test exercises, so// accept any subset of PrismaClient keys with loosely typed values.@@ -594,10 +593,7 @@ describe("v4TransitionRouter", () => {});it("rejects ranges over 30 days", async () => {- const mockPrisma = {- $queryRaw: vi.fn(),- };- const caller = createCaller(mockPrisma);+ const caller = createCaller();await expect(caller.timeSeriesByEntrypoint({@@ -608,26 +604,7 @@ describe("v4TransitionRouter", () => {}),).rejects.toThrow("30 days");- await expect(- caller.traceLevelEvalExecutionsTimeSeries({- projectId,- fromTimestamp: new Date("2026-05-25T00:00:00Z"),- toTimestamp: new Date("2026-06-25T00:00:00Z"),- granularity: "auto",- }),- ).rejects.toThrow("30 days");-- await expect(- caller.sdkUsageTimeSeries({- projectId,- fromTimestamp: new Date("2026-05-25T00:00:00Z"),- toTimestamp: new Date("2026-06-25T00:00:00Z"),- granularity: "auto",- }),- ).rejects.toThrow("30 days");-expect(mockedQueryClickhouse).not.toHaveBeenCalled();- expect(mockPrisma.$queryRaw).not.toHaveBeenCalled();});it("summarizes legacy integrations", async () => {@@ -1042,319 +1019,6 @@ describe("v4TransitionRouter", () => {);});- it("queries trace-level eval execution counts with the same 2 minute buckets as the legacy API timeline", async () => {- const mockPrisma = {- $queryRaw: vi.fn().mockResolvedValue([- {- time: "2026-06-25T12:00:00Z",- scoreName: "toxicity",- count: 4n,- },- {- time: "2026-06-25T12:04:00Z",- scoreName: "helpfulness",- count: 2,- },- ]),- };- const caller = createCaller(mockPrisma);-- const rows = await caller.traceLevelEvalExecutionsTimeSeries({- projectId,- fromTimestamp: new Date("2026-06-25T12:00:00Z"),- toTimestamp: new Date("2026-06-25T13:00:00Z"),- granularity: "auto",- });-- expect(rows).toHaveLength(60);- expect(rows.slice(0, 4)).toEqual([- {- time: "2026-06-25T12:00:00Z",- scoreName: "helpfulness",- count: 0,- },- {- time: "2026-06-25T12:00:00Z",- scoreName: "toxicity",- count: 4,- },- {- time: "2026-06-25T12:02:00Z",- scoreName: "helpfulness",- count: 0,- },- {- time: "2026-06-25T12:02:00Z",- scoreName: "toxicity",- count: 0,- },- ]);- expect(- rows.find(- (row) =>- row.time === "2026-06-25T12:04:00Z" &&- row.scoreName === "helpfulness",- ),- ).toEqual({- time: "2026-06-25T12:04:00Z",- scoreName: "helpfulness",- count: 2,- });- expect(rows.at(-1)).toEqual({- time: "2026-06-25T12:58:00Z",- scoreName: "toxicity",- count: 0,- });-- expect(mockPrisma.$queryRaw).toHaveBeenCalledTimes(1);- const query = mockPrisma.$queryRaw.mock.calls[0]?.[0] as- | { sql?: string; text?: string; values?: unknown[] }- | undefined;- const queryText = query?.sql ?? query?.text ?? "";-- expect(queryText).toContain("date_bin(?::interval, je.created_at");- expect(queryText).toContain(- "INNER JOIN job_configurations jc ON jc.id = je.job_configuration_id",- );- expect(queryText).toContain("jc.score_name AS score_name");- expect(queryText).toContain('score_name AS "scoreName"');- expect(queryText).toContain("je.project_id = ?");- expect(queryText).toContain("jc.project_id = ?");- expect(queryText).toContain("jc.job_type = 'EVAL'");- expect(queryText).toContain("jc.target_object IN (?, ?)");- expect(queryText).toContain("jc.status = 'ACTIVE'");- expect(queryText).toContain("'NEW' = ANY(jc.time_scope)");- expect(queryText).toContain("je.status != 'CANCELLED'");- expect(queryText).toContain("je.created_at >= ?");- expect(queryText).toContain("je.created_at <= ?");- expect(queryText).toContain("bucket_time AT TIME ZONE 'UTC'");- expect(queryText).toContain("GROUP BY bucket_time, score_name");- expect(query?.values).toEqual([- "2 minutes",- projectId,- projectId,- "trace",- "dataset",- new Date("2026-06-25T12:00:00Z"),- new Date("2026-06-25T13:00:00Z"),- ]);- });-- it("uses hour buckets for 7 day trace-level eval execution timelines", async () => {- const mockPrisma = {- $queryRaw: vi.fn().mockResolvedValue([]),- };- const caller = createCaller(mockPrisma);-- const rows = await caller.traceLevelEvalExecutionsTimeSeries({- projectId,- fromTimestamp: new Date("2026-06-18T00:00:00Z"),- toTimestamp: new Date("2026-06-25T00:00:00Z"),- granularity: "auto",- });-- expect(rows).toEqual([]);-- const query = mockPrisma.$queryRaw.mock.calls[0]?.[0] as- | { sql?: string; text?: string; values?: unknown[] }- | undefined;- expect(query?.values?.[0]).toBe("1 hour");- });-- it("queries SDK usage by exact SDK, version, and API key across event and score ingestion", async () => {- mockedQueryClickhouse.mockResolvedValueOnce([- {- time: "2026-06-25T12:00:00Z",- sdkName: "python",- sdkVersion: "3.9.0",- publicKey: "pk-lf-old-python",- count: "3",- firstSeen: "2026-06-25T12:01:00Z",- lastSeen: "2026-06-25T12:03:00Z",- hasDelayedOtelEvents: "0",- },- {- time: "2026-06-25T12:04:00Z",- sdkName: "@langfuse/tracing",- sdkVersion: "5.1.0",- publicKey: "pk-lf-js-current",- count: 7,- firstSeen: "2026-06-25T12:04:00Z",- lastSeen: "2026-06-25T12:05:00Z",- hasDelayedOtelEvents: 0,- },- ]);- const caller = createCaller();-- const result = await caller.sdkUsageTimeSeries({- projectId,- fromTimestamp: new Date("2026-06-25T12:00:00Z"),- toTimestamp: new Date("2026-06-25T13:00:00Z"),- granularity: "auto",- });- const rows = result.rows;-- expect(result.bucketTimes).toHaveLength(30);- expect(result.bucketTimes[0]).toBe("2026-06-25T12:00:00Z");- expect(result.bucketTimes.at(-1)).toBe("2026-06-25T12:58:00Z");- expect(rows).toHaveLength(2);- expect(- rows.find(- (row) =>- row.time === "2026-06-25T12:00:00Z" &&- row.sdkName === "python" &&- row.sdkVersion === "3.9.0" &&- row.publicKey === "pk-lf-old-python",- ),- ).toEqual({- time: "2026-06-25T12:00:00Z",- sdkName: "python",- sdkVersion: "3.9.0",- publicKey: "pk-lf-old-python",- count: 3,- firstSeen: "2026-06-25T12:01:00Z",- lastSeen: "2026-06-25T12:03:00Z",- hasDelayedOtelEvents: false,- attributionStatus: "attributed",- canonicalSdkName: "python",- latestMajor: 4,- major: 3,- upgradeStatus: "outdated_major",- });- expect(- rows.find(- (row) =>- row.time === "2026-06-25T12:04:00Z" &&- row.sdkName === "@langfuse/tracing" &&- row.sdkVersion === "5.1.0" &&- row.publicKey === "pk-lf-js-current",- ),- ).toEqual({- time: "2026-06-25T12:04:00Z",- sdkName: "@langfuse/tracing",- sdkVersion: "5.1.0",- publicKey: "pk-lf-js-current",- count: 7,- firstSeen: "2026-06-25T12:04:00Z",- lastSeen: "2026-06-25T12:05:00Z",- hasDelayedOtelEvents: false,- attributionStatus: "attributed",- canonicalSdkName: "javascript",- latestMajor: 5,- major: 5,- upgradeStatus: "current",- });- expect(- rows.find(- (row) =>- row.time === "2026-06-25T12:02:00Z" &&- row.sdkName === "python" &&- row.sdkVersion === "3.9.0" &&- row.publicKey === "pk-lf-old-python",- ),- ).toBeUndefined();-- expect(mockedQueryClickhouse).toHaveBeenCalledTimes(1);- const clickhouseQuery = mockedQueryClickhouse.mock.calls[0]?.[0];- expect(clickhouseQuery?.query).toContain("FROM events_core");- expect(clickhouseQuery?.query).toContain("UNION ALL");- expect(clickhouseQuery?.query).toContain("FROM scores FINAL");- const [eventsQuery, scoresQuery] = clickhouseQuery?.query.split(- "UNION ALL",- ) ?? ["", ""];- expect(eventsQuery).not.toContain("execution_trace_id IS NULL");- expect(scoresQuery).toContain("execution_trace_id IS NULL");- expect(- clickhouseQuery?.query.match(/project_id = \{projectId: String\}/g),- ).toHaveLength(2);- expect(clickhouseQuery?.query).not.toContain("system.columns");- expect(clickhouseQuery?.query).toContain(- "toStartOfInterval(event_time, INTERVAL 2 MINUTE, 'UTC')",- );- expect(clickhouseQuery?.query).toContain(- "if(ingestion_sdk_name = '', 'unknown', ingestion_sdk_name) AS sdk_name",- );- expect(clickhouseQuery?.query).toContain(- "if(ingestion_sdk_version = '', 'unknown', ingestion_sdk_version) AS sdk_version",- );- expect(clickhouseQuery?.query).toContain("ingestion_api_key AS public_key");- expect(clickhouseQuery?.query).toContain("false AS is_delayed_otel");- expect(clickhouseQuery?.query).toContain("false AS is_otel_ingestion");- expect(clickhouseQuery?.query).toContain(- "startsWith(source, 'otel-dual-write') AS is_delayed_otel",- );- expect(clickhouseQuery?.query).toContain(- "(source = 'otel' OR startsWith(source, 'otel-dual-write')) AS is_otel_ingestion",- );- expect(clickhouseQuery?.query).toContain(- "if(countIf(is_otel_ingestion) > 0, argMaxIf(is_delayed_otel, event_time, is_otel_ingestion), NULL) AS hasDelayedOtelEvents",- );- expect(clickhouseQuery?.query).toContain(- "ingestion_sdk_name NOT IN {internalSdkNames: Array(String)}",- );- const [eventsUsageQuery, scoresUsageQuery] =- clickhouseQuery?.query.split("UNION ALL") ?? [];- expect(eventsUsageQuery).toContain(- "AND NOT startsWith(environment, 'langfuse-')",- );- expect(scoresUsageQuery).toContain(- "AND NOT startsWith(environment, 'langfuse-')",- );- expect(clickhouseQuery?.query).not.toContain("toDate(start_time)");- expect(clickhouseQuery?.query).not.toContain("toDate(timestamp)");- expect(clickhouseQuery?.query).toContain(- "GROUP BY toStartOfInterval(event_time, INTERVAL 2 MINUTE, 'UTC'), sdk_name, sdk_version, public_key",- );- expect(clickhouseQuery?.params).toMatchObject({- projectId,- fromTimestamp: "2026-06-25 12:00:00.000",- toTimestamp: "2026-06-25 13:00:00.000",- internalSdkNames: [- "langfuse-internal-ai-sdk",- "langfuse-internal-otel-writer",- ],- });- expect(clickhouseQuery?.tags).toEqual({- projectId,- route: "v4-sdk-usage-timeseries",- });- expect(clickhouseQuery?.preferredClickhouseService).toBe("EventsReadOnly");- });-- it("distinguishes raw OTel already using real-time ingestion", async () => {- mockedQueryClickhouse.mockResolvedValueOnce([- {- time: "2026-06-25T12:00:00Z",- sdkName: "unknown",- sdkVersion: "unknown",- publicKey: "pk-lf-raw-otel",- count: "4",- firstSeen: "2026-06-25T12:01:00Z",- lastSeen: "2026-06-25T12:03:00Z",- hasDelayedOtelEvents: "0",- },- ]);- const caller = createCaller();-- const result = await caller.sdkUsageTimeSeries({- projectId,- fromTimestamp: new Date("2026-06-25T12:00:00Z"),- toTimestamp: new Date("2026-06-25T13:00:00Z"),- granularity: "auto",- });-- expect(result.rows).toEqual([- expect.objectContaining({- sdkName: "unknown",- sdkVersion: "unknown",- publicKey: "pk-lf-raw-otel",- hasDelayedOtelEvents: false,- attributionStatus: "missing_name_and_version",- upgradeStatus: "unknown",- }),- ]);- });-it.each(["MEMBER", "VIEWER"] as const)("allows project %s roles to access project-level v4 data",async (role) => {@@ -1386,55 +1050,6 @@ describe("v4TransitionRouter", () => {},);- it("queries SDK usage without a ClickHouse metadata preflight", async () => {- mockedQueryClickhouse.mockResolvedValueOnce([- {- time: "2026-06-25T12:00:00Z",- sdkName: "python",- sdkVersion: "4.0.0",- publicKey: "pk-lf-python",- count: 2,- firstSeen: "2026-06-25T12:00:00Z",- lastSeen: "2026-06-25T12:01:00Z",- },- ]);- const caller = createCaller();-- const result = await caller.sdkUsageTimeSeries({- projectId,- fromTimestamp: new Date("2026-06-25T12:00:00Z"),- toTimestamp: new Date("2026-06-25T12:10:00Z"),- granularity: "auto",- });-- expect(result.bucketTimes).toHaveLength(10);- expect(result.rows).toHaveLength(1);- expect(mockedQueryClickhouse).toHaveBeenCalledTimes(1);- const usageQuery = mockedQueryClickhouse.mock.calls[0]?.[0];- expect(usageQuery?.query).toContain("FROM events_core");- expect(usageQuery?.query).toContain("FROM scores FINAL");- expect(usageQuery?.query).toContain("UNION ALL");- expect(- usageQuery?.query.match(/project_id = \{projectId: String\}/g),- ).toHaveLength(2);- expect(usageQuery?.query).not.toContain("system.columns");- });-- it("rejects SDK usage requests for projects outside the caller session", async () => {- const caller = createCaller();-- await expect(- caller.sdkUsageTimeSeries({- projectId: outsideProjectId,- fromTimestamp: new Date("2026-06-25T12:00:00Z"),- toTimestamp: new Date("2026-06-25T13:00:00Z"),- granularity: "auto",- }),- ).rejects.toThrow("User is not a member of this project");-- expect(mockedQueryClickhouse).not.toHaveBeenCalled();- });-it("summarizes outdated SDK usage series by organization project", async () => {mockedQueryClickhouse.mockResolvedValueOnce([diff --git a/web/src/features/v4/server/timelineBuckets.ts b/web/src/features/v4/server/timelineBuckets.tsindex b38e1819a6..18217e461c 100644--- a/web/src/features/v4/server/timelineBuckets.ts+++ b/web/src/features/v4/server/timelineBuckets.ts@@ -1,5 +1,3 @@-import { Prisma } from "@langfuse/shared/src/db";-export type ResolvedTimelineGranularity =| "minute"| "2m"@@ -54,21 +52,6 @@ export const getTimelineBucketSql = (return `toStartOfInterval(${sql}, INTERVAL ${intervalByGranularity[granularity]}, 'UTC')`;};-export const getPostgresTimelineBucketExpression = (- sql: Prisma.Sql,- granularity: ResolvedTimelineGranularity,-): Prisma.Sql => {- const intervalByGranularity: Record<ResolvedTimelineGranularity, string> = {- minute: "1 minute",- "2m": "2 minutes",- "5m": "5 minutes",- hour: "1 hour",- day: "1 day",- };-- return Prisma.sql`date_bin(${intervalByGranularity[granularity]}::interval, ${sql}, '1970-01-01T00:00:00Z'::timestamptz)`;-};-export const floorTimelineBucket = (timestamp: Date,granularity: ResolvedTimelineGranularity,diff --git a/web/src/features/v4/server/v4TransitionRouter.ts b/web/src/features/v4/server/v4TransitionRouter.tsindex 7e8e20e864..d6f8ef9934 100644--- a/web/src/features/v4/server/v4TransitionRouter.ts+++ b/web/src/features/v4/server/v4TransitionRouter.ts@@ -4,10 +4,8 @@ import {protectedOrganizationProcedure,protectedProjectProcedure,} from "@/src/server/api/trpc";-import {- AnalyticsIntegrationExportSource,- Prisma,-} from "@langfuse/shared/src/db";+import { AnalyticsIntegrationExportSource } from "@langfuse/shared/src/db";+import type { Prisma } from "@langfuse/shared/src/db";import { variableMapping } from "@langfuse/shared";import type { Session } from "next-auth";import {@@ -26,7 +24,6 @@ import {addTimelineBucket,floorTimelineBucket,formatTimelineBucket,- getPostgresTimelineBucketExpression,getTimelineBucketSql,MAX_TIMELINE_RANGE_MS,resolveTimelineGranularity,@@ -120,19 +117,7 @@ type LegacyApiUsageSummaryByProjectResultRow = {count: number;};-type SdkUsageTimeSeriesRow = {- time: string;- sdkName: string;- sdkVersion: string;- publicKey: string;- count: string | number;- firstSeen: string;- lastSeen: string;- hasDelayedOtelEvents: boolean | string | number | null;-};--type SdkUsageTimeSeriesResultRow = {- time: string;+type DecoratedSdkUsageSummaryRow = {sdkName: string;sdkVersion: string;publicKey: string;@@ -142,16 +127,9 @@ type SdkUsageTimeSeriesResultRow = {hasDelayedOtelEvents: boolean | null;attributionStatus: IngestionSdkAttributionStatus;canonicalSdkName: "python" | "javascript" | null;- latestMajor: number | null;- major: number | null;upgradeStatus: IngestionSdkUpgradeStatus;};-type SdkUsageTimeSeriesResult = {- bucketTimes: string[];- rows: SdkUsageTimeSeriesResultRow[];-};-type SdkUsageSummaryByProjectRow = {projectId: string;sdkName: string;@@ -239,43 +217,6 @@ const compareTimelineRows = (return left.entrypoint.localeCompare(right.entrypoint);};-const getTimelineBucketTimes = (- fromTimestamp: Date,- toTimestamp: Date,- granularity: ResolvedTimelineGranularity,-): string[] => {- const buckets: string[] = [];-- for (- let bucket = floorTimelineBucket(fromTimestamp, granularity);- bucket.getTime() < toTimestamp.getTime();- bucket = addTimelineBucket(bucket, granularity)- ) {- buckets.push(formatTimelineBucket(bucket));- }-- return buckets;-};--const getSdkUsageSeriesKey = (row: {- sdkName: string;- sdkVersion: string;- publicKey: string;-}): string => `${row.sdkName}\u0000${row.sdkVersion}\u0000${row.publicKey}`;--const compareSdkUsageRows = (- left: SdkUsageTimeSeriesResultRow,- right: SdkUsageTimeSeriesResultRow,-): number => {- if (left.time < right.time) return -1;- if (left.time > right.time) return 1;-- const leftSeries = getSdkUsageSeriesKey(left);- const rightSeries = getSdkUsageSeriesKey(right);-- return leftSeries.localeCompare(rightSeries);-};-const toBoolean = (value: boolean | string | number): boolean =>value === true || value === 1 || value === "1";@@ -283,53 +224,6 @@ const toNullableBoolean = (value: boolean | string | number | null,): boolean | null => (value === null ? null : toBoolean(value));-const decorateSdkUsageRows = ({- rows,-}: {- rows: SdkUsageTimeSeriesRow[];-}): SdkUsageTimeSeriesResultRow[] => {- return rows- .map((row) => {- const classification = classifyIngestionSdkVersion({- sdkName: row.sdkName,- sdkVersion: row.sdkVersion,- });- const attributionStatus = classifyIngestionSdkAttribution({- sdkName: row.sdkName,- sdkVersion: row.sdkVersion,- });-- return {- time: row.time,- sdkName: row.sdkName,- sdkVersion: row.sdkVersion,- publicKey: row.publicKey,- count: Number(row.count),- firstSeen: row.firstSeen,- lastSeen: row.lastSeen,- hasDelayedOtelEvents: toNullableBoolean(row.hasDelayedOtelEvents),- attributionStatus,- canonicalSdkName: classification.canonicalSdkName,- latestMajor: classification.latestMajor,- major: classification.major,- upgradeStatus: classification.status,- };- })- .sort(compareSdkUsageRows);-};--type TraceLevelEvalExecutionTimeSeriesRow = {- time: string;- scoreName: string;- count: bigint | number;-};--type TraceLevelEvalExecutionTimeSeriesPoint = {- time: string;- scoreName: string;- count: number;-};-type TraceLevelEvalSummaryByProjectResultRow = {projectId: string;traceLevelEvalCount: number;@@ -341,48 +235,6 @@ type LegacyIntegrations = {blobStorage: boolean;};-const fillTraceLevelEvalExecutionBuckets = ({- rows,- fromTimestamp,- toTimestamp,- granularity,-}: {- rows: TraceLevelEvalExecutionTimeSeriesPoint[];- fromTimestamp: Date;- toTimestamp: Date;- granularity: ResolvedTimelineGranularity;-}): TraceLevelEvalExecutionTimeSeriesPoint[] => {- const scoreNames = Array.from(- new Set(rows.map((row) => row.scoreName)),- ).sort();- if (scoreNames.length === 0) return [];-- const counts = new Map(- rows.map(- (row) => [`${row.time}\u0000${row.scoreName}`, row.count] as const,- ),- );- const filledRows: TraceLevelEvalExecutionTimeSeriesPoint[] = [];-- for (- let bucket = floorTimelineBucket(fromTimestamp, granularity);- bucket.getTime() < toTimestamp.getTime();- bucket = addTimelineBucket(bucket, granularity)- ) {- const time = formatTimelineBucket(bucket);-- for (const scoreName of scoreNames) {- filledRows.push({- time,- scoreName,- count: counts.get(`${time}\u0000${scoreName}`) ?? 0,- });- }- }-- return filledRows;-};-const getAccessibleOrganizationProjectWhere = ({orgId,session,@@ -626,151 +478,6 @@ export const v4TransitionRouter = createTRPCRouter({);}),- traceLevelEvalExecutionsTimeSeries: protectedProjectProcedure- .input(timelineInputSchema)- .query(async ({ input, ctx }) => {- const granularity = resolveTimelineGranularity(- input.fromTimestamp,- input.toTimestamp,- );- const bucketExpression = getPostgresTimelineBucketExpression(- Prisma.sql`je.created_at`,- granularity,- );-- const rows = await ctx.prisma.$queryRaw<- TraceLevelEvalExecutionTimeSeriesRow[]- >(Prisma.sql`-WITH selected AS (- SELECT- ${bucketExpression} AS bucket_time,- jc.score_name AS score_name- FROM job_executions je- INNER JOIN job_configurations jc ON jc.id = je.job_configuration_id- AND jc.project_id = je.project_id- WHERE je.project_id = ${input.projectId}- AND jc.project_id = ${input.projectId}- AND jc.job_type = 'EVAL'- AND jc.target_object IN (${TRACE_EVAL_TARGET}, ${DATASET_EVAL_TARGET})- AND jc.status = 'ACTIVE'- AND 'NEW' = ANY(jc.time_scope)- AND je.status != 'CANCELLED'- AND je.created_at >= ${input.fromTimestamp}- AND je.created_at <= ${input.toTimestamp}-)--SELECT- to_char(bucket_time AT TIME ZONE 'UTC', 'YYYY-MM-DD"T"HH24:MI:SS"Z"') AS time,- score_name AS "scoreName",- COUNT(*)::bigint AS count-FROM selected-GROUP BY bucket_time, score_name-ORDER BY bucket_time ASC, score_name ASC- `);-- return fillTraceLevelEvalExecutionBuckets({- rows: rows.map((row) => ({- time: row.time,- scoreName: row.scoreName,- count: Number(row.count),- })),- fromTimestamp: input.fromTimestamp,- toTimestamp: input.toTimestamp,- granularity,- });- }),-- sdkUsageTimeSeries: protectedProjectProcedure- .input(timelineInputSchema)- .query(async ({ input }) => {- const granularity = resolveTimelineGranularity(- input.fromTimestamp,- input.toTimestamp,- );- const bucketTimeSql = getTimelineBucketSql("event_time", granularity);-- const scoresUnionSql = `- UNION ALL-- SELECT- timestamp AS event_time,- if(ingestion_sdk_name = '', 'unknown', ingestion_sdk_name) AS sdk_name,- if(ingestion_sdk_version = '', 'unknown', ingestion_sdk_version) AS sdk_version,- ingestion_api_key AS public_key,- false AS is_otel_ingestion,- false AS is_delayed_otel- FROM scores FINAL- WHERE- project_id = {projectId: String}- AND timestamp >= {fromTimestamp: DateTime64(3)}- AND timestamp <= {toTimestamp: DateTime64(3)}- AND NOT startsWith(environment, 'langfuse-')- AND execution_trace_id IS NULL- AND source != 'ANNOTATION'- AND ingestion_sdk_name NOT IN {internalSdkNames: Array(String)}- AND is_deleted = 0`;-- const rows = await queryClickhouse<SdkUsageTimeSeriesRow>({- query: `-WITH selected AS (- SELECT- start_time AS event_time,- if(ingestion_sdk_name = '', 'unknown', ingestion_sdk_name) AS sdk_name,- if(ingestion_sdk_version = '', 'unknown', ingestion_sdk_version) AS sdk_version,- ingestion_api_key AS public_key,- (source = 'otel' OR startsWith(source, 'otel-dual-write')) AS is_otel_ingestion,- startsWith(source, 'otel-dual-write') AS is_delayed_otel- FROM events_core- WHERE- project_id = {projectId: String}- AND start_time >= {fromTimestamp: DateTime64(3)}- AND start_time <= {toTimestamp: DateTime64(3)}- AND NOT startsWith(environment, 'langfuse-')- AND ingestion_sdk_name NOT IN {internalSdkNames: Array(String)}- AND is_deleted = 0- ${scoresUnionSql}-)--SELECT- formatDateTime(${bucketTimeSql}, '%Y-%m-%dT%H:%i:%SZ', 'UTC') AS time,- sdk_name AS sdkName,- sdk_version AS sdkVersion,- public_key AS publicKey,- count() AS count,- formatDateTime(min(event_time), '%Y-%m-%dT%H:%i:%SZ', 'UTC') AS firstSeen,- formatDateTime(max(event_time), '%Y-%m-%dT%H:%i:%SZ', 'UTC') AS lastSeen,- if(countIf(is_otel_ingestion) > 0, argMaxIf(is_delayed_otel, event_time, is_otel_ingestion), NULL) AS hasDelayedOtelEvents-FROM selected-GROUP BY ${bucketTimeSql}, sdk_name, sdk_version, public_key-ORDER BY ${bucketTimeSql} ASC, sdk_name ASC, sdk_version ASC, public_key ASC- `,- params: {- projectId: input.projectId,- fromTimestamp: convertDateToClickhouseDateTime(input.fromTimestamp),- toTimestamp: convertDateToClickhouseDateTime(input.toTimestamp),- internalSdkNames: [...INTERNAL_INGESTION_SDK_NAMES],- },- tags: {- projectId: input.projectId,- route: "v4-sdk-usage-timeseries",- },- preferredClickhouseService: "EventsReadOnly",- });-- const decoratedRows = decorateSdkUsageRows({- rows,- });-- return {- bucketTimes: getTimelineBucketTimes(- input.fromTimestamp,- input.toTimestamp,- granularity,- ),- rows: decoratedRows,- } satisfies SdkUsageTimeSeriesResult;- }),-sdkUsageSummaryByProject: protectedOrganizationProcedure.input(organizationTimeRangeInputSchema).query(async ({ input, ctx }) => {@@ -918,7 +625,7 @@ SETTINGS skip_unavailable_shards = 1return projectIds.map((projectId): SdkUsageSummaryByProjectResultRow => {const projectRows = (rowsByProjectId.get(projectId) ?? []).map(- (row): SdkUsageTimeSeriesResultRow & { eventsCount: number } => {+ (row): DecoratedSdkUsageSummaryRow & { eventsCount: number } => {const classification = classifyIngestionSdkVersion({sdkName: row.sdkName,sdkVersion: row.sdkVersion,@@ -929,7 +636,6 @@ SETTINGS skip_unavailable_shards = 1);return {- time: row.firstSeen,sdkName: row.sdkName,sdkVersion: row.sdkVersion,publicKey: row.publicKey,@@ -943,8 +649,6 @@ SETTINGS skip_unavailable_shards = 1sdkVersion: row.sdkVersion,}),canonicalSdkName: classification.canonicalSdkName,- latestMajor: classification.latestMajor,- major: classification.major,upgradeStatus:capabilityStatus === "supported"? "current"