Skip to content
This repository was archived by the owner on Jun 11, 2018. It is now read-only.

Commit c4bc1d3

Browse files
committed
fix issue with handling nonstandard s3 endpoint URLs
closes #198
1 parent 4bdfe49 commit c4bc1d3

2 files changed

Lines changed: 29 additions & 7 deletions

File tree

opbeat/instrumentation/packages/botocore.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@ def call(self, module, method, wrapped, instance, args, kwargs):
1818

1919
target_endpoint = instance._endpoint.host
2020
parsed_url = urlparse.urlparse(target_endpoint)
21-
service, region, _ = parsed_url.hostname.split('.', 2)
21+
if '.' in parsed_url.hostname:
22+
service, region = parsed_url.hostname.split('.', 2)[:2]
23+
else:
24+
service, region = parsed_url.hostname, None
2225

2326
signature = '{}:{}'.format(service, operation_name)
2427
extra_data = {

tests/instrumentation/botocore_tests.py

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
import opbeat
55
import opbeat.instrumentation.control
6+
from opbeat.instrumentation.packages.botocore import BotocoreInstrumentation
67
from opbeat.traces import trace
78
from tests.helpers import get_tempstoreclient
89
from 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

Comments
 (0)