Skip to content

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

refactor(blobstorage): split settings page into feature components (#14964)

Niklas Semmler1d48f3256ddc
diff --git a/web/src/features/blobstorage-integration/README.md b/web/src/features/blobstorage-integration/README.md
index afdfcf0fb8..378a6fc2fe 100644
--- a/web/src/features/blobstorage-integration/README.md
+++ b/web/src/features/blobstorage-integration/README.md
@@ -6,14 +6,14 @@ computed at read time by `deriveSyncStatus.ts`.
## DB fields (the state vector)
-| Field | Type | Written by |
-|---|---|---|
-| `enabled` | boolean | Web (save), Worker (catch — disables on a final-attempt customer-fault) |
-| `lastError` | string \| null | Worker (catch / success) |
-| `lastSyncAt` | Date \| null | Worker (success) |
-| `nextSyncAt` | Date \| null | Worker (success / empty-window), Web (save) |
-| `runStartedAt` | Date \| null | Worker (start / end), Web (save clears it) |
-| `lastFailureNotificationSentAt` | Date \| null | Worker (cooldown claim before the "failed" email), Web (save with enabled clears it) |
+| Field | Type | Written by |
+| ------------------------------- | -------------- | ------------------------------------------------------------------------------------ |
+| `enabled` | boolean | Web (save), Worker (catch — disables on a final-attempt customer-fault) |
+| `lastError` | string \| null | Worker (catch / success) |
+| `lastSyncAt` | Date \| null | Worker (success) |
+| `nextSyncAt` | Date \| null | Worker (success / empty-window), Web (save) |
+| `runStartedAt` | Date \| null | Worker (start / end), Web (save clears it) |
+| `lastFailureNotificationSentAt` | Date \| null | Worker (cooldown claim before the "failed" email), Web (save with enabled clears it) |
## Derived states (precedence top-to-bottom)
@@ -73,25 +73,25 @@ up_to_date ← fallthrough
## Transition detail
-| From | Trigger | Writes | To |
-|---|---|---|---|
-| **any** | User saves with `enabled=false` | `runStartedAt=null` | **disabled** |
-| **any** | User saves with `enabled=true` | `runStartedAt=null`; `nextSyncAt=now` if errored or mode changed | **idle**, **queued**, **up_to_date**, or stays **error** (`lastError` is not cleared by save) |
-| **disabled** | User saves `enabled=true` | (as above) | **idle**, **queued**, **up_to_date**, or stays **error** |
-| **idle** | Scheduler finds `lastSyncAt=null` | Enqueues BullMQ job (no DB write) | stays **idle** |
-| **queued** | Scheduler finds `nextSyncAt<=now` | Enqueues BullMQ job (no DB write) | stays **queued** |
-| **idle/queued** | Worker starts job | `runStartedAt=now` | **running** |
-| **running** | Worker: integration disabled | `runStartedAt=null` | **disabled** |
-| **running** | Worker: empty time window | `runStartedAt=null`, `nextSyncAt=now+frequency`, `lastError=null` | **up_to_date** (or **idle** if never synced) |
-| **running** | Worker: export succeeds, caught up | `lastSyncAt=max`, `nextSyncAt=max+freq`, `lastError=null`, `runStartedAt=null` | **up_to_date** |
-| **running** | Worker: export succeeds, not caught up | `lastSyncAt=max`, `nextSyncAt=now`, `lastError=null`, `runStartedAt=null` + re-enqueues job | **queued** (immediately) |
-| **running** | Worker: export fails (retries left) | `lastError=msg`, `lastErrorAt=now`, `runStartedAt=null` (no email — a later retry may succeed) | **error** |
-| **running** | Worker: export fails, retries exhausted | `lastError=msg`, `lastErrorAt=now`, `runStartedAt=null` (+ cooldown-gated "failed" email) | **error** |
-| **running** | Worker: retries exhausted on a customer-config/credential failure | `lastError=msg`, `lastErrorAt=now`, `runStartedAt=null`, `enabled=false` (+ one-time "disabled" email, no cooldown) | **disabled** |
-| **error** | User saves (enabled, same mode) | `runStartedAt=null`, `nextSyncAt=now` | stays **error** (`lastError` preserved; scheduler re-enqueues via `nextSyncAt`) |
-| **error** | User clicks Run Now | Enqueues manual job (no DB write) | stays **error** until worker clears `lastError` (success or empty-window) |
-| **running** | Stale `runStartedAt` > 2h | (no write — derived only) | falls through to **queued**, **idle**, or **up_to_date** |
-| **up_to_date** | Clock passes `nextSyncAt` | (no write — derived only) | **queued** |
+| From | Trigger | Writes | To |
+| --------------- | ----------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------- |
+| **any** | User saves with `enabled=false` | `runStartedAt=null` | **disabled** |
+| **any** | User saves with `enabled=true` | `runStartedAt=null`; `nextSyncAt=now` if errored or mode changed | **idle**, **queued**, **up_to_date**, or stays **error** (`lastError` is not cleared by save) |
+| **disabled** | User saves `enabled=true` | (as above) | **idle**, **queued**, **up_to_date**, or stays **error** |
+| **idle** | Scheduler finds `lastSyncAt=null` | Enqueues BullMQ job (no DB write) | stays **idle** |
+| **queued** | Scheduler finds `nextSyncAt<=now` | Enqueues BullMQ job (no DB write) | stays **queued** |
+| **idle/queued** | Worker starts job | `runStartedAt=now` | **running** |
+| **running** | Worker: integration disabled | `runStartedAt=null` | **disabled** |
+| **running** | Worker: empty time window | `runStartedAt=null`, `nextSyncAt=now+frequency`, `lastError=null` | **up_to_date** (or **idle** if never synced) |
+| **running** | Worker: export succeeds, caught up | `lastSyncAt=max`, `nextSyncAt=max+freq`, `lastError=null`, `runStartedAt=null` | **up_to_date** |
+| **running** | Worker: export succeeds, not caught up | `lastSyncAt=max`, `nextSyncAt=now`, `lastError=null`, `runStartedAt=null` + re-enqueues job | **queued** (immediately) |
+| **running** | Worker: export fails (retries left) | `lastError=msg`, `lastErrorAt=now`, `runStartedAt=null` (no email — a later retry may succeed) | **error** |
+| **running** | Worker: export fails, retries exhausted | `lastError=msg`, `lastErrorAt=now`, `runStartedAt=null` (+ cooldown-gated "failed" email) | **error** |
+| **running** | Worker: retries exhausted on a customer-config/credential failure | `lastError=msg`, `lastErrorAt=now`, `runStartedAt=null`, `enabled=false` (+ one-time "disabled" email, no cooldown) | **disabled** |
+| **error** | User saves (enabled, same mode) | `runStartedAt=null`, `nextSyncAt=now` | stays **error** (`lastError` preserved; scheduler re-enqueues via `nextSyncAt`) |
+| **error** | User clicks Run Now | Enqueues manual job (no DB write) | stays **error** until worker clears `lastError` (success or empty-window) |
+| **running** | Stale `runStartedAt` > 2h | (no write — derived only) | falls through to **queued**, **idle**, or **up_to_date** |
+| **up_to_date** | Clock passes `nextSyncAt` | (no write — derived only) | **queued** |
## Safety valve
@@ -109,11 +109,60 @@ worker picks up the job and sets `runStartedAt`.
## Key files
-| File | Role |
-|---|---|
-| `deriveSyncStatus.ts` | Derives display status from DB fields |
-| `types.ts` | `BlobStorageSyncStatus` type |
-| `service.ts` | Upsert logic (web save path) |
-| `blobstorage-integration-router.ts` | tRPC router (save, runNow) |
-| `worker/src/features/blobstorage/handleBlobStorageIntegrationProjectJob.ts` | Worker job handler |
-| `worker/src/features/blobstorage/handleBlobStorageIntegrationSchedule.ts` | Scheduler (enqueues due jobs) |
+| File | Role |
+| --------------------------------------------------------------------------- | ------------------------------------------------- |
+| `deriveSyncStatus.ts` | Derives display status from DB fields |
+| `types.ts` | Form zod schema, `BlobStorageSyncStatus` type |
+| `exportSource.ts` | Export-source availability/options helpers (pure) |
+| `service.ts` | Upsert logic (web save path) |
+| `blobstorage-integration-router.ts` | tRPC router (save, runNow) |
+| `worker/src/features/blobstorage/handleBlobStorageIntegrationProjectJob.ts` | Worker job handler |
+| `worker/src/features/blobstorage/handleBlobStorageIntegrationSchedule.ts` | Scheduler (enqueues due jobs) |
+
+## UI Owner Map
+
+**Surface**: Project Settings → Integrations → Blob Storage — export
+configuration form plus sync status display.
+
+**Entry point**:
+`web/src/pages/project/[projectId]/settings/integrations/blobstorage.tsx`
+owns the lifecycle: the tRPC `get` query (with status-driven refetch
+interval), the sync-status badge, and page layout. It mounts the two
+feature components below.
+
+**Structure** (`components/`):
+
+| File | Role |
+| ------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------- |
+| `BlobStorageIntegrationContainer.tsx` | State layer: availability derivation, the four mutations, entity-action buttons (Validate / Run Now / Reset), loading gate, identity key |
+| `BlobStorageIntegrationForm.tsx` | Disposable draft layer: `useForm` + schema, fields, Save; no tRPC |
+| `formValues.ts` | Pure `buildBlobStorageFormValues()` + shared `BlobStorageFormControl` type |
+| `StorageProviderFields.tsx` | Provider select + provider-dependent connection fields |
+| `ExportScheduleFields.tsx` | Frequency, file type, export mode, custom start date |
+| `ExportSourceField.tsx` | Source selector + blocked-save alert (LFE-10296) |
+| `ExportFieldGroupsField.tsx` | Field-group checkboxes |
+| `GzipCompressionField.tsx` | Gzip toggle; self-hides for Parquet |
+| `BlobStorageStatusSection.tsx` | Status header, last-error alert, sync card |
+
+**External consumers**: none — the components are only mounted by the
+settings page above.
+
+**State ownership — draft-lifetime model**: server state lives in the
+tRPC query (page). Form state is a **disposable draft scoped to one
+entity identity**: the container mounts `BlobStorageIntegrationForm`
+keyed on `projectId` + config existence, only after the query and
+project have resolved. Initial values flow in once via `defaultValues`;
+edits flow out only via `onSubmit`. There is no reset path at all — no
+reactive `values`, no `resetOptions`, no reset `useEffect`. Identity
+changes (project switch, create, delete) remount the form; same-entity
+refetches (5s status poll, post-save invalidation) keep the key stable
+and therefore can never wipe or leak a draft. Consequence, by design:
+clean fields do not live-update from background refetches while the
+form is mounted. Field-group components receive the typed `control`
+prop and subscribe to individual fields with `useWatch`; there is no
+local Zustand store and no feature `useEffect`.
+
+**Performance boundaries**: a keystroke or select change rerenders only
+the field-group component watching that field. The form layer reads no
+field values and holds no async state; mutation pending-state lives in
+the container.
diff --git a/web/src/features/blobstorage-integration/components/BlobStorageIntegrationContainer.tsx b/web/src/features/blobstorage-integration/components/BlobStorageIntegrationContainer.tsx
new file mode 100644
index 0000000000..c6239430f0
--- /dev/null
+++ b/web/src/features/blobstorage-integration/components/BlobStorageIntegrationContainer.tsx
@@ -0,0 +1,174 @@
+import { useMemo } from "react";
+import { Button } from "@/src/components/ui/button";
+import { Skeleton } from "@/src/components/ui/skeleton";
+import { usePostHogClientCapture } from "@/src/features/posthog-analytics/usePostHogClientCapture";
+import { showSuccessToast } from "@/src/features/notifications/showSuccessToast";
+import { showErrorToast } from "@/src/features/notifications/showErrorToast";
+import { api } from "@/src/utils/api";
+import {
+ isLegacyBlobExportAllowed,
+ isLegacyBlobExporter,
+ type BlobStorageIntegration,
+} from "@langfuse/shared";
+import {
+ parquetEnabledFromTuning,
+ type BlobStorageIntegrationFormSchema,
+} from "@/src/features/blobstorage-integration/types";
+import { useLangfuseCloudRegion } from "@/src/features/organizations/hooks";
+import { useQueryProject } from "@/src/features/projects/hooks";
+import { buildBlobStorageFormValues } from "@/src/features/blobstorage-integration/components/formValues";
+import { BlobStorageIntegrationForm } from "@/src/features/blobstorage-integration/components/BlobStorageIntegrationForm";
+
+// State layer. Owns everything async and entity-scoped: availability
+// derivation, the four mutations, and the entity-action buttons. The form
+// below it is a disposable draft: it is not mounted until every input has
+// resolved, and it is remounted (via key) whenever the entity identity
+// changes — project switch, create, delete. Background refetches of the
+// same entity (status poll, post-save invalidation) keep the key stable so
+// they can never touch a draft in progress.
+export const BlobStorageIntegrationContainer = ({
+ config,
+ projectId,
+ isLoading,
+ isEnrichedExportAvailable,
+}: {
+ config: Partial<BlobStorageIntegration> | null;
+ projectId: string;
+ isLoading: boolean;
+ isEnrichedExportAvailable: boolean;
+}) => {
+ const capture = usePostHogClientCapture();
+ const { isLangfuseCloud } = useLangfuseCloudRegion();
+ const { project } = useQueryProject();
+
+ const isPostCutoffCloud =
+ project?.createdAt != null &&
+ !isLegacyBlobExportAllowed(new Date(project.createdAt), isLangfuseCloud);
+ const eventsExportAvailable = isEnrichedExportAvailable;
+ // 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(
+ config?.createdAt ? new Date(config.createdAt) : null,
+ isLangfuseCloud,
+ );
+ const forceEventsExport =
+ isPostCutoffCloud || (eventsExportAvailable && !isLegacyExporter);
+ const availability = useMemo(
+ () => ({ eventsExportAvailable, forceEventsExport }),
+ [eventsExportAvailable, forceEventsExport],
+ );
+
+ const utils = api.useUtils();
+ const mut = api.blobStorageIntegration.update.useMutation({
+ onSuccess: () => {
+ utils.blobStorageIntegration.invalidate();
+ },
+ onError: (error) => {
+ showErrorToast("Failed to save integration", error.message);
+ },
+ });
+ const mutDelete = api.blobStorageIntegration.delete.useMutation({
+ onSuccess: () => {
+ utils.blobStorageIntegration.invalidate();
+ },
+ });
+ const mutRunNow = api.blobStorageIntegration.runNow.useMutation({
+ onSuccess: () => {
+ utils.blobStorageIntegration.invalidate();
+ },
+ });
+ const mutValidate = api.blobStorageIntegration.validate.useMutation({
+ onSuccess: (data) => {
+ showSuccessToast({
+ title: data.message,
+ description: `Test file: ${data.testFileName}`,
+ });
+ },
+ onError: (error) => {
+ showErrorToast("Validation failed", error.message);
+ },
+ });
+
+ // The form is never mounted before its inputs resolve, so there is no
+ // mid-flight reset to protect a draft from.
+ if (isLoading || !project) {
+ return (
+ <div className="space-y-3">
+ <Skeleton className="h-9 w-full" />
+ <Skeleton className="h-9 w-full" />
+ <Skeleton className="h-9 w-full" />
+ </div>
+ );
+ }
+
+ const handleSubmit = (values: BlobStorageIntegrationFormSchema) => {
+ capture("integrations:blob_storage_form_submitted");
+ mut.mutate({
+ projectId,
+ ...values,
+ });
+ };
+
+ return (
+ <BlobStorageIntegrationForm
+ // Draft lifetime = entity identity. Deliberately NOT updatedAt:
+ // exists→exists refetches (5s status poll, post-update refetch) must
+ // not remount, so mid-save typing survives. Delete flips
+ // configured→new and remounts blank; create flips new→configured and
+ // remounts from the saved row (clearing stale dirty flags).
+ key={`${projectId}:${config ? "configured" : "new"}`}
+ initialValues={buildBlobStorageFormValues(
+ config ?? undefined,
+ availability,
+ )}
+ availability={availability}
+ persistedExportSource={config?.exportSource}
+ isParquetOverride={parquetEnabledFromTuning(config?.exportTuning)}
+ isSaving={mut.isPending}
+ onSubmit={handleSubmit}
+ >
+ <Button
+ variant="secondary"
+ loading={mutValidate.isPending}
+ disabled={!config}
+ title="Test your saved configuration by uploading a small test file to your storage"
+ onClick={() => {
+ mutValidate.mutate({ projectId });
+ }}
+ >
+ Validate
+ </Button>
+ <Button
+ variant="secondary"
+ loading={mutRunNow.isPending}
+ disabled={!config?.enabled}
+ title="Trigger an immediate export of all data since the last sync"
+ onClick={() => {
+ if (
+ confirm(
+ "Are you sure you want to run the blob storage export now? This will export all data since the last sync.",
+ )
+ )
+ mutRunNow.mutate({ projectId });
+ }}
+ >
+ Run Now
+ </Button>
+ <Button
+ variant="ghost"
+ loading={mutDelete.isPending}
+ disabled={!config}
+ onClick={() => {
+ if (
+ confirm(
+ "Are you sure you want to reset the Blob Storage integration for this project?",
+ )
+ )
+ mutDelete.mutate({ projectId });
+ }}
+ >
+ Reset
+ </Button>
+ </BlobStorageIntegrationForm>
+ );
+};
diff --git a/web/src/features/blobstorage-integration/components/BlobStorageIntegrationForm.clienttest.tsx b/web/src/features/blobstorage-integration/components/BlobStorageIntegrationForm.clienttest.tsx
new file mode 100644
index 0000000000..0a223c4807
--- /dev/null
+++ b/web/src/features/blobstorage-integration/components/BlobStorageIntegrationForm.clienttest.tsx
@@ -0,0 +1,167 @@
+import { fireEvent, render, screen, waitFor } from "@testing-library/react";
+import {
+ BlobStorageIntegrationFileType,
+ BlobStorageIntegrationType,
+ type BlobStorageIntegration,
+} from "@langfuse/shared";
+import { TooltipProvider } from "@/src/components/ui/tooltip";
+import { BlobStorageIntegrationForm } from "./BlobStorageIntegrationForm";
+import {
+ buildBlobStorageFormValues,
+ type BlobStorageFormValues,
+} from "./formValues";
+import { type ExportSourceAvailability } from "@/src/features/blobstorage-integration/exportSource";
+
+// EVENTS-only deployment: single selectable source, selector hidden —
+// keeps the rendered tree small and the submit payload valid.
+const availability: ExportSourceAvailability = {
+ eventsExportAvailable: true,
+ forceEventsExport: true,
+};
+
+const savedConfig: Partial<BlobStorageIntegration> = {
+ type: BlobStorageIntegrationType.S3,
+ bucketName: "seed-bucket",
+ region: "us-east-1",
+ accessKeyId: "AKIA-SEED",
+ fileType: BlobStorageIntegrationFileType.JSONL,
+ enabled: true,
+};
+
+const ui = (
+ key: string,
+ initialValues: BlobStorageFormValues,
+ onSubmit: (values: unknown) => void = () => {},
+) => (
+ <TooltipProvider>
+ <BlobStorageIntegrationForm
+ key={key}
+ initialValues={initialValues}
+ availability={availability}
+ persistedExportSource={null}
+ isParquetOverride={false}
+ isSaving={false}
+ onSubmit={onSubmit}
+ />
+ </TooltipProvider>
+);
+
+const bucketInput = () =>
+ screen.getByLabelText("Bucket Name") as HTMLInputElement;
+
+describe("BlobStorageIntegrationForm draft lifetime (keyed remount)", () => {
+ beforeAll(() => {
+ vi.stubGlobal(
+ "ResizeObserver",
+ class {
+ observe() {}
+ unobserve() {}
+ disconnect() {}
+ },
+ );
+ Element.prototype.scrollIntoView = vi.fn();
+ Element.prototype.hasPointerCapture = vi.fn();
+ Element.prototype.releasePointerCapture = vi.fn();
+ });
+
+ it("delete flow: dirty configured form + key flip to 'new' renders blank defaults", () => {
+ const { rerender } = render(
+ ui(
+ "p1:configured",
+ buildBlobStorageFormValues(savedConfig, availability),
+ ),
+ );
+ fireEvent.change(bucketInput(), { target: { value: "edited-bucket" } });
+ expect(bucketInput()).toHaveValue("edited-bucket");
+
+ // Container behavior after delete: config becomes null → key flips.
+ rerender(ui("p1:new", buildBlobStorageFormValues(undefined, availability)));
+
+ expect(bucketInput()).toHaveValue("");
+ expect(screen.getByLabelText("Region")).toHaveValue("auto");
+ });
+
+ it("project switch: key change discards unsaved input from the previous project", () => {
+ const { rerender } = render(
+ ui("p1:new", buildBlobStorageFormValues(undefined, availability)),
+ );
+ fireEvent.change(bucketInput(), {
+ target: { value: "project-a-secret-bucket" },
+ });
+ fireEvent.change(screen.getByLabelText(/Access Key ID/), {
+ target: { value: "AKIA-PROJECT-A" },
+ });
+
+ rerender(ui("p2:new", buildBlobStorageFormValues(undefined, availability)));
+
+ expect(bucketInput()).toHaveValue("");
+ expect(screen.getByLabelText(/Access Key ID/)).toHaveValue("");
+ });
+
+ it("post-create: key flip to 'configured' initializes from the saved config", () => {
+ const { rerender } = render(
+ ui("p1:new", buildBlobStorageFormValues(undefined, availability)),
+ );
+ fireEvent.change(bucketInput(), { target: { value: "typed-before-save" } });
+
+ rerender(
+ ui(
+ "p1:configured",
+ buildBlobStorageFormValues(savedConfig, availability),
+ ),
+ );
+
+ expect(bucketInput()).toHaveValue("seed-bucket");
+ expect(screen.getByLabelText("Region")).toHaveValue("us-east-1");
+ });
+
+ it("same key: rerender with new initialValues does NOT touch the mounted draft", () => {
+ // Container behavior during the 5s status poll: same entity refetches
+ // keep the key stable, so a draft in progress is never wiped.
+ const { rerender } = render(
+ ui(
+ "p1:configured",
+ buildBlobStorageFormValues(savedConfig, availability),
+ ),
+ );
+ fireEvent.change(bucketInput(), { target: { value: "mid-save-typing" } });
+
+ rerender(
+ ui(
+ "p1:configured",
+ buildBlobStorageFormValues(
+ { ...savedConfig, bucketName: "refetched-bucket" },
+ availability,
+ ),
+ ),
+ );
+
+ expect(bucketInput()).toHaveValue("mid-save-typing");
+ });
+
+ it("submit passes the draft values through unchanged", async () => {
+ const onSubmit = vi.fn();
+ render(
+ ui(
+ "p1:new",
+ buildBlobStorageFormValues(undefined, availability),
+ onSubmit,
+ ),
+ );
+ fireEvent.change(bucketInput(), { target: { value: "my-new-bucket" } });
+ fireEvent.click(screen.getByRole("button", { name: "Save" }));
+
+ await waitFor(() => expect(onSubmit).toHaveBeenCalledTimes(1));
+ expect(onSubmit).toHaveBeenCalledWith(
+ expect.objectContaining({
+ type: BlobStorageIntegrationType.S3,
+ bucketName: "my-new-bucket",
+ region: "auto",
+ exportFrequency: "daily",
+ fileType: BlobStorageIntegrationFileType.PARQUET,
+ enabled: false,
+ }),
+ expect.anything(),
+ );
+ });
+});
diff --git a/web/src/features/blobstorage-integration/components/BlobStorageIntegrationForm.tsx b/web/src/features/blobstorage-integration/components/BlobStorageIntegrationForm.tsx
new file mode 100644
index 0000000000..fdb70a7742
--- /dev/null
+++ b/web/src/features/blobstorage-integration/components/BlobStorageIntegrationForm.tsx
@@ -0,0 +1,139 @@
+import { useMemo, type ReactNode } from "react";
+import { useForm } from "react-hook-form";
+import { zodResolver } from "@hookform/resolvers/zod";
+import { Button } from "@/src/components/ui/button";
+import {
+ Form,
+ FormControl,
+ FormField,
+ FormItem,
+ FormLabel,
+ FormMessage,
+} from "@/src/components/ui/form";
+import { Switch } from "@/src/components/design-system/Switch/Switch";
+import { type AnalyticsIntegrationExportSource } from "@langfuse/shared";
+import {
+ blobStorageIntegrationFormSchema,
+ type BlobStorageIntegrationFormSchema,
+} from "@/src/features/blobstorage-integration/types";
+import {
+ isExportSourceSelectable,
+ type ExportSourceAvailability,
+} from "@/src/features/blobstorage-integration/exportSource";
+import { type BlobStorageFormValues } from "@/src/features/blobstorage-integration/components/formValues";
+import { StorageProviderFields } from "@/src/features/blobstorage-integration/components/StorageProviderFields";
+import { ExportScheduleFields } from "@/src/features/blobstorage-integration/components/ExportScheduleFields";
+import { ExportSourceField } from "@/src/features/blobstorage-integration/components/ExportSourceField";
+import { ExportFieldGroupsField } from "@/src/features/blobstorage-integration/components/ExportFieldGroupsField";
+import { GzipCompressionField } from "@/src/features/blobstorage-integration/components/GzipCompressionField";
+
+// Disposable draft layer. The container mounts one instance per entity
+// identity (project + config existence, via React key) after all async
+// inputs have resolved. Initial state flows in once through defaultValues;
+// edits flow out only through onSubmit. There is deliberately no reset
+// logic and no tRPC access here — a stale draft is discarded by remount,
+// never patched in place.
+export const BlobStorageIntegrationForm = ({
+ initialValues,
+ availability,
+ persistedExportSource,
+ isParquetOverride,
+ isSaving,
+ onSubmit,
+ children,
+}: {
+ initialValues: BlobStorageFormValues;
+ availability: ExportSourceAvailability;
+ persistedExportSource: AnalyticsIntegrationExportSource | null | undefined;
+ // Internal `exportTuning.parquet` override (no write path); reflected
+ // read-only since the worker forces Parquet over the persisted fileType
+ // + gzip.
+ isParquetOverride: boolean;
+ isSaving: boolean;
+ onSubmit: (values: BlobStorageIntegrationFormSchema) => void;
+ // Entity-scoped action buttons (Validate / Run Now / Reset) rendered by
+ // the container next to Save — they act on the persisted entity, not on
+ // this draft.
+ children?: ReactNode;
+}) => {
+ // Block the save when the persisted source is no longer selectable rather
+ // than silently rewriting it (LFE-10296). Availability is fixed for the
+ // lifetime of this mount: it derives from the project and config identity,
+ // and any identity change remounts the form via the container key.
+ 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(formSchema),
+ defaultValues: initialValues,
+ });
+
+ const control = blobStorageForm.control;
+
+ return (
+ <Form {...blobStorageForm}>
+ <form
+ className="space-y-3"
+ onSubmit={blobStorageForm.handleSubmit(onSubmit)}
+ >
+ <StorageProviderFields control={control} />
+ <ExportScheduleFields
+ control={control}
+ isParquetOverride={isParquetOverride}
+ />
+ <ExportSourceField
+ control={control}
+ persistedExportSource={persistedExportSource}
+ availability={availability}
+ />
+ <ExportFieldGroupsField
+ control={control}
+ isParquetOverride={isParquetOverride}
+ />
+ <GzipCompressionField
+ control={control}
+ isParquetOverride={isParquetOverride}
+ />
+ <FormField
+ control={control}
+ name="enabled"
+ render={({ field }) => (
+ <FormItem>
+ <FormLabel>Enabled</FormLabel>
+ <FormControl>
+ <div className="mt-1 ml-4">
+ <Switch
+ checked={field.value}
+ onCheckedChange={field.onChange}
+ />
+ </div>
+ </FormControl>
+ <FormMessage />
+ </FormItem>
+ )}
+ />
+ </form>
+ <div className="mt-8 flex gap-2">
+ <Button
+ loading={isSaving}
+ onClick={blobStorageForm.handleSubmit(onSubmit)}
+ >
+ Save
+ </Button>
+ {children}
+ </div>
+ </Form>
+ );
+};
diff --git a/web/src/features/blobstorage-integration/components/BlobStorageStatusSection.tsx b/web/src/features/blobstorage-integration/components/BlobStorageStatusSection.tsx
new file mode 100644
index 0000000000..0991c55a44
--- /dev/null
+++ b/web/src/features/blobstorage-integration/components/BlobStorageStatusSection.tsx
@@ -0,0 +1,73 @@
+import Header from "@/src/components/layouts/header";
+import { Alert, AlertDescription, AlertTitle } from "@/src/components/ui/alert";
+import { Card } from "@/src/components/ui/card";
+import { BlobStorageExportMode } from "@langfuse/shared";
+import { type RouterOutputs } from "@/src/utils/api";
+
+type BlobStorageIntegrationConfig = NonNullable<
+ RouterOutputs["blobStorageIntegration"]["get"]["config"]
+>;
+
+const EXPORT_MODE_LABELS: Record<BlobStorageExportMode, string> = {
+ [BlobStorageExportMode.FULL_HISTORY]: "Full history",
+ [BlobStorageExportMode.FROM_TODAY]: "From setup date",
+ [BlobStorageExportMode.FROM_CUSTOM_DATE]: "From custom date",
+};
+
+export const BlobStorageStatusSection = ({
+ config,
+}: {
+ config: BlobStorageIntegrationConfig;
+}) => {
+ return (
+ <>
+ <Header title="Status" />
+ {config.lastError && (
+ <Alert variant="destructive" className="mb-4">
+ <AlertTitle>Last export failed</AlertTitle>
+ <AlertDescription>
+ {config.lastError}
+ {config.lastErrorAt && (
+ <>
+ <br />
+ <span className="text-xs opacity-70">
+ {new Date(config.lastErrorAt).toLocaleString()}
+ </span>
+ </>
+ )}
+ </AlertDescription>
+ </Alert>
+ )}
+ <Card className="p-3">
+ <div className="grid grid-cols-[auto,1fr] gap-x-4 gap-y-1 text-sm">
+ <span className="text-muted-foreground">Data exported up to</span>
+ <span>
+ {config.lastSyncAt
+ ? new Date(config.lastSyncAt).toLocaleString()
+ : "Never (pending)"}
+ </span>
+ {config.nextSyncAt && (
+ <>
+ <span className="text-muted-foreground">
+ Next export scheduled
+ </span>
+ <span>{new Date(config.nextSyncAt).toLocaleString()}</span>
+ </>
+ )}
+ <span className="text-muted-foreground">Export mode</span>
+ <span>{EXPORT_MODE_LABELS[config.exportMode] ?? "Unknown"}</span>
+ {(config.exportMode === BlobStorageExportMode.FROM_CUSTOM_DATE ||
+ config.exportMode === BlobStorageExportMode.FROM_TODAY) &&
+ config.exportStartDate && (
+ <>
+ <span className="text-muted-foreground">Export start date</span>
+ <span>
+ {new Date(config.exportStartDate).toLocaleDateString()}
+ </span>
+ </>
+ )}
+ </div>
+ </Card>
+ </>
+ );
+};
diff --git a/web/src/features/blobstorage-integration/components/ExportFieldGroupsField.tsx b/web/src/features/blobstorage-integration/components/ExportFieldGroupsField.tsx
new file mode 100644
index 0000000000..194f167ac0
--- /dev/null
+++ b/web/src/features/blobstorage-integration/components/ExportFieldGroupsField.tsx
@@ -0,0 +1,133 @@
+import { useFormState, useWatch } from "react-hook-form";
+import { Checkbox } from "@/src/components/ui/checkbox";
+import {
+ FormDescription,
+ FormField,
+ FormItem,
+ FormLabel,
+ FormMessage,
+} from "@/src/components/ui/form";
+import {
+ AnalyticsIntegrationExportSource,
+ BlobStorageIntegrationFileType,
+ EXPORT_FIELD_GROUP_OPTIONS,
+ type ObservationFieldGroupFull,
+} from "@langfuse/shared";
+import { type BlobStorageFormControl } from "@/src/features/blobstorage-integration/components/formValues";
+
+// Field-group checkboxes; descriptions and available groups depend on the
+// selected export source and file type.
+export const ExportFieldGroupsField = ({
+ control,
+ isParquetOverride,
+}: {
+ control: BlobStorageFormControl;
+ isParquetOverride: boolean;
+}) => {
+ const [watchedExportSource, watchedFileType] = useWatch({
+ control,
+ name: ["exportSource", "fileType"],
+ });
+ const { errors } = useFormState({ control, name: "exportFieldGroups" });
+ const isParquetExport =
+ isParquetOverride ||
+ watchedFileType === BlobStorageIntegrationFileType.PARQUET;
+ // The legacy observations table contains fewer columns than the enriched
+ // observations, so the per-group field lists differ for legacy-only exports.
+ const isLegacyOnlyExport =
+ watchedExportSource ===
+ AnalyticsIntegrationExportSource.TRACES_OBSERVATIONS;
+ // Traces and legacy observations are only exported for the legacy and mixed
+ // sources; an EVENTS-only export produces scores and enriched observations.
+ const includesLegacyExport =
+ watchedExportSource ===
+ AnalyticsIntegrationExportSource.TRACES_OBSERVATIONS ||
+ watchedExportSource ===
+ AnalyticsIntegrationExportSource.TRACES_OBSERVATIONS_EVENTS;
+
+ return (
+ <FormField
+ control={control}
+ name="exportFieldGroups"
+ render={({ field }) => (
+ <FormItem>
+ <FormLabel>Export Field Groups</FormLabel>
+ <FormDescription>
+ Choose which field groups to include in the observation exports.
+ Deselect large groups (e.g. Input / Output) to reduce export size,
+ or privacy-sensitive groups (e.g. Metadata) to avoid storing user
+ data.
+ {includesLegacyExport
+ ? isLegacyOnlyExport
+ ? " Traces and scores are always exported in full. Field groups that only exist on the enriched observations (e.g. Trace Context) are not available for this export source."
+ : " Traces and scores are always exported in full. Fields that only exist on the enriched observations (e.g. Trace Context) are omitted from the legacy observations export."
+ : " Scores are always exported in full."}
+ </FormDescription>
+ <div className="mt-2 space-y-2">
+ {EXPORT_FIELD_GROUP_OPTIONS.filter(
+ // Hide no-op groups (no legacy columns) for legacy-only
+ // exports; a saved selection is kept and applies again if
+ // the source is migrated to enriched observations.
+ (option) => !isLegacyOnlyExport || option.includedInLegacyExport,
+ ).map((option) => {
+ const isCore = option.value === "core";
+ return (
+ <div key={option.value} className="flex items-start gap-2">
+ <Checkbox
+ id={`field-group-${option.value}`}
+ checked={
+ isCore ? true : (field.value ?? []).includes(option.value)
+ }
+ disabled={isCore}
+ onCheckedChange={
+ isCore
+ ? undefined
+ : (checked) => {
+ const current = field.value ?? [];
+ const next =
+ checked === true
+ ? current.includes(option.value)
+ ? current
+ : [...current, option.value]
+ : current.filter(
+ (v: ObservationFieldGroupFull) =>
+ v !== option.value,
+ );
+ field.onChange(next);
+ }
+ }
+ />
+ <label
+ htmlFor={`field-group-${option.value}`}
+ className={
+ isCore ? "space-y-0.5" : "cursor-pointer space-y-0.5"
+ }
+ >
+ <div className="text-sm leading-none font-medium">
+ {option.label}
+ {isCore && (
+ <span className="text-muted-foreground ml-1 font-normal">
+ (required)
+ </span>
+ )}
+ </div>
+ <div className="text-muted-foreground text-xs">
+ {isParquetExport
+ ? isLegacyOnlyExport
+ ? option.legacyParquetDescription
+ : option.parquetDescription
+ : isLegacyOnlyExport
+ ? option.legacyDescription
+ : option.description}
+ </div>
+ </label>
+ </div>
+ );
+ })}
+ </div>
+ <FormMessage>{errors.exportFieldGroups?.message}</FormMessage>
+ </FormItem>
+ )}
+ />
+ );
+};
diff --git a/web/src/features/blobstorage-integration/components/ExportScheduleFields.tsx b/web/src/features/blobstorage-integration/components/ExportScheduleFields.tsx
new file mode 100644
index 0000000000..4b84a52a4f
--- /dev/null
+++ b/web/src/features/blobstorage-integration/components/ExportScheduleFields.tsx
@@ -0,0 +1,176 @@
+import { useWatch } from "react-hook-form";
+import {
+ FormControl,
+ FormDescription,
+ FormField,
+ FormItem,
+ FormLabel,
+ FormMessage,
+} from "@/src/components/ui/form";
+import { Input } from "@/src/components/ui/input";
+import {
+ Select,
+ SelectContent,
+ SelectItem,
+ SelectTrigger,
+ SelectValue,
+} from "@/src/components/ui/select";
+import {
+ BlobStorageExportMode,
+ BlobStorageIntegrationFileType,
+} from "@langfuse/shared";
+import { type BlobStorageFormControl } from "@/src/features/blobstorage-integration/components/formValues";
+
+// Frequency, file type, and export mode (with the custom start date when the
+// mode requires one).
+export const ExportScheduleFields = ({
+ control,
+ isParquetOverride,
+}: {
+ control: BlobStorageFormControl;
+ // Internal `exportTuning.parquet` override (no write path); reflected
+ // read-only since the worker forces Parquet over the persisted fileType.
+ isParquetOverride: boolean;
+}) => {
+ const watchedExportMode = useWatch({ control, name: "exportMode" });
+
+ return (
+ <>
+ <FormField
+ control={control}
+ name="exportFrequency"
+ render={({ field }) => (
+ <FormItem>
+ <FormLabel>Export Frequency</FormLabel>
+ <FormControl>
+ <Select value={field.value} onValueChange={field.onChange}>
+ <SelectTrigger>
+ <SelectValue placeholder="Select frequency" />
+ </SelectTrigger>
+ <SelectContent>
+ <SelectItem value="every_20_minutes">
+ Every 20 Minutes
+ </SelectItem>
+ <SelectItem value="hourly">Hourly</SelectItem>
+ <SelectItem value="daily">Daily</SelectItem>
+ <SelectItem value="weekly">Weekly</SelectItem>
+ </SelectContent>
+ </Select>
+ </FormControl>
+ <FormDescription>
+ How often the data should be exported. Changes are taken into
+ consideration from the next run onwards.
+ </FormDescription>
+ <FormMessage />
+ </FormItem>
+ )}
+ />
+
+ <FormField
+ control={control}
+ name="fileType"
+ render={({ field }) => (
+ <FormItem>
+ <FormLabel>File Type</FormLabel>
+ <FormControl>
+ <Select
+ value={isParquetOverride ? "PARQUET" : field.value}
+ onValueChange={field.onChange}
+ disabled={isParquetOverride}
+ >
+ <SelectTrigger>
+ <SelectValue placeholder="Select file type" />
+ </SelectTrigger>
+ <SelectContent>
+ <SelectItem value="PARQUET">Parquet</SelectItem>
+ <SelectItem value="JSONL">JSONL</SelectItem>
+ <SelectItem value="CSV">CSV</SelectItem>
+ <SelectItem value="JSON">JSON</SelectItem>
+ </SelectContent>
+ </Select>
+ </FormControl>
+ <FormDescription>
+ {isParquetOverride
+ ? "Exporting as Apache Parquet — a columnar binary format encoded and compressed by ClickHouse. This is configured for your project and overrides the file type; gzip compression is not applicable."
+ : field.value === BlobStorageIntegrationFileType.PARQUET
+ ? "Apache Parquet — a columnar binary format encoded and compressed by ClickHouse. Gzip compression does not apply."
+ : "The file format for exported data."}
+ </FormDescription>
+ <FormMessage />
+ </FormItem>
+ )}
+ />
+
+ <FormField
+ control={control}
+ name="exportMode"
+ render={({ field }) => (
+ <FormItem>
+ <FormLabel>Export Mode</FormLabel>
+ <FormControl>
+ <Select value={field.value} onValueChange={field.onChange}>
+ <SelectTrigger>
+ <SelectValue placeholder="Select export mode" />
+ </SelectTrigger>
+ <SelectContent>
+ <SelectItem value={BlobStorageExportMode.FULL_HISTORY}>
+ Full history
+ </SelectItem>
+ <SelectItem value={BlobStorageExportMode.FROM_TODAY}>
+ Today
+ </SelectItem>
+ <SelectItem value={BlobStorageExportMode.FROM_CUSTOM_DATE}>
+ Custom date
+ </SelectItem>
+ </SelectContent>
+ </Select>
+ </FormControl>
+ <FormDescription>
+ Choose when to start exporting data. &quot;Today&quot; and
+ &quot;Custom date&quot; modes will not include historical data
+ before the specified date.
+ </FormDescription>
+ <FormMessage />
+ </FormItem>
+ )}
+ />
+
+ {watchedExportMode === BlobStorageExportMode.FROM_CUSTOM_DATE && (
+ <FormField
+ control={control}
+ name="exportStartDate"
+ render={({ field }) => (
+ <FormItem>
+ <FormLabel>Export Start Date</FormLabel>
+ <FormControl>
+ <Input
+ type="date"
+ max={(() => {
+ const t = new Date();
+ return `${t.getFullYear()}-${String(t.getMonth() + 1).padStart(2, "0")}-${String(t.getDate()).padStart(2, "0")}`;
+ })()}
+ value={
+ field.value instanceof Date
+ ? field.value.toISOString().split("T")[0]
+ : ""
+ }
+ onChange={(e) => {
+ const date = e.target.value
+ ? new Date(e.target.value)
+ : null;
+ field.onChange(date);
+ }}
+ placeholder="Select start date"
+ />
+ </FormControl>
+ <FormDescription>
+ Data before this date will not be included in exports
+ </FormDescription>
+ <FormMessage />
+ </FormItem>
+ )}
+ />
+ )}
+ </>
+ );
+};
diff --git a/web/src/features/blobstorage-integration/components/ExportSourceField.tsx b/web/src/features/blobstorage-integration/components/ExportSourceField.tsx
new file mode 100644
index 0000000000..f44b12a228
--- /dev/null
+++ b/web/src/features/blobstorage-integration/components/ExportSourceField.tsx
@@ -0,0 +1,148 @@
+import { useWatch } from "react-hook-form";
+import { Info, ExternalLink } from "lucide-react";
+import { Alert, AlertDescription, AlertTitle } from "@/src/components/ui/alert";
+import {
+ FormControl,
+ FormDescription,
+ FormField,
+ FormItem,
+ FormLabel,
+ FormMessage,
+} from "@/src/components/ui/form";
+import {
+ Select,
+ SelectContent,
+ SelectItem,
+ SelectTrigger,
+ SelectValue,
+} from "@/src/components/ui/select";
+import {
+ Tooltip,
+ TooltipContent,
+ TooltipTrigger,
+} from "@/src/components/ui/tooltip";
+import { type AnalyticsIntegrationExportSource } from "@langfuse/shared";
+import {
+ getExportSourceOptions,
+ isExportSourceSelectable,
+ shouldHideExportSourceSelector,
+ type ExportSourceAvailability,
+} from "@/src/features/blobstorage-integration/exportSource";
+import { type BlobStorageFormControl } from "@/src/features/blobstorage-integration/components/formValues";
+
+// Export source selector plus the blocked-save alert for a persisted source
+// that is no longer selectable on this deployment.
+export const ExportSourceField = ({
+ control,
+ persistedExportSource,
+ availability,
+}: {
+ control: BlobStorageFormControl;
+ persistedExportSource: AnalyticsIntegrationExportSource | null | undefined;
+ availability: ExportSourceAvailability;
+}) => {
+ const watchedExportSource = useWatch({ control, name: "exportSource" });
+ const exportSourceOptions = getExportSourceOptions(
+ persistedExportSource,
+ availability,
+ );
+ // No decision to make → no selector. Only the degenerate single-option
+ // state (stale persisted source) stays visible, locked, so the
+ // unavailable-source alert below has something to refer to.
+ const hideExportSource = shouldHideExportSourceSelector(exportSourceOptions);
+ const exportSourceLocked = exportSourceOptions.length === 1;
+ const exportSourceUnavailable =
+ watchedExportSource != null &&
+ !isExportSourceSelectable(watchedExportSource, availability);
+
+ return (
+ <>
+ {!hideExportSource && (
+ <FormField
+ control={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>
+ ))}
+ <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>
+ )}
+ </>
+ );
+};
diff --git a/web/src/features/blobstorage-integration/components/GzipCompressionField.tsx b/web/src/features/blobstorage-integration/components/GzipCompressionField.tsx
new file mode 100644
index 0000000000..a2fd893517
--- /dev/null
+++ b/web/src/features/blobstorage-integration/components/GzipCompressionField.tsx
@@ -0,0 +1,48 @@
+import { useWatch } from "react-hook-form";
+import {
+ FormControl,
+ FormDescription,
+ FormField,
+ FormItem,
+ FormLabel,
+ FormMessage,
+} from "@/src/components/ui/form";
+import { Switch } from "@/src/components/design-system/Switch/Switch";
+import { BlobStorageIntegrationFileType } from "@langfuse/shared";
+import { type BlobStorageFormControl } from "@/src/features/blobstorage-integration/components/formValues";
+
+export const GzipCompressionField = ({
+ control,
+ isParquetOverride,
+}: {
+ control: BlobStorageFormControl;
+ isParquetOverride: boolean;
+}) => {
+ const watchedFileType = useWatch({ control, name: "fileType" });
+ // Parquet compresses internally — gzip does not apply.
+ const isParquetExport =
+ isParquetOverride ||
+ watchedFileType === BlobStorageIntegrationFileType.PARQUET;
+ if (isParquetExport) return null;
+
+ return (
+ <FormField
+ control={control}
+ name="compressed"
+ render={({ field }) => (
+ <FormItem>
+ <FormLabel>Gzip Compression</FormLabel>
+ <FormControl>
+ <div className="mt-1 ml-4">
+ <Switch checked={field.value} onCheckedChange={field.onChange} />
+ </div>
+ </FormControl>
+ <FormDescription>
+ Compress exported files with gzip (.csv.gz, .json.gz, .jsonl.gz)
+ </FormDescription>
+ <FormMessage />
+ </FormItem>
+ )}
+ />
+ );
+};
diff --git a/web/src/features/blobstorage-integration/components/StorageProviderFields.tsx b/web/src/features/blobstorage-integration/components/StorageProviderFields.tsx
new file mode 100644
index 0000000000..df822b0c1b
--- /dev/null
+++ b/web/src/features/blobstorage-integration/components/StorageProviderFields.tsx
@@ -0,0 +1,254 @@
+import { useWatch } from "react-hook-form";
+import {
+ FormControl,
+ FormDescription,
+ FormField,
+ FormItem,
+ FormLabel,
+ FormMessage,
+} from "@/src/components/ui/form";
+import { Input } from "@/src/components/ui/input";
+import { PasswordInput } from "@/src/components/ui/password-input";
+import { Switch } from "@/src/components/design-system/Switch/Switch";
+import {
+ Select,
+ SelectContent,
+ SelectItem,
+ SelectTrigger,
+ SelectValue,
+} from "@/src/components/ui/select";
+import { BlobStorageIntegrationType } from "@langfuse/shared";
+import { useLangfuseCloudRegion } from "@/src/features/organizations/hooks";
+import { type BlobStorageFormControl } from "@/src/features/blobstorage-integration/components/formValues";
+
+// Provider selection plus the connection fields whose labels and visibility
+// depend on it: bucket/container, endpoint, region, path style, credentials,
+// and prefix.
+export const StorageProviderFields = ({
+ control,
+}: {
+ control: BlobStorageFormControl;
+}) => {
+ const { isLangfuseCloud } = useLangfuseCloudRegion();
+ // Check if this is a self-hosted instance (no cloud region set)
+ const isSelfHosted = !isLangfuseCloud;
+ const integrationType =
+ useWatch({ control, name: "type" }) ?? BlobStorageIntegrationType.S3;
+
+ return (
+ <>
+ <FormField
+ control={control}
+ name="type"
+ render={({ field }) => (
+ <FormItem>
+ <FormLabel>Storage Provider</FormLabel>
+ <FormControl>
+ <Select value={field.value} onValueChange={field.onChange}>
+ <SelectTrigger>
+ <SelectValue placeholder="Select provider" />
+ </SelectTrigger>
+ <SelectContent>
+ <SelectItem value="S3">AWS S3</SelectItem>
+ <SelectItem value="S3_COMPATIBLE">
+ S3 Compatible Storage
+ </SelectItem>
+ <SelectItem value="AZURE_BLOB_STORAGE">
+ Azure Blob Storage
+ </SelectItem>
+ </SelectContent>
+ </Select>
+ </FormControl>
+ <FormDescription>
+ Choose your cloud storage provider
+ </FormDescription>
+ <FormMessage />
+ </FormItem>
+ )}
+ />
+
+ <FormField
+ control={control}
+ name="bucketName"
+ render={({ field }) => (
+ <FormItem>
+ <FormLabel>
+ {integrationType === "AZURE_BLOB_STORAGE"
+ ? "Container Name"
+ : "Bucket Name"}
+ </FormLabel>
+ <FormControl>
+ <Input {...field} />
+ </FormControl>
+ <FormDescription>
+ {integrationType === "AZURE_BLOB_STORAGE"
+ ? "Azure container name (3-63 chars, lowercase letters, numbers, and hyphens only)"
+ : "The S3 bucket name"}
+ </FormDescription>
+ <FormMessage />
+ </FormItem>
+ )}
+ />
+
+ {/* Endpoint URL field - Only shown for S3-compatible and Azure */}
+ {integrationType !== "S3" && (
+ <FormField
+ control={control}
+ name="endpoint"
+ render={({ field }) => (
+ <FormItem>
+ <FormLabel>Endpoint URL</FormLabel>
+ <FormControl>
+ <Input {...field} value={field.value || ""} />
+ </FormControl>
+ <FormDescription>
+ {integrationType === "AZURE_BLOB_STORAGE"
+ ? "Azure Blob Storage endpoint URL (e.g., https://accountname.blob.core.windows.net)"
+ : "S3 compatible endpoint URL (e.g., https://play.min.io)"}
+ </FormDescription>
+ <FormMessage />
+ </FormItem>
+ )}
+ />
+ )}
+
+ {/* Region field - Only shown for AWS S3 or compatible storage */}
+ {integrationType !== "AZURE_BLOB_STORAGE" && (
+ <FormField
+ control={control}
+ name="region"
+ render={({ field }) => (
+ <FormItem>
+ <FormLabel>Region</FormLabel>
+ <FormControl>
+ <Input {...field} />
+ </FormControl>
+ <FormDescription>
+ {integrationType === "S3"
+ ? "AWS region (e.g., us-east-1)"
+ : "S3 compatible storage region"}
+ </FormDescription>
+ <FormMessage />
+ </FormItem>
+ )}
+ />
+ )}
+
+ {/* Force Path Style switch - Only shown for S3-compatible */}
+ {integrationType === "S3_COMPATIBLE" && (
+ <FormField
+ control={control}
+ name="forcePathStyle"
+ render={({ field }) => (
+ <FormItem>
+ <FormLabel>Force Path Style</FormLabel>
+ <FormControl>
+ <div className="mt-1 ml-4">
+ <Switch
+ checked={field.value}
+ onCheckedChange={field.onChange}
+ />
+ </div>
+ </FormControl>
+ <FormDescription>
+ Enable for MinIO and some other S3 compatible providers
+ </FormDescription>
+ <FormMessage />
+ </FormItem>
+ )}
+ />
+ )}
+
+ <FormField
+ control={control}
+ name="accessKeyId"
+ render={({ field }) => (
+ <FormItem>
+ <FormLabel>
+ {integrationType === "AZURE_BLOB_STORAGE"
+ ? "Storage Account Name"
+ : integrationType === "S3"
+ ? "AWS Access Key ID"
+ : "Access Key ID"}
+ {/* Show optional indicator for S3 types on self-hosted instances with entitlement */}
+ {isSelfHosted && integrationType === "S3" && (
+ <span className="text-muted-foreground"> (optional)</span>
+ )}
+ </FormLabel>
+ <FormControl>
+ <Input {...field} />
+ </FormControl>
+ <FormDescription>
+ {integrationType === "AZURE_BLOB_STORAGE"
+ ? "Your Azure storage account name"
+ : integrationType === "S3"
+ ? isSelfHosted
+ ? "Your AWS IAM user access key ID. Leave empty to use host credentials (IAM roles, instance profiles, etc.)"
+ : "Your AWS IAM user access key ID"
+ : "Access key for your S3-compatible storage"}
+ </FormDescription>
+ <FormMessage />
+ </FormItem>
+ )}
+ />
+
+ <FormField
+ control={control}
+ name="secretAccessKey"
+ render={({ field }) => (
+ <FormItem>
+ <FormLabel>
+ {integrationType === "AZURE_BLOB_STORAGE"
+ ? "Storage Account Key"
+ : integrationType === "S3"
+ ? "AWS Secret Access Key"
+ : "Secret Access Key"}
+ {/* Show optional indicator for S3 types on self-hosted instances with entitlement */}
+ {isSelfHosted && integrationType === "S3" && (
+ <span className="text-muted-foreground"> (optional)</span>
+ )}
+ </FormLabel>
+ <FormControl>
+ <PasswordInput
+ placeholder="********************"
+ {...field}
+ value={field.value || ""}
+ />
+ </FormControl>
+ <FormDescription>
+ {integrationType === "AZURE_BLOB_STORAGE"
+ ? "Your Azure storage account access key"
+ : integrationType === "S3"
+ ? isSelfHosted
+ ? "Your AWS IAM user secret access key. Leave empty to use host credentials (IAM roles, instance profiles, etc.)"
+ : "Your AWS IAM user secret access key"
+ : "Secret key for your S3-compatible storage"}
+ </FormDescription>
+ <FormMessage />
+ </FormItem>
+ )}
+ />
+
+ <FormField
+ control={control}
+ name="prefix"
+ render={({ field }) => (
+ <FormItem>
+ <FormLabel>Export Prefix</FormLabel>
+ <FormControl>
+ <Input {...field} />
+ </FormControl>
+ <FormDescription>
+ {integrationType === "AZURE_BLOB_STORAGE"
+ ? 'Optional prefix path for exported files in your Azure container (e.g., "langfuse-exports/")'
+ : integrationType === "S3"
+ ? 'Optional prefix path for exported files in your S3 bucket (e.g., "langfuse-exports/")'
+ : 'Optional prefix path for exported files (e.g., "langfuse-exports/")'}
+ </FormDescription>
+ <FormMessage />
+ </FormItem>
+ )}
+ />
+ </>
+ );
+};
diff --git a/web/src/features/blobstorage-integration/components/formValues.ts b/web/src/features/blobstorage-integration/components/formValues.ts
new file mode 100644
index 0000000000..198762371e
--- /dev/null
+++ b/web/src/features/blobstorage-integration/components/formValues.ts
@@ -0,0 +1,59 @@
+import { type Control } from "react-hook-form";
+import { type z } from "zod";
+import {
+ BlobStorageIntegrationType,
+ BlobStorageIntegrationFileType,
+ BlobStorageExportMode,
+ OBSERVATION_FIELD_GROUPS_FULL,
+ type BlobStorageIntegration,
+ type ObservationFieldGroupFull,
+} from "@langfuse/shared";
+import type {
+ blobStorageIntegrationFormSchema,
+ BlobStorageIntegrationFormSchema,
+} from "@/src/features/blobstorage-integration/types";
+import {
+ getExportSourceFormValue,
+ type ExportSourceAvailability,
+} from "@/src/features/blobstorage-integration/exportSource";
+
+// Pre-parse (input) shape of the form; zod defaults make some fields optional.
+export type BlobStorageFormValues = z.input<
+ typeof blobStorageIntegrationFormSchema
+>;
+
+// Control handle shared by the form's field-group components.
+export type BlobStorageFormControl = Control<
+ BlobStorageFormValues,
+ unknown,
+ BlobStorageIntegrationFormSchema
+>;
+
+export function buildBlobStorageFormValues(
+ state: Partial<BlobStorageIntegration> | undefined,
+ availability: ExportSourceAvailability,
+): BlobStorageFormValues {
+ return {
+ type: state?.type || BlobStorageIntegrationType.S3,
+ bucketName: state?.bucketName || "",
+ endpoint: state?.endpoint || null,
+ region: state?.region || "auto",
+ accessKeyId: state?.accessKeyId || "",
+ secretAccessKey: state?.secretAccessKey || null,
+ prefix: state?.prefix || "",
+ exportFrequency: (state?.exportFrequency ||
+ "daily") as BlobStorageFormValues["exportFrequency"],
+ enabled: state?.enabled || false,
+ forcePathStyle: state?.forcePathStyle || false,
+ fileType: state?.fileType || BlobStorageIntegrationFileType.PARQUET,
+ exportMode: state?.exportMode || BlobStorageExportMode.FULL_HISTORY,
+ exportStartDate: state?.exportStartDate || null,
+ 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
+ ? (state.exportFieldGroups as ObservationFieldGroupFull[])
+ : [...OBSERVATION_FIELD_GROUPS_FULL],
+ compressed: state?.compressed ?? true,
+ };
+}
diff --git a/web/src/pages/project/[projectId]/settings/integrations/blobstorage.tsx b/web/src/pages/project/[projectId]/settings/integrations/blobstorage.tsx
index 32283a516e..4633772678 100644
--- a/web/src/pages/project/[projectId]/settings/integrations/blobstorage.tsx
+++ b/web/src/pages/project/[projectId]/settings/integrations/blobstorage.tsx
@@ -2,71 +2,35 @@ import Header from "@/src/components/layouts/header";
import ContainerPage from "@/src/components/layouts/container-page";
import { StatusBadge } from "@/src/components/layouts/status-badge";
import { Button } from "@/src/components/ui/button";
-import {
- Form,
- FormControl,
- FormDescription,
- FormField,
- FormItem,
- FormLabel,
- FormMessage,
-} from "@/src/components/ui/form";
-import { Input } from "@/src/components/ui/input";
-import { PasswordInput } from "@/src/components/ui/password-input";
-import { Switch } from "@/src/components/design-system/Switch/Switch";
-import { Checkbox } from "@/src/components/ui/checkbox";
-import {
- Select,
- SelectContent,
- SelectItem,
- SelectTrigger,
- SelectValue,
-} from "@/src/components/ui/select";
-import {
- Tooltip,
- TooltipTrigger,
- TooltipContent,
-} from "@/src/components/ui/tooltip";
-import { usePostHogClientCapture } from "@/src/features/posthog-analytics/usePostHogClientCapture";
-import {
- blobStorageIntegrationFormSchema,
- parquetEnabledFromTuning,
- type BlobStorageIntegrationFormSchema,
- type BlobStorageSyncStatus,
-} from "@/src/features/blobstorage-integration/types";
-import { deriveSyncStatus } from "@/src/features/blobstorage-integration/deriveSyncStatus";
-import { Alert, AlertTitle, AlertDescription } from "@/src/components/ui/alert";
-import { useHasProjectAccess } from "@/src/features/rbac/utils/checkProjectAccess";
-import { api } from "@/src/utils/api";
-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, useMemo } from "react";
-import { useForm } from "react-hook-form";
-import { showSuccessToast } from "@/src/features/notifications/showSuccessToast";
-import { showErrorToast } from "@/src/features/notifications/showErrorToast";
-import {
- BlobStorageIntegrationType,
- BlobStorageIntegrationFileType,
- BlobStorageExportMode,
- AnalyticsIntegrationExportSource,
- type BlobStorageIntegration,
- EXPORT_FIELD_GROUP_OPTIONS,
- OBSERVATION_FIELD_GROUPS_FULL,
- type ObservationFieldGroupFull,
- isLegacyBlobExportAllowed,
- isLegacyBlobExporter,
-} from "@langfuse/shared";
-import {
- getExportSourceFormValue,
- getExportSourceOptions,
- isExportSourceSelectable,
- shouldHideExportSourceSelector,
-} 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";
+import { useHasProjectAccess } from "@/src/features/rbac/utils/checkProjectAccess";
+import { api, type RouterOutputs } from "@/src/utils/api";
+import { deriveSyncStatus } from "@/src/features/blobstorage-integration/deriveSyncStatus";
+import { type BlobStorageSyncStatus } from "@/src/features/blobstorage-integration/types";
+import { BlobStorageIntegrationContainer } from "@/src/features/blobstorage-integration/components/BlobStorageIntegrationContainer";
+import { BlobStorageStatusSection } from "@/src/features/blobstorage-integration/components/BlobStorageStatusSection";
+
+const syncStatusToBadge: Record<BlobStorageSyncStatus, string> = {
+ up_to_date: "active",
+ running: "running",
+ queued: "queued",
+ idle: "pending",
+ disabled: "disabled",
+ error: "error",
+};
+
+const syncStatusFromConfig = (
+ config: NonNullable<RouterOutputs["blobStorageIntegration"]["get"]["config"]>,
+): BlobStorageSyncStatus =>
+ deriveSyncStatus({
+ enabled: config.enabled,
+ lastError: config.lastError,
+ lastSyncAt: config.lastSyncAt ? new Date(config.lastSyncAt) : null,
+ nextSyncAt: config.nextSyncAt ? new Date(config.nextSyncAt) : null,
+ runStartedAt: config.runStartedAt ? new Date(config.runStartedAt) : null,
+ });
export default function BlobStorageIntegrationSettings() {
const router = useRouter();
@@ -86,13 +50,7 @@ export default function BlobStorageIntegrationSettings() {
refetchInterval: (query) => {
const cfg = query.state.data?.config;
if (!cfg) return false;
- const status = deriveSyncStatus({
- enabled: cfg.enabled,
- lastError: cfg.lastError,
- lastSyncAt: cfg.lastSyncAt ? new Date(cfg.lastSyncAt) : null,
- nextSyncAt: cfg.nextSyncAt ? new Date(cfg.nextSyncAt) : null,
- runStartedAt: cfg.runStartedAt ? new Date(cfg.runStartedAt) : null,
- });
+ const status = syncStatusFromConfig(cfg);
return status === "running" || status === "queued" ? 5_000 : false;
},
},
@@ -101,28 +59,7 @@ export default function BlobStorageIntegrationSettings() {
const syncStatus =
state.isLoading || !hasAccess || !state.data?.config
? undefined
- : deriveSyncStatus({
- enabled: state.data.config.enabled,
- lastError: state.data.config.lastError,
- lastSyncAt: state.data.config.lastSyncAt
- ? new Date(state.data.config.lastSyncAt)
- : null,
- nextSyncAt: state.data.config.nextSyncAt
- ? new Date(state.data.config.nextSyncAt)
- : null,
- runStartedAt: state.data.config.runStartedAt
- ? new Date(state.data.config.runStartedAt)
- : null,
- });
-
- const syncStatusToBadge: Record<BlobStorageSyncStatus, string> = {
- up_to_date: "active",
- running: "running",
- queued: "queued",
- idle: "pending",
- disabled: "disabled",
- error: "error",
- };
+ : syncStatusFromConfig(state.data.config);
return (
<ContainerPage
@@ -163,81 +100,14 @@ export default function BlobStorageIntegrationSettings() {
</p>
)}
{state.data?.config && (
- <>
- <Header title="Status" />
- {state.data.config.lastError && (
- <Alert variant="destructive" className="mb-4">
- <AlertTitle>Last export failed</AlertTitle>
- <AlertDescription>
- {state.data.config.lastError}
- {state.data.config.lastErrorAt && (
- <>
- <br />
- <span className="text-xs opacity-70">
- {new Date(state.data.config.lastErrorAt).toLocaleString()}
- </span>
- </>
- )}
- </AlertDescription>
- </Alert>
- )}
- <Card className="p-3">
- <div className="grid grid-cols-[auto,1fr] gap-x-4 gap-y-1 text-sm">
- <span className="text-muted-foreground">Data exported up to</span>
- <span>
- {state.data.config.lastSyncAt
- ? new Date(state.data.config.lastSyncAt).toLocaleString()
- : "Never (pending)"}
- </span>
- {state.data.config.nextSyncAt && (
- <>
- <span className="text-muted-foreground">
- Next export scheduled
- </span>
- <span>
- {new Date(state.data.config.nextSyncAt).toLocaleString()}
- </span>
- </>
- )}
- <span className="text-muted-foreground">Export mode</span>
- <span>
- {state.data.config.exportMode ===
- BlobStorageExportMode.FULL_HISTORY
- ? "Full history"
- : state.data.config.exportMode ===
- BlobStorageExportMode.FROM_TODAY
- ? "From setup date"
- : state.data.config.exportMode ===
- BlobStorageExportMode.FROM_CUSTOM_DATE
- ? "From custom date"
- : "Unknown"}
- </span>
- {(state.data.config.exportMode ===
- BlobStorageExportMode.FROM_CUSTOM_DATE ||
- state.data.config.exportMode ===
- BlobStorageExportMode.FROM_TODAY) &&
- state.data.config.exportStartDate && (
- <>
- <span className="text-muted-foreground">
- Export start date
- </span>
- <span>
- {new Date(
- state.data.config.exportStartDate,
- ).toLocaleDateString()}
- </span>
- </>
- )}
- </div>
- </Card>
- </>
+ <BlobStorageStatusSection config={state.data.config} />
)}
{hasAccess && (
<>
<Header title="Configuration" className="mt-8" />
<Card className="p-3">
- <BlobStorageIntegrationSettingsForm
- state={state.data?.config || undefined}
+ <BlobStorageIntegrationContainer
+ config={state.data?.config ?? null}
projectId={projectId}
isLoading={state.isLoading}
isEnrichedExportAvailable={
@@ -250,840 +120,3 @@ export default function BlobStorageIntegrationSettings() {
</ContainerPage>
);
}
-
-const BlobStorageIntegrationSettingsForm = ({
- state,
- projectId,
- isLoading,
- isEnrichedExportAvailable,
-}: {
- state?: Partial<BlobStorageIntegration>;
- projectId: string;
- isLoading: boolean;
- isEnrichedExportAvailable: boolean;
-}) => {
- const capture = usePostHogClientCapture();
- const { isLangfuseCloud } = useLangfuseCloudRegion();
- const { project } = useQueryProject();
-
- // Check if this is a self-hosted instance (no cloud region set)
- const isSelfHosted = !isLangfuseCloud;
-
- const isPostCutoffCloud =
- project?.createdAt != null &&
- !isLegacyBlobExportAllowed(new Date(project.createdAt), isLangfuseCloud);
- const eventsExportAvailable = isEnrichedExportAvailable;
- // 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);
- 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(formSchema),
- defaultValues: {
- type: state?.type || BlobStorageIntegrationType.S3,
- bucketName: state?.bucketName || "",
- endpoint: state?.endpoint || null,
- region: state?.region || "",
- accessKeyId: state?.accessKeyId || "",
- secretAccessKey: state?.secretAccessKey || null,
- prefix: state?.prefix || "",
- exportFrequency: (state?.exportFrequency || "daily") as
- | "every_20_minutes"
- | "daily"
- | "weekly"
- | "hourly",
- enabled: state?.enabled || false,
- forcePathStyle: state?.forcePathStyle || false,
- fileType: state?.fileType || BlobStorageIntegrationFileType.PARQUET,
- exportMode: state?.exportMode || BlobStorageExportMode.FULL_HISTORY,
- exportStartDate: state?.exportStartDate || null,
- 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
- ? (state.exportFieldGroups as ObservationFieldGroupFull[])
- : [...OBSERVATION_FIELD_GROUPS_FULL],
- compressed: state?.compressed ?? true,
- },
- disabled: isLoading,
- });
-
- const integrationType =
- blobStorageForm.watch("type") ?? BlobStorageIntegrationType.S3;
-
- useEffect(() => {
- blobStorageForm.reset(
- {
- type: state?.type || BlobStorageIntegrationType.S3,
- bucketName: state?.bucketName || "",
- endpoint: state?.endpoint || null,
- region: state?.region || "auto",
- accessKeyId: state?.accessKeyId || "",
- secretAccessKey: state?.secretAccessKey || null,
- prefix: state?.prefix || "",
- exportFrequency: (state?.exportFrequency || "daily") as
- | "every_20_minutes"
- | "daily"
- | "weekly"
- | "hourly",
- enabled: state?.enabled || false,
- forcePathStyle: state?.forcePathStyle || false,
- fileType: state?.fileType || BlobStorageIntegrationFileType.PARQUET,
- exportMode: state?.exportMode || BlobStorageExportMode.FULL_HISTORY,
- exportStartDate: state?.exportStartDate || null,
- 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
- ? (state.exportFieldGroups as ObservationFieldGroupFull[])
- : [...OBSERVATION_FIELD_GROUPS_FULL],
- compressed: state?.compressed ?? true,
- },
- state ? { keepDirtyValues: true } : undefined,
- );
- // eslint-disable-next-line react-hooks/exhaustive-deps
- }, [state, availability]);
-
- const watchedExportMode = blobStorageForm.watch("exportMode");
- const watchedExportSource = blobStorageForm.watch("exportSource");
- // Internal `exportTuning.parquet` override (no write path); reflected read-only
- // below since the worker forces Parquet over the persisted fileType + gzip.
- const isParquetOverride = parquetEnabledFromTuning(state?.exportTuning);
- const watchedFileType = blobStorageForm.watch("fileType");
- const isParquetExport =
- isParquetOverride ||
- watchedFileType === BlobStorageIntegrationFileType.PARQUET;
- const exportSourceOptions = getExportSourceOptions(
- state?.exportSource,
- availability,
- );
- // No decision to make → no selector. Only the degenerate single-option
- // state (stale persisted source) stays visible, locked, so the
- // unavailable-source alert below has something to refer to.
- const hideExportSource = shouldHideExportSourceSelector(exportSourceOptions);
- 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 =
- watchedExportSource ===
- AnalyticsIntegrationExportSource.TRACES_OBSERVATIONS;
- // Traces and legacy observations are only exported for the legacy and mixed
- // sources; an EVENTS-only export produces scores and enriched observations.
- const includesLegacyExport =
- watchedExportSource ===
- AnalyticsIntegrationExportSource.TRACES_OBSERVATIONS ||
- watchedExportSource ===
- AnalyticsIntegrationExportSource.TRACES_OBSERVATIONS_EVENTS;
-
- const utils = api.useUtils();
- const mut = api.blobStorageIntegration.update.useMutation({
- onSuccess: () => {
- utils.blobStorageIntegration.invalidate();
- },
- onError: (error) => {
- showErrorToast("Failed to save integration", error.message);
- },
- });
- const mutDelete = api.blobStorageIntegration.delete.useMutation({
- onSuccess: () => {
- utils.blobStorageIntegration.invalidate();
- },
- });
- const mutRunNow = api.blobStorageIntegration.runNow.useMutation({
- onSuccess: () => {
- utils.blobStorageIntegration.invalidate();
- },
- });
- const mutValidate = api.blobStorageIntegration.validate.useMutation({
- onSuccess: (data) => {
- showSuccessToast({
- title: data.message,
- description: `Test file: ${data.testFileName}`,
- });
- },
- onError: (error) => {
- showErrorToast("Validation failed", error.message);
- },
- });
-
- async function onSubmit(values: BlobStorageIntegrationFormSchema) {
- capture("integrations:blob_storage_form_submitted");
- mut.mutate({
- projectId,
- ...values,
- });
- }
-
- const handleIntegrationTypeChange = (value: BlobStorageIntegrationType) => {
- blobStorageForm.setValue("type", value, { shouldDirty: true });
- };
-
- return (
- <Form {...blobStorageForm}>
- <form
- className="space-y-3"
- onSubmit={blobStorageForm.handleSubmit(onSubmit)}
- >
- <FormField
- control={blobStorageForm.control}
- name="type"
- render={({ field }) => (
- <FormItem>
- <FormLabel>Storage Provider</FormLabel>
- <FormControl>
- <Select
- value={field.value}
- onValueChange={(value) =>
- handleIntegrationTypeChange(
- value as BlobStorageIntegrationType,
- )
- }
- >
- <SelectTrigger>
- <SelectValue placeholder="Select provider" />
- </SelectTrigger>
- <SelectContent>
- <SelectItem value="S3">AWS S3</SelectItem>
- <SelectItem value="S3_COMPATIBLE">
- S3 Compatible Storage
- </SelectItem>
- <SelectItem value="AZURE_BLOB_STORAGE">
- Azure Blob Storage
- </SelectItem>
- </SelectContent>
- </Select>
- </FormControl>
- <FormDescription>
- Choose your cloud storage provider
- </FormDescription>
- <FormMessage />
- </FormItem>
- )}
- />
-
- <FormField
- control={blobStorageForm.control}
- name="bucketName"
- render={({ field }) => (
- <FormItem>
- <FormLabel>
- {integrationType === "AZURE_BLOB_STORAGE"
- ? "Container Name"
- : "Bucket Name"}
- </FormLabel>
- <FormControl>
- <Input {...field} />
- </FormControl>
- <FormDescription>
- {integrationType === "AZURE_BLOB_STORAGE"
- ? "Azure container name (3-63 chars, lowercase letters, numbers, and hyphens only)"
- : "The S3 bucket name"}
- </FormDescription>
- <FormMessage />
- </FormItem>
- )}
- />
-
- {/* Endpoint URL field - Only shown for S3-compatible and Azure */}
- {integrationType !== "S3" && (
- <FormField
- control={blobStorageForm.control}
- name="endpoint"
- render={({ field }) => (
- <FormItem>
- <FormLabel>Endpoint URL</FormLabel>
- <FormControl>
- <Input {...field} value={field.value || ""} />
- </FormControl>
- <FormDescription>
- {integrationType === "AZURE_BLOB_STORAGE"
- ? "Azure Blob Storage endpoint URL (e.g., https://accountname.blob.core.windows.net)"
- : "S3 compatible endpoint URL (e.g., https://play.min.io)"}
- </FormDescription>
- <FormMessage />
- </FormItem>
- )}
- />
- )}
-
- {/* Region field - Only shown for AWS S3 or compatible storage */}
- {integrationType !== "AZURE_BLOB_STORAGE" && (
- <FormField
- control={blobStorageForm.control}
- name="region"
- render={({ field }) => (
- <FormItem>
- <FormLabel>Region</FormLabel>
- <FormControl>
- <Input {...field} />
- </FormControl>
- <FormDescription>
- {integrationType === "S3"
- ? "AWS region (e.g., us-east-1)"
- : "S3 compatible storage region"}
- </FormDescription>
- <FormMessage />
- </FormItem>
- )}
- />
- )}
-
- {/* Force Path Style switch - Only shown for S3-compatible */}
- {integrationType === "S3_COMPATIBLE" && (
- <FormField
- control={blobStorageForm.control}
- name="forcePathStyle"
- render={({ field }) => (
- <FormItem>
- <FormLabel>Force Path Style</FormLabel>
- <FormControl>
- <div className="mt-1 ml-4">
- <Switch
- checked={field.value}
- onCheckedChange={field.onChange}
- />
- </div>
- </FormControl>
- <FormDescription>
- Enable for MinIO and some other S3 compatible providers
- </FormDescription>
- <FormMessage />
- </FormItem>
- )}
- />
- )}
-
- <FormField
- control={blobStorageForm.control}
- name="accessKeyId"
- render={({ field }) => (
- <FormItem>
- <FormLabel>
- {integrationType === "AZURE_BLOB_STORAGE"
- ? "Storage Account Name"
- : integrationType === "S3"
- ? "AWS Access Key ID"
- : "Access Key ID"}
- {/* Show optional indicator for S3 types on self-hosted instances with entitlement */}
- {isSelfHosted && integrationType === "S3" && (
- <span className="text-muted-foreground"> (optional)</span>
- )}
- </FormLabel>
- <FormControl>
- <Input {...field} />
- </FormControl>
- <FormDescription>
- {integrationType === "AZURE_BLOB_STORAGE"
- ? "Your Azure storage account name"
- : integrationType === "S3"
- ? isSelfHosted
- ? "Your AWS IAM user access key ID. Leave empty to use host credentials (IAM roles, instance profiles, etc.)"
- : "Your AWS IAM user access key ID"
- : "Access key for your S3-compatible storage"}
- </FormDescription>
- <FormMessage />
- </FormItem>
- )}
- />
-
- <FormField
- control={blobStorageForm.control}
- name="secretAccessKey"
- render={({ field }) => (
- <FormItem>
- <FormLabel>
- {integrationType === "AZURE_BLOB_STORAGE"
- ? "Storage Account Key"
- : integrationType === "S3"
- ? "AWS Secret Access Key"
- : "Secret Access Key"}
- {/* Show optional indicator for S3 types on self-hosted instances with entitlement */}
- {isSelfHosted && integrationType === "S3" && (
- <span className="text-muted-foreground"> (optional)</span>
- )}
- </FormLabel>
- <FormControl>
- <PasswordInput
- placeholder="********************"
- {...field}
- value={field.value || ""}
- />
- </FormControl>
- <FormDescription>
- {integrationType === "AZURE_BLOB_STORAGE"
- ? "Your Azure storage account access key"
- : integrationType === "S3"
- ? isSelfHosted
- ? "Your AWS IAM user secret access key. Leave empty to use host credentials (IAM roles, instance profiles, etc.)"
- : "Your AWS IAM user secret access key"
- : "Secret key for your S3-compatible storage"}
- </FormDescription>
- <FormMessage />
- </FormItem>
- )}
- />
-
- <FormField
- control={blobStorageForm.control}
- name="prefix"
- render={({ field }) => (
- <FormItem>
- <FormLabel>Export Prefix</FormLabel>
- <FormControl>
- <Input {...field} />
- </FormControl>
- <FormDescription>
- {integrationType === "AZURE_BLOB_STORAGE"
- ? 'Optional prefix path for exported files in your Azure container (e.g., "langfuse-exports/")'
- : integrationType === "S3"
- ? 'Optional prefix path for exported files in your S3 bucket (e.g., "langfuse-exports/")'
- : 'Optional prefix path for exported files (e.g., "langfuse-exports/")'}
- </FormDescription>
- <FormMessage />
- </FormItem>
- )}
- />
-
- <FormField
- control={blobStorageForm.control}
- name="exportFrequency"
- render={({ field }) => (
- <FormItem>
- <FormLabel>Export Frequency</FormLabel>
- <FormControl>
- <Select value={field.value} onValueChange={field.onChange}>
- <SelectTrigger>
- <SelectValue placeholder="Select frequency" />
- </SelectTrigger>
- <SelectContent>
- <SelectItem value="every_20_minutes">
- Every 20 Minutes
- </SelectItem>
- <SelectItem value="hourly">Hourly</SelectItem>
- <SelectItem value="daily">Daily</SelectItem>
- <SelectItem value="weekly">Weekly</SelectItem>
- </SelectContent>
- </Select>
- </FormControl>
- <FormDescription>
- How often the data should be exported. Changes are taken into
- consideration from the next run onwards.
- </FormDescription>
- <FormMessage />
- </FormItem>
- )}
- />
-
- <FormField
- control={blobStorageForm.control}
- name="fileType"
- render={({ field }) => (
- <FormItem>
- <FormLabel>File Type</FormLabel>
- <FormControl>
- <Select
- value={isParquetOverride ? "PARQUET" : field.value}
- onValueChange={field.onChange}
- disabled={isParquetOverride}
- >
- <SelectTrigger>
- <SelectValue placeholder="Select file type" />
- </SelectTrigger>
- <SelectContent>
- <SelectItem value="PARQUET">Parquet</SelectItem>
- <SelectItem value="JSONL">JSONL</SelectItem>
- <SelectItem value="CSV">CSV</SelectItem>
- <SelectItem value="JSON">JSON</SelectItem>
- </SelectContent>
- </Select>
- </FormControl>
- <FormDescription>
- {isParquetOverride
- ? "Exporting as Apache Parquet — a columnar binary format encoded and compressed by ClickHouse. This is configured for your project and overrides the file type; gzip compression is not applicable."
- : field.value === BlobStorageIntegrationFileType.PARQUET
- ? "Apache Parquet — a columnar binary format encoded and compressed by ClickHouse. Gzip compression does not apply."
- : "The file format for exported data."}
- </FormDescription>
- <FormMessage />
- </FormItem>
- )}
- />
-
- <FormField
- control={blobStorageForm.control}
- name="exportMode"
- render={({ field }) => (
- <FormItem>
- <FormLabel>Export Mode</FormLabel>
- <FormControl>
- <Select value={field.value} onValueChange={field.onChange}>
- <SelectTrigger>
- <SelectValue placeholder="Select export mode" />
- </SelectTrigger>
- <SelectContent>
- <SelectItem value={BlobStorageExportMode.FULL_HISTORY}>
- Full history
- </SelectItem>
- <SelectItem value={BlobStorageExportMode.FROM_TODAY}>
- Today
- </SelectItem>
- <SelectItem value={BlobStorageExportMode.FROM_CUSTOM_DATE}>
- Custom date
- </SelectItem>
- </SelectContent>
- </Select>
- </FormControl>
- <FormDescription>
- Choose when to start exporting data. &quot;Today&quot; and
- &quot;Custom date&quot; modes will not include historical data
- before the specified date.
- </FormDescription>
- <FormMessage />
- </FormItem>
- )}
- />
-
- {watchedExportMode === BlobStorageExportMode.FROM_CUSTOM_DATE && (
- <FormField
- control={blobStorageForm.control}
- name="exportStartDate"
- render={({ field }) => (
- <FormItem>
- <FormLabel>Export Start Date</FormLabel>
- <FormControl>
- <Input
- type="date"
- max={(() => {
- const t = new Date();
- return `${t.getFullYear()}-${String(t.getMonth() + 1).padStart(2, "0")}-${String(t.getDate()).padStart(2, "0")}`;
- })()}
- value={
- field.value instanceof Date
- ? field.value.toISOString().split("T")[0]
- : ""
- }
- onChange={(e) => {
- const date = e.target.value
- ? new Date(e.target.value)
- : null;
- field.onChange(date);
- }}
- placeholder="Select start date"
- />
- </FormControl>
- <FormDescription>
- Data before this date will not be included in exports
- </FormDescription>
- <FormMessage />
- </FormItem>
- )}
- />
- )}
-
- {!hideExportSource && (
- <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>
- ))}
- <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
- control={blobStorageForm.control}
- name="exportFieldGroups"
- render={({ field }) => (
- <FormItem>
- <FormLabel>Export Field Groups</FormLabel>
- <FormDescription>
- Choose which field groups to include in the observation exports.
- Deselect large groups (e.g. Input / Output) to reduce export
- size, or privacy-sensitive groups (e.g. Metadata) to avoid
- storing user data.
- {includesLegacyExport
- ? isLegacyOnlyExport
- ? " Traces and scores are always exported in full. Field groups that only exist on the enriched observations (e.g. Trace Context) are not available for this export source."
- : " Traces and scores are always exported in full. Fields that only exist on the enriched observations (e.g. Trace Context) are omitted from the legacy observations export."
- : " Scores are always exported in full."}
- </FormDescription>
- <div className="mt-2 space-y-2">
- {EXPORT_FIELD_GROUP_OPTIONS.filter(
- // Hide no-op groups (no legacy columns) for legacy-only
- // exports; a saved selection is kept and applies again if
- // the source is migrated to enriched observations.
- (option) =>
- !isLegacyOnlyExport || option.includedInLegacyExport,
- ).map((option) => {
- const isCore = option.value === "core";
- return (
- <div key={option.value} className="flex items-start gap-2">
- <Checkbox
- id={`field-group-${option.value}`}
- checked={
- isCore
- ? true
- : (field.value ?? []).includes(option.value)
- }
- disabled={isCore}
- onCheckedChange={
- isCore
- ? undefined
- : (checked) => {
- const current = field.value ?? [];
- const next =
- checked === true
- ? current.includes(option.value)
- ? current
- : [...current, option.value]
- : current.filter(
- (v: ObservationFieldGroupFull) =>
- v !== option.value,
- );
- field.onChange(next);
- }
- }
- />
- <label
- htmlFor={`field-group-${option.value}`}
- className={
- isCore ? "space-y-0.5" : "cursor-pointer space-y-0.5"
- }
- >
- <div className="text-sm leading-none font-medium">
- {option.label}
- {isCore && (
- <span className="text-muted-foreground ml-1 font-normal">
- (required)
- </span>
- )}
- </div>
- <div className="text-muted-foreground text-xs">
- {isParquetExport
- ? isLegacyOnlyExport
- ? option.legacyParquetDescription
- : option.parquetDescription
- : isLegacyOnlyExport
- ? option.legacyDescription
- : option.description}
- </div>
- </label>
- </div>
- );
- })}
- </div>
- <FormMessage>
- {blobStorageForm.formState.errors.exportFieldGroups?.message}
- </FormMessage>
- </FormItem>
- )}
- />
-
- {/* Parquet compresses internally — gzip does not apply. */}
- {!isParquetExport && (
- <FormField
- control={blobStorageForm.control}
- name="compressed"
- render={({ field }) => (
- <FormItem>
- <FormLabel>Gzip Compression</FormLabel>
- <FormControl>
- <div className="mt-1 ml-4">
- <Switch
- checked={field.value}
- onCheckedChange={field.onChange}
- />
- </div>
- </FormControl>
- <FormDescription>
- Compress exported files with gzip (.csv.gz, .json.gz,
- .jsonl.gz)
- </FormDescription>
- <FormMessage />
- </FormItem>
- )}
- />
- )}
-
- <FormField
- control={blobStorageForm.control}
- name="enabled"
- render={({ field }) => (
- <FormItem>
- <FormLabel>Enabled</FormLabel>
- <FormControl>
- <div className="mt-1 ml-4">
- <Switch
- checked={field.value}
- onCheckedChange={field.onChange}
- />
- </div>
- </FormControl>
- <FormMessage />
- </FormItem>
- )}
- />
- </form>
- <div className="mt-8 flex gap-2">
- <Button
- loading={mut.isPending}
- onClick={blobStorageForm.handleSubmit(onSubmit)}
- disabled={isLoading}
- >
- Save
- </Button>
- <Button
- variant="secondary"
- loading={mutValidate.isPending}
- disabled={isLoading || !state}
- title="Test your saved configuration by uploading a small test file to your storage"
- onClick={() => {
- mutValidate.mutate({ projectId });
- }}
- >
- Validate
- </Button>
- <Button
- variant="secondary"
- loading={mutRunNow.isPending}
- disabled={isLoading || !state?.enabled}
- title="Trigger an immediate export of all data since the last sync"
- onClick={() => {
- if (
- confirm(
- "Are you sure you want to run the blob storage export now? This will export all data since the last sync.",
- )
- )
- mutRunNow.mutate({ projectId });
- }}
- >
- Run Now
- </Button>
- <Button
- variant="ghost"
- loading={mutDelete.isPending}
- disabled={isLoading || !!!state}
- onClick={() => {
- if (
- confirm(
- "Are you sure you want to reset the Blob Storage integration for this project?",
- )
- )
- mutDelete.mutate({ projectId });
- }}
- >
- Reset
- </Button>
- </div>
- </Form>
- );
-};