From 444f537a7af86f5e9b0181010a02fa9cf48b7f2b Mon Sep 17 00:00:00 2001 From: Alexander Alderman Webb Date: Wed, 11 Nov 2026 17:46:18 +0100 Subject: [PATCH] feat(bedrock): Record gen_ai.response.finish_reasons for non-streaming responses --- sentry_sdk/integrations/boto3/_services/bedrock.py | 3 +++ tests/integrations/boto3/test_bedrock.py | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/sentry_sdk/integrations/boto3/_services/bedrock.py b/sentry_sdk/integrations/boto3/_services/bedrock.py index d35fc26efb..e7b7ddcf2e 100644 --- a/sentry_sdk/integrations/boto3/_services/bedrock.py +++ b/sentry_sdk/integrations/boto3/_services/bedrock.py @@ -512,6 +512,9 @@ def on_success_response( set_on_span(SPANDATA.GEN_AI_USAGE_INPUT_TOKENS, input_tokens) + finish_reasons: "list[str]" = [response["stopReason"]] + set_on_span(SPANDATA.GEN_AI_RESPONSE_FINISH_REASONS, finish_reasons) + client = sentry_sdk.get_client() if "message" in response["output"] and ( ( diff --git a/tests/integrations/boto3/test_bedrock.py b/tests/integrations/boto3/test_bedrock.py index 4696293eda..3ecd3f357e 100644 --- a/tests/integrations/boto3/test_bedrock.py +++ b/tests/integrations/boto3/test_bedrock.py @@ -476,6 +476,9 @@ def test_converse( assert span["attributes"][SPANDATA.GEN_AI_REQUEST_MAX_TOKENS] == 1024 assert span["attributes"][SPANDATA.GEN_AI_REQUEST_TEMPERATURE] == 0.7 assert span["attributes"][SPANDATA.GEN_AI_REQUEST_TOP_P] == 0.9 + assert span["attributes"][SPANDATA.GEN_AI_RESPONSE_FINISH_REASONS] == [ + "end_turn" + ] assert span["attributes"][SPANDATA.GEN_AI_USAGE_OUTPUT_TOKENS] == 20 assert span["attributes"][SPANDATA.GEN_AI_USAGE_TOTAL_TOKENS] == 30 @@ -513,6 +516,7 @@ def test_converse( assert span["data"][SPANDATA.GEN_AI_REQUEST_MAX_TOKENS] == 1024 assert span["data"][SPANDATA.GEN_AI_REQUEST_TEMPERATURE] == 0.7 assert span["data"][SPANDATA.GEN_AI_REQUEST_TOP_P] == 0.9 + assert span["data"][SPANDATA.GEN_AI_RESPONSE_FINISH_REASONS] == ["end_turn"] assert span["data"][SPANDATA.GEN_AI_USAGE_OUTPUT_TOKENS] == 20 assert span["data"][SPANDATA.GEN_AI_USAGE_TOTAL_TOKENS] == 30