From 90c75f2be0f59d3b45be01276f9d277973d47814 Mon Sep 17 00:00:00 2001 From: Tat Dat Duong Date: Fri, 25 Oct 2024 22:15:52 +0200 Subject: [PATCH] Add root run check --- js/src/vercel.ts | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/js/src/vercel.ts b/js/src/vercel.ts index 840defaba..2d703ba97 100644 --- a/js/src/vercel.ts +++ b/js/src/vercel.ts @@ -687,6 +687,21 @@ export class AISDKExporter { } } + /** @internal */ + protected isRootRun(span: AISDKSpan): boolean { + switch (span.name) { + case "ai.generateText": + case "ai.streamText": + case "ai.generateObject": + case "ai.streamObject": + case "ai.embed": + case "ai.embedMany": + return true; + default: + return false; + } + } + export( spans: unknown[], resultCallback: (result: { code: 0 | 1; error?: Error }) => void @@ -705,10 +720,13 @@ export class AISDKExporter { }; const runId = uuid5(spanId, RUN_ID_NAMESPACE); - const parentRunId = parentId + let parentRunId = parentId ? uuid5(parentId, RUN_ID_NAMESPACE) : undefined; + // in LangSmith we currently only support certain spans + // which may be deeply nested within other traces + if (this.isRootRun(span)) parentRunId = undefined; const traceMap = this.traceByMap[traceId]; const run = this.getRunCreate(span);