Skip to content

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

fix(blob-storage): never silently overwrite enriched export source after V4-preview rollback (LFE-10296) (#14225)

Niklas Semmler03c38ec6d0dc
diff --git a/packages/shared/src/features/analytics-integrations/blob-export-gate.ts b/packages/shared/src/features/analytics-integrations/blob-export-gate.ts
index 136f028acb..da86b34b2a 100644
--- a/packages/shared/src/features/analytics-integrations/blob-export-gate.ts
+++ b/packages/shared/src/features/analytics-integrations/blob-export-gate.ts
@@ -54,6 +54,26 @@ export function isLegacyBlobExportAllowed(
return projectCreatedAt < LEGACY_BLOB_EXPORT_CUTOFF;
}
+// Internal enum values whose export includes the enriched observations
+// (events) path. satisfies ensures each element remains a valid
+// AnalyticsIntegrationExportSource. Adding a new enum variant does NOT
+// automatically produce an error here; the list must be reviewed manually.
+export const ENRICHED_BLOB_EXPORT_SOURCES = [
+ AnalyticsIntegrationExportSource.EVENTS,
+ AnalyticsIntegrationExportSource.TRACES_OBSERVATIONS_EVENTS,
+] as const satisfies ReadonlyArray<AnalyticsIntegrationExportSource>;
+
+export function isEnrichedBlobExportSource(
+ source: AnalyticsIntegrationExportSource | null | undefined,
+): boolean {
+ return (
+ source != null &&
+ (
+ ENRICHED_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/web/src/__tests__/server/blob-storage-integration-trpc.servertest.ts b/web/src/__tests__/server/blob-storage-integration-trpc.servertest.ts
index d68f55adf8..e97847332d 100644
--- a/web/src/__tests__/server/blob-storage-integration-trpc.servertest.ts
+++ b/web/src/__tests__/server/blob-storage-integration-trpc.servertest.ts
@@ -97,9 +97,14 @@ const prepare = async () => {
const createIntegration = async ({
projectId,
enabled = true,
+ exportSource,
}: {
projectId: string;
enabled?: boolean;
+ exportSource?:
+ | "TRACES_OBSERVATIONS"
+ | "TRACES_OBSERVATIONS_EVENTS"
+ | "EVENTS";
}) =>
prisma.blobStorageIntegration.create({
data: {
@@ -115,6 +120,7 @@ const createIntegration = async ({
forcePathStyle: false,
fileType: "JSONL",
exportMode: "FULL_HISTORY",
+ ...(exportSource ? { exportSource } : {}),
},
});
@@ -868,4 +874,128 @@ describe("Blob Storage Integration tRPC Router", () => {
}
});
});
+
+ // LFE-10296: an update that omits exportSource must preserve the persisted
+ // value (parity with the public REST handler) — never rewrite it to the
+ // legacy default — and must be rejected when preserving would keep a stale
+ // enriched source alive on a deployment without the enriched export path.
+ describe("update: omitted exportSource", () => {
+ const originalRegion = env.NEXT_PUBLIC_LANGFUSE_CLOUD_REGION;
+ const originalV4Preview = env.LANGFUSE_MIGRATION_V4_ALLOW_PREVIEW_OPT_IN;
+
+ afterEach(() => {
+ (env as any).NEXT_PUBLIC_LANGFUSE_CLOUD_REGION = originalRegion;
+ (env as any).LANGFUSE_MIGRATION_V4_ALLOW_PREVIEW_OPT_IN =
+ originalV4Preview;
+ });
+
+ const { exportSource: _ignored, ...configWithoutExportSource } = baseConfig;
+
+ it("preserves a persisted enriched source when enriched export is available", async () => {
+ (env as any).NEXT_PUBLIC_LANGFUSE_CLOUD_REGION = undefined;
+ (env as any).LANGFUSE_MIGRATION_V4_ALLOW_PREVIEW_OPT_IN = "true";
+ const { caller, project } = await prepare();
+ await createIntegration({
+ projectId: project.id,
+ exportSource: "EVENTS",
+ });
+
+ await caller.blobStorageIntegration.update({
+ projectId: project.id,
+ ...configWithoutExportSource,
+ });
+
+ const row = await prisma.blobStorageIntegration.findUniqueOrThrow({
+ where: { projectId: project.id },
+ });
+ expect(row.exportSource).toBe("EVENTS");
+ });
+
+ it("rejects an omitted exportSource over a stale enriched row on rolled-back self-hosted", async () => {
+ (env as any).NEXT_PUBLIC_LANGFUSE_CLOUD_REGION = undefined;
+ (env as any).LANGFUSE_MIGRATION_V4_ALLOW_PREVIEW_OPT_IN = "false";
+ const { caller, project } = await prepare();
+ await createIntegration({
+ projectId: project.id,
+ exportSource: "EVENTS",
+ });
+
+ await expect(
+ caller.blobStorageIntegration.update({
+ projectId: project.id,
+ ...configWithoutExportSource,
+ }),
+ ).rejects.toMatchObject({ code: "BAD_REQUEST" });
+
+ const row = await prisma.blobStorageIntegration.findUniqueOrThrow({
+ where: { projectId: project.id },
+ });
+ expect(row.exportSource).toBe("EVENTS");
+ });
+
+ it("preserves a persisted legacy source on rolled-back self-hosted", async () => {
+ (env as any).NEXT_PUBLIC_LANGFUSE_CLOUD_REGION = undefined;
+ (env as any).LANGFUSE_MIGRATION_V4_ALLOW_PREVIEW_OPT_IN = "false";
+ const { caller, project } = await prepare();
+ await createIntegration({
+ projectId: project.id,
+ exportSource: "TRACES_OBSERVATIONS",
+ });
+
+ await caller.blobStorageIntegration.update({
+ projectId: project.id,
+ ...configWithoutExportSource,
+ });
+
+ const row = await prisma.blobStorageIntegration.findUniqueOrThrow({
+ where: { projectId: project.id },
+ });
+ expect(row.exportSource).toBe("TRACES_OBSERVATIONS");
+ });
+
+ it("creates with EVENTS when exportSource is omitted for a post-cutoff Cloud project", async () => {
+ // The legacy gate only checks explicit values, so an omitted
+ // exportSource on CREATE must not fall through to the Prisma column
+ // default (TRACES_OBSERVATIONS) — mirror of the REST handler's
+ // forceEventsOnCreate behavior.
+ (env as any).NEXT_PUBLIC_LANGFUSE_CLOUD_REGION = "us";
+ (env as any).LANGFUSE_MIGRATION_V4_ALLOW_PREVIEW_OPT_IN = "false";
+ const { caller, project } = await prepare();
+ await prisma.project.update({
+ where: { id: project.id },
+ data: { createdAt: POST_CUTOFF },
+ });
+
+ await caller.blobStorageIntegration.update({
+ projectId: project.id,
+ ...configWithoutExportSource,
+ });
+
+ const row = await prisma.blobStorageIntegration.findUniqueOrThrow({
+ where: { projectId: project.id },
+ });
+ expect(row.exportSource).toBe("EVENTS");
+ });
+
+ it("still allows an explicit downgrade to a legacy source on rolled-back self-hosted", async () => {
+ (env as any).NEXT_PUBLIC_LANGFUSE_CLOUD_REGION = undefined;
+ (env as any).LANGFUSE_MIGRATION_V4_ALLOW_PREVIEW_OPT_IN = "false";
+ const { caller, project } = await prepare();
+ await createIntegration({
+ projectId: project.id,
+ exportSource: "EVENTS",
+ });
+
+ await caller.blobStorageIntegration.update({
+ projectId: project.id,
+ ...configWithoutExportSource,
+ exportSource: "TRACES_OBSERVATIONS" as const,
+ });
+
+ const row = await prisma.blobStorageIntegration.findUniqueOrThrow({
+ where: { projectId: project.id },
+ });
+ expect(row.exportSource).toBe("TRACES_OBSERVATIONS");
+ });
+ });
});
diff --git a/web/src/features/blobstorage-integration/blobstorage-integration-router.ts b/web/src/features/blobstorage-integration/blobstorage-integration-router.ts
index 2aa5cf2217..096bf6a699 100644
--- a/web/src/features/blobstorage-integration/blobstorage-integration-router.ts
+++ b/web/src/features/blobstorage-integration/blobstorage-integration-router.ts
@@ -27,6 +27,7 @@ import {
import { randomUUID } from "crypto";
import { decrypt } from "@langfuse/shared/encryption";
import {
+ AnalyticsIntegrationExportSource,
BlobStorageIntegrationType,
InvalidRequestError,
isEnrichedBlobExportAvailable,
@@ -100,7 +101,12 @@ export const blobStorageIntegrationRouter = createTRPCRouter({
update: protectedProjectProcedure
.input(
blobStorageIntegrationFormSchemaBase
- .extend({ projectId: z.string() })
+ .extend({
+ projectId: z.string(),
+ // Drop the base schema default so an omitted value preserves the
+ // persisted source instead of rewriting it to the legacy default.
+ exportSource: z.enum(AnalyticsIntegrationExportSource).optional(),
+ })
.superRefine(validateAzureContainerName)
.superRefine(validateExportFieldGroups),
)
@@ -112,32 +118,41 @@ export const blobStorageIntegrationRouter = createTRPCRouter({
scope: "integrations:CRUD",
});
+ const isCloud = Boolean(env.NEXT_PUBLIC_LANGFUSE_CLOUD_REGION);
+ const isV4PreviewEnabled =
+ env.LANGFUSE_MIGRATION_V4_ALLOW_PREVIEW_OPT_IN === "true";
+
+ // Feeds both gates: the legacy gate needs createdAt for an explicit
+ // source; the enriched gate needs the persisted source to reject a
+ // stale enriched value on an omitted update.
+ const existingIntegration =
+ await ctx.prisma.blobStorageIntegration.findUnique({
+ where: { projectId: input.projectId },
+ select: { createdAt: true, exportSource: true },
+ });
+
+ // Legacy gate checks explicit values only; omitted preserves the row,
+ // CREATE is covered by forceEventsOnCreate below.
if (input.exportSource) {
- const isCloud = Boolean(env.NEXT_PUBLIC_LANGFUSE_CLOUD_REGION);
- const [project, existingIntegration] = await Promise.all([
- ctx.prisma.project.findUniqueOrThrow({
- where: { id: input.projectId },
- select: { createdAt: true },
- }),
- ctx.prisma.blobStorageIntegration.findUnique({
- where: { projectId: input.projectId },
- select: { createdAt: true },
- }),
- ]);
+ const project = await ctx.prisma.project.findUniqueOrThrow({
+ where: { id: input.projectId },
+ select: { createdAt: true },
+ });
assertLegacyBlobExportSourceAllowedForUpsert({
project,
existingIntegration,
nextInternalExportSource: input.exportSource,
isCloud,
});
- assertEnrichedBlobExportSourceAllowed({
- nextInternalExportSource: input.exportSource,
- isCloud,
- isV4PreviewEnabled:
- env.LANGFUSE_MIGRATION_V4_ALLOW_PREVIEW_OPT_IN === "true",
- });
}
+ assertEnrichedBlobExportSourceAllowed({
+ nextInternalExportSource: input.exportSource,
+ existingExportSource: existingIntegration?.exportSource,
+ isCloud,
+ isV4PreviewEnabled,
+ });
+
await auditLog({
session: ctx.session,
action: "update",
@@ -150,10 +165,11 @@ export const blobStorageIntegrationRouter = createTRPCRouter({
return await upsertBlobStorageIntegration({
prisma: ctx.prisma,
projectId,
- // In-transaction backstop closing the TOCTOU window: if a concurrent
- // DELETE flips this upsert to the CREATE branch, refuse a legacy
- // source so a new (post-cutoff) Cloud row can never be born legacy.
- refuseLegacyOnCreate: Boolean(env.NEXT_PUBLIC_LANGFUSE_CLOUD_REGION),
+ // Mirror the REST handler: substitute EVENTS for an omitted source on
+ // a new Cloud row, and refuse a legacy source if a concurrent DELETE
+ // flips this upsert to CREATE.
+ forceEventsOnCreate: input.exportSource === undefined && isCloud,
+ refuseLegacyOnCreate: isCloud,
data: {
type: rest.type,
bucketName: rest.bucketName,
diff --git a/web/src/features/blobstorage-integration/exportSource.clienttest.ts b/web/src/features/blobstorage-integration/exportSource.clienttest.ts
new file mode 100644
index 0000000000..a575922f14
--- /dev/null
+++ b/web/src/features/blobstorage-integration/exportSource.clienttest.ts
@@ -0,0 +1,179 @@
+import { AnalyticsIntegrationExportSource } from "@langfuse/shared";
+
+import {
+ getExportSourceFormValue,
+ getExportSourceOptions,
+ isExportSourceSelectable,
+} from "./exportSource";
+
+const cloudPreCutoff = {
+ eventsExportAvailable: true,
+ forceEventsExport: false,
+};
+const cloudPostCutoff = {
+ eventsExportAvailable: true,
+ forceEventsExport: true,
+};
+const selfHostedWithPreview = {
+ eventsExportAvailable: true,
+ forceEventsExport: false,
+};
+const selfHostedRolledBack = {
+ eventsExportAvailable: false,
+ forceEventsExport: false,
+};
+
+describe("getExportSourceFormValue", () => {
+ it("keeps a persisted enriched value when enriched export is unavailable (LFE-10296)", () => {
+ // Regression: the form used to substitute TRACES_OBSERVATIONS here, so any
+ // save silently overwrote the persisted enriched configuration.
+ expect(
+ getExportSourceFormValue(
+ AnalyticsIntegrationExportSource.EVENTS,
+ selfHostedRolledBack,
+ ),
+ ).toBe(AnalyticsIntegrationExportSource.EVENTS);
+ expect(
+ getExportSourceFormValue(
+ AnalyticsIntegrationExportSource.TRACES_OBSERVATIONS_EVENTS,
+ selfHostedRolledBack,
+ ),
+ ).toBe(AnalyticsIntegrationExportSource.TRACES_OBSERVATIONS_EVENTS);
+ });
+
+ it("keeps any persisted value regardless of deployment state", () => {
+ for (const persisted of Object.values(AnalyticsIntegrationExportSource)) {
+ for (const availability of [
+ cloudPreCutoff,
+ cloudPostCutoff,
+ selfHostedWithPreview,
+ selfHostedRolledBack,
+ ]) {
+ expect(getExportSourceFormValue(persisted, availability)).toBe(
+ persisted,
+ );
+ }
+ }
+ });
+
+ it("defaults new configurations to EVENTS when enriched export is available", () => {
+ expect(getExportSourceFormValue(undefined, cloudPreCutoff)).toBe(
+ AnalyticsIntegrationExportSource.EVENTS,
+ );
+ expect(getExportSourceFormValue(undefined, cloudPostCutoff)).toBe(
+ AnalyticsIntegrationExportSource.EVENTS,
+ );
+ expect(getExportSourceFormValue(null, selfHostedWithPreview)).toBe(
+ AnalyticsIntegrationExportSource.EVENTS,
+ );
+ });
+
+ it("defaults new configurations to TRACES_OBSERVATIONS when enriched export is unavailable", () => {
+ expect(getExportSourceFormValue(undefined, selfHostedRolledBack)).toBe(
+ AnalyticsIntegrationExportSource.TRACES_OBSERVATIONS,
+ );
+ });
+});
+
+describe("isExportSourceSelectable", () => {
+ it("rejects enriched sources when enriched export is unavailable", () => {
+ expect(
+ isExportSourceSelectable(
+ AnalyticsIntegrationExportSource.EVENTS,
+ selfHostedRolledBack,
+ ),
+ ).toBe(false);
+ expect(
+ isExportSourceSelectable(
+ AnalyticsIntegrationExportSource.TRACES_OBSERVATIONS_EVENTS,
+ selfHostedRolledBack,
+ ),
+ ).toBe(false);
+ expect(
+ isExportSourceSelectable(
+ AnalyticsIntegrationExportSource.TRACES_OBSERVATIONS,
+ selfHostedRolledBack,
+ ),
+ ).toBe(true);
+ });
+
+ it("rejects legacy sources on post-cutoff Cloud projects", () => {
+ expect(
+ isExportSourceSelectable(
+ AnalyticsIntegrationExportSource.TRACES_OBSERVATIONS,
+ cloudPostCutoff,
+ ),
+ ).toBe(false);
+ expect(
+ isExportSourceSelectable(
+ AnalyticsIntegrationExportSource.TRACES_OBSERVATIONS_EVENTS,
+ cloudPostCutoff,
+ ),
+ ).toBe(false);
+ expect(
+ isExportSourceSelectable(
+ AnalyticsIntegrationExportSource.EVENTS,
+ cloudPostCutoff,
+ ),
+ ).toBe(true);
+ });
+
+ it("accepts all sources when enriched export is available and legacy is allowed", () => {
+ for (const source of Object.values(AnalyticsIntegrationExportSource)) {
+ expect(isExportSourceSelectable(source, cloudPreCutoff)).toBe(true);
+ expect(isExportSourceSelectable(source, selfHostedWithPreview)).toBe(
+ true,
+ );
+ }
+ });
+});
+
+describe("getExportSourceOptions", () => {
+ it("offers all sources when everything is available", () => {
+ const options = getExportSourceOptions(undefined, cloudPreCutoff);
+ expect(options.map((o) => o.value)).toEqual([
+ AnalyticsIntegrationExportSource.TRACES_OBSERVATIONS,
+ AnalyticsIntegrationExportSource.TRACES_OBSERVATIONS_EVENTS,
+ AnalyticsIntegrationExportSource.EVENTS,
+ ]);
+ expect(options.every((o) => !o.unavailable)).toBe(true);
+ });
+
+ it("offers only the legacy source on a rolled-back self-hosted deployment", () => {
+ const options = getExportSourceOptions(
+ AnalyticsIntegrationExportSource.TRACES_OBSERVATIONS,
+ selfHostedRolledBack,
+ );
+ expect(options.map((o) => o.value)).toEqual([
+ AnalyticsIntegrationExportSource.TRACES_OBSERVATIONS,
+ ]);
+ expect(options[0].unavailable).toBe(false);
+ });
+
+ it("offers only EVENTS for post-cutoff Cloud projects", () => {
+ const options = getExportSourceOptions(undefined, cloudPostCutoff);
+ expect(options.map((o) => o.value)).toEqual([
+ AnalyticsIntegrationExportSource.EVENTS,
+ ]);
+ });
+
+ it("includes a stale persisted enriched source, marked unavailable (LFE-10296)", () => {
+ const options = getExportSourceOptions(
+ AnalyticsIntegrationExportSource.EVENTS,
+ selfHostedRolledBack,
+ );
+ expect(options.map((o) => o.value)).toEqual([
+ AnalyticsIntegrationExportSource.TRACES_OBSERVATIONS,
+ AnalyticsIntegrationExportSource.EVENTS,
+ ]);
+ expect(
+ options.find((o) => o.value === AnalyticsIntegrationExportSource.EVENTS)
+ ?.unavailable,
+ ).toBe(true);
+ expect(
+ options.find(
+ (o) => o.value === AnalyticsIntegrationExportSource.TRACES_OBSERVATIONS,
+ )?.unavailable,
+ ).toBe(false);
+ });
+});
diff --git a/web/src/features/blobstorage-integration/exportSource.ts b/web/src/features/blobstorage-integration/exportSource.ts
new file mode 100644
index 0000000000..b4aece2fec
--- /dev/null
+++ b/web/src/features/blobstorage-integration/exportSource.ts
@@ -0,0 +1,55 @@
+import {
+ AnalyticsIntegrationExportSource,
+ EXPORT_SOURCE_OPTIONS,
+ isEnrichedBlobExportSource,
+ LEGACY_BLOB_EXPORT_SOURCES,
+ type ExportSourceOption,
+} from "@langfuse/shared";
+
+export type ExportSourceAvailability = {
+ eventsExportAvailable: boolean;
+ forceEventsExport: boolean;
+};
+
+// Mirrors the two server asserts: TRACES_OBSERVATIONS_EVENTS is both enriched
+// and legacy, so it must clear both checks.
+export function isExportSourceSelectable(
+ source: AnalyticsIntegrationExportSource,
+ availability: ExportSourceAvailability,
+): boolean {
+ if (isEnrichedBlobExportSource(source) && !availability.eventsExportAvailable)
+ return false;
+ const isLegacy = (
+ LEGACY_BLOB_EXPORT_SOURCES as readonly AnalyticsIntegrationExportSource[]
+ ).includes(source);
+ return !(isLegacy && availability.forceEventsExport);
+}
+
+// The persisted value always wins so initialize+save can never silently
+// rewrite it (LFE-10296); validation blocks the save if it is not selectable.
+export function getExportSourceFormValue(
+ persisted: AnalyticsIntegrationExportSource | null | undefined,
+ availability: ExportSourceAvailability,
+): AnalyticsIntegrationExportSource {
+ if (persisted) return persisted;
+ return availability.eventsExportAvailable || availability.forceEventsExport
+ ? AnalyticsIntegrationExportSource.EVENTS
+ : AnalyticsIntegrationExportSource.TRACES_OBSERVATIONS;
+}
+
+export type SelectableExportSourceOption = ExportSourceOption & {
+ unavailable: boolean;
+};
+
+// Selectable sources, plus the persisted one (marked unavailable) when it is
+// no longer selectable, so the conflict is visible rather than silently rewritten.
+export function getExportSourceOptions(
+ persisted: AnalyticsIntegrationExportSource | null | undefined,
+ availability: ExportSourceAvailability,
+): SelectableExportSourceOption[] {
+ return EXPORT_SOURCE_OPTIONS.flatMap((option) => {
+ const selectable = isExportSourceSelectable(option.value, availability);
+ if (!selectable && option.value !== persisted) return [];
+ return [{ ...option, unavailable: !selectable }];
+ });
+}
diff --git a/web/src/features/blobstorage-integration/server/assertEnrichedBlobExportSourceAllowed.ts b/web/src/features/blobstorage-integration/server/assertEnrichedBlobExportSourceAllowed.ts
index 700408de2b..8c7664b0fa 100644
--- a/web/src/features/blobstorage-integration/server/assertEnrichedBlobExportSourceAllowed.ts
+++ b/web/src/features/blobstorage-integration/server/assertEnrichedBlobExportSourceAllowed.ts
@@ -1,7 +1,8 @@
import {
- AnalyticsIntegrationExportSource,
+ type AnalyticsIntegrationExportSource,
InvalidRequestError,
isEnrichedBlobExportAvailable,
+ isEnrichedBlobExportSource,
} from "@langfuse/shared";
/**
@@ -26,12 +27,7 @@ export function assertEnrichedBlobExportSourceAllowed({
isV4PreviewEnabled: boolean;
}): void {
const effectiveSource = nextInternalExportSource ?? existingExportSource;
- if (
- effectiveSource !== AnalyticsIntegrationExportSource.EVENTS &&
- effectiveSource !==
- AnalyticsIntegrationExportSource.TRACES_OBSERVATIONS_EVENTS
- )
- return;
+ if (!isEnrichedBlobExportSource(effectiveSource)) return;
if (isEnrichedBlobExportAvailable(isCloud, isV4PreviewEnabled)) return;
diff --git a/web/src/features/blobstorage-integration/validation.ts b/web/src/features/blobstorage-integration/validation.ts
index 8aaa96e8a5..38e5187704 100644
--- a/web/src/features/blobstorage-integration/validation.ts
+++ b/web/src/features/blobstorage-integration/validation.ts
@@ -1,7 +1,7 @@
import type { z } from "zod";
export function validateExportFieldGroups(
- data: { exportSource: string; exportFieldGroups: unknown[] },
+ data: { exportFieldGroups: unknown[] },
ctx: z.RefinementCtx,
) {
// Field groups apply to all export sources (legacy observations honor them
diff --git a/web/src/features/public-api/types/blob-storage-integrations.ts b/web/src/features/public-api/types/blob-storage-integrations.ts
index 2722ec02f3..dbbf633d31 100644
--- a/web/src/features/public-api/types/blob-storage-integrations.ts
+++ b/web/src/features/public-api/types/blob-storage-integrations.ts
@@ -132,10 +132,7 @@ export const CreateBlobStorageIntegrationRequest = z
}
if (data.exportFieldGroups != null && data.exportSource != null) {
validateExportFieldGroups(
- {
- exportSource: toInternalExportSource(data.exportSource),
- exportFieldGroups: data.exportFieldGroups,
- },
+ { exportFieldGroups: data.exportFieldGroups },
ctx,
);
}
diff --git a/web/src/pages/api/public/integrations/blob-storage/index.ts b/web/src/pages/api/public/integrations/blob-storage/index.ts
index 0ef0c0e35c..b2e2d0f39d 100644
--- a/web/src/pages/api/public/integrations/blob-storage/index.ts
+++ b/web/src/pages/api/public/integrations/blob-storage/index.ts
@@ -15,7 +15,6 @@ import {
LangfuseNotFoundError,
UnauthorizedError,
ForbiddenError,
- isEnrichedBlobExportAvailable,
} from "@langfuse/shared";
import { upsertBlobStorageIntegration } from "@/src/features/blobstorage-integration/service";
import { assertLegacyBlobExportSourceAllowedForUpsert } from "@/src/features/blobstorage-integration/server/assertLegacyBlobExportSourceAllowedForUpsert";
@@ -167,18 +166,14 @@ async function handleUpsertBlobStorageIntegration(
? toInternalExportSource(validatedData.exportSource)
: undefined;
- // Single conditional read serving both write-time gates: the legacy upsert
- // gate needs the row's createdAt when exportSource is provided; the enriched
- // gate needs the persisted exportSource when it is omitted (partial PUT) and
- // enriched export is unavailable, so a stale enriched value is rejected.
- const existingIntegration =
- internalExportSource !== undefined ||
- !isEnrichedBlobExportAvailable(isCloud, isV4PreviewEnabled)
- ? await prisma.blobStorageIntegration.findUnique({
- where: { projectId: validatedData.projectId },
- select: { createdAt: true, exportSource: true },
- })
- : null;
+ // Feeds both write-time gates: the legacy upsert gate needs the row's
+ // createdAt when exportSource is provided; the enriched gate needs the
+ // persisted exportSource when it is omitted (partial PUT), so a stale
+ // enriched value is rejected.
+ const existingIntegration = await prisma.blobStorageIntegration.findUnique({
+ where: { projectId: validatedData.projectId },
+ select: { createdAt: true, exportSource: true },
+ });
if (internalExportSource) {
assertLegacyBlobExportSourceAllowedForUpsert({
diff --git a/web/src/pages/project/[projectId]/settings/integrations/blobstorage.tsx b/web/src/pages/project/[projectId]/settings/integrations/blobstorage.tsx
index 397d701502..31632f7502 100644
--- a/web/src/pages/project/[projectId]/settings/integrations/blobstorage.tsx
+++ b/web/src/pages/project/[projectId]/settings/integrations/blobstorage.tsx
@@ -41,7 +41,7 @@ import { zodResolver } from "@hookform/resolvers/zod";
import { Card } from "@/src/components/ui/card";
import Link from "next/link";
import { useRouter } from "next/router";
-import { useEffect, useState } from "react";
+import { useEffect, useMemo, useState } from "react";
import { useForm } from "react-hook-form";
import { showSuccessToast } from "@/src/features/notifications/showSuccessToast";
import { showErrorToast } from "@/src/features/notifications/showErrorToast";
@@ -51,13 +51,17 @@ import {
BlobStorageExportMode,
AnalyticsIntegrationExportSource,
type BlobStorageIntegration,
- EXPORT_SOURCE_OPTIONS,
EXPORT_FIELD_GROUP_OPTIONS,
OBSERVATION_FIELD_GROUPS_FULL,
type ObservationFieldGroupFull,
isLegacyBlobExportAllowed,
isLegacyBlobExporter,
} from "@langfuse/shared";
+import {
+ getExportSourceFormValue,
+ getExportSourceOptions,
+ isExportSourceSelectable,
+} from "@/src/features/blobstorage-integration/exportSource";
import { useLangfuseCloudRegion } from "@/src/features/organizations/hooks";
import { useQueryProject } from "@/src/features/projects/hooks";
import { Info, ExternalLink } from "lucide-react";
@@ -249,31 +253,42 @@ const BlobStorageIntegrationSettingsForm = ({
// Check if this is a self-hosted instance (no cloud region set)
const isSelfHosted = !isLangfuseCloud;
- // Post-cutoff Cloud projects may only use OBSERVATIONS_V2 (EVENTS). The
- // Export Source field is hidden in that case; the form value is pinned to
- // EVENTS via the default below.
const isPostCutoffCloud =
project?.createdAt != null &&
!isLegacyBlobExportAllowed(new Date(project.createdAt), isLangfuseCloud);
const eventsExportAvailable = isEnrichedExportAvailable;
- // Integration-level cutoff (Cloud only): an existing row created before
- // LEGACY_BLOB_EXPORTER_CUTOFF stays legacy (picker visible); a new row (no
- // state yet) or a post-cutoff row is not legacy (picker hidden, pinned to
- // EVENTS). Stable across revisits because the row's createdAt is immutable.
+ // Integration-level cutoff (Cloud only): a row predating the exporter cutoff
+ // keeps legacy options; a new or post-cutoff row is locked to EVENTS.
const isLegacyExporter = isLegacyBlobExporter(
state?.createdAt ? new Date(state.createdAt) : null,
isLangfuseCloud,
);
const forceEventsExport =
isPostCutoffCloud || (eventsExportAvailable && !isLegacyExporter);
- // The picker only exists where the enriched events export is available
- // (Cloud, or self-hosted with the V4 preview opt-in — server-computed flag).
- // Where it isn't, the picker stays hidden and the form defaults to
- // TRACES_OBSERVATIONS, since EVENTS is not provisioned there.
- const showExportSourceField = eventsExportAvailable && !forceEventsExport;
+ const availability = useMemo(
+ () => ({ eventsExportAvailable, forceEventsExport }),
+ [eventsExportAvailable, forceEventsExport],
+ );
+
+ // Block the save when the persisted source is no longer selectable rather
+ // than silently rewriting it (LFE-10296).
+ const formSchema = useMemo(
+ () =>
+ blobStorageIntegrationFormSchema.superRefine((data, ctx) => {
+ if (!isExportSourceSelectable(data.exportSource, availability)) {
+ ctx.addIssue({
+ code: "custom",
+ path: ["exportSource"],
+ message:
+ "This export source is not available on this deployment. Select an available export source to save.",
+ });
+ }
+ }),
+ [availability],
+ );
const blobStorageForm = useForm({
- resolver: zodResolver(blobStorageIntegrationFormSchema),
+ resolver: zodResolver(formSchema),
defaultValues: {
type: state?.type || BlobStorageIntegrationType.S3,
bucketName: state?.bucketName || "",
@@ -292,20 +307,7 @@ const BlobStorageIntegrationSettingsForm = ({
fileType: state?.fileType || BlobStorageIntegrationFileType.JSONL,
exportMode: state?.exportMode || BlobStorageExportMode.FULL_HISTORY,
exportStartDate: state?.exportStartDate || null,
- exportSource: forceEventsExport
- ? AnalyticsIntegrationExportSource.EVENTS
- : (() => {
- const persisted = state?.exportSource;
- const isEnriched =
- persisted === AnalyticsIntegrationExportSource.EVENTS ||
- persisted ===
- AnalyticsIntegrationExportSource.TRACES_OBSERVATIONS_EVENTS;
- if (persisted && (!isEnriched || eventsExportAvailable))
- return persisted;
- return eventsExportAvailable
- ? AnalyticsIntegrationExportSource.EVENTS
- : AnalyticsIntegrationExportSource.TRACES_OBSERVATIONS;
- })(),
+ exportSource: getExportSourceFormValue(state?.exportSource, availability),
// Empty array in the DB means "export everything" (the worker falls back
// to all groups), so surface it as the full selection in the form.
exportFieldGroups: state?.exportFieldGroups?.length
@@ -336,20 +338,7 @@ const BlobStorageIntegrationSettingsForm = ({
fileType: state?.fileType || BlobStorageIntegrationFileType.JSONL,
exportMode: state?.exportMode || BlobStorageExportMode.FULL_HISTORY,
exportStartDate: state?.exportStartDate || null,
- exportSource: forceEventsExport
- ? AnalyticsIntegrationExportSource.EVENTS
- : (() => {
- const persisted = state?.exportSource;
- const isEnriched =
- persisted === AnalyticsIntegrationExportSource.EVENTS ||
- persisted ===
- AnalyticsIntegrationExportSource.TRACES_OBSERVATIONS_EVENTS;
- if (persisted && (!isEnriched || eventsExportAvailable))
- return persisted;
- return eventsExportAvailable
- ? AnalyticsIntegrationExportSource.EVENTS
- : AnalyticsIntegrationExportSource.TRACES_OBSERVATIONS;
- })(),
+ exportSource: getExportSourceFormValue(state?.exportSource, availability),
// Empty array in the DB means "export everything" (the worker falls back
// to all groups), so surface it as the full selection in the form.
exportFieldGroups: state?.exportFieldGroups?.length
@@ -358,10 +347,19 @@ const BlobStorageIntegrationSettingsForm = ({
compressed: state?.compressed ?? true,
});
// eslint-disable-next-line react-hooks/exhaustive-deps
- }, [state, isEnrichedExportAvailable, isPostCutoffCloud]);
+ }, [state, availability]);
const watchedExportMode = blobStorageForm.watch("exportMode");
const watchedExportSource = blobStorageForm.watch("exportSource");
+ const exportSourceOptions = getExportSourceOptions(
+ state?.exportSource,
+ availability,
+ );
+ // Visible but locked when there is only one selectable option.
+ const exportSourceLocked = exportSourceOptions.length === 1;
+ const exportSourceUnavailable =
+ watchedExportSource != null &&
+ !isExportSourceSelectable(watchedExportSource, availability);
// The legacy observations table contains fewer columns than the enriched
// observations, so the per-group field lists differ for legacy-only exports.
const isLegacyOnlyExport =
@@ -734,66 +732,89 @@ const BlobStorageIntegrationSettingsForm = ({
)}
/>
- {showExportSourceField && (
- <FormField
- control={blobStorageForm.control}
- name="exportSource"
- render={({ field }) => (
- <FormItem>
- <FormLabel className="flex items-center gap-1.5 pt-2">
- Export Source
- <Tooltip>
- <TooltipTrigger>
- <Info className="text-muted-foreground h-3.5 w-3.5" />
- </TooltipTrigger>
- <TooltipContent
- side="bottom"
- className="max-w-[350px] space-y-2 p-3"
- >
- {EXPORT_SOURCE_OPTIONS.map((option) => (
- <div key={option.value} className="space-y-0.5">
- <div className="font-medium">{option.label}</div>
- <div className="text-muted-foreground text-xs">
- {option.description}
- </div>
+ <FormField
+ control={blobStorageForm.control}
+ name="exportSource"
+ render={({ field }) => (
+ <FormItem>
+ <FormLabel className="flex items-center gap-1.5 pt-2">
+ Export Source
+ <Tooltip>
+ <TooltipTrigger>
+ <Info className="text-muted-foreground h-3.5 w-3.5" />
+ </TooltipTrigger>
+ <TooltipContent
+ side="bottom"
+ className="max-w-[350px] space-y-2 p-3"
+ >
+ {exportSourceOptions.map((option) => (
+ <div key={option.value} className="space-y-0.5">
+ <div className="font-medium">{option.label}</div>
+ <div className="text-muted-foreground text-xs">
+ {option.description}
</div>
- ))}
- <div className="border-t pt-2">
- <a
- href="https://langfuse.com/docs/integrations/export-sources"
- target="_blank"
- rel="noopener noreferrer"
- className="text-muted-foreground hover:text-primary inline-flex items-center gap-1 text-xs hover:underline"
- >
- For further information see
- <ExternalLink className="h-3 w-3" />
- </a>
</div>
- </TooltipContent>
- </Tooltip>
- </FormLabel>
- <Select onValueChange={field.onChange} value={field.value}>
- <FormControl>
- <SelectTrigger>
- <SelectValue placeholder="Select data to export" />
- </SelectTrigger>
- </FormControl>
- <SelectContent>
- {EXPORT_SOURCE_OPTIONS.map((option) => (
- <SelectItem key={option.value} value={option.value}>
- {option.label}
- </SelectItem>
))}
- </SelectContent>
- </Select>
- <FormDescription>
- Choose which data sources to export to blob storage. Scores
- are always included.
- </FormDescription>
- <FormMessage />
- </FormItem>
- )}
- />
+ <div className="border-t pt-2">
+ <a
+ href="https://langfuse.com/docs/integrations/export-sources"
+ target="_blank"
+ rel="noopener noreferrer"
+ className="text-muted-foreground hover:text-primary inline-flex items-center gap-1 text-xs hover:underline"
+ >
+ For further information see
+ <ExternalLink className="h-3 w-3" />
+ </a>
+ </div>
+ </TooltipContent>
+ </Tooltip>
+ </FormLabel>
+ <Select
+ onValueChange={field.onChange}
+ value={field.value}
+ disabled={exportSourceLocked}
+ >
+ <FormControl>
+ <SelectTrigger>
+ <SelectValue placeholder="Select data to export" />
+ </SelectTrigger>
+ </FormControl>
+ <SelectContent>
+ {exportSourceOptions.map((option) => (
+ <SelectItem
+ key={option.value}
+ value={option.value}
+ disabled={option.unavailable}
+ >
+ {option.unavailable
+ ? `${option.label} (not available on this deployment)`
+ : option.label}
+ </SelectItem>
+ ))}
+ </SelectContent>
+ </Select>
+ <FormDescription>
+ Choose which data sources to export to blob storage. Scores are
+ always included.
+ </FormDescription>
+ <FormMessage />
+ </FormItem>
+ )}
+ />
+
+ {exportSourceUnavailable && (
+ <Alert variant="destructive">
+ <AlertTitle>Saved export source is no longer available</AlertTitle>
+ <AlertDescription>
+ {/* Two distinct rejection reasons; key on the deployment, not the
+ source, since TRACES_OBSERVATIONS_EVENTS is both enriched and
+ legacy. !eventsExportAvailable means enriched is genuinely
+ unavailable; otherwise the block is the Cloud legacy cutoff. */}
+ {!availability.eventsExportAvailable
+ ? "This integration is configured to export enriched observations, but enriched export is not available on this deployment. Saving is blocked until you select an available export source above. To keep the current configuration instead, re-enable enriched export (V4 preview opt-in) on your deployment."
+ : "This integration is configured to export legacy traces and observations, which is no longer available for this project. Saving is blocked until you select an available export source above."}
+ </AlertDescription>
+ </Alert>
)}
<FormField
diff --git a/worker/src/__tests__/blobStorageIntegrationProcessing.test.ts b/worker/src/__tests__/blobStorageIntegrationProcessing.test.ts
index 5050d43485..3c612f01d7 100644
--- a/worker/src/__tests__/blobStorageIntegrationProcessing.test.ts
+++ b/worker/src/__tests__/blobStorageIntegrationProcessing.test.ts
@@ -107,6 +107,61 @@ describe("BlobStorageIntegrationProcessingJob", () => {
s3Prefix = null;
});
+ // LFE-10296: a persisted enriched export source on a deployment without the
+ // enriched export path (e.g. after a V4-preview rollback) must fail the job
+ // loudly instead of silently exporting from unpopulated tables.
+ describe("enriched export source guard", () => {
+ const originalV4Preview = env.LANGFUSE_MIGRATION_V4_ALLOW_PREVIEW_OPT_IN;
+
+ afterEach(() => {
+ (env as any).LANGFUSE_MIGRATION_V4_ALLOW_PREVIEW_OPT_IN =
+ originalV4Preview;
+ });
+
+ it("fails the job and persists lastError when the enriched export path is unavailable", async () => {
+ (env as any).LANGFUSE_MIGRATION_V4_ALLOW_PREVIEW_OPT_IN = "false";
+ const { projectId } = await createOrgProjectAndApiKey();
+ s3Prefix = projectId;
+
+ await prisma.blobStorageIntegration.create({
+ data: {
+ projectId,
+ type: BlobStorageIntegrationType.S3,
+ bucketName,
+ prefix: s3Prefix,
+ accessKeyId,
+ secretAccessKey: encrypt(secretAccessKey),
+ region: region ? region : "auto",
+ endpoint: endpoint ? endpoint : null,
+ forcePathStyle:
+ env.LANGFUSE_S3_EVENT_UPLOAD_FORCE_PATH_STYLE === "true",
+ enabled: true,
+ exportFrequency: "daily",
+ exportSource: "EVENTS",
+ // A past lastSyncAt yields a non-empty export window without
+ // requiring ClickHouse data.
+ lastSyncAt: new Date(Date.now() - 2 * 24 * 60 * 60 * 1000),
+ },
+ });
+
+ await expect(
+ handleBlobStorageIntegrationProjectJob({
+ data: { payload: { projectId } },
+ } as Job),
+ ).rejects.toThrow(/enriched/i);
+
+ const row = await prisma.blobStorageIntegration.findUniqueOrThrow({
+ where: { projectId },
+ });
+ expect(row.lastError).toMatch(/enriched/i);
+ expect(row.lastErrorAt).not.toBeNull();
+
+ // Nothing was exported.
+ const files = await storageService.listFiles(s3Prefix);
+ expect(files.filter((f) => f.file.includes(projectId))).toHaveLength(0);
+ });
+ });
+
it("should not process when blob storage integration is disabled", async () => {
const { projectId } = await createOrgProjectAndApiKey();
s3Prefix = projectId;
diff --git a/worker/src/features/blobstorage/handleBlobStorageIntegrationProjectJob.ts b/worker/src/features/blobstorage/handleBlobStorageIntegrationProjectJob.ts
index f477dfa8db..7c88214e5c 100644
--- a/worker/src/features/blobstorage/handleBlobStorageIntegrationProjectJob.ts
+++ b/worker/src/features/blobstorage/handleBlobStorageIntegrationProjectJob.ts
@@ -30,10 +30,12 @@ import {
BlobStorageExportMode,
OBSERVATION_FIELD_GROUPS_FULL,
type ObservationFieldGroupFull,
+ isEnrichedBlobExportAvailable,
+ isEnrichedBlobExportSource,
} from "@langfuse/shared";
import { decrypt } from "@langfuse/shared/encryption";
import { randomUUID } from "crypto";
-import { env } from "../../env";
+import { env, v4AllowPreviewOptIn } from "../../env";
export const BLOB_STORAGE_LAG_BUFFER_MS = 20 * 60 * 1000; // 20-minute lag buffer
@@ -427,6 +429,22 @@ export const handleBlobStorageIntegrationProjectJob = async (
}
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
+ // V4-preview rollback. The catch persists lastError and notifies admins
+ // (LFE-10296).
+ if (
+ isEnrichedBlobExportSource(blobStorageIntegration.exportSource) &&
+ !isEnrichedBlobExportAvailable(
+ Boolean(env.NEXT_PUBLIC_LANGFUSE_CLOUD_REGION),
+ 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.",
+ );
+ }
+
// Preflight the persisted integration endpoint once per job inside the
// export error path. StorageService connection-time validation remains the
// DNS-rebinding defense for each SDK connection.