πͺ’ 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(worker): write deprecation notice into blob export for legacy sources (LFE-10896) (#15068)
Niklas Semmler6569f6e4c940
diff --git a/packages/shared/src/features/analytics-integrations/blob-export-gate.test.ts b/packages/shared/src/features/analytics-integrations/blob-export-gate.test.tsnew file mode 100644index 0000000000..20cc72dc36--- /dev/null+++ b/packages/shared/src/features/analytics-integrations/blob-export-gate.test.ts@@ -0,0 +1,44 @@+import { describe, it, expect } from "vitest";+import { AnalyticsIntegrationExportSource } from "@prisma/client";++import {+ isEnrichedBlobExportSource,+ isLegacyBlobExportSource,+} from "./blob-export-gate";++describe("isLegacyBlobExportSource", () => {+ it("is true for the legacy sources", () => {+ expect(+ isLegacyBlobExportSource(+ AnalyticsIntegrationExportSource.TRACES_OBSERVATIONS,+ ),+ ).toBe(true);+ expect(+ isLegacyBlobExportSource(+ AnalyticsIntegrationExportSource.TRACES_OBSERVATIONS_EVENTS,+ ),+ ).toBe(true);+ });++ it("is false for the enriched-only source and nullish values", () => {+ expect(+ isLegacyBlobExportSource(AnalyticsIntegrationExportSource.EVENTS),+ ).toBe(false);+ expect(isLegacyBlobExportSource(null)).toBe(false);+ expect(isLegacyBlobExportSource(undefined)).toBe(false);+ });++ it("TRACES_OBSERVATIONS_EVENTS counts as both legacy and enriched", () => {+ // It exports the legacy tables *and* the enriched events, so both+ // predicates must return true β this project still needs the warning.+ const source = AnalyticsIntegrationExportSource.TRACES_OBSERVATIONS_EVENTS;+ expect(isLegacyBlobExportSource(source)).toBe(true);+ expect(isEnrichedBlobExportSource(source)).toBe(true);+ });++ it("EVENTS is enriched-only, never legacy", () => {+ const source = AnalyticsIntegrationExportSource.EVENTS;+ expect(isLegacyBlobExportSource(source)).toBe(false);+ expect(isEnrichedBlobExportSource(source)).toBe(true);+ });+});diff --git a/packages/shared/src/features/analytics-integrations/blob-export-gate.ts b/packages/shared/src/features/analytics-integrations/blob-export-gate.tsindex da86b34b2a..9725ba34e3 100644--- a/packages/shared/src/features/analytics-integrations/blob-export-gate.ts+++ b/packages/shared/src/features/analytics-integrations/blob-export-gate.ts@@ -74,6 +74,24 @@ export function isEnrichedBlobExportSource();}+/**+ * Whether an export source is one of the deprecated legacy sources β i.e. it+ * still exports the legacy traces/observations tables. True for both+ * TRACES_OBSERVATIONS and TRACES_OBSERVATIONS_EVENTS (the latter exports the+ * legacy tables *and* the enriched events); false for the EVENTS-only source.+ * Symmetric with isEnrichedBlobExportSource.+ */+export function isLegacyBlobExportSource(+ source: AnalyticsIntegrationExportSource | null | undefined,+): boolean {+ return (+ source != null &&+ (+ LEGACY_BLOB_EXPORT_SOURCES as readonly AnalyticsIntegrationExportSource[]+ ).includes(source)+ );+}+/*** Whether a blob storage integration row counts as legacy β i.e. may still use* legacy export sources. Applied to `BlobStorageIntegration.createdAt`.diff --git a/worker/src/__tests__/blobStorageIntegrationProcessing.test.ts b/worker/src/__tests__/blobStorageIntegrationProcessing.test.tsindex bbc59e41ce..61d86cbeb1 100644--- a/worker/src/__tests__/blobStorageIntegrationProcessing.test.ts+++ b/worker/src/__tests__/blobStorageIntegrationProcessing.test.ts@@ -64,6 +64,7 @@ import {import {BlobStorageIntegrationType,BlobStorageIntegrationFileType,+ LEGACY_BLOB_EXPORTER_CUTOFF,} from "@langfuse/shared";import { encrypt } from "@langfuse/shared/encryption";@@ -1907,6 +1908,269 @@ describe("BlobStorageIntegrationProcessingJob", () => {);});+ // LFE-10896: legacy-source projects get a plain-text deprecation notice in+ // their destination; enriched-only (EVENTS) projects do not, and a stale+ // notice is removed once a project migrates off a legacy source. The notice+ // is Cloud-only, so set a cloud region for this suite (the top-level harness+ // clears it) and restore it afterwards.+ describe("legacy-source deprecation notice (LFE-10896)", () => {+ const NOTICE_SUFFIX = "/DEPRECATION_NOTICE.txt";+ const originalCloudRegion = env.NEXT_PUBLIC_LANGFUSE_CLOUD_REGION;++ beforeAll(() => {+ env.NEXT_PUBLIC_LANGFUSE_CLOUD_REGION = "DEV";+ });+ afterAll(() => {+ env.NEXT_PUBLIC_LANGFUSE_CLOUD_REGION = originalCloudRegion;+ });++ maybeIt(+ "writes DEPRECATION_NOTICE.txt for a legacy export source",+ async () => {+ const { projectId } = await createOrgProjectAndApiKey();+ s3Prefix = `${projectId}/`;+ const now = new Date();+ const oneHourAgo = new Date(now.getTime() - 60 * 60 * 1000);+ const dataTime = now.getTime() - 40 * 60 * 1000;++ await prisma.blobStorageIntegration.create({+ data: {+ projectId,+ type: BlobStorageIntegrationType.S3,+ bucketName,+ prefix: s3Prefix,+ accessKeyId: minioAccessKeyId,+ secretAccessKey: encrypt(minioAccessKeySecret),+ region: region ? region : "auto",+ endpoint: minioEndpoint,+ forcePathStyle:+ env.LANGFUSE_S3_EVENT_UPLOAD_FORCE_PATH_STYLE === "true",+ enabled: true,+ exportFrequency: "hourly",+ exportSource: "TRACES_OBSERVATIONS",+ fileType: BlobStorageIntegrationFileType.JSONL,+ compressed: false,+ lastSyncAt: oneHourAgo,+ },+ });++ await createTracesCh([+ createTrace({+ id: randomUUID(),+ project_id: projectId,+ timestamp: dataTime,+ name: "Notice Trace",+ }),+ ]);++ await handleBlobStorageIntegrationProjectJob({+ data: { payload: { projectId } },+ } as Job);++ const files = await s3StorageService.listFiles(s3Prefix);+ const noticeFile = files.find((f) => f.file.endsWith(NOTICE_SUFFIX));+ expect(noticeFile).toBeDefined();+ expect(noticeFile!.file).toBe(+ `${s3Prefix}${projectId}${NOTICE_SUFFIX}`,+ );++ const notice = await s3StorageService.download(noticeFile!.file);+ expect(notice).toContain("Traces and observations (legacy)");+ expect(notice).toContain("Enriched observations (recommended)");+ expect(notice).toContain(+ "https://langfuse.com/docs/api-and-data-platform/features/export-to-blob-storage",+ );+ },+ );++ // The EVENTS export reads the enriched events table, which only the+ // V4-preview CI leg provisions β gate these like every other enriched test.+ // isCloud is set by the suite's beforeAll, so the notice logic still runs.+ maybeDescribe("after migrating to the enriched-only source", () => {+ maybeIt(+ "does not write a deprecation notice for the EVENTS source",+ async () => {+ const { projectId } = await createOrgProjectAndApiKey();+ s3Prefix = `${projectId}/`;+ const now = new Date();+ const oneHourAgo = new Date(now.getTime() - 60 * 60 * 1000);+ const dataTime = now.getTime() - 40 * 60 * 1000;++ await prisma.blobStorageIntegration.create({+ data: {+ projectId,+ type: BlobStorageIntegrationType.S3,+ bucketName,+ prefix: s3Prefix,+ accessKeyId: minioAccessKeyId,+ secretAccessKey: encrypt(minioAccessKeySecret),+ region: region ? region : "auto",+ endpoint: minioEndpoint,+ forcePathStyle:+ env.LANGFUSE_S3_EVENT_UPLOAD_FORCE_PATH_STYLE === "true",+ enabled: true,+ exportFrequency: "hourly",+ exportSource: "EVENTS",+ fileType: BlobStorageIntegrationFileType.JSONL,+ compressed: false,+ lastSyncAt: oneHourAgo,+ },+ });++ await createEventsCh([+ createEvent({+ id: randomUUID(),+ project_id: projectId,+ start_time: dataTime,+ name: "No Notice Event",+ }),+ ]);++ await handleBlobStorageIntegrationProjectJob({+ data: { payload: { projectId } },+ } as Job);++ const files = await s3StorageService.listFiles(s3Prefix);+ expect(files.some((f) => f.file.endsWith(NOTICE_SUFFIX))).toBe(false);+ },+ );++ // A notice written while on a legacy source must be cleaned up once the+ // project migrates to the enriched-only source, so it can't linger with+ // now-false claims. Cleanup only runs for integrations old enough to have+ // used a legacy source (pre-exporter-cutoff createdAt).+ maybeIt(+ "removes a stale notice after migrating to the EVENTS source",+ async () => {+ const { projectId } = await createOrgProjectAndApiKey();+ s3Prefix = `${projectId}/`;+ const noticeKey = `${s3Prefix}${projectId}${NOTICE_SUFFIX}`;+ const now = new Date();+ const oneHourAgo = new Date(now.getTime() - 60 * 60 * 1000);+ const dataTime = now.getTime() - 40 * 60 * 1000;++ // Simulate a notice left behind by an earlier legacy-source run.+ await s3StorageService.uploadFile({+ fileName: noticeKey,+ fileType: "text/plain; charset=utf-8",+ data: "stale notice from a previous legacy run",+ });+ const before = await s3StorageService.listFiles(s3Prefix);+ expect(before.some((f) => f.file === noticeKey)).toBe(true);++ await prisma.blobStorageIntegration.create({+ data: {+ projectId,+ type: BlobStorageIntegrationType.S3,+ bucketName,+ prefix: s3Prefix,+ accessKeyId: minioAccessKeyId,+ secretAccessKey: encrypt(minioAccessKeySecret),+ region: region ? region : "auto",+ endpoint: minioEndpoint,+ forcePathStyle:+ env.LANGFUSE_S3_EVENT_UPLOAD_FORCE_PATH_STYLE === "true",+ enabled: true,+ exportFrequency: "hourly",+ exportSource: "EVENTS",+ fileType: BlobStorageIntegrationFileType.JSONL,+ compressed: false,+ lastSyncAt: oneHourAgo,+ // Pre-exporter-cutoff: old enough to have used a legacy source, so+ // cleanup runs. Derived from the live cutoff so an env override+ // can't flip the gate.+ createdAt: new Date(+ LEGACY_BLOB_EXPORTER_CUTOFF.getTime() - 24 * 60 * 60 * 1000,+ ),+ },+ });++ await createEventsCh([+ createEvent({+ id: randomUUID(),+ project_id: projectId,+ start_time: dataTime,+ name: "Migrated Event",+ }),+ ]);++ await handleBlobStorageIntegrationProjectJob({+ data: { payload: { projectId } },+ } as Job);++ const after = await s3StorageService.listFiles(s3Prefix);+ expect(after.some((f) => f.file.endsWith(NOTICE_SUFFIX))).toBe(false);+ },+ );++ // Post-cutoff integrations can never have used a legacy source, so they+ // never wrote a notice β the cleanup delete must be skipped for them to+ // avoid a needless per-run s3:DeleteObject on every enriched-only export.+ maybeIt(+ "skips notice cleanup for a post-cutoff enriched-only integration",+ async () => {+ const { projectId } = await createOrgProjectAndApiKey();+ s3Prefix = `${projectId}/`;+ const noticeKey = `${s3Prefix}${projectId}${NOTICE_SUFFIX}`;+ const now = new Date();+ const oneHourAgo = new Date(now.getTime() - 60 * 60 * 1000);+ const dataTime = now.getTime() - 40 * 60 * 1000;++ // A stray notice a post-cutoff project could never legitimately have β+ // the gate must leave it untouched (no delete attempted).+ await s3StorageService.uploadFile({+ fileName: noticeKey,+ fileType: "text/plain; charset=utf-8",+ data: "stray notice that must not be touched",+ });++ await prisma.blobStorageIntegration.create({+ data: {+ projectId,+ type: BlobStorageIntegrationType.S3,+ bucketName,+ prefix: s3Prefix,+ accessKeyId: minioAccessKeyId,+ secretAccessKey: encrypt(minioAccessKeySecret),+ region: region ? region : "auto",+ endpoint: minioEndpoint,+ forcePathStyle:+ env.LANGFUSE_S3_EVENT_UPLOAD_FORCE_PATH_STYLE === "true",+ enabled: true,+ exportFrequency: "hourly",+ exportSource: "EVENTS",+ fileType: BlobStorageIntegrationFileType.JSONL,+ compressed: false,+ lastSyncAt: oneHourAgo,+ // Post-exporter-cutoff: never could have used a legacy source, so+ // cleanup is skipped and the stray file is left in place. Derived+ // from the live cutoff so an env override can't flip the gate.+ createdAt: new Date(+ LEGACY_BLOB_EXPORTER_CUTOFF.getTime() + 24 * 60 * 60 * 1000,+ ),+ },+ });++ await createEventsCh([+ createEvent({+ id: randomUUID(),+ project_id: projectId,+ start_time: dataTime,+ name: "Post-cutoff Event",+ }),+ ]);++ await handleBlobStorageIntegrationProjectJob({+ data: { payload: { projectId } },+ } as Job);++ const after = await s3StorageService.listFiles(s3Prefix);+ expect(after.some((f) => f.file === noticeKey)).toBe(true);+ },+ );+ });+ });+// LFE-10402: raw-passthrough streams ClickHouse JSONEachRow bytes straight to// gzip β upload, skipping the per-row JS parse/enrich/serialize pipeline. The// output must be parsed-equal to the standard path minus the dropped pricediff --git a/worker/src/features/blobstorage/deprecationNotice.test.ts b/worker/src/features/blobstorage/deprecationNotice.test.tsnew file mode 100644index 0000000000..896dc248d5--- /dev/null+++ b/worker/src/features/blobstorage/deprecationNotice.test.ts@@ -0,0 +1,51 @@+import { describe, it, expect } from "vitest";+import {+ BLOB_EXPORT_DEPRECATION_NOTICE_FILENAME,+ buildBlobExportDeprecationNotice,+ buildBlobExportDeprecationNoticeKey,+} from "./deprecationNotice";++describe("buildBlobExportDeprecationNoticeKey", () => {+ it("nests the notice under the project directory", () => {+ expect(buildBlobExportDeprecationNoticeKey({ projectId: "proj-1" })).toBe(+ `proj-1/${BLOB_EXPORT_DEPRECATION_NOTICE_FILENAME}`,+ );+ });++ it("prepends the integration prefix when present", () => {+ expect(+ buildBlobExportDeprecationNoticeKey({+ prefix: "exports/",+ projectId: "proj-1",+ }),+ ).toBe(`exports/proj-1/${BLOB_EXPORT_DEPRECATION_NOTICE_FILENAME}`);+ });++ it("treats an absent prefix the same as an empty one (table-file parity)", () => {+ expect(+ buildBlobExportDeprecationNoticeKey({ prefix: "", projectId: "proj-1" }),+ ).toBe(buildBlobExportDeprecationNoticeKey({ projectId: "proj-1" }));+ });+});++describe("buildBlobExportDeprecationNotice", () => {+ const notice = buildBlobExportDeprecationNotice();++ it("names both the deprecated and recommended sources", () => {+ expect(notice).toContain("Traces and observations (legacy)");+ expect(notice).toContain("Enriched observations (recommended)");+ });++ it("links the public migration guide", () => {+ expect(notice).toContain(+ "https://langfuse.com/docs/api-and-data-platform/features/export-to-blob-storage",+ );+ });++ it("leaks no internal implementation details", () => {+ // This file lands in the customer's bucket: no env vars, flags, or tickets.+ expect(notice).not.toMatch(/LFE-\d+/);+ expect(notice).not.toMatch(/LANGFUSE_/);+ expect(notice).not.toMatch(/TRACES_OBSERVATIONS|EVENTS/);+ });+});diff --git a/worker/src/features/blobstorage/deprecationNotice.ts b/worker/src/features/blobstorage/deprecationNotice.tsnew file mode 100644index 0000000000..71bd3e53f2--- /dev/null+++ b/worker/src/features/blobstorage/deprecationNotice.ts@@ -0,0 +1,46 @@+// Deprecation notice written into the export destination for projects still on+// a legacy export source (LFE-10896): a plain-text file warning that the+// "Traces and observations (legacy)" sources are deprecated in favour of the+// enriched observations source. Written on every successful run for legacy+// projects; new / enriched-only (EVENTS) projects never receive it.++/** Fixed file name, overwritten each run so the notice is always current. */+export const BLOB_EXPORT_DEPRECATION_NOTICE_FILENAME = "DEPRECATION_NOTICE.txt";++/** `{prefix}{projectId}/DEPRECATION_NOTICE.txt` β fixed key, overwritten each run. */+export const buildBlobExportDeprecationNoticeKey = (params: {+ prefix?: string;+ projectId: string;+}): string =>+ `${params.prefix ?? ""}${params.projectId}/${BLOB_EXPORT_DEPRECATION_NOTICE_FILENAME}`;++// Migration guide for consumers of the export. Wording mirrors the public docs+// so the notice stays consistent with what customers read there.+const BLOB_EXPORT_DOCS_URL =+ "https://langfuse.com/docs/api-and-data-platform/features/export-to-blob-storage";++/**+ * Plain-text notice describing the legacy-source deprecation from the+ * consumer's point of view. Intentionally free of internal implementation+ * details (env vars, flags, ticket IDs) β this file lands in the customer's+ * bucket.+ */+export const buildBlobExportDeprecationNotice = (): string =>+ [+ "DEPRECATION NOTICE",+ "==================",+ "",+ 'This export includes the "Traces and observations (legacy)" data source. The',+ "legacy traces and observations tables are deprecated and will be removed in a",+ "future release.",+ "",+ 'Please switch this integration to the "Enriched observations (recommended)"',+ "export source, which combines observations with their trace attributes in a",+ "single row and offers significantly better export performance. If this export",+ "currently produces both the legacy tables and enriched observations, move to",+ "the enriched-only source to stop writing the deprecated legacy tables.",+ "",+ "Migration guide:",+ BLOB_EXPORT_DOCS_URL,+ "",+ ].join("\n");diff --git a/worker/src/features/blobstorage/handleBlobStorageIntegrationProjectJob.ts b/worker/src/features/blobstorage/handleBlobStorageIntegrationProjectJob.tsindex fc528b3b81..a54534bda1 100644--- a/worker/src/features/blobstorage/handleBlobStorageIntegrationProjectJob.ts+++ b/worker/src/features/blobstorage/handleBlobStorageIntegrationProjectJob.ts@@ -58,6 +58,8 @@ import {type ObservationFieldGroupFull,isEnrichedBlobExportAvailable,isEnrichedBlobExportSource,+ isLegacyBlobExportSource,+ isLegacyBlobExporter,resolveBlobExportTuning,DEFAULT_BLOB_EXPORT_PART_SIZE_BYTES,} from "@langfuse/shared";@@ -74,6 +76,10 @@ import {formatBlobExportTimestamp,type BlobExportManifestFile,} from "./manifest";+import {+ buildBlobExportDeprecationNotice,+ buildBlobExportDeprecationNoticeKey,+} from "./deprecationNotice";export const BlobExportFormat = {JSON_RAW: "json-raw",@@ -1095,6 +1101,59 @@ const writeBlobExportManifest = async (params: {);};+// LFE-10896: drop a plain-text deprecation notice into the export destination+// for legacy-source projects. Best-effort β a failure to write the notice must+// not fail the export run, so it is called after the manifest commit point and+// swallows its own error.+const writeBlobExportDeprecationNotice = async (params: {+ storageService: StorageService;+ prefix?: string;+ projectId: string;+}): Promise<void> => {+ const key = buildBlobExportDeprecationNoticeKey({+ prefix: params.prefix,+ projectId: params.projectId,+ });+ try {+ await params.storageService.uploadFile({+ fileName: key,+ fileType: "text/plain; charset=utf-8",+ data: buildBlobExportDeprecationNotice(),+ });+ logger.info(+ `[BLOB INTEGRATION] Wrote legacy-source deprecation notice for project ${params.projectId}: key=${key}`,+ );+ } catch (error) {+ logger.warn(+ `[BLOB INTEGRATION] Failed to write legacy-source deprecation notice for project ${params.projectId} (key=${key}); export run is unaffected`,+ error,+ );+ }+};++// Counterpart to the writer: once a project migrates off a legacy source (the+// action the notice asks for), a notice left from an earlier run would linger+// with now-false claims. Best-effort delete on the non-legacy path clears it.+// Idempotent β deleting a non-existent key is a no-op β and never fails the run.+const removeBlobExportDeprecationNotice = async (params: {+ storageService: StorageService;+ prefix?: string;+ projectId: string;+}): Promise<void> => {+ const key = buildBlobExportDeprecationNoticeKey({+ prefix: params.prefix,+ projectId: params.projectId,+ });+ try {+ await params.storageService.deleteFiles([key]);+ } catch (error) {+ logger.warn(+ `[BLOB INTEGRATION] Failed to remove stale deprecation notice for project ${params.projectId} (key=${key}); export run is unaffected`,+ error,+ );+ }+};+export const handleBlobStorageIntegrationProjectJob = async (job: Job<TQueueJobTypes[QueueName.BlobStorageIntegrationProcessingQueue]>,) => {@@ -1197,6 +1256,11 @@ export const handleBlobStorageIntegrationProjectJob = async (return;}+ // Legacy-source deprecation is a Cloud policy (see blob-export-gate.ts:+ // isLegacyBlobExportAllowed / isLegacyBlobExporter both exempt self-hosted),+ // so the deprecation notice below is Cloud-only too.+ const isCloud = Boolean(env.NEXT_PUBLIC_LANGFUSE_CLOUD_REGION);+try {// Fail loudly rather than export from unpopulated tables when an enriched// source survives on a deployment without the enriched path, e.g. after a@@ -1204,10 +1268,7 @@ export const handleBlobStorageIntegrationProjectJob = async (// (LFE-10296).if (isEnrichedBlobExportSource(blobStorageIntegration.exportSource) &&- !isEnrichedBlobExportAvailable(- Boolean(env.NEXT_PUBLIC_LANGFUSE_CLOUD_REGION),- v4AllowPreviewOptIn(env),- )+ !isEnrichedBlobExportAvailable(isCloud, v4AllowPreviewOptIn(env))) {throw new Error("The configured export source includes enriched observations, but enriched export is not available on this deployment. Select a different export source in the blob storage integration settings, or re-enable enriched export (V4 preview opt-in) on this deployment.",@@ -1365,6 +1426,28 @@ export const handleBlobStorageIntegrationProjectJob = async (files: runFiles,});+ // Cloud-only v3-deprecation notice; both sides best-effort (never fail the run).+ if (isCloud) {+ if (isLegacyBlobExportSource(blobStorageIntegration.exportSource)) {+ await writeBlobExportDeprecationNotice({+ storageService,+ prefix: blobStorageIntegration.prefix || undefined,+ projectId,+ });+ } else if (+ // Gate cleanup on "old enough to have written a notice": otherwise every+ // enriched-only export adds a needless per-run s3:DeleteObject on the+ // destination, which is write-only for many customers.+ isLegacyBlobExporter(blobStorageIntegration.createdAt, isCloud)+ ) {+ await removeBlobExportDeprecationNotice({+ storageService,+ prefix: blobStorageIntegration.prefix || undefined,+ projectId,+ });+ }+ }+// Determine if we've caught up with present-day dataconst caughtUp = maxTimestamp.getTime() >= uncappedMaxTimestamp.getTime();