33
44import opbeat
55import opbeat .instrumentation .control
6+ from opbeat .instrumentation .packages .botocore import BotocoreInstrumentation
67from opbeat .traces import trace
78from tests .helpers import get_tempstoreclient
89from tests .utils .compat import TestCase
@@ -20,13 +21,31 @@ def test_botocore_instrumentation(self, mock_make_request):
2021 mock_make_request .return_value = (mock_response , {})
2122
2223 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 ()
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 ()
2929 self .client .end_transaction ("MyView" )
3030
3131 _ , traces = self .client .instrumentation_store .get_all ()
32+ trace = traces [0 ]
3233 self .assertIn ('ec2:DescribeInstances' , map (lambda x : x ['signature' ], traces ))
34+ self .assertEqual (trace ['signature' ], 'ec2:DescribeInstances' )
35+ self .assertEqual (trace ['extra' ]['service' ], 'ec2' )
36+ self .assertEqual (trace ['extra' ]['region' ], 'us-west-2' )
37+
38+ def test_nonstandard_endpoint_url (self ):
39+ instrument = BotocoreInstrumentation ()
40+ self .client .begin_transaction ('test' )
41+ module , method = BotocoreInstrumentation .instrument_list [0 ]
42+ instance = mock .Mock (_endpoint = mock .Mock (host = 'https://example' ))
43+ instrument .call (module , method , lambda * args , ** kwargs : None , instance ,
44+ ('DescribeInstances' ,), {})
45+ self .client .end_transaction ('test' , 'test' )
46+ _ , traces = self .client .instrumentation_store .get_all ()
47+
48+ trace = traces [0 ]
49+ self .assertEqual (trace ['signature' ], 'example:DescribeInstances' )
50+ self .assertEqual (trace ['extra' ]['service' ], 'example' )
51+ self .assertIsNone (trace ['extra' ]['region' ])
0 commit comments