Skip to content

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

fix(otel): Make sure we do not process empty otel events (#9082)

Valery Meleshkin19e9da214e5e
diff --git a/packages/shared/src/server/ingestion/processEventBatch.ts b/packages/shared/src/server/ingestion/processEventBatch.ts
index 2bea1ab272..b684de5284 100644
--- a/packages/shared/src/server/ingestion/processEventBatch.ts
+++ b/packages/shared/src/server/ingestion/processEventBatch.ts
@@ -115,6 +115,9 @@ export const processEventBatch = async (
error?: string;
}[];
}> => {
+ if (input.length === 0) {
+ return { successes: [], errors: [] };
+ }
const { delay = null, source = "api", isLangfuseInternal = false } = options;
// add context of api call to the span
diff --git a/worker/src/__tests__/processEventBatch.test.ts b/worker/src/__tests__/processEventBatch.test.ts
new file mode 100644
index 0000000000..41b91b8c65
--- /dev/null
+++ b/worker/src/__tests__/processEventBatch.test.ts
@@ -0,0 +1,25 @@
+import { describe, it, expect, assert } from "vitest";
+import { processEventBatch } from "@langfuse/shared/src/server";
+
+describe("processEventBatch", () => {
+ it("returns early on empty input", async () => {
+ // Auth check with missing projectId will cause an exception unless
+ // there is an early return in processEventBatch
+ const authCheck = {
+ validKey: true as const,
+ scope: {
+ projectId: null,
+ accessLevel: "project" as const,
+ },
+ };
+
+ assert.doesNotThrow(
+ async () => await processEventBatch([], authCheck, {}),
+ "UnauthorizedError",
+ );
+
+ const res = await processEventBatch([], authCheck, {});
+ expect(res.successes).toEqual([]);
+ expect(res.errors).toEqual([]);
+ });
+});