11import boto3
22import mock
33
4- from elasticapm .traces import capture_span
4+ from elasticapm .instrumentation . packages . botocore import BotocoreInstrumentation
55
66
77@mock .patch ("botocore.endpoint.Endpoint.make_request" )
@@ -11,14 +11,32 @@ def test_botocore_instrumentation(mock_make_request, elasticapm_client):
1111 mock_make_request .return_value = (mock_response , {})
1212
1313 elasticapm_client .begin_transaction ("transaction.test" )
14- with capture_span ("test_pipeline" , "test" ):
15- session = boto3 .Session (aws_access_key_id = 'foo' ,
16- aws_secret_access_key = 'bar' ,
17- region_name = 'us-west-2' )
18- ec2 = session .client ('ec2' )
19- ec2 .describe_instances ()
20- elasticapm_client .end_transaction ("MyView" )
21-
22- transactions = elasticapm_client .instrumentation_store .get_all ()
23- spans = transactions [0 ]['spans' ]
24- assert 'ec2:DescribeInstances' in map (lambda x : x ['name' ], spans )
14+ session = boto3 .Session (aws_access_key_id = 'foo' ,
15+ aws_secret_access_key = 'bar' ,
16+ region_name = 'us-west-2' )
17+ ec2 = session .client ('ec2' )
18+ ec2 .describe_instances ()
19+ transaction = elasticapm_client .end_transaction ("MyView" )
20+ span = transaction .spans [0 ]
21+
22+ assert span .name == 'ec2:DescribeInstances'
23+ assert span .context ['service' ] == 'ec2'
24+ assert span .context ['region' ] == 'us-west-2'
25+ assert span .context ['operation' ] == 'DescribeInstances'
26+
27+
28+
29+ def test_nonstandard_endpoint_url (elasticapm_client ):
30+ instrument = BotocoreInstrumentation ()
31+ elasticapm_client .begin_transaction ('test' )
32+ module , method = BotocoreInstrumentation .instrument_list [0 ]
33+ instance = mock .Mock (_endpoint = mock .Mock (host = 'https://example' ))
34+ instrument .call (module , method , lambda * args , ** kwargs : None , instance ,
35+ ('DescribeInstances' ,), {})
36+ transaction = elasticapm_client .end_transaction ('test' , 'test' )
37+ span = transaction .spans [0 ]
38+
39+ assert span .name == 'example:DescribeInstances'
40+ assert span .context ['service' ] == 'example'
41+ assert span .context ['region' ] is None
42+ assert span .context ['operation' ] == 'DescribeInstances'
0 commit comments