Skip to content

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

feat(worker): count started/incomplete blob export attempts (LFE-10407) (#14396)

Niklas Semmler39f439e97316
diff --git a/worker/src/__tests__/blobStorageIntegrationProcessing.test.ts b/worker/src/__tests__/blobStorageIntegrationProcessing.test.ts
index 3c612f01d7..3dc7763ddb 100644
--- a/worker/src/__tests__/blobStorageIntegrationProcessing.test.ts
+++ b/worker/src/__tests__/blobStorageIntegrationProcessing.test.ts
@@ -15,6 +15,14 @@ const originalCloudRegion = vi.hoisted(() => {
return cloudRegion;
});
+// Override only recordIncrement so the attempt counter is assertable.
+const mockRecordIncrement = vi.hoisted(() => vi.fn());
+vi.mock("@langfuse/shared/src/server", async (importOriginal) => {
+ const actual =
+ await importOriginal<typeof import("@langfuse/shared/src/server")>();
+ return { ...actual, recordIncrement: mockRecordIncrement };
+});
+
import { env } from "../env";
import { randomUUID } from "crypto";
import {
@@ -335,11 +343,28 @@ describe("BlobStorageIntegrationProcessingJob", () => {
]);
// When
+ mockRecordIncrement.mockClear();
await handleBlobStorageIntegrationProjectJob({
data: { payload: { projectId } },
} as Job);
// Then
+ // Each of the 4 tables emits a started + success attempt counter (LFE-10407).
+ for (const table of [
+ "traces",
+ "observations",
+ "scores",
+ "observations_v2",
+ ]) {
+ for (const outcome of ["started", "success"]) {
+ expect(mockRecordIncrement).toHaveBeenCalledWith(
+ "langfuse.blobstorage.table_export.count",
+ 1,
+ { outcome, table, projectId },
+ );
+ }
+ }
+
const files = await s3StorageService.listFiles(s3Prefix);
const projectFiles = files.filter((f) => f.file.includes(projectId));
diff --git a/worker/src/__tests__/inFlightExports.unit.test.ts b/worker/src/__tests__/inFlightExports.unit.test.ts
index 5c58abc5b1..e72eee6942 100644
--- a/worker/src/__tests__/inFlightExports.unit.test.ts
+++ b/worker/src/__tests__/inFlightExports.unit.test.ts
@@ -1,8 +1,11 @@
import { beforeEach, describe, expect, it, vi } from "vitest";
-// The tracker only needs a logger; stub the heavy shared server barrel.
+const mockRecordIncrement = vi.hoisted(() => vi.fn());
+
+// The tracker only needs a logger + metric sink; stub the heavy shared barrel.
vi.mock("@langfuse/shared/src/server", () => ({
logger: { info: vi.fn(), warn: vi.fn(), error: vi.fn() },
+ recordIncrement: mockRecordIncrement,
}));
import {
@@ -11,6 +14,7 @@ import {
getInFlightBlobExportCount,
logInFlightBlobExportsOnShutdown,
resetInFlightBlobExports,
+ BLOB_TABLE_EXPORT_METRIC,
} from "../features/blobstorage/inFlightExports";
const makeEntry = (table: string) => ({
@@ -24,7 +28,10 @@ const makeEntry = (table: string) => ({
describe("inFlightExports", () => {
// Singleton registry — drain it so tests are order-independent.
- beforeEach(() => resetInFlightBlobExports());
+ beforeEach(() => {
+ resetInFlightBlobExports();
+ mockRecordIncrement.mockClear();
+ });
it("tracks and clears in-flight exports by handle", () => {
expect(getInFlightBlobExportCount()).toBe(0);
@@ -58,4 +65,38 @@ describe("inFlightExports", () => {
expect(() => logInFlightBlobExportsOnShutdown()).not.toThrow();
unregisterInFlightBlobExport(h);
});
+
+ it("emits an aborted increment per in-flight export on shutdown", () => {
+ // Empty registry: nothing to abort.
+ logInFlightBlobExportsOnShutdown();
+ expect(mockRecordIncrement).not.toHaveBeenCalled();
+
+ const h1 = registerInFlightBlobExport(makeEntry("observations_v2"));
+ const h2 = registerInFlightBlobExport(makeEntry("scores"));
+
+ logInFlightBlobExportsOnShutdown();
+
+ expect(mockRecordIncrement).toHaveBeenCalledTimes(2);
+ expect(mockRecordIncrement).toHaveBeenCalledWith(
+ BLOB_TABLE_EXPORT_METRIC,
+ 1,
+ {
+ outcome: "aborted",
+ table: "observations_v2",
+ projectId: "p-1",
+ },
+ );
+ expect(mockRecordIncrement).toHaveBeenCalledWith(
+ BLOB_TABLE_EXPORT_METRIC,
+ 1,
+ {
+ outcome: "aborted",
+ table: "scores",
+ projectId: "p-1",
+ },
+ );
+
+ unregisterInFlightBlobExport(h1);
+ unregisterInFlightBlobExport(h2);
+ });
});
diff --git a/worker/src/features/blobstorage/handleBlobStorageIntegrationProjectJob.ts b/worker/src/features/blobstorage/handleBlobStorageIntegrationProjectJob.ts
index 31e74ae5e7..10eafecef5 100644
--- a/worker/src/features/blobstorage/handleBlobStorageIntegrationProjectJob.ts
+++ b/worker/src/features/blobstorage/handleBlobStorageIntegrationProjectJob.ts
@@ -17,6 +17,7 @@ import {
getCurrentSpan,
instrumentAsync,
recordGauge,
+ recordIncrement,
BlobStorageIntegrationProcessingQueue,
queryClickhouse,
QueueJobs,
@@ -30,6 +31,8 @@ import {
import {
registerInFlightBlobExport,
unregisterInFlightBlobExport,
+ BLOB_TABLE_EXPORT_METRIC,
+ type BlobTableExportOutcome,
} from "./inFlightExports";
import { WORKER_HOST_ID } from "../../utils/hostId";
import {
@@ -317,6 +320,16 @@ const processBlobStorageExport = async (config: {
startedAt: Date.now(),
});
+ recordIncrement(BLOB_TABLE_EXPORT_METRIC, 1, {
+ outcome: "started" satisfies BlobTableExportOutcome,
+ table: config.table,
+ projectId: config.projectId,
+ });
+
+ // Outside the try so the catch can distinguish a real upload success from
+ // a failure.
+ let uploadSucceeded = false;
+
try {
const blobStorageProps = getFileTypeProperties(config.fileType);
@@ -432,6 +445,14 @@ const processBlobStorageExport = async (config: {
data: fileStream,
partSizeBytes: 100 * 1024 * 1024, // 100 MB part size
});
+ // Record at the upload boundary so a throw in the `finally` below
+ // can't miscount a real success as a failure.
+ uploadSucceeded = true;
+ recordIncrement(BLOB_TABLE_EXPORT_METRIC, 1, {
+ outcome: "success" satisfies BlobTableExportOutcome,
+ table: config.table,
+ projectId: config.projectId,
+ });
logger.info(
`[BLOB INTEGRATION] Successfully exported ${config.table} for project ${config.projectId}: ` +
@@ -457,6 +478,14 @@ const processBlobStorageExport = async (config: {
}
}
} catch (error) {
+ // Skip if `success` already fired (a later step threw post-upload).
+ if (!uploadSucceeded) {
+ recordIncrement(BLOB_TABLE_EXPORT_METRIC, 1, {
+ outcome: "failure" satisfies BlobTableExportOutcome,
+ table: config.table,
+ projectId: config.projectId,
+ });
+ }
logger.error(
`[BLOB INTEGRATION] Error exporting ${config.table} for project ${config.projectId} ` +
`(jobId=${config.bullmqJobId} attemptsMade=${config.bullmqAttemptsMade} host=${WORKER_HOST_ID})`,
diff --git a/worker/src/features/blobstorage/inFlightExports.ts b/worker/src/features/blobstorage/inFlightExports.ts
index 497afe138b..8ba4cc02db 100644
--- a/worker/src/features/blobstorage/inFlightExports.ts
+++ b/worker/src/features/blobstorage/inFlightExports.ts
@@ -1,6 +1,18 @@
-import { logger } from "@langfuse/shared/src/server";
+import { logger, recordIncrement } from "@langfuse/shared/src/server";
import { WORKER_HOST_ID } from "../../utils/hostId";
+// Per-table attempt counter. Residual `started - success - failure - aborted`
+// counts silent hard kills (OOM) that emit nothing. Lives here to avoid an
+// import cycle with the handler. See LFE-10407.
+export const BLOB_TABLE_EXPORT_METRIC =
+ "langfuse.blobstorage.table_export.count";
+
+export type BlobTableExportOutcome =
+ | "started"
+ | "success"
+ | "failure"
+ | "aborted";
+
export type InFlightBlobExport = {
jobId: string | undefined;
projectId: string;
@@ -53,5 +65,11 @@ export const logInFlightBlobExportsOnShutdown = (): void => {
`window=[${entry.minTimestamp}, ${entry.maxTimestamp}] ` +
`elapsedMs=${now - entry.startedAt}`,
);
+ // May double with `success` if the export finishes within the grace period.
+ recordIncrement(BLOB_TABLE_EXPORT_METRIC, 1, {
+ outcome: "aborted" satisfies BlobTableExportOutcome,
+ table: entry.table,
+ projectId: entry.projectId,
+ });
}
};