🪢 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(v4): improve SDK migration detection (#15385)
Max Deichmannc6580b7b0d84
diff --git a/packages/shared/src/server/ingestion/ingestionAttribution.test.ts b/packages/shared/src/server/ingestion/ingestionAttribution.test.tsindex 9716d4bf71..d81affdb00 100644--- a/packages/shared/src/server/ingestion/ingestionAttribution.test.ts+++ b/packages/shared/src/server/ingestion/ingestionAttribution.test.ts@@ -2,6 +2,7 @@ import { describe, expect, it } from "vitest";import type { AuthHeaderValidVerificationResult } from "../auth/types";import {+ classifyIngestionSdkAttribution,classifyIngestionSdkVersion,createIngestionAttribution,createUnknownSdkIngestionAttribution,@@ -145,4 +146,19 @@ describe("ingestion attribution", () => {);},);++ it.each([+ ["python", "4.7.0", "attributed"],+ ["unknown", "4.7.0", "missing_name"],+ ["python", "unknown", "missing_version"],+ ["unknown", "unknown", "missing_name_and_version"],+ ["", "", "missing_name_and_version"],+ ] as const)(+ "classifies %s@%s attribution as %s",+ (sdkName, sdkVersion, expected) => {+ expect(classifyIngestionSdkAttribution({ sdkName, sdkVersion })).toBe(+ expected,+ );+ },+ );});diff --git a/packages/shared/src/server/ingestion/ingestionAttribution.ts b/packages/shared/src/server/ingestion/ingestionAttribution.tsindex 54c97d7ce9..0fe180c21c 100644--- a/packages/shared/src/server/ingestion/ingestionAttribution.ts+++ b/packages/shared/src/server/ingestion/ingestionAttribution.ts@@ -12,6 +12,11 @@ export type IngestionAttribution = {export const UNKNOWN_INGESTION_SDK_VALUE = "unknown";+export const INTERNAL_INGESTION_SDK_NAMES = [+ "langfuse-internal-ai-sdk",+ "langfuse-internal-otel-writer",+] as const;+export const LANGFUSE_SDK_LATEST_MAJOR = {python: 4,javascript: 5,@@ -33,6 +38,12 @@ export type IngestionSdkVersionClassification = {status: IngestionSdkUpgradeStatus;};+export type IngestionSdkAttributionStatus =+ | "attributed"+ | "missing_name"+ | "missing_version"+ | "missing_name_and_version";+const getHeaderValue = (headers: IngestionHeaderMap | undefined,name: string,@@ -158,6 +169,22 @@ export const classifyIngestionSdkVersion = (params: {};};+export const classifyIngestionSdkAttribution = (params: {+ sdkName: string | null | undefined;+ sdkVersion: string | null | undefined;+}): IngestionSdkAttributionStatus => {+ const sdkName = params.sdkName?.trim();+ const sdkVersion = params.sdkVersion?.trim();+ const missingName = !sdkName || sdkName === UNKNOWN_INGESTION_SDK_VALUE;+ const missingVersion =+ !sdkVersion || sdkVersion === UNKNOWN_INGESTION_SDK_VALUE;++ if (missingName && missingVersion) return "missing_name_and_version";+ if (missingName) return "missing_name";+ if (missingVersion) return "missing_version";+ return "attributed";+};+export const createIngestionAttribution = (params: {headers?: IngestionHeaderMap;authCheck: AuthHeaderValidVerificationResult;diff --git a/packages/shared/src/server/repositories/events.ts b/packages/shared/src/server/repositories/events.tsindex 7f34872bb1..d16a814a68 100644--- a/packages/shared/src/server/repositories/events.ts+++ b/packages/shared/src/server/repositories/events.ts@@ -30,7 +30,6 @@ import {readProjectHasTracesFlag,} from "./traces";import {- DateTimeFilter,type Filter,FilterList,type FullEventsObservation,@@ -88,7 +87,10 @@ import {EventsObservationRecordReadType,TraceRecordReadType,} from "./definitions";-import { UNKNOWN_INGESTION_SDK_VALUE } from "../ingestion/ingestionAttribution";+import {+ INTERNAL_INGESTION_SDK_NAMES,+ UNKNOWN_INGESTION_SDK_VALUE,+} from "../ingestion/ingestionAttribution";import type { AnalyticsObservationEvent } from "../analytics-integrations/types";import {getObservationByIdFromObservationsTable,@@ -3412,41 +3414,41 @@ export async function getLatestSdkVersionInfoFromEvents(params: {// Time filter: last 7 daysconst sevenDaysAgo = new Date(Date.now() - 7 * 24 * 60 * 60 * 1000);- const filter = new FilterList([- new DateTimeFilter({- clickhouseTable: "events_proto",- field: "start_time",- operator: ">=",- value: sevenDaysAgo,- tablePrefix: "e",- }),- ]);-- const builder = new EventsQueryBuilder({ projectId })- .selectRaw(- "e.ingestion_sdk_name AS ingestion_sdk_name",- "e.ingestion_sdk_version AS ingestion_sdk_version",- "e.telemetry_sdk_language AS telemetry_sdk_language",- )- .applyFilters(filter)- // Matches all OTel-compatible write paths: 'otel' (direct) plus the- // 'otel-dual-write(-experiments)' and 'otel-backfill' variants- .where({- query: "startsWith(e.source, 'otel')",- params: {},- })- .orderByDefault()- .limit(1);-- const { query, params: queryParams } = builder.buildWithParams();-const result = await queryClickhouse<{ingestion_sdk_name: string;ingestion_sdk_version: string;telemetry_sdk_language: string;+ first_seen: string;+ last_seen: string;+ event_count: string;}>({- query,- params: queryParams,+ query: `+SELECT+ e.ingestion_sdk_name AS ingestion_sdk_name,+ e.ingestion_sdk_version AS ingestion_sdk_version,+ e.telemetry_sdk_language AS telemetry_sdk_language,+ min(e.start_time) AS first_seen,+ max(e.start_time) AS last_seen,+ count() AS event_count+FROM events_core e+WHERE+ e.project_id = {projectId: String}+ AND e.start_time >= {sevenDaysAgo: DateTime64(3)}+ AND toDate(e.start_time) >= toDate({sevenDaysAgo: DateTime64(3)})+ AND startsWith(e.source, 'otel')+ AND e.ingestion_sdk_name NOT IN {internalSdkNames: Array(String)}+ AND e.is_deleted = 0+GROUP BY+ e.ingestion_sdk_name,+ e.ingestion_sdk_version,+ e.telemetry_sdk_language+ORDER BY last_seen DESC+ `,+ params: {+ projectId,+ sevenDaysAgo: convertDateToClickhouseDateTime(sevenDaysAgo),+ internalSdkNames: [...INTERNAL_INGESTION_SDK_NAMES],+ },tags: { projectId },preferredClickhouseService: "EventsReadOnly",});diff --git a/web/src/__tests__/server/repositories/event-repository.servertest.ts b/web/src/__tests__/server/repositories/event-repository.servertest.tsindex f81f3a4585..60ee75581b 100644--- a/web/src/__tests__/server/repositories/event-repository.servertest.ts+++ b/web/src/__tests__/server/repositories/event-repository.servertest.ts@@ -3793,6 +3793,41 @@ describe("Clickhouse Events Repository Test", () => {expect(result.version).toBeUndefined();expect(result.language).toBe("nodejs");});++ it("should ignore newer internal OTel writer events", async () => {+ const uniqueProjectId = randomUUID();+ const now = Date.now() * 1000;++ await createEventsCh([+ createEvent({+ project_id: uniqueProjectId,+ start_time: now - 10000000,+ source: "otel",+ ingestion_sdk_name: "python",+ ingestion_sdk_version: "4.7.0",+ telemetry_sdk_language: "python",+ }),+ createEvent({+ project_id: uniqueProjectId,+ start_time: now,+ source: "otel",+ ingestion_sdk_name: "langfuse-internal-otel-writer",+ ingestion_sdk_version: "1.0.0",+ telemetry_sdk_language: "nodejs",+ }),+ ]);++ const result = await getLatestSdkVersionInfoFromEvents({+ projectId: uniqueProjectId,+ });++ expect(result).toEqual({+ isOtel: true,+ name: "python",+ version: "4.7.0",+ language: "python",+ });+ });});// LFE-10596: in v4 the traces/observations list is served from the eventsdiff --git a/web/src/__tests__/server/unit/v4TransitionRouter.servertest.ts b/web/src/__tests__/server/unit/v4TransitionRouter.servertest.tsindex b287e8e001..6b059b7adc 100644--- a/web/src/__tests__/server/unit/v4TransitionRouter.servertest.ts+++ b/web/src/__tests__/server/unit/v4TransitionRouter.servertest.ts@@ -10,6 +10,10 @@ vi.mock("@/src/server/auth", () => ({const sharedServerMock = vi.hoisted(() => ({queryClickhouse: vi.fn(),+ INTERNAL_INGESTION_SDK_NAMES: [+ "langfuse-internal-ai-sdk",+ "langfuse-internal-otel-writer",+ ],convertDateToClickhouseDateTime: (date: Date) =>date.toISOString().replace("T", " ").replace("Z", ""),systemTableRef: (table: "system.processes" | "system.query_log") =>@@ -74,6 +78,21 @@ const sharedServerMock = vi.hoisted(() => ({status: major >= latestMajor ? "current" : "outdated_major",};},+ classifyIngestionSdkAttribution: ({+ sdkName,+ sdkVersion,+ }: {+ sdkName: string | null | undefined;+ sdkVersion: string | null | undefined;+ }) => {+ const missingName = !sdkName || sdkName === "unknown";+ const missingVersion = !sdkVersion || sdkVersion === "unknown";++ if (missingName && missingVersion) return "missing_name_and_version";+ if (missingName) return "missing_name";+ if (missingVersion) return "missing_version";+ return "attributed";+ },}));vi.mock("@langfuse/shared/src/server", async () => {@@ -1049,6 +1068,7 @@ describe("v4TransitionRouter", () => {count: "3",firstSeen: "2026-06-25T12:01:00Z",lastSeen: "2026-06-25T12:03:00Z",+ hasDelayedOtelEvents: "0",},{time: "2026-06-25T12:04:00Z",@@ -1058,6 +1078,7 @@ describe("v4TransitionRouter", () => {count: 7,firstSeen: "2026-06-25T12:04:00Z",lastSeen: "2026-06-25T12:05:00Z",+ hasDelayedOtelEvents: 0,},]);const caller = createCaller();@@ -1090,6 +1111,8 @@ describe("v4TransitionRouter", () => {count: 3,firstSeen: "2026-06-25T12:01:00Z",lastSeen: "2026-06-25T12:03:00Z",+ hasDelayedOtelEvents: false,+ attributionStatus: "attributed",canonicalSdkName: "python",latestMajor: 4,major: 3,@@ -1111,6 +1134,8 @@ describe("v4TransitionRouter", () => {count: 7,firstSeen: "2026-06-25T12:04:00Z",lastSeen: "2026-06-25T12:05:00Z",+ hasDelayedOtelEvents: false,+ attributionStatus: "attributed",canonicalSdkName: "javascript",latestMajor: 5,major: 5,@@ -1145,6 +1170,22 @@ describe("v4TransitionRouter", () => {"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)}",+ );+ 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",);@@ -1152,6 +1193,10 @@ describe("v4TransitionRouter", () => {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,@@ -1160,6 +1205,126 @@ describe("v4TransitionRouter", () => {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("detects a clean major SDK upgrade within the selected range", async () => {+ mockedQueryClickhouse.mockResolvedValueOnce([+ {+ time: "2026-06-25T12:00:00Z",+ sdkName: "python",+ sdkVersion: "3.9.0",+ publicKey: "pk-lf-python",+ count: "8",+ firstSeen: "2026-06-25T12:00:00Z",+ lastSeen: "2026-06-25T12:10:00Z",+ hasDelayedOtelEvents: "1",+ },+ {+ time: "2026-06-25T12:20:00Z",+ sdkName: "langfuse-python",+ sdkVersion: "4.7.0",+ publicKey: "pk-lf-python",+ count: "13",+ firstSeen: "2026-06-25T12:20:00Z",+ lastSeen: "2026-06-25T12:30:00Z",+ hasDelayedOtelEvents: "1",+ },+ ]);+ 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.upgradeTransitions).toEqual([+ {+ canonicalSdkName: "python",+ publicKey: "pk-lf-python",+ fromVersions: ["3.9.0"],+ toVersions: ["4.7.0"],+ firstCurrentVersionSeenAt: "2026-06-25T12:20:00Z",+ lastOutdatedVersionSeenAt: "2026-06-25T12:10:00Z",+ status: "upgrade_detected",+ },+ ]);+ });++ it("keeps overlapping old and current SDK traffic marked as mixed versions", async () => {+ mockedQueryClickhouse.mockResolvedValueOnce([+ {+ time: "2026-06-25T12:00:00Z",+ sdkName: "python",+ sdkVersion: "3.9.0",+ publicKey: "pk-lf-python",+ count: "8",+ firstSeen: "2026-06-25T12:00:00Z",+ lastSeen: "2026-06-25T12:30:00Z",+ hasDelayedOtelEvents: "1",+ },+ {+ time: "2026-06-25T12:20:00Z",+ sdkName: "langfuse-python",+ sdkVersion: "4.7.0",+ publicKey: "pk-lf-python",+ count: "13",+ firstSeen: "2026-06-25T12:20:00Z",+ lastSeen: "2026-06-25T12:40:00Z",+ hasDelayedOtelEvents: "1",+ },+ ]);+ 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.upgradeTransitions).toEqual([+ expect.objectContaining({+ canonicalSdkName: "python",+ publicKey: "pk-lf-python",+ status: "mixed_versions",+ }),+ ]);+ });+it.each(["MEMBER", "VIEWER"] as const)("allows project %s roles to access project-level v4 data",async (role) => {@@ -1246,29 +1411,71 @@ describe("v4TransitionRouter", () => {projectId,sdkName: "python",sdkVersion: "3.9.0",- publicKey: "pk-lf-old-python",- lastSeen: "2026-06-24T12:00:00Z",+ publicKey: "pk-lf-python",+ count: "8",+ firstSeen: "2026-06-24T01:00:00Z",+ lastSeen: "2026-06-24T02:00:00Z",+ hasDelayedOtelEvents: "1",+ },+ {+ projectId,+ sdkName: "python",+ sdkVersion: "4.14.1",+ publicKey: "pk-lf-python",+ count: "13",+ firstSeen: "2026-06-24T03:00:00Z",+ lastSeen: "2026-06-24T04:00:00Z",+ hasDelayedOtelEvents: "1",},{projectId,sdkName: "python",sdkVersion: "4.6.9",publicKey: "pk-lf-pre-v4-python",+ count: "5",+ firstSeen: "2026-06-24T12:00:00Z",lastSeen: "2026-06-24T13:00:00Z",+ hasDelayedOtelEvents: "1",},{projectId,sdkName: "python",sdkVersion: "4.7.0",publicKey: "pk-lf-current-python",+ count: "6",+ firstSeen: "2026-06-24T13:30:00Z",lastSeen: "2026-06-24T14:00:00Z",+ hasDelayedOtelEvents: "1",},{projectId: secondProjectId,sdkName: "@langfuse/tracing",sdkVersion: "5.3.9",- publicKey: "pk-lf-pre-v4-js",- lastSeen: "2026-06-24T15:00:00Z",+ publicKey: "pk-lf-old-js",+ count: "5",+ firstSeen: "2026-06-24T01:00:00Z",+ lastSeen: "2026-06-24T04:00:00Z",+ hasDelayedOtelEvents: "1",+ },+ {+ projectId: secondProjectId,+ sdkName: "unknown",+ sdkVersion: "unknown",+ publicKey: "pk-lf-otel",+ count: "3",+ firstSeen: "2026-06-24T01:00:00Z",+ lastSeen: "2026-06-24T04:00:00Z",+ hasDelayedOtelEvents: "0",+ },+ {+ projectId: secondProjectId,+ sdkName: "custom-otel-writer",+ sdkVersion: "1.2.3",+ publicKey: "pk-lf-custom-otel",+ count: "2",+ firstSeen: "2026-06-24T02:00:00Z",+ lastSeen: "2026-06-24T03:00:00Z",+ hasDelayedOtelEvents: "1",},]);const mockPrisma = {@@ -1289,45 +1496,106 @@ describe("v4TransitionRouter", () => {expect(rows).toEqual([{projectId,- outdatedSdkUsageSeriesCount: 2,+ outdatedSdkUsageSeriesCount: 1,+ delayedOtelIngestionSeriesCount: 0,sdkUsageSeries: [{sdkName: "python",sdkVersion: "3.9.0",canonicalSdkName: "python",- publicKey: "pk-lf-old-python",- lastSeen: "2026-06-24T12:00:00Z",+ publicKey: "pk-lf-python",+ count: 8,+ firstSeen: "2026-06-24T01:00:00Z",+ lastSeen: "2026-06-24T02:00:00Z",+ hasDelayedOtelEvents: true,+ attributionStatus: "attributed",v4MigrationStatus: "upgrade_required",+ upgradeCompleted: true,+ },+ {+ sdkName: "python",+ sdkVersion: "4.14.1",+ canonicalSdkName: "python",+ publicKey: "pk-lf-python",+ count: 13,+ firstSeen: "2026-06-24T03:00:00Z",+ lastSeen: "2026-06-24T04:00:00Z",+ hasDelayedOtelEvents: true,+ attributionStatus: "attributed",+ v4MigrationStatus: "compatible",+ upgradeCompleted: false,},{sdkName: "python",sdkVersion: "4.6.9",canonicalSdkName: "python",publicKey: "pk-lf-pre-v4-python",+ count: 5,+ firstSeen: "2026-06-24T12:00:00Z",lastSeen: "2026-06-24T13:00:00Z",+ hasDelayedOtelEvents: true,+ attributionStatus: "attributed",v4MigrationStatus: "upgrade_required",+ upgradeCompleted: false,},{sdkName: "python",sdkVersion: "4.7.0",canonicalSdkName: "python",publicKey: "pk-lf-current-python",+ count: 6,+ firstSeen: "2026-06-24T13:30:00Z",lastSeen: "2026-06-24T14:00:00Z",+ hasDelayedOtelEvents: true,+ attributionStatus: "attributed",v4MigrationStatus: "compatible",+ upgradeCompleted: false,},],},{projectId: secondProjectId,outdatedSdkUsageSeriesCount: 1,+ delayedOtelIngestionSeriesCount: 1,sdkUsageSeries: [{sdkName: "@langfuse/tracing",sdkVersion: "5.3.9",canonicalSdkName: "javascript",- publicKey: "pk-lf-pre-v4-js",- lastSeen: "2026-06-24T15:00:00Z",+ publicKey: "pk-lf-old-js",+ count: 5,+ firstSeen: "2026-06-24T01:00:00Z",+ lastSeen: "2026-06-24T04:00:00Z",+ hasDelayedOtelEvents: true,+ attributionStatus: "attributed",v4MigrationStatus: "upgrade_required",+ upgradeCompleted: false,+ },+ {+ sdkName: "unknown",+ sdkVersion: "unknown",+ canonicalSdkName: null,+ publicKey: "pk-lf-otel",+ count: 3,+ firstSeen: "2026-06-24T01:00:00Z",+ lastSeen: "2026-06-24T04:00:00Z",+ hasDelayedOtelEvents: false,+ attributionStatus: "missing_name_and_version",+ v4MigrationStatus: "unknown",+ upgradeCompleted: false,+ },+ {+ sdkName: "custom-otel-writer",+ sdkVersion: "1.2.3",+ canonicalSdkName: null,+ publicKey: "pk-lf-custom-otel",+ count: 2,+ firstSeen: "2026-06-24T02:00:00Z",+ lastSeen: "2026-06-24T03:00:00Z",+ hasDelayedOtelEvents: true,+ attributionStatus: "attributed",+ v4MigrationStatus: "unknown",+ upgradeCompleted: false,},],},@@ -1355,7 +1623,21 @@ describe("v4TransitionRouter", () => {expect(usageQuery?.query).toContain("GROUP BY project_id, sdk_name, sdk_version, public_key",);- expect(usageQuery?.query).toContain("max(event_time)");+ expect(usageQuery?.query).toContain(+ "if(countIf(is_otel_ingestion) > 0, argMaxIf(is_delayed_otel, event_time, is_otel_ingestion), NULL) AS hasDelayedOtelEvents",+ );+ expect(usageQuery?.query.match(/AS event_time/g)).toHaveLength(2);+ expect(usageQuery?.query).toContain(+ "formatDateTime(min(event_time), '%Y-%m-%dT%H:%i:%SZ', 'UTC') AS firstSeen",+ );+ expect(usageQuery?.query).toContain(+ "formatDateTime(max(event_time), '%Y-%m-%dT%H:%i:%SZ', 'UTC') AS lastSeen",+ );+ expect(usageQuery?.query).toContain(+ "ingestion_sdk_name NOT IN {internalSdkNames: Array(String)}",+ );+ expect(usageQuery?.query).not.toContain("toDate(start_time)");+ expect(usageQuery?.query).not.toContain("toDate(timestamp)");expect(usageQuery?.params).toMatchObject({projectIds: [projectId, secondProjectId],fromTimestamp: "2026-06-24 00:00:00.000",diff --git a/web/src/features/sdk-version/hooks/useProjectSdkVersionInfo.clienttest.ts b/web/src/features/sdk-version/hooks/useProjectSdkVersionInfo.clienttest.tsindex abf3d4ba22..8fd09095d5 100644--- a/web/src/features/sdk-version/hooks/useProjectSdkVersionInfo.clienttest.ts+++ b/web/src/features/sdk-version/hooks/useProjectSdkVersionInfo.clienttest.ts@@ -132,7 +132,7 @@ describe("project SDK version hook", () => {);expect(result.current).toMatchObject({- sdkVersion: { language: "python", version: "4.7.1" },+ sdkVersion: { language: "python", version: "4.7.1", isOtel: true },checkedAt: new Date(checkedAt).toISOString(),});@@ -140,6 +140,7 @@ describe("project SDK version hook", () => {await waitFor(() => {expect(window.localStorage.getItem(keys.language)).toBe("python");expect(window.localStorage.getItem(keys.version)).toBe("4.7.1");+ expect(window.localStorage.getItem(keys.isOtel)).toBe("true");expect(window.localStorage.getItem(keys.checkedAt)).toBe(new Date(checkedAt).toISOString(),);diff --git a/web/src/features/sdk-version/hooks/useProjectSdkVersionInfo.ts b/web/src/features/sdk-version/hooks/useProjectSdkVersionInfo.tsindex 62c06400e7..67ce409079 100644--- a/web/src/features/sdk-version/hooks/useProjectSdkVersionInfo.ts+++ b/web/src/features/sdk-version/hooks/useProjectSdkVersionInfo.ts@@ -21,6 +21,7 @@ const readCachedSdkVersion = (projectId: string) => {? {language: window.localStorage.getItem(keys.language),version: window.localStorage.getItem(keys.version),+ isOtel: window.localStorage.getItem(keys.isOtel) === "true",}: undefined,checkedAt,diff --git a/web/src/features/sdk-version/lib/sdkVersionCapabilities.ts b/web/src/features/sdk-version/lib/sdkVersionCapabilities.tsindex 84560cd9fa..e84201fc67 100644--- a/web/src/features/sdk-version/lib/sdkVersionCapabilities.ts+++ b/web/src/features/sdk-version/lib/sdkVersionCapabilities.ts@@ -9,6 +9,7 @@ type SdkMetadata = {export type SdkVersionInfo = {language: string | null;version: string | null;+ isOtel?: boolean;};const SDK_VERSION_RECHECK_MS = 30 * 86_400_000;@@ -16,6 +17,7 @@ const SDK_VERSION_RECHECK_MS = 30 * 86_400_000;export const sdkVersionStorageKeys = (projectId: string) => ({language: `events-sdk-language:${projectId}`,version: `events-sdk-version:${projectId}`,+ isOtel: `events-sdk-is-otel:${projectId}`,checkedAt: `events-sdk-checkedAt:${projectId}`,});@@ -39,6 +41,7 @@ export const toSdkVersionInfo = (? {language: sdk.isOtel ? normalizeIngestionSdkName(sdk.name) : null,version: sdk.isOtel ? (sdk.version?.trim() ?? null) : null,+ isOtel: sdk.isOtel,}: undefined;diff --git a/web/src/features/sdk-version/lib/sdkVersionStorage.clienttest.ts b/web/src/features/sdk-version/lib/sdkVersionStorage.clienttest.tsindex 9f32bdb3de..e332d03818 100644--- a/web/src/features/sdk-version/lib/sdkVersionStorage.clienttest.ts+++ b/web/src/features/sdk-version/lib/sdkVersionStorage.clienttest.ts@@ -38,12 +38,13 @@ describe("SDK version storage", () => {persistProjectSdkVersionInfo(projectId,- { language: null, version: null },+ { language: null, version: null, isOtel: true },"2026-07-23T10:00:00.000Z",);expect(window.localStorage.getItem(keys.language)).toBeNull();expect(window.localStorage.getItem(keys.version)).toBeNull();+ expect(window.localStorage.getItem(keys.isOtel)).toBe("true");expect(window.localStorage.getItem(keys.checkedAt)).toBe("2026-07-23T10:00:00.000Z",);@@ -61,6 +62,7 @@ describe("SDK version storage", () => {expect(window.localStorage.getItem(keys.language)).toBeNull();expect(window.localStorage.getItem(keys.version)).toBeNull();+ expect(window.localStorage.getItem(keys.isOtel)).toBeNull();expect(window.localStorage.getItem(keys.checkedAt)).toBeNull();});diff --git a/web/src/features/sdk-version/lib/sdkVersionStorage.ts b/web/src/features/sdk-version/lib/sdkVersionStorage.tsindex 4a34666183..f0ab879596 100644--- a/web/src/features/sdk-version/lib/sdkVersionStorage.ts+++ b/web/src/features/sdk-version/lib/sdkVersionStorage.ts@@ -24,6 +24,10 @@ export const persistProjectSdkVersionInfo = (writeStorageValue(keys.language, sdkVersion.language);writeStorageValue(keys.version, sdkVersion.version);+ writeStorageValue(+ keys.isOtel,+ typeof sdkVersion.isOtel === "boolean" ? String(sdkVersion.isOtel) : null,+ );writeStorageValue(keys.checkedAt, checkedAt);} catch {// Storage can be unavailable in hardened/private browser contexts.@@ -37,6 +41,7 @@ export const clearProjectSdkVersionInfo = (projectId: string) => {try {writeStorageValue(keys.language, null);writeStorageValue(keys.version, null);+ writeStorageValue(keys.isOtel, null);writeStorageValue(keys.checkedAt, null);} catch {// Storage can be unavailable in hardened/private browser contexts.diff --git a/web/src/features/v4-migration/V4MigrationContent.tsx b/web/src/features/v4-migration/V4MigrationContent.tsxindex 1186a571bb..2258e4f748 100644--- a/web/src/features/v4-migration/V4MigrationContent.tsx+++ b/web/src/features/v4-migration/V4MigrationContent.tsx@@ -39,6 +39,8 @@ import { useProject } from "@/src/features/projects/hooks";const V4_DOCS_URL = "https://langfuse.com/docs/v4";const SDK_UPGRADE_URL ="https://langfuse.com/docs/observability/sdk/upgrade-path";+const OTEL_V4_MIGRATION_URL =+ "https://langfuse.com/integrations/native/opentelemetry/migration-to-v4";const CODING_AGENT_PROMPT = `Migrate this project's Langfuse setup to v4:1. Upgrade the Langfuse SDK to the latest major version. Upgrade guide: ${SDK_UPGRADE_URL}@@ -160,8 +162,12 @@ function V4MigrationSdkSection({ sdk }: { sdk: V4MigrationSdkState }) {const chip =sdk.status === "latest" ? (<Chip variant="success">Up to date</Chip>+ ) : sdk.status === "otel_realtime" ? (+ <Chip variant="success">OTel real-time</Chip>) : sdk.status === "checking" ? (<Chip variant="warning">Checking</Chip>+ ) : sdk.status === "otel_header_required" ? (+ <Chip variant="warning">OTel header required</Chip>) : sdk.status === "unknown" ? (<Chip variant="warning">{detectedSdkSeries.length > 0 ? "Needs review" : "Not detected"}@@ -177,6 +183,19 @@ function V4MigrationSdkSection({ sdk }: { sdk: V4MigrationSdkState }) {<p className="text-muted-foreground text-sm leading-relaxed">{sdk.status === "checking" ? ("Checking the latest traces for this project…"+ ) : sdk.status === "otel_header_required" ? (+ <>+ OTel data is arriving through the delayed ingestion path. Set the{" "}+ <MonoValue>x-langfuse-ingestion-version</MonoValue> header to{" "}+ <MonoValue>4</MonoValue> on the OTLP exporter to use real-time+ ingestion.{" "}+ <ExternalLink href={OTEL_V4_MIGRATION_URL}>+ OpenTelemetry migration guide+ </ExternalLink>+ .+ </>+ ) : sdk.status === "otel_realtime" ? (+ "OTel data is using real-time ingestion. No ingestion header update is required.") : sdk.status === "unknown" ? (detectedSdkSeries.length > 0 ? ("We could not recognize every detected SDK version. Verify that these SDKs are up to date."@@ -226,9 +245,11 @@ function V4MigrationSdkSection({ sdk }: { sdk: V4MigrationSdkState }) {· last seen{" "}{formatCompactRelativeTime(new Date(series.lastSeen))}</span>- {series.v4MigrationStatus === "upgrade_required" && (- <span className="text-dark-yellow">· upgrade required</span>- )}+ {series.v4MigrationStatus === "upgrade_required" &&+ !series.upgradeCompleted && (+ <span className="text-dark-yellow">· upgrade required</span>+ )}+ {series.upgradeCompleted && <span>· upgrade completed</span>}{series.v4MigrationStatus === "unknown" && (<span className="text-dark-yellow">· version not recognizeddiff --git a/web/src/features/v4-migration/V4MigrationStatusPage.clienttest.tsx b/web/src/features/v4-migration/V4MigrationStatusPage.clienttest.tsxindex aa8df1ada1..00a0f257aa 100644--- a/web/src/features/v4-migration/V4MigrationStatusPage.clienttest.tsx+++ b/web/src/features/v4-migration/V4MigrationStatusPage.clienttest.tsx@@ -1,16 +1,28 @@-import { render, screen } from "@testing-library/react";+import { fireEvent, render, screen } from "@testing-library/react";import { describe, expect, it, vi } from "vitest";import V4MigrationStatusPage from "./V4MigrationStatusPage";const mocks = vi.hoisted(() => ({+ capture: vi.fn(),+ openForProject: vi.fn(),+ routerPush: vi.fn(),sdk: {- status: "latest" as "latest" | "legacy",+ status: "latest" as+ | "latest"+ | "legacy"+ | "otel_realtime"+ | "otel_header_required",sdkUsageSeries: [],upgradeRequiredCount: 0,+ delayedOtelIngestionCount: 0,},}));+vi.mock("next/router", () => ({+ useRouter: () => ({ push: mocks.routerPush }),+}));+vi.mock("next-auth/react", () => ({useSession: () => ({status: "authenticated",@@ -46,7 +58,7 @@ vi.mock("@/src/features/support-chat/SupportDrawerProvider", () => ({}));vi.mock("@/src/features/v4-migration/V4MigrationPanelProvider", () => ({- useV4MigrationPanel: () => ({ openForProject: vi.fn() }),+ useV4MigrationPanel: () => ({ openForProject: mocks.openForProject }),}));vi.mock(@@ -61,7 +73,7 @@ vi.mock("@/src/features/v4-migration/V4MigrationContent", () => ({}));vi.mock("@/src/features/posthog-analytics/usePostHogClientCapture", () => ({- usePostHogClientCapture: () => vi.fn(),+ usePostHogClientCapture: () => mocks.capture,}));vi.mock("@/src/features/v4-migration/useV4UpgradeUiEnabled", () => ({@@ -95,10 +107,14 @@ vi.mock("@/src/utils/api", () => ({describe("V4MigrationStatusPage", () => {beforeEach(() => {+ mocks.capture.mockClear();+ mocks.openForProject.mockClear();+ mocks.routerPush.mockClear();mocks.sdk = {status: "latest",sdkUsageSeries: [],upgradeRequiredCount: 0,+ delayedOtelIngestionCount: 0,};});@@ -117,15 +133,82 @@ describe("V4MigrationStatusPage", () => {expect(screen.getByText("of 1 projects migrated")).toBeInTheDocument();});+ it("links projects to traces and opens the migration panel", () => {+ render(<V4MigrationStatusPage />);++ const projectLink = screen.getByRole("link", { name: "Test project" });+ expect(projectLink).toHaveAttribute("href", "/project/project-1/traces");++ projectLink.addEventListener("click", (event) => event.preventDefault(), {+ once: true,+ });+ fireEvent.click(projectLink);++ expect(mocks.openForProject).toHaveBeenCalledWith({+ id: "project-1",+ name: "Test project",+ });+ expect(mocks.capture).toHaveBeenCalledWith(+ "v4_migration:status_row_clicked",+ );+ });++ it("navigates row clicks to traces with the migration panel open", () => {+ render(<V4MigrationStatusPage />);++ const projectRow = screen+ .getByRole("link", { name: "Test project" })+ .closest("tr");+ expect(projectRow).not.toBeNull();++ fireEvent.click(projectRow!);++ expect(mocks.openForProject).toHaveBeenCalledWith({+ id: "project-1",+ name: "Test project",+ });+ expect(mocks.routerPush).toHaveBeenCalledWith("/project/project-1/traces");+ });+it("shows the exact number of outdated SDK configurations", () => {mocks.sdk = {status: "legacy",sdkUsageSeries: [],upgradeRequiredCount: 2,+ delayedOtelIngestionCount: 0,};render(<V4MigrationStatusPage />);expect(screen.getByText("2 outdated")).toBeInTheDocument();});++ it("shows the OTel ingestion header issue separately from outdated SDKs", () => {+ mocks.sdk = {+ status: "otel_header_required",+ sdkUsageSeries: [],+ upgradeRequiredCount: 0,+ delayedOtelIngestionCount: 2,+ };++ render(<V4MigrationStatusPage />);++ expect(screen.getByText("2 OTel header issues")).toBeInTheDocument();+ expect(screen.queryByText("0 outdated")).not.toBeInTheDocument();+ });++ it("shows real-time OTel as ready without claiming an SDK version", () => {+ mocks.sdk = {+ status: "otel_realtime",+ sdkUsageSeries: [],+ upgradeRequiredCount: 0,+ delayedOtelIngestionCount: 0,+ };++ render(<V4MigrationStatusPage />);++ expect(screen.getByText("Ready")).toBeInTheDocument();+ expect(screen.getByText("OTel real-time")).toBeInTheDocument();+ expect(screen.queryByText("Latest")).not.toBeInTheDocument();+ });});diff --git a/web/src/features/v4-migration/V4MigrationStatusPage.tsx b/web/src/features/v4-migration/V4MigrationStatusPage.tsxindex b968ba007a..eac7e5b81e 100644--- a/web/src/features/v4-migration/V4MigrationStatusPage.tsx+++ b/web/src/features/v4-migration/V4MigrationStatusPage.tsx@@ -1,5 +1,6 @@import { useState, type ReactNode } from "react";import Link from "next/link";+import { useRouter } from "next/router";import { useSession } from "next-auth/react";import { ArrowRight, Copy } from "lucide-react";import ContainerPage from "@/src/components/layouts/container-page";@@ -140,6 +141,7 @@ function OrgStatusSection({org: V4MigrationOrganization;statusByProjectId: Map<string, ProjectMigrationStatus>;}) {+ const router = useRouter();const capture = usePostHogClientCapture();const openMigrationPanel = useOpenV4MigrationPanel();const { data: lastTraceTimes } =@@ -148,11 +150,16 @@ function OrgStatusSection({{ enabled: org.projects.length > 0 },);- const handleRowClick = (row: { id: string; name: string }) => {+ const openProjectMigration = (row: { id: string; name: string }) => {capture("v4_migration:status_row_clicked");openMigrationPanel({ id: row.id, name: row.name });};+ const handleRowClick = (row: { id: string; name: string }) => {+ openProjectMigration(row);+ router.push(`/project/${row.id}/traces`);+ };+const [orderBy, setOrderBy] = useState<OrderBy>(null);const handleSort = (column: SortKey) => {@@ -202,14 +209,18 @@ function OrgStatusSection({: 0;case "sdk":return row.status?.sdk.status === "latest"- ? 4- : row.status?.sdk.status === "legacy"- ? 3- : row.status?.sdk.status === "unknown"- ? 2- : row.status?.sdk.status === "checking"- ? 1- : 0;+ ? 5+ : row.status?.sdk.status === "otel_realtime"+ ? 5+ : row.status?.sdk.status === "legacy"+ ? 4+ : row.status?.sdk.status === "otel_header_required"+ ? 3+ : row.status?.sdk.status === "unknown"+ ? 2+ : row.status?.sdk.status === "checking"+ ? 1+ : 0;case "evals":return row.status?.evals.count ?? 0;case "apis":@@ -302,10 +313,13 @@ function OrgStatusSection({><TableCell density="comfortable" className="max-w-48"><Link- href={`/project/${row.id}`}+ href={`/project/${row.id}/traces`}className="block truncate font-bold hover:underline"title={row.name}- onClick={(event) => event.stopPropagation()}+ onClick={(event) => {+ event.stopPropagation();+ openProjectMigration(row);+ }}>{row.name}</Link>@@ -319,6 +333,10 @@ function OrgStatusSection({<TableCell density="comfortable">{row.status.sdk.status === "latest" ? (<span className="text-foreground-tertiary">Latest</span>+ ) : row.status.sdk.status === "otel_realtime" ? (+ <span className="text-foreground-tertiary">+ OTel real-time+ </span>) : row.status.sdk.status === "checking" ? (<span className="text-foreground-tertiary">Checking…@@ -327,6 +345,13 @@ function OrgStatusSection({<span className="text-foreground-tertiary">Unknown</span>+ ) : row.status.sdk.status === "otel_header_required" ? (+ <span>+ {row.status.sdk.delayedOtelIngestionCount} OTel header{" "}+ {row.status.sdk.delayedOtelIngestionCount === 1+ ? "required"+ : "issues"}+ </span>) : row.status.sdk.status === "error" ? (<span className="text-foreground-tertiary">Unavailablediff --git a/web/src/features/v4-migration/hooks/useV4MigrationData.clienttest.ts b/web/src/features/v4-migration/hooks/useV4MigrationData.clienttest.tsindex 8d896de10b..752ecf0366 100644--- a/web/src/features/v4-migration/hooks/useV4MigrationData.clienttest.ts+++ b/web/src/features/v4-migration/hooks/useV4MigrationData.clienttest.ts@@ -46,8 +46,13 @@ const currentSdkSeries = {sdkVersion: "4.7.0",canonicalSdkName: "python" as const,publicKey: "pk-lf-python",+ count: 1,+ firstSeen: "2026-07-23T09:00:00Z",lastSeen: "2026-07-23T10:00:00Z",+ hasDelayedOtelEvents: true,+ attributionStatus: "attributed" as const,v4MigrationStatus: "compatible" as const,+ upgradeCompleted: false,};describe("account v4 migration data", () => {@@ -86,6 +91,7 @@ describe("account v4 migration data", () => {{projectId: "project-1",outdatedSdkUsageSeriesCount: 0,+ delayedOtelIngestionSeriesCount: 0,sdkUsageSeries: [currentSdkSeries],},]),@@ -126,6 +132,7 @@ describe("account v4 migration data", () => {status: "latest",sdkUsageSeries: [currentSdkSeries],upgradeRequiredCount: 0,+ delayedOtelIngestionCount: 0,},evals: { status: "loaded", count: 2 },apis: { status: "loaded", count: 2 },diff --git a/web/src/features/v4-migration/migrationData.clienttest.ts b/web/src/features/v4-migration/migrationData.clienttest.tsindex ee935ba520..f154373666 100644--- a/web/src/features/v4-migration/migrationData.clienttest.ts+++ b/web/src/features/v4-migration/migrationData.clienttest.ts@@ -15,6 +15,7 @@ const migrationStatus = (status: "latest",sdkUsageSeries: [],upgradeRequiredCount: 0,+ delayedOtelIngestionCount: 0,},evals: loaded(0),apis: loaded(0),@@ -51,6 +52,16 @@ describe("v4 migration data", () => {it("only marks a fully loaded project without affected items as ready", () => {expect(getProjectMigrationReadiness(migrationStatus())).toBe("ready");+ expect(+ getProjectMigrationReadiness(+ migrationStatus({+ sdk: {+ ...migrationStatus().sdk,+ status: "otel_realtime",+ },+ }),+ ),+ ).toBe("ready");expect(getProjectMigrationReadiness(migrationStatus({ evals: loaded(1) })),).toBe("action-needed");@@ -66,6 +77,7 @@ describe("v4 migration data", () => {status: "error",sdkUsageSeries: [],upgradeRequiredCount: 0,+ delayedOtelIngestionCount: 0,},}),),diff --git a/web/src/features/v4-migration/migrationData.ts b/web/src/features/v4-migration/migrationData.tsindex 56e3c85e9d..d0304520cb 100644--- a/web/src/features/v4-migration/migrationData.ts+++ b/web/src/features/v4-migration/migrationData.ts@@ -82,7 +82,7 @@ export const getProjectMigrationReadiness = (return "checking";}if (- status.sdk.status === "latest" &&+ (status.sdk.status === "latest" || status.sdk.status === "otel_realtime") &&counts.every((count) => count.count === 0)) {return "ready";diff --git a/web/src/features/v4-migration/sdkVersionStatus.clienttest.ts b/web/src/features/v4-migration/sdkVersionStatus.clienttest.tsindex f34fb61eea..3fe231dde0 100644--- a/web/src/features/v4-migration/sdkVersionStatus.clienttest.ts+++ b/web/src/features/v4-migration/sdkVersionStatus.clienttest.ts@@ -11,8 +11,13 @@ const sdkSeries = (sdkVersion: "4.7.0",canonicalSdkName: "python" as const,publicKey: "pk-lf-python",+ count: 1,+ firstSeen: "2026-07-23T09:00:00Z",lastSeen: "2026-07-23T10:00:00Z",+ hasDelayedOtelEvents: false,+ attributionStatus: "attributed" as const,v4MigrationStatus: "compatible" as const,+ upgradeCompleted: false,...overrides,});@@ -21,6 +26,7 @@ const getLoadedSdkState = (...sdkUsageSeries: ReturnType<typeof sdkSeries>[]) =>summary: {projectId: "project-1",outdatedSdkUsageSeriesCount: 0,+ delayedOtelIngestionSeriesCount: 0,sdkUsageSeries,},isError: false,@@ -44,7 +50,27 @@ describe("v4 migration SDK status", () => {});});- it("does not let unattributed usage override a compatible SDK", () => {+ it("does not require action for raw OTel already using real-time ingestion", () => {+ expect(+ getLoadedSdkState(+ sdkSeries({+ sdkName: "unknown",+ sdkVersion: "unknown",+ canonicalSdkName: null,+ publicKey: "",+ attributionStatus: "missing_name_and_version",+ v4MigrationStatus: "unknown",+ hasDelayedOtelEvents: false,+ }),+ ),+ ).toMatchObject({+ status: "otel_realtime",+ upgradeRequiredCount: 0,+ delayedOtelIngestionCount: 0,+ });+ });++ it("requires the ingestion header for delayed raw OTel traffic", () => {expect(getLoadedSdkState(sdkSeries(),@@ -53,10 +79,32 @@ describe("v4 migration SDK status", () => {sdkVersion: "unknown",canonicalSdkName: null,publicKey: "",+ attributionStatus: "missing_name_and_version",v4MigrationStatus: "unknown",+ hasDelayedOtelEvents: true,}),),- ).toMatchObject({ status: "latest", upgradeRequiredCount: 0 });+ ).toMatchObject({+ status: "otel_header_required",+ upgradeRequiredCount: 0,+ delayedOtelIngestionCount: 1,+ });+ });++ it("does not require action for an SDK series superseded by a clean upgrade", () => {+ expect(+ getLoadedSdkState(+ sdkSeries({+ sdkVersion: "4.6.9",+ v4MigrationStatus: "upgrade_required",+ upgradeCompleted: true,+ }),+ sdkSeries(),+ ),+ ).toMatchObject({+ status: "latest",+ upgradeRequiredCount: 0,+ });});it("keeps a recognized SDK with an invalid version unknown", () => {diff --git a/web/src/features/v4-migration/sdkVersionStatus.ts b/web/src/features/v4-migration/sdkVersionStatus.tsindex 3141ed3845..a1b2a814e8 100644--- a/web/src/features/v4-migration/sdkVersionStatus.ts+++ b/web/src/features/v4-migration/sdkVersionStatus.ts@@ -5,6 +5,8 @@ export type V4MigrationSdkStatus =| "checking"| "error"| "unknown"+ | "otel_realtime"+ | "otel_header_required"| "legacy"| "latest";@@ -18,24 +20,26 @@ export type V4MigrationSdkState = {status: V4MigrationSdkStatus;sdkUsageSeries: V4MigrationSdkUsageSeries[];upgradeRequiredCount: number;+ delayedOtelIngestionCount: number;};-const statusOrder: Record<- V4MigrationSdkUsageSeries["v4MigrationStatus"],- number-> = {- upgrade_required: 0,- unknown: 1,- compatible: 2,-};+const requiresOtelIngestionHeader = (+ series: V4MigrationSdkUsageSeries,+): boolean =>+ series.hasDelayedOtelEvents === true && series.canonicalSdkName === null;const sortSdkUsageSeries = (rows: V4MigrationSdkUsageSeries[],): V4MigrationSdkUsageSeries[] =>[...rows].sort((left, right) =>- statusOrder[left.v4MigrationStatus] -- statusOrder[right.v4MigrationStatus],+ Number(right.v4MigrationStatus === "upgrade_required") -+ Number(left.v4MigrationStatus === "upgrade_required") ||+ Number(requiresOtelIngestionHeader(right)) -+ Number(requiresOtelIngestionHeader(left)) ||+ Number(right.v4MigrationStatus === "unknown") -+ Number(left.v4MigrationStatus === "unknown") ||+ left.lastSeen.localeCompare(right.lastSeen),);export const getV4MigrationSdkState = (params: {@@ -52,12 +56,18 @@ export const getV4MigrationSdkState = (params: {: "unknown",sdkUsageSeries: [],upgradeRequiredCount: 0,+ delayedOtelIngestionCount: 0,};}const sdkUsageSeries = sortSdkUsageSeries(params.summary.sdkUsageSeries);const upgradeRequiredCount = sdkUsageSeries.filter(- (series) => series.v4MigrationStatus === "upgrade_required",+ (series) =>+ series.v4MigrationStatus === "upgrade_required" &&+ !series.upgradeCompleted,+ ).length;+ const delayedOtelIngestionCount = sdkUsageSeries.filter(+ requiresOtelIngestionHeader,).length;const hasUnknownRecognizedSdk = sdkUsageSeries.some((series) =>@@ -67,18 +77,27 @@ export const getV4MigrationSdkState = (params: {const hasCompatibleSdk = sdkUsageSeries.some((series) => series.v4MigrationStatus === "compatible",);+ const hasRealtimeOtelIngestion = sdkUsageSeries.some(+ (series) =>+ series.canonicalSdkName === null && series.hasDelayedOtelEvents === false,+ );return {status:upgradeRequiredCount > 0? "legacy"- : hasUnknownRecognizedSdk- ? "unknown"- : hasCompatibleSdk- ? "latest"- : "unknown",+ : delayedOtelIngestionCount > 0+ ? "otel_header_required"+ : hasUnknownRecognizedSdk+ ? "unknown"+ : hasCompatibleSdk+ ? "latest"+ : hasRealtimeOtelIngestion+ ? "otel_realtime"+ : "unknown",sdkUsageSeries,upgradeRequiredCount,+ delayedOtelIngestionCount,};};diff --git a/web/src/features/v4/server/v4TransitionRouter.ts b/web/src/features/v4/server/v4TransitionRouter.tsindex 1c8d901579..75b725e5e1 100644--- a/web/src/features/v4/server/v4TransitionRouter.ts+++ b/web/src/features/v4/server/v4TransitionRouter.ts@@ -10,10 +10,13 @@ import {} from "@langfuse/shared/src/db";import type { Session } from "next-auth";import {+ classifyIngestionSdkAttribution,classifyIngestionSdkVersion,convertDateToClickhouseDateTime,+ INTERNAL_INGESTION_SDK_NAMES,queryClickhouse,systemTableRef,+ type IngestionSdkAttributionStatus,type IngestionSdkUpgradeStatus,} from "@langfuse/shared/src/server";import { getSdkVersionCapabilityStatus } from "@/src/features/sdk-version/lib/sdkVersionCapabilities";@@ -120,6 +123,7 @@ type SdkUsageTimeSeriesRow = {count: string | number;firstSeen: string;lastSeen: string;+ hasDelayedOtelEvents: boolean | string | number | null;};type SdkUsageTimeSeriesResultRow = {@@ -130,15 +134,28 @@ type SdkUsageTimeSeriesResultRow = {count: number;firstSeen: string | null;lastSeen: string | null;+ hasDelayedOtelEvents: boolean | null;+ attributionStatus: IngestionSdkAttributionStatus;canonicalSdkName: "python" | "javascript" | null;latestMajor: number | null;major: number | null;upgradeStatus: IngestionSdkUpgradeStatus;};+type SdkUpgradeTransition = {+ canonicalSdkName: "python" | "javascript";+ publicKey: string;+ fromVersions: string[];+ toVersions: string[];+ firstCurrentVersionSeenAt: string;+ lastOutdatedVersionSeenAt: string;+ status: "upgrade_detected" | "mixed_versions";+};+type SdkUsageTimeSeriesResult = {bucketTimes: string[];rows: SdkUsageTimeSeriesResultRow[];+ upgradeTransitions: SdkUpgradeTransition[];};type SdkUsageSummaryByProjectRow = {@@ -146,7 +163,10 @@ type SdkUsageSummaryByProjectRow = {sdkName: string;sdkVersion: string;publicKey: string;+ count: string | number;+ firstSeen: string;lastSeen: string;+ hasDelayedOtelEvents: boolean | string | number | null;};type SdkUsageSummaryByProjectSeries = {@@ -154,13 +174,19 @@ type SdkUsageSummaryByProjectSeries = {sdkVersion: string;canonicalSdkName: "python" | "javascript" | null;publicKey: string;+ count: number;+ firstSeen: string;lastSeen: string;+ hasDelayedOtelEvents: boolean | null;+ attributionStatus: IngestionSdkAttributionStatus;v4MigrationStatus: "compatible" | "upgrade_required" | "unknown";+ upgradeCompleted: boolean;};type SdkUsageSummaryByProjectResultRow = {projectId: string;outdatedSdkUsageSeriesCount: number;+ delayedOtelIngestionSeriesCount: number;sdkUsageSeries: SdkUsageSummaryByProjectSeries[];};@@ -235,6 +261,13 @@ const compareSdkUsageRows = (return leftSeries.localeCompare(rightSeries);};+const toBoolean = (value: boolean | string | number): boolean =>+ value === true || value === 1 || value === "1";++const toNullableBoolean = (+ value: boolean | string | number | null,+): boolean | null => (value === null ? null : toBoolean(value));+const decorateSdkUsageRows = ({rows,}: {@@ -246,6 +279,10 @@ const decorateSdkUsageRows = ({sdkName: row.sdkName,sdkVersion: row.sdkVersion,});+ const attributionStatus = classifyIngestionSdkAttribution({+ sdkName: row.sdkName,+ sdkVersion: row.sdkVersion,+ });return {time: row.time,@@ -255,6 +292,8 @@ const decorateSdkUsageRows = ({count: Number(row.count),firstSeen: row.firstSeen,lastSeen: row.lastSeen,+ hasDelayedOtelEvents: toNullableBoolean(row.hasDelayedOtelEvents),+ attributionStatus,canonicalSdkName: classification.canonicalSdkName,latestMajor: classification.latestMajor,major: classification.major,@@ -264,6 +303,144 @@ const decorateSdkUsageRows = ({.sort(compareSdkUsageRows);};+const detectSdkUpgradeTransitions = (+ rows: SdkUsageTimeSeriesResultRow[],+): SdkUpgradeTransition[] => {+ const seriesByClient = new Map<+ string,+ {+ canonicalSdkName: "python" | "javascript";+ publicKey: string;+ versions: Map<+ string,+ {+ status: IngestionSdkUpgradeStatus;+ firstSeen: string;+ lastSeen: string;+ }+ >;+ }+ >();++ for (const row of rows) {+ if (+ row.attributionStatus !== "attributed" ||+ !row.canonicalSdkName ||+ !row.firstSeen ||+ !row.lastSeen+ ) {+ continue;+ }++ const clientKey = `${row.canonicalSdkName}\u0000${row.publicKey}`;+ const client =+ seriesByClient.get(clientKey) ??+ ({+ canonicalSdkName: row.canonicalSdkName,+ publicKey: row.publicKey,+ versions: new Map(),+ } satisfies {+ canonicalSdkName: "python" | "javascript";+ publicKey: string;+ versions: Map<+ string,+ {+ status: IngestionSdkUpgradeStatus;+ firstSeen: string;+ lastSeen: string;+ }+ >;+ });+ const version = client.versions.get(row.sdkVersion);++ client.versions.set(row.sdkVersion, {+ status: row.upgradeStatus,+ firstSeen:+ version && version.firstSeen < row.firstSeen+ ? version.firstSeen+ : row.firstSeen,+ lastSeen:+ version && version.lastSeen > row.lastSeen+ ? version.lastSeen+ : row.lastSeen,+ });+ seriesByClient.set(clientKey, client);+ }++ return Array.from(seriesByClient.values())+ .flatMap((client): SdkUpgradeTransition[] => {+ const versions = Array.from(client.versions, ([sdkVersion, usage]) => ({+ sdkVersion,+ ...usage,+ }));+ const currentVersions = versions.filter(+ (version) => version.status === "current",+ );+ const outdatedVersions = versions.filter(+ (version) => version.status === "outdated_major",+ );++ if (currentVersions.length === 0 || outdatedVersions.length === 0) {+ return [];+ }++ const firstCurrentVersionSeenAt = currentVersions+ .map((version) => version.firstSeen)+ .sort()[0]!;+ const earlierOutdatedVersions = outdatedVersions.filter(+ (version) => version.firstSeen < firstCurrentVersionSeenAt,+ );++ if (earlierOutdatedVersions.length === 0) return [];++ const lastOutdatedVersionSeenAt = earlierOutdatedVersions+ .map((version) => version.lastSeen)+ .sort()+ .at(-1)!;++ return [+ {+ canonicalSdkName: client.canonicalSdkName,+ publicKey: client.publicKey,+ fromVersions: earlierOutdatedVersions+ .map((version) => version.sdkVersion)+ .sort(),+ toVersions: currentVersions+ .map((version) => version.sdkVersion)+ .sort(),+ firstCurrentVersionSeenAt,+ lastOutdatedVersionSeenAt,+ status:+ lastOutdatedVersionSeenAt < firstCurrentVersionSeenAt+ ? "upgrade_detected"+ : "mixed_versions",+ },+ ];+ })+ .sort(+ (left, right) =>+ left.firstCurrentVersionSeenAt.localeCompare(+ right.firstCurrentVersionSeenAt,+ ) ||+ left.canonicalSdkName.localeCompare(right.canonicalSdkName) ||+ left.publicKey.localeCompare(right.publicKey),+ );+};++const getCompletedSdkUpgradeVersionKeys = (+ rows: SdkUsageTimeSeriesResultRow[],+): Set<string> =>+ new Set(+ detectSdkUpgradeTransitions(rows)+ .filter((transition) => transition.status === "upgrade_detected")+ .flatMap((transition) =>+ transition.fromVersions.map(+ (version) =>+ `${transition.canonicalSdkName}\u0000${version}\u0000${transition.publicKey}`,+ ),+ ),+ );+type TraceLevelEvalExecutionTimeSeriesRow = {time: string;scoreName: string;@@ -606,14 +783,15 @@ ORDER BY bucket_time ASC, score_name ASCtimestamp 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+ ingestion_api_key AS public_key,+ false AS is_otel_ingestion,+ false AS is_delayed_otelFROM scores FINALWHEREproject_id = {projectId: String}AND timestamp >= {fromTimestamp: DateTime64(3)}AND timestamp <= {toTimestamp: DateTime64(3)}- AND toDate(timestamp) >= toDate({fromTimestamp: DateTime64(3)})- AND toDate(timestamp) <= toDate({toTimestamp: DateTime64(3)})+ AND ingestion_sdk_name NOT IN {internalSdkNames: Array(String)}AND is_deleted = 0`;const rows = await queryClickhouse<SdkUsageTimeSeriesRow>({@@ -623,14 +801,15 @@ WITH selected AS (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+ 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_otelFROM events_coreWHEREproject_id = {projectId: String}AND start_time >= {fromTimestamp: DateTime64(3)}AND start_time <= {toTimestamp: DateTime64(3)}- AND toDate(start_time) >= toDate({fromTimestamp: DateTime64(3)})- AND toDate(start_time) <= toDate({toTimestamp: DateTime64(3)})+ AND ingestion_sdk_name NOT IN {internalSdkNames: Array(String)}AND is_deleted = 0${scoresUnionSql})@@ -642,7 +821,8 @@ SELECTpublic_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+ 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 hasDelayedOtelEventsFROM selectedGROUP BY ${bucketTimeSql}, sdk_name, sdk_version, public_keyORDER BY ${bucketTimeSql} ASC, sdk_name ASC, sdk_version ASC, public_key ASC@@ -651,6 +831,7 @@ ORDER BY ${bucketTimeSql} ASC, sdk_name ASC, sdk_version ASC, public_key ASCprojectId: input.projectId,fromTimestamp: convertDateToClickhouseDateTime(input.fromTimestamp),toTimestamp: convertDateToClickhouseDateTime(input.toTimestamp),+ internalSdkNames: [...INTERNAL_INGESTION_SDK_NAMES],},tags: {projectId: input.projectId,@@ -659,15 +840,18 @@ ORDER BY ${bucketTimeSql} ASC, sdk_name ASC, sdk_version ASC, public_key ASCpreferredClickhouseService: "EventsReadOnly",});+ const decoratedRows = decorateSdkUsageRows({+ rows,+ });+return {bucketTimes: getTimelineBucketTimes(input.fromTimestamp,input.toTimestamp,granularity,),- rows: decorateSdkUsageRows({- rows,- }),+ rows: decoratedRows,+ upgradeTransitions: detectSdkUpgradeTransitions(decoratedRows),} satisfies SdkUsageTimeSeriesResult;}),@@ -695,14 +879,15 @@ ORDER BY ${bucketTimeSql} ASC, sdk_name ASC, sdk_version ASC, public_key ASCtimestamp 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+ ingestion_api_key AS public_key,+ false AS is_otel_ingestion,+ false AS is_delayed_otelFROM scores FINALWHEREproject_id IN {projectIds: Array(String)}AND timestamp >= {fromTimestamp: DateTime64(3)}AND timestamp <= {toTimestamp: DateTime64(3)}- AND toDate(timestamp) >= toDate({fromTimestamp: DateTime64(3)})- AND toDate(timestamp) <= toDate({toTimestamp: DateTime64(3)})+ AND ingestion_sdk_name NOT IN {internalSdkNames: Array(String)}AND is_deleted = 0`;const rows = await queryClickhouse<SdkUsageSummaryByProjectRow>({@@ -713,14 +898,15 @@ WITH selected AS (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+ 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_otelFROM events_coreWHEREproject_id IN {projectIds: Array(String)}AND start_time >= {fromTimestamp: DateTime64(3)}AND start_time <= {toTimestamp: DateTime64(3)}- AND toDate(start_time) >= toDate({fromTimestamp: DateTime64(3)})- AND toDate(start_time) <= toDate({toTimestamp: DateTime64(3)})+ AND ingestion_sdk_name NOT IN {internalSdkNames: Array(String)}AND is_deleted = 0${scoresUnionSql})@@ -730,7 +916,10 @@ SELECTsdk_name AS sdkName,sdk_version AS sdkVersion,public_key AS publicKey,- formatDateTime(max(event_time), '%Y-%m-%dT%H:%i:%SZ', 'UTC') AS lastSeen+ 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 hasDelayedOtelEventsFROM selectedGROUP BY project_id, sdk_name, sdk_version, public_keyORDER BY project_id ASC, sdk_name ASC, sdk_version ASC, public_key ASC@@ -739,6 +928,7 @@ ORDER BY project_id ASC, sdk_name ASC, sdk_version ASC, public_key ASCprojectIds,fromTimestamp: convertDateToClickhouseDateTime(input.fromTimestamp),toTimestamp: convertDateToClickhouseDateTime(input.toTimestamp),+ internalSdkNames: [...INTERNAL_INGESTION_SDK_NAMES],},tags: {route: "v4-org-sdk-usage-summary",@@ -746,54 +936,96 @@ ORDER BY project_id ASC, sdk_name ASC, sdk_version ASC, public_key ASCpreferredClickhouseService: "EventsReadOnly",});- const outdatedCountsByProjectId = new Map<string, number>();- const sdkUsageSeriesByProjectId = new Map<- string,- SdkUsageSummaryByProjectSeries[]- >();-+ const rowsByProjectId = new Map<string, SdkUsageSummaryByProjectRow[]>();for (const row of rows) {- const classification = classifyIngestionSdkVersion({- sdkName: row.sdkName,- sdkVersion: row.sdkVersion,- });- const capabilityStatus = getSdkVersionCapabilityStatus(- { language: row.sdkName, version: row.sdkVersion },- "appRootObservations",- );- if (capabilityStatus === "unsupported") {- outdatedCountsByProjectId.set(- row.projectId,- (outdatedCountsByProjectId.get(row.projectId) ?? 0) + 1,- );- }-- const projectSeries =- sdkUsageSeriesByProjectId.get(row.projectId) ?? [];- projectSeries.push({- sdkName: row.sdkName,- sdkVersion: row.sdkVersion,- canonicalSdkName: classification.canonicalSdkName,- publicKey: row.publicKey,- lastSeen: row.lastSeen,- v4MigrationStatus:- capabilityStatus === "supported"- ? "compatible"- : capabilityStatus === "unsupported"- ? "upgrade_required"- : "unknown",- });- sdkUsageSeriesByProjectId.set(row.projectId, projectSeries);+ const projectRows = rowsByProjectId.get(row.projectId) ?? [];+ projectRows.push(row);+ rowsByProjectId.set(row.projectId, projectRows);}- return projectIds.map(- (projectId): SdkUsageSummaryByProjectResultRow => ({+ return projectIds.map((projectId): SdkUsageSummaryByProjectResultRow => {+ const projectRows = (rowsByProjectId.get(projectId) ?? []).map(+ (row): SdkUsageTimeSeriesResultRow => {+ const classification = classifyIngestionSdkVersion({+ sdkName: row.sdkName,+ sdkVersion: row.sdkVersion,+ });+ const capabilityStatus = getSdkVersionCapabilityStatus(+ { language: row.sdkName, version: row.sdkVersion },+ "appRootObservations",+ );++ return {+ time: row.firstSeen,+ sdkName: row.sdkName,+ sdkVersion: row.sdkVersion,+ publicKey: row.publicKey,+ count: Number(row.count),+ firstSeen: row.firstSeen,+ lastSeen: row.lastSeen,+ hasDelayedOtelEvents: toNullableBoolean(row.hasDelayedOtelEvents),+ attributionStatus: classifyIngestionSdkAttribution({+ sdkName: row.sdkName,+ sdkVersion: row.sdkVersion,+ }),+ canonicalSdkName: classification.canonicalSdkName,+ latestMajor: classification.latestMajor,+ major: classification.major,+ upgradeStatus:+ capabilityStatus === "supported"+ ? "current"+ : capabilityStatus === "unsupported"+ ? "outdated_major"+ : classification.status,+ };+ },+ );+ const completedUpgradeVersionKeys =+ getCompletedSdkUpgradeVersionKeys(projectRows);+ const sdkUsageSeries = projectRows.map(+ (row): SdkUsageSummaryByProjectSeries => {+ const versionKey = `${row.canonicalSdkName}\u0000${row.sdkVersion}\u0000${row.publicKey}`;+ const upgradeCompleted =+ completedUpgradeVersionKeys.has(versionKey);++ return {+ sdkName: row.sdkName,+ sdkVersion: row.sdkVersion,+ canonicalSdkName: row.canonicalSdkName,+ publicKey: row.publicKey,+ count: row.count,+ firstSeen: row.firstSeen!,+ lastSeen: row.lastSeen!,+ hasDelayedOtelEvents: row.hasDelayedOtelEvents,+ attributionStatus: row.attributionStatus,+ v4MigrationStatus:+ row.upgradeStatus === "current"+ ? "compatible"+ : row.upgradeStatus === "outdated_major"+ ? "upgrade_required"+ : "unknown",+ upgradeCompleted,+ };+ },+ );++ return {projectId,- outdatedSdkUsageSeriesCount:- outdatedCountsByProjectId.get(projectId) ?? 0,- sdkUsageSeries: sdkUsageSeriesByProjectId.get(projectId) ?? [],- }),- );+ outdatedSdkUsageSeriesCount: sdkUsageSeries.filter(+ (series) =>+ series.count > 0 &&+ series.v4MigrationStatus === "upgrade_required" &&+ !series.upgradeCompleted,+ ).length,+ delayedOtelIngestionSeriesCount: sdkUsageSeries.filter(+ (series) =>+ series.count > 0 &&+ series.hasDelayedOtelEvents === true &&+ series.canonicalSdkName === null,+ ).length,+ sdkUsageSeries,+ };+ });}),legacyApiUsageSummaryByProject: protectedOrganizationProcedure