Skip to content

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

feat(blob-integration): allow custom start date for blob storage exports (#7745)

Steffen Schmitzc8c031e0bde0
diff --git a/packages/shared/prisma/generated/types.ts b/packages/shared/prisma/generated/types.ts
index c0ce64aa50..4c49baa5cd 100644
--- a/packages/shared/prisma/generated/types.ts
+++ b/packages/shared/prisma/generated/types.ts
@@ -109,6 +109,13 @@ export const BlobStorageIntegrationType = {
} as const;
export type BlobStorageIntegrationType =
(typeof BlobStorageIntegrationType)[keyof typeof BlobStorageIntegrationType];
+export const BlobStorageExportMode = {
+ FULL_HISTORY: "FULL_HISTORY",
+ FROM_TODAY: "FROM_TODAY",
+ FROM_CUSTOM_DATE: "FROM_CUSTOM_DATE",
+} as const;
+export type BlobStorageExportMode =
+ (typeof BlobStorageExportMode)[keyof typeof BlobStorageExportMode];
export const DashboardWidgetViews = {
TRACES: "TRACES",
OBSERVATIONS: "OBSERVATIONS",
@@ -298,6 +305,8 @@ export type BlobStorageIntegration = {
enabled: boolean;
export_frequency: string;
file_type: Generated<BlobStorageIntegrationFileType>;
+ export_mode: Generated<BlobStorageExportMode>;
+ export_start_date: Timestamp | null;
created_at: Generated<Timestamp>;
updated_at: Generated<Timestamp>;
};
diff --git a/packages/shared/prisma/migrations/20250709113103_check_empty/migration.sql b/packages/shared/prisma/migrations/20250709113103_check_empty/migration.sql
new file mode 100644
index 0000000000..94783ca237
--- /dev/null
+++ b/packages/shared/prisma/migrations/20250709113103_check_empty/migration.sql
@@ -0,0 +1,6 @@
+-- CreateEnum
+CREATE TYPE "BlobStorageExportMode" AS ENUM ('FULL_HISTORY', 'FROM_TODAY', 'FROM_CUSTOM_DATE');
+
+-- AlterTable
+ALTER TABLE "blob_storage_integrations" ADD COLUMN "export_mode" "BlobStorageExportMode" NOT NULL DEFAULT 'FULL_HISTORY',
+ADD COLUMN "export_start_date" TIMESTAMP(3);
diff --git a/packages/shared/prisma/schema.prisma b/packages/shared/prisma/schema.prisma
index 42958bb733..6390123915 100644
--- a/packages/shared/prisma/schema.prisma
+++ b/packages/shared/prisma/schema.prisma
@@ -967,6 +967,8 @@ model BlobStorageIntegration {
enabled Boolean
exportFrequency String @map("export_frequency")
fileType BlobStorageIntegrationFileType @default(CSV) @map("file_type")
+ exportMode BlobStorageExportMode @default(FULL_HISTORY) @map("export_mode")
+ exportStartDate DateTime? @map("export_start_date")
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @default(now()) @updatedAt @map("updated_at")
@@ -990,6 +992,14 @@ enum BlobStorageIntegrationType {
@@map("BlobStorageIntegrationType")
}
+enum BlobStorageExportMode {
+ FULL_HISTORY
+ FROM_TODAY
+ FROM_CUSTOM_DATE
+
+ @@map("BlobStorageExportMode")
+}
+
model BatchExport {
id String @id @default(cuid())
createdAt DateTime @default(now()) @map("created_at")
diff --git a/web/src/features/blobstorage-integration/blobstorage-integration-router.ts b/web/src/features/blobstorage-integration/blobstorage-integration-router.ts
index 182fb98fa7..cc4b180470 100644
--- a/web/src/features/blobstorage-integration/blobstorage-integration-router.ts
+++ b/web/src/features/blobstorage-integration/blobstorage-integration-router.ts
@@ -20,6 +20,7 @@ import { decrypt } from "@langfuse/shared/encryption";
import {
type BlobStorageIntegration,
BlobStorageIntegrationType,
+ BlobStorageExportMode,
} from "@langfuse/shared";
import { env } from "@/src/env.mjs";
@@ -85,6 +86,8 @@ export const blobStorageIntegrationRouter = createTRPCRouter({
enabled,
forcePathStyle,
fileType,
+ exportMode,
+ exportStartDate,
} = input;
const isSelfHosted = !env.NEXT_PUBLIC_LANGFUSE_CLOUD_REGION;
@@ -100,6 +103,15 @@ export const blobStorageIntegrationRouter = createTRPCRouter({
});
}
+ // Determine the export start date based on export mode
+ let finalExportStartDate: Date | null = null;
+ if (exportMode === BlobStorageExportMode.FROM_TODAY) {
+ finalExportStartDate = new Date();
+ } else if (exportMode === BlobStorageExportMode.FROM_CUSTOM_DATE) {
+ finalExportStartDate = exportStartDate || new Date();
+ }
+ // For FULL_HISTORY mode, exportStartDate remains null
+
const data: Partial<BlobStorageIntegration> = {
type,
bucketName,
@@ -111,6 +123,8 @@ export const blobStorageIntegrationRouter = createTRPCRouter({
accessKeyId,
forcePathStyle: forcePathStyle || false,
fileType,
+ exportMode,
+ exportStartDate: finalExportStartDate,
};
// Use a transaction to check if record exists, then create or update
diff --git a/web/src/features/blobstorage-integration/types.ts b/web/src/features/blobstorage-integration/types.ts
index 9b535eeb1f..f01bbb95e7 100644
--- a/web/src/features/blobstorage-integration/types.ts
+++ b/web/src/features/blobstorage-integration/types.ts
@@ -2,6 +2,7 @@ import { z } from "zod/v4";
import {
BlobStorageIntegrationType,
BlobStorageIntegrationFileType,
+ BlobStorageExportMode,
} from "@langfuse/shared";
export const blobStorageIntegrationFormSchema = z.object({
@@ -24,6 +25,10 @@ export const blobStorageIntegrationFormSchema = z.object({
fileType: z
.enum(BlobStorageIntegrationFileType)
.default(BlobStorageIntegrationFileType.JSONL),
+ exportMode: z
+ .enum(BlobStorageExportMode)
+ .default(BlobStorageExportMode.FULL_HISTORY),
+ exportStartDate: z.coerce.date().optional().nullable(),
});
export type BlobStorageIntegrationFormSchema = z.infer<
diff --git a/web/src/pages/project/[projectId]/settings/integrations/blobstorage.tsx b/web/src/pages/project/[projectId]/settings/integrations/blobstorage.tsx
index 0f234a0eb8..e5869988e3 100644
--- a/web/src/pages/project/[projectId]/settings/integrations/blobstorage.tsx
+++ b/web/src/pages/project/[projectId]/settings/integrations/blobstorage.tsx
@@ -40,6 +40,7 @@ import { showErrorToast } from "@/src/features/notifications/showErrorToast";
import {
BlobStorageIntegrationType,
BlobStorageIntegrationFileType,
+ BlobStorageExportMode,
type BlobStorageIntegration,
} from "@langfuse/shared";
@@ -117,12 +118,34 @@ export default function BlobStorageIntegrationSettings() {
{state.data?.enabled && (
<>
<Header title="Status" className="mt-8" />
- <p className="text-sm text-primary">
- Data last exported:{" "}
- {state.data?.lastSyncAt
- ? new Date(state.data.lastSyncAt).toLocaleString()
- : "Never (pending)"}
- </p>
+ <div className="space-y-2">
+ <p className="text-sm text-primary">
+ Data last exported:{" "}
+ {state.data?.lastSyncAt
+ ? new Date(state.data.lastSyncAt).toLocaleString()
+ : "Never (pending)"}
+ </p>
+ <p className="text-sm text-primary">
+ Export mode:{" "}
+ {state.data?.exportMode === BlobStorageExportMode.FULL_HISTORY
+ ? "Full history"
+ : state.data?.exportMode === BlobStorageExportMode.FROM_TODAY
+ ? "From setup date"
+ : state.data?.exportMode ===
+ BlobStorageExportMode.FROM_CUSTOM_DATE
+ ? "From custom date"
+ : "Unknown"}
+ </p>
+ {(state.data?.exportMode ===
+ BlobStorageExportMode.FROM_CUSTOM_DATE ||
+ state.data?.exportMode === BlobStorageExportMode.FROM_TODAY) &&
+ state.data?.exportStartDate && (
+ <p className="text-sm text-primary">
+ Export start date:{" "}
+ {new Date(state.data.exportStartDate).toLocaleDateString()}
+ </p>
+ )}
+ </div>
</>
)}
</ContainerPage>
@@ -162,6 +185,8 @@ const BlobStorageIntegrationSettingsForm = ({
enabled: state?.enabled || false,
forcePathStyle: state?.forcePathStyle || false,
fileType: state?.fileType || BlobStorageIntegrationFileType.JSONL,
+ exportMode: state?.exportMode || BlobStorageExportMode.FULL_HISTORY,
+ exportStartDate: state?.exportStartDate || null,
},
disabled: isLoading,
});
@@ -183,6 +208,8 @@ const BlobStorageIntegrationSettingsForm = ({
enabled: state?.enabled || false,
forcePathStyle: state?.forcePathStyle || false,
fileType: state?.fileType || BlobStorageIntegrationFileType.JSONL,
+ exportMode: state?.exportMode || BlobStorageExportMode.FULL_HISTORY,
+ exportStartDate: state?.exportStartDate || null,
});
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [state]);
@@ -503,6 +530,74 @@ const BlobStorageIntegrationSettingsForm = ({
)}
/>
+ <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>
+ )}
+ />
+
+ {blobStorageForm.watch("exportMode") ===
+ BlobStorageExportMode.FROM_CUSTOM_DATE && (
+ <FormField
+ control={blobStorageForm.control}
+ name="exportStartDate"
+ render={({ field }) => (
+ <FormItem>
+ <FormLabel>Export Start Date</FormLabel>
+ <FormControl>
+ <Input
+ type="date"
+ 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>
+ )}
+ />
+ )}
+
<FormField
control={blobStorageForm.control}
name="enabled"
diff --git a/worker/src/__tests__/blobStorageIntegrationProcessing.test.ts b/worker/src/__tests__/blobStorageIntegrationProcessing.test.ts
index df1ce16c36..4d936fd793 100644
--- a/worker/src/__tests__/blobStorageIntegrationProcessing.test.ts
+++ b/worker/src/__tests__/blobStorageIntegrationProcessing.test.ts
@@ -439,4 +439,178 @@ describe("BlobStorageIntegrationProcessingJob", () => {
}
}
});
+
+ describe("BlobStorageExportMode minTimestamp behavior", () => {
+ it("should use epoch date for FULL_HISTORY mode on first export", async () => {
+ const { projectId } = await createOrgProjectAndApiKey();
+
+ // Create trace with old timestamp
+ const epochTrace = createTrace({
+ project_id: projectId,
+ timestamp: 1000, // Very old timestamp
+ name: "Epoch Trace",
+ });
+ await createTracesCh([epochTrace]);
+
+ // Create integration with FULL_HISTORY mode and no lastSyncAt
+ await prisma.blobStorageIntegration.create({
+ data: {
+ projectId,
+ type: BlobStorageIntegrationType.S3,
+ bucketName,
+ prefix: `${projectId}/test-full-history/`,
+ 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: "hourly",
+ exportMode: "FULL_HISTORY",
+ exportStartDate: null,
+ lastSyncAt: null, // First export
+ },
+ });
+
+ await handleBlobStorageIntegrationProjectJob({
+ data: { payload: { projectId } },
+ } as Job);
+
+ // Check that the trace file exists (indicating it found data from epoch)
+ const files = await storageService.listFiles(
+ `${projectId}/test-full-history/`,
+ );
+ const projectFiles = files.filter((f) => f.file.includes(projectId));
+ const traceFile = projectFiles.find((f) => f.file.includes("/traces/"));
+
+ expect(traceFile).toBeDefined();
+
+ // Verify the file contains the old trace data
+ if (traceFile) {
+ const content = await storageService.download(traceFile.file);
+ expect(content).toContain(epochTrace.id);
+ }
+ });
+
+ it("should use current date for FROM_TODAY mode on first export", async () => {
+ const { projectId } = await createOrgProjectAndApiKey();
+ const now = new Date();
+ const yesterday = new Date(now.getTime() - 24 * 60 * 60 * 1000);
+ const veryOldTrace = new Date(now.getTime() - 2 * 24 * 60 * 60 * 1000); // 2 days ago
+
+ // Create traces from different time periods
+ const oldTrace = createTrace({
+ project_id: projectId,
+ timestamp: yesterday.getTime(),
+ name: "Old Trace",
+ });
+ const veryOldTraceObj = createTrace({
+ project_id: projectId,
+ timestamp: veryOldTrace.getTime(),
+ name: "Very Old Trace",
+ });
+ await createTracesCh([oldTrace, veryOldTraceObj]);
+
+ // Create integration with FROM_TODAY mode
+ await prisma.blobStorageIntegration.create({
+ data: {
+ projectId,
+ type: BlobStorageIntegrationType.S3,
+ bucketName,
+ prefix: `${projectId}/test-today/`,
+ 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: "hourly",
+ exportMode: "FROM_TODAY" as any,
+ exportStartDate: new Date(), // Use current date
+ lastSyncAt: null, // First export
+ },
+ });
+
+ await handleBlobStorageIntegrationProjectJob({
+ data: { payload: { projectId } },
+ } as Job);
+
+ const files = await storageService.listFiles(`${projectId}/test-today/`);
+ const projectFiles = files.filter((f) => f.file.includes(projectId));
+ const traceFile = projectFiles.find((f) => f.file.includes("/traces/"));
+
+ // On azure the empty file is not created, for others we proceed to check that it's empty.
+ if (traceFile) {
+ const content = await storageService.download(traceFile.file);
+ // With FROM_TODAY mode and a current exportStartDate, the minTimestamp is set to the provided date (current time)
+ // which means only traces within the last 30 minutes would be exported
+ // Our test traces are older, so content should be empty or not contain old traces
+ expect(content).not.toContain(oldTrace.id);
+ expect(content).not.toContain(veryOldTraceObj.id);
+ }
+ });
+
+ it("should use custom date for FROM_CUSTOM_DATE mode on first export", async () => {
+ const { projectId } = await createOrgProjectAndApiKey();
+ const now = new Date();
+ const customDate = new Date(now.getTime() - 12 * 60 * 60 * 1000); // 12 hours ago
+ const beforeCustomDate = new Date(customDate.getTime() - 60 * 60 * 1000); // 13 hours ago
+ const afterCustomDate = new Date(
+ customDate.getTime() + 2 * 60 * 60 * 1000,
+ ); // 10 hours ago (safe margin)
+
+ // Create traces before and after custom date
+ const oldTrace = createTrace({
+ project_id: projectId,
+ timestamp: beforeCustomDate.getTime(),
+ name: "Before Custom Date Trace",
+ });
+ const recentTrace = createTrace({
+ project_id: projectId,
+ timestamp: afterCustomDate.getTime(),
+ name: "After Custom Date Trace",
+ });
+ await createTracesCh([oldTrace, recentTrace]);
+
+ // Create integration with FROM_CUSTOM_DATE mode
+ await prisma.blobStorageIntegration.create({
+ data: {
+ projectId,
+ type: BlobStorageIntegrationType.S3,
+ bucketName,
+ prefix: `${projectId}/test-custom/`,
+ 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: "hourly",
+ exportMode: "FROM_CUSTOM_DATE" as any,
+ exportStartDate: customDate,
+ lastSyncAt: null, // First export
+ },
+ });
+
+ await handleBlobStorageIntegrationProjectJob({
+ data: { payload: { projectId } },
+ } as Job);
+
+ const files = await storageService.listFiles(`${projectId}/test-custom/`);
+ const projectFiles = files.filter((f) => f.file.includes(projectId));
+ const traceFile = projectFiles.find((f) => f.file.includes("/traces/"));
+
+ expect(traceFile).toBeDefined();
+
+ // Should only include traces from custom date onwards
+ if (traceFile) {
+ const content = await storageService.download(traceFile.file);
+ expect(content).not.toContain(oldTrace.id);
+ expect(content).toContain(recentTrace.id);
+ }
+ });
+ });
});
diff --git a/worker/src/features/blobstorage/handleBlobStorageIntegrationProjectJob.ts b/worker/src/features/blobstorage/handleBlobStorageIntegrationProjectJob.ts
index 9b88561ab1..92b89295f8 100644
--- a/worker/src/features/blobstorage/handleBlobStorageIntegrationProjectJob.ts
+++ b/worker/src/features/blobstorage/handleBlobStorageIntegrationProjectJob.ts
@@ -15,9 +15,34 @@ import {
import {
BlobStorageIntegrationType,
BlobStorageIntegrationFileType,
+ BlobStorageExportMode,
} from "@langfuse/shared";
import { decrypt } from "@langfuse/shared/encryption";
+const getMinTimestampForExport = (
+ lastSyncAt: Date | null,
+ exportMode: BlobStorageExportMode,
+ exportStartDate: Date | null,
+): Date => {
+ // If we have a lastSyncAt, use it (this is for subsequent exports)
+ if (lastSyncAt) {
+ return lastSyncAt;
+ }
+
+ // For first export, use the export mode to determine start date
+ switch (exportMode) {
+ case BlobStorageExportMode.FULL_HISTORY:
+ return new Date(0); // Export all historical data
+ case BlobStorageExportMode.FROM_TODAY:
+ case BlobStorageExportMode.FROM_CUSTOM_DATE:
+ return exportStartDate || new Date(); // Use export start date or current time as fallback
+ default:
+ // eslint-disable-next-line no-case-declarations, no-unused-vars
+ const _exhaustiveCheck: never = exportMode;
+ throw new Error(`Invalid export mode: ${exportMode}`);
+ }
+};
+
const getFileTypeProperties = (fileType: BlobStorageIntegrationFileType) => {
switch (fileType) {
case BlobStorageIntegrationFileType.JSON:
@@ -48,7 +73,7 @@ const processBlobStorageExport = async (config: {
maxTimestamp: Date;
bucketName: string;
endpoint: string | null;
- region?: string;
+ region: string;
accessKeyId: string | undefined;
secretAccessKey: string | undefined;
prefix?: string;
@@ -174,7 +199,11 @@ export const handleBlobStorageIntegrationProjectJob = async (
}
// Sync between lastSyncAt and now - 30 minutes
- const minTimestamp = blobStorageIntegration.lastSyncAt || new Date(0);
+ const minTimestamp = getMinTimestampForExport(
+ blobStorageIntegration.lastSyncAt,
+ blobStorageIntegration.exportMode,
+ blobStorageIntegration.exportStartDate,
+ );
const maxTimestamp = new Date(new Date().getTime() - 30 * 60 * 1000);
try {
@@ -185,7 +214,7 @@ export const handleBlobStorageIntegrationProjectJob = async (
maxTimestamp,
bucketName: blobStorageIntegration.bucketName,
endpoint: blobStorageIntegration.endpoint,
- region: blobStorageIntegration.region || undefined,
+ region: blobStorageIntegration.region ?? "auto",
accessKeyId: blobStorageIntegration.accessKeyId || undefined,
secretAccessKey: blobStorageIntegration.secretAccessKey
? decrypt(blobStorageIntegration.secretAccessKey)