Skip to content

Commit 81a8869

Browse files
committed
fix(telemetry): fix endToolSpan status on success — toolCalls is empty in finally
Root cause: checkAndNotifyCompletion clears this.toolCalls before the finally block in executeSingleToolCall runs, so the tc lookup always returns undefined. Fix: set OK status explicitly in _executeToolCallBody's success path via safeSetStatus(span, OK), and call endToolSpan() without metadata in finally (just ends the span, preserves pre-set status from any path).
1 parent 155fbd1 commit 81a8869

1 file changed

Lines changed: 2 additions & 6 deletions

File tree

packages/core/src/core/coreToolScheduler.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1868,12 +1868,7 @@ export class CoreToolScheduler {
18681868
this._executeToolCallBody(scheduledCall, signal, toolSpan),
18691869
);
18701870
} finally {
1871-
const tc = this.toolCalls.find((c) => c.request.callId === callId);
1872-
if (tc?.status === 'success') {
1873-
endToolSpan(toolSpan, { success: true });
1874-
} else {
1875-
endToolSpan(toolSpan);
1876-
}
1871+
endToolSpan(toolSpan);
18771872
}
18781873
}
18791874

@@ -2170,6 +2165,7 @@ export class CoreToolScheduler {
21702165
: {}),
21712166
};
21722167
this.setStatusInternal(callId, 'success', successResponse);
2168+
safeSetStatus(span, { code: SpanStatusCode.OK });
21732169
} else {
21742170
// It is a failure
21752171
// PostToolUseFailure Hook

0 commit comments

Comments
 (0)