🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.
TypeScript analyticsautogenevaluationlangchainlarge-language-modelsllama-indexllmllm-evaluationllm-observabilityllmopsmonitoringobservabilityopen-sourceopenaiplaygroundprompt-engineeringprompt-managementself-hostedycombinator
fix(core): for failed events return correct errors on ingestion (#566)
Max Deichmannf27c8a0629dd
diff --git a/src/__tests__/ingestion.servertest.ts b/src/__tests__/ingestion.servertest.tsindex 877a3dad67..f03e743f0e 100644--- a/src/__tests__/ingestion.servertest.ts+++ b/src/__tests__/ingestion.servertest.ts@@ -247,6 +247,108 @@ describe("/api/public/ingestion API Endpoint", () => {expect(dbTrace.length).toBe(1);});+ it("should fail for auth errors", async () => {+ const traceId = v4();+ const scoreId = v4();++ const responseOne = await makeAPICall("POST", "/api/public/ingestion", {+ batch: [+ {+ id: v4(),+ type: "trace-create",+ timestamp: new Date().toISOString(),+ body: {+ id: traceId,+ name: "trace-name",+ userId: "user-1",+ metadata: { key: "value" },+ release: "1.0.0",+ version: "2.0.0",+ },+ },+ {+ id: v4(),+ type: "score-create",+ timestamp: new Date().toISOString(),+ body: {+ id: scoreId,+ name: "score-name",+ value: 100.5,+ traceId: "some-random-id",+ },+ },+ ],+ });++ console.log(responseOne.body);+ expect(responseOne.status).toBe(207);++ expect("errors" in responseOne.body).toBe(true);+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access+ expect(responseOne.body?.errors.length).toBe(1);+ expect("successes" in responseOne.body).toBe(true);+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access+ expect(responseOne.body?.successes.length).toBe(1);++ const dbTrace = await prisma.trace.findMany({+ where: {+ name: "trace-name",+ },+ });++ expect(dbTrace.length).toBe(1);+ });++ it("should fail for resource not found", async () => {+ const traceId = v4();++ const responseOne = await makeAPICall("POST", "/api/public/ingestion", {+ batch: [+ {+ id: v4(),+ type: "trace-create",+ timestamp: new Date().toISOString(),+ body: {+ id: traceId,+ name: "trace-name",+ userId: "user-1",+ metadata: { key: "value" },+ release: "1.0.0",+ version: "2.0.0",+ },+ },+ {+ id: v4(),+ type: "observation-update",+ timestamp: new Date().toISOString(),+ body: {+ id: "some-random-id",+ type: "GENERATION",+ output: { key: "this is a great gpt output" },+ },+ },+ ],+ });++ console.log(responseOne.body);+ expect(responseOne.status).toBe(207);++ expect("errors" in responseOne.body).toBe(true);+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access+ expect(responseOne.body?.errors.length).toBe(1);+ expect("successes" in responseOne.body).toBe(true);+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access+ expect(responseOne.body?.successes.length).toBe(1);++ const dbTrace = await prisma.trace.findMany({+ where: {+ name: "trace-name",+ },+ });++ expect(dbTrace.length).toBe(1);+ });+it("should update all token counts if update does not contain model name", async () => {const traceId = v4();const generationId = v4();diff --git a/src/pages/api/public/ingestion.ts b/src/pages/api/public/ingestion.tsindex 9b5e84c50e..8003c33428 100644--- a/src/pages/api/public/ingestion.ts+++ b/src/pages/api/public/ingestion.ts@@ -245,24 +245,27 @@ export const handleBatchResult = (message: "Invalid request data",error: error.error.message,});+ } else if (error.error instanceof AuthenticationError) {+ returnedErrors.push({+ id: error.id,+ status: 401,+ message: "Authentication error",+ error: error.error.message,+ });} else if (error.error instanceof ResourceNotFoundError) {- if (!errors.some((res) => res.id === error.id)) {- returnedErrors.push({- id: error.id,- status: 404,- message: "Resource not found",- error: error.error.message,- });- }+ returnedErrors.push({+ id: error.id,+ status: 404,+ message: "Resource not found",+ error: error.error.message,+ });} else {- if (!errors.some((res) => res.id === error.id)) {- returnedErrors.push({- id: error.id,- status: 500,- message: "Error processing events",- error: "Internal Server Error",- });- }+ returnedErrors.push({+ id: error.id,+ status: 500,+ message: "Error processing events",+ error: "Internal Server Error",+ });}});