Skip to content

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

chore: upsert tracesessions from clickhouse ingestion pipeline (#4254)

Steffen Schmitz615728754945
diff --git a/worker/src/services/IngestionService/index.ts b/worker/src/services/IngestionService/index.ts
index 97884c1f79..4e51f1dea5 100644
--- a/worker/src/services/IngestionService/index.ts
+++ b/worker/src/services/IngestionService/index.ts
@@ -1,5 +1,4 @@
import { Redis } from "ioredis";
-import { randomUUID } from "node:crypto";
import { v4 } from "uuid";
import { Prisma } from "@prisma/client";
@@ -240,6 +239,23 @@ export class IngestionService {
traceRecords,
});
+ // If the trace has a sessionId, we upsert the corresponding session into Postgres.
+ if (finalTraceRecord.session_id) {
+ await this.prisma.traceSession.upsert({
+ where: {
+ id_projectId: {
+ id: finalTraceRecord.session_id,
+ projectId,
+ },
+ },
+ create: {
+ id: finalTraceRecord.session_id,
+ projectId,
+ },
+ update: {},
+ });
+ }
+
this.clickHouseWriter.addToQueue(TableName.Traces, finalTraceRecord);
}