Skip to content

Commit 2434a0e

Browse files
authored
fix(openai-agents): End child spans on trace end (#1813)
Supersedes #1361 Ends child spans of an openai agents trace before ending the root span - making sure that all the spans in the trace are properly ended.
1 parent b6d6240 commit 2434a0e

2 files changed

Lines changed: 10 additions & 0 deletions

File tree

.changeset/lazy-dots-send.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"braintrust": patch
3+
---
4+
5+
fix(openai-agents): End child spans on trace end

integrations/openai-agents-js/src/index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,11 @@ export class OpenAIAgentsTraceProcessor {
322322
const traceData = this.traceSpans.get(trace.traceId);
323323

324324
if (traceData) {
325+
for (const [spanId, braintrustSpan] of traceData.childSpans) {
326+
braintrustSpan.end();
327+
traceData.childSpans.delete(spanId);
328+
}
329+
325330
try {
326331
traceData.rootSpan.log({
327332
input: traceData.metadata.firstInput,

0 commit comments

Comments
 (0)