🪢 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(api): dedupe and sort trace tags (#2122)
Marc Klingenfabbb75e40ec
diff --git a/web/src/__tests__/ingestion.servertest.ts b/web/src/__tests__/ingestion.servertest.tsindex 668d727577..edc4da3e6a 100644--- a/web/src/__tests__/ingestion.servertest.ts+++ b/web/src/__tests__/ingestion.servertest.ts@@ -727,7 +727,7 @@ describe("/api/public/ingestion API Endpoint", () => {metadata: { key: "value" },release: "1.0.0",version: "2.0.0",- tags: ["tag-1", "tag-2"],+ tags: ["tag-1", "tag-2", "tag-2"],},},],@@ -744,7 +744,7 @@ describe("/api/public/ingestion API Endpoint", () => {id: traceId,name: "trace-name",userId: "user-2",- tags: ["tag-3", "tag-4"],+ tags: ["tag-1", "tag-4", "tag-3"],},},],@@ -766,6 +766,7 @@ describe("/api/public/ingestion API Endpoint", () => {expect(dbTrace[0]?.version).toBe("2.0.0");expect(dbTrace[0]?.projectId).toBe("7a88fb47-b4e2-43b8-a06c-a5ce950dc53a");expect(dbTrace[0]?.tags).toEqual(["tag-1", "tag-2", "tag-3", "tag-4"]);+ expect(dbTrace[0]?.tags.length).toBe(4);});it("should fail for wrong event formats", async () => {diff --git a/web/src/server/api/services/EventProcessor.ts b/web/src/server/api/services/EventProcessor.tsindex 3d7861caf3..bf57173243 100644--- a/web/src/server/api/services/EventProcessor.ts+++ b/web/src/server/api/services/EventProcessor.ts@@ -449,9 +449,12 @@ export class TraceProcessor implements EventProcessor {body.metadata ?? undefined,);- const mergedTags = existingTrace?.tags- ? existingTrace.tags.concat(body.tags ?? [])- : body.tags;+ const mergedTags =+ existingTrace?.tags && body.tags+ ? Array.from(new Set(existingTrace.tags.concat(body.tags ?? []))).sort()+ : body.tags+ ? Array.from(new Set(body.tags)).sort()+ : undefined;if (body.sessionId) {await prisma.traceSession.upsert({