Skip to content

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

fix: support large amount of traces for sessions in session.byid (#4847)

Max Deichmann33fddb134450
diff --git a/web/src/server/api/routers/sessions.ts b/web/src/server/api/routers/sessions.ts
index f8251ee7b8..b51755442e 100644
--- a/web/src/server/api/routers/sessions.ts
+++ b/web/src/server/api/routers/sessions.ts
@@ -503,17 +503,29 @@ export const sessionRouter = createTRPCRouter({
input.sessionId,
);
- const [scores, costData] = await Promise.all([
- getScoresForTraces(
- input.projectId,
- clickhouseTraces.map((t) => t.id),
- ),
- getCostForTraces(
- input.projectId,
- clickhouseTraces.map((t) => t.id),
+ const traceIds = clickhouseTraces.map((t) => t.id);
+ const chunkSize = 500;
+ const chunks = [];
+
+ for (let i = 0; i < traceIds.length; i += chunkSize) {
+ chunks.push(traceIds.slice(i, i + chunkSize));
+ }
+
+ const [scores, costs] = await Promise.all([
+ Promise.all(
+ chunks.map((chunk) =>
+ getScoresForTraces(input.projectId, chunk),
+ ),
+ ).then((results) => results.flat()),
+ Promise.all(
+ chunks.map((chunk) => getCostForTraces(input.projectId, chunk)),
+ ).then((results) =>
+ results.reduce((sum, cost) => (sum ?? 0) + (cost ?? 0), 0),
),
]);
+ const costData = costs;
+
const validatedScores = filterAndValidateDbScoreList(
scores,
traceException,