Skip to content

Commit ee60599

Browse files
committed
End unsampled Bedrock streaming spans instead of leaking them
1 parent 80ee483 commit ee60599

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

packages/server-utils/src/integrations/tracing-channel/aws-sdk/services/bedrock-runtime.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,19 @@ export class BedrockRuntimeServiceExtension implements ServiceExtension {
5858
}
5959

6060
public responseHook(response: NormalizedResponse, span: Span): void {
61+
const commandName = response.request.commandName;
62+
6163
if (!span.isRecording()) {
64+
// Streaming spans are ended by the wrapped stream (the subscriber's `deferSpanEnd` suppresses
65+
// the helper's own `end()`). When the span isn't recording we skip wrapping, so end it here to
66+
// avoid leaking an open span. Non-streaming commands are ended by the helper, so leave them.
67+
if (commandName === 'ConverseStream' || commandName === 'InvokeModelWithResponseStream') {
68+
span.end();
69+
}
6270
return;
6371
}
6472

65-
switch (response.request.commandName) {
73+
switch (commandName) {
6674
case 'Converse':
6775
return this._responseHookConverse(response, span);
6876
case 'ConverseStream':

0 commit comments

Comments
 (0)