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

Commit 6d1bd50

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

2 files changed

Lines changed: 29 additions & 8 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 & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

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

Comments
 (0)