🪢 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: export i/o for traces (#4673)
Max Deichmann273d29c3836a
diff --git a/worker/src/__tests__/batch-export.test.ts b/worker/src/__tests__/batch-export.test.tsindex 1d35edf301..5b53a436a4 100644--- a/worker/src/__tests__/batch-export.test.ts+++ b/worker/src/__tests__/batch-export.test.ts@@ -339,10 +339,20 @@ describe("batch export test suite", () => {createTrace({project_id: projectId,id: randomUUID(),+ input: "test",+ output: "test",+ metadata: {+ test: "test",+ },}),createTrace({project_id: projectId,id: randomUUID(),+ input: "test",+ output: "test",+ metadata: {+ test: "test",+ },}),];@@ -398,9 +408,20 @@ describe("batch export test suite", () => {expect.objectContaining({id: traces[0].id,test: [score.value],+ input: "test",+ output: "test",+ metadata: {+ test: "test",+ },}),+expect.objectContaining({id: traces[1].id,+ input: "test",+ output: "test",+ metadata: {+ test: "test",+ },}),]),);diff --git a/worker/src/features/batchExport/handleBatchExportJob.ts b/worker/src/features/batchExport/handleBatchExportJob.tsindex 932d1cb5e1..27eb1ac967 100644--- a/worker/src/features/batchExport/handleBatchExportJob.ts+++ b/worker/src/features/batchExport/handleBatchExportJob.ts@@ -32,6 +32,7 @@ import {getTracesTableMetrics,getScoresForTraces,logger,+ getTracesByIds,} from "@langfuse/shared/src/server";import { env } from "../../env";import { BatchExportSessionsRow, BatchExportTracesRow } from "./types";@@ -358,18 +359,28 @@ export const getDatabaseReadStream = async ({Math.floor(offset / pageSize),);- const metrics = await getTracesTableMetrics({- projectId,- filter: [- ...(filter ?? []),- {- type: "stringOptions",- operator: "any of",- column: "ID",- value: traces.map((t) => t.id),- },- ],- });+ const [metrics, fullTraces] = await Promise.all([+ getTracesTableMetrics({+ projectId,+ filter: [+ ...(filter ?? []),+ {+ type: "stringOptions",+ operator: "any of",+ column: "ID",+ value: traces.map((t) => t.id),+ },+ ],+ }),+ getTracesByIds(+ traces.map((t) => t.id),+ projectId,+ traces.reduce(+ (min, t) => (!min || t.timestamp < min ? t.timestamp : min),+ undefined as Date | undefined,+ ),+ ),+ ]);const scores = await getScoresForTraces(projectId,@@ -381,9 +392,15 @@ export const getDatabaseReadStream = async ({const outputScores: Record<string, string[] | number[]> =prepareScoresForOutput(filteredScores);+ const fullTrace = fullTraces.find(+ (fullTrace) => fullTrace.id === t.id,+ );return {...t,+ input: fullTrace?.input,+ output: fullTrace?.output,+ metadata: fullTrace?.metadata,name: t.name ?? "",usage: {promptTokens: metric?.promptTokens,