@@ -84,7 +84,10 @@ def _run_patch_behaviour_tests(self):
84
84
self ._test_unpatched_botocore_propagator ()
85
85
self ._test_unpatched_gevent_instrumentation ()
86
86
self ._test_unpatched_starlette_instrumentation ()
87
- self ._test_unpatched_bedrock_runtime_instrumentation ()
87
+ # TODO: remove these tests once we bump botocore instrumentation version to 0.56b0
88
+ # Bedrock Runtime tests
89
+ self ._test_unpatched_converse_stream_wrapper ()
90
+ self ._test_unpatched_extract_tool_calls ()
88
91
89
92
# Apply patches
90
93
apply_instrumentation_patches ()
@@ -220,8 +223,10 @@ def _test_patched_botocore_instrumentation(self):
220
223
# Bedrock Agent Operation
221
224
self ._test_patched_bedrock_agent_instrumentation ()
222
225
226
+ # TODO: remove these tests once we bump botocore instrumentation version to 0.56b0
223
227
# Bedrock Runtime
224
- self ._test_patched_bedrock_runtime_instrumentation ()
228
+ self ._test_patched_converse_stream_wrapper ()
229
+ self ._test_patched_extract_tool_calls ()
225
230
226
231
# Bedrock Agent Runtime
227
232
self .assertTrue ("bedrock-agent-runtime" in _KNOWN_EXTENSIONS )
@@ -474,7 +479,13 @@ def _test_patched_bedrock_instrumentation(self):
474
479
self .assertEqual (len (bedrock_sucess_attributes ), 1 )
475
480
self .assertEqual (bedrock_sucess_attributes ["aws.bedrock.guardrail.id" ], _BEDROCK_GUARDRAIL_ID )
476
481
477
- def _test_unpatched_bedrock_runtime_instrumentation (self ):
482
+ def _test_unpatched_extract_tool_calls (self ):
483
+ """Test unpatched extract_tool_calls with string content throws AttributeError"""
484
+ message_with_string_content = {"role" : "assistant" , "content" : "{" }
485
+ with self .assertRaises (AttributeError ) as context :
486
+ bedrock_utils .extract_tool_calls (message_with_string_content , True )
487
+
488
+ def _test_unpatched_converse_stream_wrapper (self ):
478
489
"""Test unpatched bedrock-runtime where input values remain as numbers"""
479
490
480
491
mock_stream = MagicMock ()
@@ -518,7 +529,7 @@ def _test_unpatched_bedrock_runtime_instrumentation(self):
518
529
self .assertEqual (len (wrapper ._message ["content" ]), 1 )
519
530
self .assertEqual (wrapper ._message ["content" ][0 ]["toolUse" ], expected_tool_use )
520
531
521
- def _test_patched_bedrock_runtime_instrumentation (self ):
532
+ def _test_patched_converse_stream_wrapper (self ):
522
533
"""Test patched bedrock-runtime"""
523
534
524
535
# Create mock arguments for ConverseStreamWrapper
@@ -581,6 +592,14 @@ def _test_patched_bedrock_runtime_instrumentation(self):
581
592
self .assertEqual (len (wrapper ._message ["content" ]), 1 )
582
593
self .assertEqual (wrapper ._message ["content" ][0 ]["toolUse" ], expected_tool_use )
583
594
595
+ def _test_patched_extract_tool_calls (self ):
596
+ """Test patched extract_tool_calls with string content"""
597
+
598
+ # Test extract_tool_calls with string content (should return None)
599
+ message_with_string_content = {"role" : "assistant" , "content" : "{" }
600
+ result = bedrock_utils .extract_tool_calls (message_with_string_content , True )
601
+ self .assertIsNone (result )
602
+
584
603
def _test_patched_bedrock_agent_instrumentation (self ):
585
604
"""For bedrock-agent service, both extract_attributes and on_success provides attributes,
586
605
the attributes depend on the API being invoked."""
0 commit comments