Skip to content

πŸͺ’ Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.

feat: add blob storage integration status endpoint with error tracking (#12570)

Valery Meleshkine84ca4576a20
diff --git a/fern/apis/server/definition/blob-storage-integrations.yml b/fern/apis/server/definition/blob-storage-integrations.yml
index 54d31dd8a8..dab6c87072 100644
--- a/fern/apis/server/definition/blob-storage-integrations.yml
+++ b/fern/apis/server/definition/blob-storage-integrations.yml
@@ -19,6 +19,14 @@ service:
request: CreateBlobStorageIntegrationRequest
response: BlobStorageIntegrationResponse
+ getBlobStorageIntegrationStatus:
+ docs: Get the sync status of a blob storage integration by integration ID (requires organization-scoped API key)
+ method: GET
+ path: "/{id}"
+ path-parameters:
+ id: string
+ response: BlobStorageIntegrationStatusResponse
+
deleteBlobStorageIntegration:
docs: Delete a blob storage integration by ID (requires organization-scoped API key)
method: DELETE
@@ -95,18 +103,20 @@ types:
projectId: string
type: BlobStorageIntegrationType
bucketName: string
- endpoint: optional<string>
+ endpoint: nullable<string>
region: string
- accessKeyId: optional<string>
+ accessKeyId: nullable<string>
prefix: string
exportFrequency: BlobStorageExportFrequency
enabled: boolean
forcePathStyle: boolean
fileType: BlobStorageIntegrationFileType
exportMode: BlobStorageExportMode
- exportStartDate: optional<datetime>
- nextSyncAt: optional<datetime>
- lastSyncAt: optional<datetime>
+ exportStartDate: nullable<datetime>
+ nextSyncAt: nullable<datetime>
+ lastSyncAt: nullable<datetime>
+ lastError: nullable<string>
+ lastErrorAt: nullable<datetime>
createdAt: datetime
updatedAt: datetime
@@ -114,6 +124,44 @@ types:
properties:
data: list<BlobStorageIntegrationResponse>
+ BlobStorageSyncStatus:
+ docs: |
+ Sync status of the blob storage integration:
+ - `disabled` β€” integration is not enabled
+ - `error` β€” last export failed (see `lastError` for details)
+ - `idle` β€” enabled but has never exported yet
+ - `queued` β€” next export is overdue (`nextSyncAt` is in the past) and waiting to be picked up by the worker
+ - `up_to_date` β€” all available data has been exported; next export is scheduled for the future
+
+ **ETL usage**: poll this endpoint and check for `up_to_date` status. Compare `lastSyncAt` against your
+ ETL bookmark to determine if new data is available. Note that exports run with a 30-minute lag buffer,
+ so `lastSyncAt` will always be at least 30 minutes behind real-time.
+ enum:
+ - idle
+ - queued
+ - up_to_date
+ - disabled
+ - error
+
+ BlobStorageIntegrationStatusResponse:
+ properties:
+ id: string
+ projectId: string
+ syncStatus: BlobStorageSyncStatus
+ enabled: boolean
+ lastSyncAt:
+ type: nullable<datetime>
+ docs: End of the last successfully exported time window. Compare against your ETL bookmark to determine if new data is available. Null if the integration has never synced.
+ nextSyncAt:
+ type: nullable<datetime>
+ docs: When the next export is scheduled. Null if no sync has occurred yet.
+ lastError:
+ type: nullable<string>
+ docs: Raw error message from the storage provider (S3/Azure/GCS) if the last export failed. Cleared on successful export.
+ lastErrorAt:
+ type: nullable<datetime>
+ docs: When the last error occurred. Cleared on successful export.
+
BlobStorageIntegrationDeletionResponse:
properties:
message: string
diff --git a/packages/shared/prisma/generated/types.ts b/packages/shared/prisma/generated/types.ts
index f2e46ac888..88b2a3a49d 100644
--- a/packages/shared/prisma/generated/types.ts
+++ b/packages/shared/prisma/generated/types.ts
@@ -378,6 +378,8 @@ export type BlobStorageIntegration = {
export_mode: Generated<BlobStorageExportMode>;
export_start_date: Timestamp | null;
export_source: Generated<AnalyticsIntegrationExportSource>;
+ last_error: string | null;
+ last_error_at: Timestamp | null;
created_at: Generated<Timestamp>;
updated_at: Generated<Timestamp>;
};
diff --git a/packages/shared/prisma/migrations/20260312000000_add_blob_storage_integration_error_fields/migration.sql b/packages/shared/prisma/migrations/20260312000000_add_blob_storage_integration_error_fields/migration.sql
new file mode 100644
index 0000000000..27f220873e
--- /dev/null
+++ b/packages/shared/prisma/migrations/20260312000000_add_blob_storage_integration_error_fields/migration.sql
@@ -0,0 +1,2 @@
+ALTER TABLE "blob_storage_integrations" ADD COLUMN IF NOT EXISTS "last_error" TEXT;
+ALTER TABLE "blob_storage_integrations" ADD COLUMN IF NOT EXISTS "last_error_at" TIMESTAMP(3);
diff --git a/packages/shared/prisma/schema.prisma b/packages/shared/prisma/schema.prisma
index 046107a103..396e6e0904 100644
--- a/packages/shared/prisma/schema.prisma
+++ b/packages/shared/prisma/schema.prisma
@@ -1126,6 +1126,10 @@ model BlobStorageIntegration {
exportStartDate DateTime? @map("export_start_date")
exportSource AnalyticsIntegrationExportSource @default(TRACES_OBSERVATIONS) @map("export_source")
+ // Error tracking
+ lastError String? @map("last_error")
+ lastErrorAt DateTime? @map("last_error_at")
+
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @default(now()) @updatedAt @map("updated_at")
diff --git a/web/public/generated/api/openapi.yml b/web/public/generated/api/openapi.yml
index ab0b617539..29cdf973ca 100644
--- a/web/public/generated/api/openapi.yml
+++ b/web/public/generated/api/openapi.yml
@@ -650,6 +650,53 @@ paths:
schema:
$ref: '#/components/schemas/CreateBlobStorageIntegrationRequest'
/api/public/integrations/blob-storage/{id}:
+ get:
+ description: >-
+ Get the sync status of a blob storage integration by integration ID
+ (requires organization-scoped API key)
+ operationId: blobStorageIntegrations_getBlobStorageIntegrationStatus
+ tags:
+ - BlobStorageIntegrations
+ parameters:
+ - name: id
+ in: path
+ required: true
+ schema:
+ type: string
+ responses:
+ '200':
+ description: ''
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/BlobStorageIntegrationStatusResponse'
+ '400':
+ description: ''
+ content:
+ application/json:
+ schema: {}
+ '401':
+ description: ''
+ content:
+ application/json:
+ schema: {}
+ '403':
+ description: ''
+ content:
+ application/json:
+ schema: {}
+ '404':
+ description: ''
+ content:
+ application/json:
+ schema: {}
+ '405':
+ description: ''
+ content:
+ application/json:
+ schema: {}
+ security:
+ - BasicAuth: []
delete:
description: >-
Delete a blob storage integration by ID (requires organization-scoped
@@ -6349,6 +6396,13 @@ components:
type: string
format: date-time
nullable: true
+ lastError:
+ type: string
+ nullable: true
+ lastErrorAt:
+ type: string
+ format: date-time
+ nullable: true
createdAt:
type: string
format: date-time
@@ -6379,6 +6433,79 @@ components:
$ref: '#/components/schemas/BlobStorageIntegrationResponse'
required:
- data
+ BlobStorageSyncStatus:
+ title: BlobStorageSyncStatus
+ type: string
+ enum:
+ - idle
+ - queued
+ - up_to_date
+ - disabled
+ - error
+ description: >-
+ Sync status of the blob storage integration:
+
+ - `disabled` β€” integration is not enabled
+
+ - `error` β€” last export failed (see `lastError` for details)
+
+ - `idle` β€” enabled but has never exported yet
+
+ - `queued` β€” next export is overdue (`nextSyncAt` is in the past) and
+ waiting to be picked up by the worker
+
+ - `up_to_date` β€” all available data has been exported; next export is
+ scheduled for the future
+
+
+ **ETL usage**: poll this endpoint and check for `up_to_date` status.
+ Compare `lastSyncAt` against your
+
+ ETL bookmark to determine if new data is available. Note that exports
+ run with a 30-minute lag buffer,
+
+ so `lastSyncAt` will always be at least 30 minutes behind real-time.
+ BlobStorageIntegrationStatusResponse:
+ title: BlobStorageIntegrationStatusResponse
+ type: object
+ properties:
+ id:
+ type: string
+ projectId:
+ type: string
+ syncStatus:
+ $ref: '#/components/schemas/BlobStorageSyncStatus'
+ enabled:
+ type: boolean
+ lastSyncAt:
+ type: string
+ format: date-time
+ nullable: true
+ description: >-
+ End of the last successfully exported time window. Compare against
+ your ETL bookmark to determine if new data is available. Null if the
+ integration has never synced.
+ nextSyncAt:
+ type: string
+ format: date-time
+ nullable: true
+ description: When the next export is scheduled. Null if no sync has occurred yet.
+ lastError:
+ type: string
+ nullable: true
+ description: >-
+ Raw error message from the storage provider (S3/Azure/GCS) if the
+ last export failed. Cleared on successful export.
+ lastErrorAt:
+ type: string
+ format: date-time
+ nullable: true
+ description: When the last error occurred. Cleared on successful export.
+ required:
+ - id
+ - projectId
+ - syncStatus
+ - enabled
BlobStorageIntegrationDeletionResponse:
title: BlobStorageIntegrationDeletionResponse
type: object
diff --git a/web/src/__tests__/server/blob-storage-integration-status-api.servertest.ts b/web/src/__tests__/server/blob-storage-integration-status-api.servertest.ts
new file mode 100644
index 0000000000..8be5916902
--- /dev/null
+++ b/web/src/__tests__/server/blob-storage-integration-status-api.servertest.ts
@@ -0,0 +1,417 @@
+/** @jest-environment node */
+
+import {
+ makeZodVerifiedAPICall,
+ makeAPICall,
+} from "@/src/__tests__/test-utils";
+import { prisma } from "@langfuse/shared/src/db";
+import { z } from "zod/v4";
+import { randomUUID } from "crypto";
+import {
+ createAndAddApiKeysToDb,
+ createBasicAuthHeader,
+} from "@langfuse/shared/src/server";
+
+const BlobStorageIntegrationStatusResponseSchema = z
+ .object({
+ id: z.string(),
+ projectId: z.string(),
+ syncStatus: z.enum(["idle", "queued", "up_to_date", "disabled", "error"]),
+ enabled: z.boolean(),
+ lastSyncAt: z.coerce.date().nullable(),
+ nextSyncAt: z.coerce.date().nullable(),
+ lastError: z.string().nullable(),
+ lastErrorAt: z.coerce.date().nullable(),
+ })
+ .strict();
+
+// Stable reference timestamps for table tests
+const NOW = Date.now();
+const HOUR_AGO = new Date(NOW - 60 * 60 * 1000);
+const TWO_HOURS_AGO = new Date(NOW - 2 * 60 * 60 * 1000);
+const THIRTY_MIN_AGO = new Date(NOW - 30 * 60 * 1000);
+const TEN_MIN_AGO = new Date(NOW - 10 * 60 * 1000);
+const TOMORROW = new Date(NOW + 24 * 60 * 60 * 1000);
+
+describe("Blob Storage Integration Status API - GET /api/public/integrations/blob-storage/{id}", () => {
+ let testOrgId: string;
+ let testProjectId: string;
+ let testApiKey: string;
+ let testApiSecretKey: string;
+ let otherOrgId: string;
+ let otherProjectId: string;
+
+ beforeAll(async () => {
+ const testOrg = await prisma.organization.create({
+ data: {
+ name: `Blob Status Test Org ${randomUUID().substring(0, 8)}`,
+ cloudConfig: { plan: "Team" },
+ },
+ });
+ testOrgId = testOrg.id;
+
+ const testProject = await prisma.project.create({
+ data: {
+ name: `Blob Status Test Project ${randomUUID().substring(0, 8)}`,
+ orgId: testOrgId,
+ },
+ });
+ testProjectId = testProject.id;
+
+ const orgApiKey = await createAndAddApiKeysToDb({
+ prisma,
+ entityId: testOrgId,
+ scope: "ORGANIZATION",
+ note: "Test API Key for Blob Status API",
+ predefinedKeys: {
+ publicKey: `pk-lf-bstat-${randomUUID().substring(0, 8)}`,
+ secretKey: `sk-lf-bstat-${randomUUID().substring(0, 8)}`,
+ },
+ });
+ testApiKey = orgApiKey.publicKey;
+ testApiSecretKey = orgApiKey.secretKey;
+
+ const otherOrg = await prisma.organization.create({
+ data: {
+ name: `Other Blob Status Org ${randomUUID().substring(0, 8)}`,
+ cloudConfig: { plan: "Team" },
+ },
+ });
+ otherOrgId = otherOrg.id;
+
+ const otherProject = await prisma.project.create({
+ data: {
+ name: `Other Blob Status Project ${randomUUID().substring(0, 8)}`,
+ orgId: otherOrgId,
+ },
+ });
+ otherProjectId = otherProject.id;
+ });
+
+ afterAll(async () => {
+ await prisma.organization.delete({ where: { id: testOrgId } });
+ await prisma.organization.delete({ where: { id: otherOrgId } });
+ });
+
+ afterEach(async () => {
+ await prisma.blobStorageIntegration.deleteMany({
+ where: { projectId: { in: [testProjectId, otherProjectId] } },
+ });
+ });
+
+ // --- Auth & 404 tests (unique setup, not table-friendly) ---
+
+ it("should return 401 with invalid API key", async () => {
+ const result = await makeAPICall(
+ "GET",
+ `/api/public/integrations/blob-storage/${testProjectId}`,
+ undefined,
+ createBasicAuthHeader("invalid-key", "invalid-secret"),
+ );
+ expect(result.status).toBe(401);
+ });
+
+ it("should return 403 with project-scoped API key", async () => {
+ const projectApiKey = await createAndAddApiKeysToDb({
+ prisma,
+ entityId: testProjectId,
+ scope: "PROJECT",
+ note: "Project API Key for status test",
+ predefinedKeys: {
+ publicKey: `pk-lf-pstat-${randomUUID().substring(0, 8)}`,
+ secretKey: `sk-lf-pstat-${randomUUID().substring(0, 8)}`,
+ },
+ });
+
+ const result = await makeAPICall(
+ "GET",
+ `/api/public/integrations/blob-storage/${testProjectId}`,
+ undefined,
+ createBasicAuthHeader(projectApiKey.publicKey, projectApiKey.secretKey),
+ );
+ expect(result.status).toBe(403);
+
+ await prisma.apiKey.delete({ where: { id: projectApiKey.id } });
+ });
+
+ it("should return 404 when no integration exists", async () => {
+ const result = await makeAPICall(
+ "GET",
+ `/api/public/integrations/blob-storage/${testProjectId}`,
+ undefined,
+ createBasicAuthHeader(testApiKey, testApiSecretKey),
+ );
+ expect(result.status).toBe(404);
+ });
+
+ it("should return 404 for integration from different organization", async () => {
+ await prisma.blobStorageIntegration.create({
+ data: {
+ projectId: otherProjectId,
+ type: "S3",
+ bucketName: "other-bucket",
+ region: "us-east-1",
+ accessKeyId: "other-key",
+ secretAccessKey: "other-secret",
+ prefix: "",
+ exportFrequency: "daily",
+ enabled: true,
+ forcePathStyle: false,
+ fileType: "JSONL",
+ exportMode: "FULL_HISTORY",
+ },
+ });
+
+ const result = await makeAPICall(
+ "GET",
+ `/api/public/integrations/blob-storage/${otherProjectId}`,
+ undefined,
+ createBasicAuthHeader(testApiKey, testApiSecretKey),
+ );
+ expect(result.status).toBe(404);
+ });
+
+ // --- syncStatus derivation (table-driven) ---
+
+ it.each<{
+ name: string;
+ enabled: boolean;
+ lastSyncAt: Date | null;
+ nextSyncAt: Date | null;
+ lastError: string | null;
+ lastErrorAt: Date | null;
+ expectedStatus: string;
+ expectedFields?: Record<string, unknown>;
+ }>([
+ {
+ name: "disabled (basic)",
+ enabled: false,
+ lastSyncAt: null,
+ nextSyncAt: null,
+ lastError: null,
+ lastErrorAt: null,
+ expectedStatus: "disabled",
+ expectedFields: { enabled: false },
+ },
+ {
+ name: "idle (enabled, never synced)",
+ enabled: true,
+ lastSyncAt: null,
+ nextSyncAt: null,
+ lastError: null,
+ lastErrorAt: null,
+ expectedStatus: "idle",
+ expectedFields: { enabled: true, lastSyncAt: null },
+ },
+ {
+ name: "up_to_date (nextSyncAt in future)",
+ enabled: true,
+ lastSyncAt: HOUR_AGO,
+ nextSyncAt: TOMORROW,
+ lastError: null,
+ lastErrorAt: null,
+ expectedStatus: "up_to_date",
+ expectedFields: { lastError: null, lastErrorAt: null },
+ },
+ {
+ // Edge case: lastSyncAt set but nextSyncAt null (data inconsistency).
+ // Worker always sets both, but defensive test documents the fallthrough.
+ name: "up_to_date (lastSyncAt set, nextSyncAt null β€” data inconsistency)",
+ enabled: true,
+ lastSyncAt: HOUR_AGO,
+ nextSyncAt: null,
+ lastError: null,
+ lastErrorAt: null,
+ expectedStatus: "up_to_date",
+ },
+ {
+ name: "queued (nextSyncAt in past)",
+ enabled: true,
+ lastSyncAt: TWO_HOURS_AGO,
+ nextSyncAt: THIRTY_MIN_AGO,
+ lastError: null,
+ lastErrorAt: null,
+ expectedStatus: "queued",
+ },
+ {
+ name: "error (lastError set, nextSyncAt in past)",
+ enabled: true,
+ lastSyncAt: HOUR_AGO,
+ nextSyncAt: HOUR_AGO,
+ lastError: "Access Denied",
+ lastErrorAt: THIRTY_MIN_AGO,
+ expectedStatus: "error",
+ expectedFields: { lastError: "Access Denied" },
+ },
+ {
+ name: "disabled > error (precedence: disabled wins over lastError)",
+ enabled: false,
+ lastSyncAt: HOUR_AGO,
+ nextSyncAt: THIRTY_MIN_AGO,
+ lastError: "Access Denied",
+ lastErrorAt: THIRTY_MIN_AGO,
+ expectedStatus: "disabled",
+ expectedFields: { lastError: "Access Denied" },
+ },
+ {
+ name: "error > up_to_date (precedence: lastError wins over future nextSyncAt)",
+ enabled: true,
+ lastSyncAt: HOUR_AGO,
+ nextSyncAt: TOMORROW,
+ lastError: "The bucket does not exist",
+ lastErrorAt: TEN_MIN_AGO,
+ expectedStatus: "error",
+ expectedFields: { lastError: "The bucket does not exist" },
+ },
+ ])(
+ "should return '$expectedStatus' when $name",
+ async ({
+ enabled,
+ lastSyncAt,
+ nextSyncAt,
+ lastError,
+ lastErrorAt,
+ expectedStatus,
+ expectedFields,
+ }) => {
+ await prisma.blobStorageIntegration.create({
+ data: {
+ projectId: testProjectId,
+ type: "S3",
+ bucketName: "test-bucket",
+ region: "us-east-1",
+ accessKeyId: "test-key",
+ secretAccessKey: "test-secret",
+ prefix: "",
+ exportFrequency: "daily",
+ enabled,
+ forcePathStyle: false,
+ fileType: "JSONL",
+ exportMode: "FULL_HISTORY",
+ lastSyncAt,
+ nextSyncAt,
+ lastError,
+ lastErrorAt,
+ },
+ });
+
+ const response = await makeZodVerifiedAPICall(
+ BlobStorageIntegrationStatusResponseSchema,
+ "GET",
+ `/api/public/integrations/blob-storage/${testProjectId}`,
+ undefined,
+ createBasicAuthHeader(testApiKey, testApiSecretKey),
+ 200,
+ );
+
+ expect(response.status).toBe(200);
+ expect(response.body.syncStatus).toBe(expectedStatus);
+ if (expectedFields) {
+ expect(response.body).toMatchObject(expectedFields);
+ }
+ },
+ );
+
+ // --- lastErrorAt exact value assertion ---
+
+ it("should return exact lastErrorAt timestamp", async () => {
+ const errorDate = new Date(Date.now() - 30 * 60 * 1000);
+
+ await prisma.blobStorageIntegration.create({
+ data: {
+ projectId: testProjectId,
+ type: "S3",
+ bucketName: "test-bucket",
+ region: "us-east-1",
+ accessKeyId: "test-key",
+ secretAccessKey: "test-secret",
+ prefix: "",
+ exportFrequency: "hourly",
+ enabled: true,
+ forcePathStyle: false,
+ fileType: "JSONL",
+ exportMode: "FULL_HISTORY",
+ lastSyncAt: HOUR_AGO,
+ nextSyncAt: HOUR_AGO,
+ lastError: "Access Denied",
+ lastErrorAt: errorDate,
+ },
+ });
+
+ const response = await makeZodVerifiedAPICall(
+ BlobStorageIntegrationStatusResponseSchema,
+ "GET",
+ `/api/public/integrations/blob-storage/${testProjectId}`,
+ undefined,
+ createBasicAuthHeader(testApiKey, testApiSecretKey),
+ 200,
+ );
+
+ expect(new Date(response.body.lastErrorAt).getTime()).toBe(
+ errorDate.getTime(),
+ );
+ });
+
+ // --- Error clearing (multi-step, not table-friendly) ---
+
+ it("should clear error fields when lastError is set back to null (simulates successful sync)", async () => {
+ const errorDate = new Date(Date.now() - 60 * 60 * 1000);
+
+ await prisma.blobStorageIntegration.create({
+ data: {
+ projectId: testProjectId,
+ type: "S3",
+ bucketName: "test-bucket",
+ region: "us-east-1",
+ accessKeyId: "test-key",
+ secretAccessKey: "test-secret",
+ prefix: "",
+ exportFrequency: "daily",
+ enabled: true,
+ forcePathStyle: false,
+ fileType: "JSONL",
+ exportMode: "FULL_HISTORY",
+ lastSyncAt: errorDate,
+ nextSyncAt: errorDate,
+ lastError: "Access Denied",
+ lastErrorAt: errorDate,
+ },
+ });
+
+ // Verify it's in error state
+ const errorResponse = await makeZodVerifiedAPICall(
+ BlobStorageIntegrationStatusResponseSchema,
+ "GET",
+ `/api/public/integrations/blob-storage/${testProjectId}`,
+ undefined,
+ createBasicAuthHeader(testApiKey, testApiSecretKey),
+ 200,
+ );
+ expect(errorResponse.body.syncStatus).toBe("error");
+
+ // Simulate successful sync: clear error, advance timestamps
+ const futureDate = new Date(Date.now() + 24 * 60 * 60 * 1000);
+ await prisma.blobStorageIntegration.update({
+ where: { projectId: testProjectId },
+ data: {
+ lastSyncAt: new Date(),
+ nextSyncAt: futureDate,
+ lastError: null,
+ lastErrorAt: null,
+ },
+ });
+
+ // Verify error is cleared and status is now up_to_date
+ const clearedResponse = await makeZodVerifiedAPICall(
+ BlobStorageIntegrationStatusResponseSchema,
+ "GET",
+ `/api/public/integrations/blob-storage/${testProjectId}`,
+ undefined,
+ createBasicAuthHeader(testApiKey, testApiSecretKey),
+ 200,
+ );
+ expect(clearedResponse.body.syncStatus).toBe("up_to_date");
+ expect(clearedResponse.body.lastError).toBeNull();
+ expect(clearedResponse.body.lastErrorAt).toBeNull();
+ });
+});
diff --git a/web/src/features/blobstorage-integration/deriveSyncStatus.ts b/web/src/features/blobstorage-integration/deriveSyncStatus.ts
new file mode 100644
index 0000000000..c7da0b8b44
--- /dev/null
+++ b/web/src/features/blobstorage-integration/deriveSyncStatus.ts
@@ -0,0 +1,19 @@
+import type { BlobStorageSyncStatus } from "@/src/features/blobstorage-integration/types";
+
+export function deriveSyncStatus(integration: {
+ enabled: boolean;
+ lastError: string | null;
+ lastSyncAt: Date | null;
+ nextSyncAt: Date | null;
+}): BlobStorageSyncStatus {
+ if (!integration.enabled) return "disabled";
+ if (integration.lastError) return "error";
+ if (!integration.lastSyncAt) return "idle";
+
+ const now = new Date();
+ if (integration.nextSyncAt && integration.nextSyncAt <= now) {
+ return "queued";
+ }
+
+ return "up_to_date";
+}
diff --git a/web/src/features/blobstorage-integration/types.ts b/web/src/features/blobstorage-integration/types.ts
index fdf91018d9..6b1cd6017c 100644
--- a/web/src/features/blobstorage-integration/types.ts
+++ b/web/src/features/blobstorage-integration/types.ts
@@ -38,3 +38,10 @@ export const blobStorageIntegrationFormSchema = z.object({
export type BlobStorageIntegrationFormSchema = z.infer<
typeof blobStorageIntegrationFormSchema
>;
+
+export type BlobStorageSyncStatus =
+ | "idle"
+ | "queued"
+ | "up_to_date"
+ | "disabled"
+ | "error";
diff --git a/web/src/features/public-api/types/blob-storage-integrations.ts b/web/src/features/public-api/types/blob-storage-integrations.ts
index 6ce7f464f7..0bf92ad1e3 100644
--- a/web/src/features/public-api/types/blob-storage-integrations.ts
+++ b/web/src/features/public-api/types/blob-storage-integrations.ts
@@ -76,6 +76,8 @@ export const BlobStorageIntegrationResponse = z
exportStartDate: z.coerce.date().nullable(),
nextSyncAt: z.coerce.date().nullable(),
lastSyncAt: z.coerce.date().nullable(),
+ lastError: z.string().nullable(),
+ lastErrorAt: z.coerce.date().nullable(),
createdAt: z.coerce.date(),
updatedAt: z.coerce.date(),
})
@@ -84,3 +86,28 @@ export const BlobStorageIntegrationResponse = z
export type BlobStorageIntegrationResponseType = z.infer<
typeof BlobStorageIntegrationResponse
>;
+
+export const BlobStorageSyncStatus = z.enum([
+ "idle",
+ "queued",
+ "up_to_date",
+ "disabled",
+ "error",
+]);
+
+export const BlobStorageIntegrationStatusResponse = z
+ .object({
+ id: z.string(),
+ projectId: z.string(),
+ syncStatus: BlobStorageSyncStatus,
+ enabled: z.boolean(),
+ lastSyncAt: z.coerce.date().nullable(),
+ nextSyncAt: z.coerce.date().nullable(),
+ lastError: z.string().nullable(),
+ lastErrorAt: z.coerce.date().nullable(),
+ })
+ .strict();
+
+export type BlobStorageIntegrationStatusResponseType = z.infer<
+ typeof BlobStorageIntegrationStatusResponse
+>;
diff --git a/web/src/pages/api/public/integrations/blob-storage/[id].ts b/web/src/pages/api/public/integrations/blob-storage/[id].ts
index 6c6da3f735..09ec760a64 100644
--- a/web/src/pages/api/public/integrations/blob-storage/[id].ts
+++ b/web/src/pages/api/public/integrations/blob-storage/[id].ts
@@ -5,12 +5,16 @@ import { redis } from "@langfuse/shared/src/server";
import { type NextApiRequest, type NextApiResponse } from "next";
import { hasEntitlementBasedOnPlan } from "@/src/features/entitlements/server/hasEntitlement";
import {
+ InvalidRequestError,
LangfuseNotFoundError,
UnauthorizedError,
ForbiddenError,
} from "@langfuse/shared";
+import type { BlobStorageIntegrationStatusResponseType } from "@/src/features/public-api/types/blob-storage-integrations";
+import { deriveSyncStatus } from "@/src/features/blobstorage-integration/deriveSyncStatus";
export default withMiddlewares({
+ GET: handleGetBlobStorageIntegrationStatus,
DELETE: handleDeleteBlobStorageIntegration,
});
@@ -51,7 +55,7 @@ async function handleDeleteBlobStorageIntegration(
const { id } = req.query;
if (!id || typeof id !== "string") {
- throw new Error("Invalid integration ID");
+ throw new InvalidRequestError("Invalid integration ID");
}
// Check if the integration exists and belongs to a project in the organization
@@ -77,3 +81,67 @@ async function handleDeleteBlobStorageIntegration(
message: "Blob storage integration successfully deleted",
});
}
+
+async function handleGetBlobStorageIntegrationStatus(
+ req: NextApiRequest,
+ res: NextApiResponse,
+) {
+ const authCheck = await new ApiAuthService(
+ prisma,
+ redis,
+ ).verifyAuthHeaderAndReturnScope(req.headers.authorization);
+ if (!authCheck.validKey) {
+ throw new UnauthorizedError(authCheck.error ?? "Unauthorized");
+ }
+
+ if (
+ authCheck.scope.accessLevel !== "organization" ||
+ !authCheck.scope.orgId
+ ) {
+ throw new ForbiddenError(
+ "Organization-scoped API key required for this operation.",
+ );
+ }
+
+ if (
+ !hasEntitlementBasedOnPlan({
+ plan: authCheck.scope.plan,
+ entitlement: "scheduled-blob-exports",
+ })
+ ) {
+ throw new ForbiddenError(
+ "scheduled-blob-exports entitlement required for this feature.",
+ );
+ }
+
+ const { id } = req.query;
+ if (!id || typeof id !== "string") {
+ throw new InvalidRequestError("Invalid integration ID");
+ }
+
+ const integration = await prisma.blobStorageIntegration.findUnique({
+ where: { projectId: id },
+ include: {
+ project: {
+ select: { orgId: true },
+ },
+ },
+ });
+
+ if (!integration || integration.project.orgId !== authCheck.scope.orgId) {
+ throw new LangfuseNotFoundError("Blob storage integration not found");
+ }
+
+ const responseData: BlobStorageIntegrationStatusResponseType = {
+ id: integration.projectId,
+ projectId: integration.projectId,
+ syncStatus: deriveSyncStatus(integration),
+ enabled: integration.enabled,
+ lastSyncAt: integration.lastSyncAt,
+ nextSyncAt: integration.nextSyncAt,
+ lastError: integration.lastError,
+ lastErrorAt: integration.lastErrorAt,
+ };
+
+ return res.status(200).json(responseData);
+}
diff --git a/web/src/pages/api/public/integrations/blob-storage/index.ts b/web/src/pages/api/public/integrations/blob-storage/index.ts
index 59e70a27ad..364d00f3da 100644
--- a/web/src/pages/api/public/integrations/blob-storage/index.ts
+++ b/web/src/pages/api/public/integrations/blob-storage/index.ts
@@ -87,6 +87,8 @@ async function handleGetBlobStorageIntegrations(
exportStartDate: integration.exportStartDate,
nextSyncAt: integration.nextSyncAt,
lastSyncAt: integration.lastSyncAt,
+ lastError: integration.lastError,
+ lastErrorAt: integration.lastErrorAt,
createdAt: integration.createdAt,
updatedAt: integration.updatedAt,
}),
@@ -189,6 +191,8 @@ async function handleUpsertBlobStorageIntegration(
exportStartDate: integration.exportStartDate,
nextSyncAt: integration.nextSyncAt,
lastSyncAt: integration.lastSyncAt,
+ lastError: integration.lastError,
+ lastErrorAt: integration.lastErrorAt,
createdAt: integration.createdAt,
updatedAt: integration.updatedAt,
};
diff --git a/worker/src/features/blobstorage/handleBlobStorageIntegrationProjectJob.ts b/worker/src/features/blobstorage/handleBlobStorageIntegrationProjectJob.ts
index 61486e1720..cc411723ad 100644
--- a/worker/src/features/blobstorage/handleBlobStorageIntegrationProjectJob.ts
+++ b/worker/src/features/blobstorage/handleBlobStorageIntegrationProjectJob.ts
@@ -433,6 +433,8 @@ export const handleBlobStorageIntegrationProjectJob = async (
data: {
lastSyncAt: maxTimestamp,
nextSyncAt,
+ lastError: null,
+ lastErrorAt: null,
},
});
@@ -461,6 +463,21 @@ export const handleBlobStorageIntegrationProjectJob = async (
`[BLOB INTEGRATION] Successfully processed blob storage integration for project ${projectId}`,
);
} catch (error) {
+ try {
+ const errorMessage = extractStorageErrorMessage(error);
+ await prisma.blobStorageIntegration.update({
+ where: { projectId },
+ data: {
+ lastError: errorMessage,
+ lastErrorAt: new Date(),
+ },
+ });
+ } catch (persistError) {
+ logger.error(
+ `[BLOB INTEGRATION] Failed to persist blob storage error for project ${projectId}`,
+ persistError,
+ );
+ }
logger.error(
`[BLOB INTEGRATION] Error processing blob storage integration for project ${projectId}`,
error,
@@ -468,3 +485,17 @@ export const handleBlobStorageIntegrationProjectJob = async (
throw error; // Rethrow to trigger retries
}
};
+
+function extractStorageErrorMessage(error: unknown): string {
+ if (!(error instanceof Error)) return String(error).slice(0, 1000);
+
+ // handleStorageError wraps SDK errors via { cause: sdkError }
+ // Unwrap to get the raw SDK message (S3/Azure/GCS)
+ const cause = error.cause;
+ if (cause instanceof Error) {
+ return cause.message.slice(0, 1000);
+ }
+
+ // Fallback: ClickHouse errors or other non-wrapped errors
+ return error.message.slice(0, 1000);
+}