Skip to content

Commit

Permalink
Add root run check
Browse files Browse the repository at this point in the history
  • Loading branch information
dqbd committed Oct 25, 2024
1 parent 4a65bb9 commit 90c75f2
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion js/src/vercel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
Expand Down

0 comments on commit 90c75f2

Please sign in to comment.