33
44import opbeat
55import opbeat .instrumentation .control
6- from opbeat .traces import trace
6+ from opbeat .instrumentation . packages . botocore import BotocoreInstrumentation
77from tests .helpers import get_tempstoreclient
88from tests .utils .compat import TestCase
99
@@ -20,13 +20,31 @@ def test_botocore_instrumentation(self, mock_make_request):
2020 mock_make_request .return_value = (mock_response , {})
2121
2222 self .client .begin_transaction ("transaction.test" )
23- with trace ("test_pipeline" , "test" ):
24- session = boto3 .Session (aws_access_key_id = 'foo' ,
25- aws_secret_access_key = 'bar' ,
26- region_name = 'us-west-2' )
27- ec2 = session .client ('ec2' )
28- ec2 .describe_instances ()
23+ session = boto3 .Session (aws_access_key_id = 'foo' ,
24+ aws_secret_access_key = 'bar' ,
25+ region_name = 'us-west-2' )
26+ ec2 = session .client ('ec2' )
27+ ec2 .describe_instances ()
2928 self .client .end_transaction ("MyView" )
3029
3130 _ , traces = self .client .instrumentation_store .get_all ()
31+ trace = traces [0 ]
3232 self .assertIn ('ec2:DescribeInstances' , map (lambda x : x ['signature' ], traces ))
33+ self .assertEqual (trace ['signature' ], 'ec2:DescribeInstances' )
34+ self .assertEqual (trace ['extra' ]['service' ], 'ec2' )
35+ self .assertEqual (trace ['extra' ]['region' ], 'us-west-2' )
36+
37+ def test_nonstandard_endpoint_url (self ):
38+ instrument = BotocoreInstrumentation ()
39+ self .client .begin_transaction ('test' )
40+ module , method = BotocoreInstrumentation .instrument_list [0 ]
41+ instance = mock .Mock (_endpoint = mock .Mock (host = 'https://example' ))
42+ instrument .call (module , method , lambda * args , ** kwargs : None , instance ,
43+ ('DescribeInstances' ,), {})
44+ self .client .end_transaction ('test' , 'test' )
45+ _ , traces = self .client .instrumentation_store .get_all ()
46+
47+ trace = traces [0 ]
48+ self .assertEqual (trace ['signature' ], 'example:DescribeInstances' )
49+ self .assertEqual (trace ['extra' ]['service' ], 'example' )
50+ self .assertIsNone (trace ['extra' ]['region' ])
0 commit comments