Skip to content
This repository was archived by the owner on Jun 11, 2018. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion opbeat/instrumentation/packages/botocore.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ def call(self, module, method, wrapped, instance, args, kwargs):

target_endpoint = instance._endpoint.host
parsed_url = urlparse.urlparse(target_endpoint)
service, region, _ = parsed_url.hostname.split('.', 2)
if '.' in parsed_url.hostname:
service, region = parsed_url.hostname.split('.', 2)[:2]
else:
service, region = parsed_url.hostname, None

signature = '{}:{}'.format(service, operation_name)
extra_data = {
Expand Down
32 changes: 25 additions & 7 deletions tests/instrumentation/botocore_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import opbeat
import opbeat.instrumentation.control
from opbeat.traces import trace
from opbeat.instrumentation.packages.botocore import BotocoreInstrumentation
from tests.helpers import get_tempstoreclient
from tests.utils.compat import TestCase

Expand All @@ -20,13 +20,31 @@ def test_botocore_instrumentation(self, mock_make_request):
mock_make_request.return_value = (mock_response, {})

self.client.begin_transaction("transaction.test")
with trace("test_pipeline", "test"):
session = boto3.Session(aws_access_key_id='foo',
aws_secret_access_key='bar',
region_name='us-west-2')
ec2 = session.client('ec2')
ec2.describe_instances()
session = boto3.Session(aws_access_key_id='foo',
aws_secret_access_key='bar',
region_name='us-west-2')
ec2 = session.client('ec2')
ec2.describe_instances()
self.client.end_transaction("MyView")

_, traces = self.client.instrumentation_store.get_all()
trace = [t for t in traces if t['kind'] == 'ext.http.aws'][0]
self.assertIn('ec2:DescribeInstances', map(lambda x: x['signature'], traces))
self.assertEqual(trace['signature'], 'ec2:DescribeInstances')
self.assertEqual(trace['extra']['service'], 'ec2')
self.assertEqual(trace['extra']['region'], 'us-west-2')

def test_nonstandard_endpoint_url(self):
instrument = BotocoreInstrumentation()
self.client.begin_transaction('test')
module, method = BotocoreInstrumentation.instrument_list[0]
instance = mock.Mock(_endpoint=mock.Mock(host='https://example'))
instrument.call(module, method, lambda *args, **kwargs: None, instance,
('DescribeInstances',), {})
self.client.end_transaction('test', 'test')
_, traces = self.client.instrumentation_store.get_all()

trace = [t for t in traces if t['kind'] == 'ext.http.aws'][0]
self.assertEqual(trace['signature'], 'example:DescribeInstances')
self.assertEqual(trace['extra']['service'], 'example')
self.assertIsNone(trace['extra']['region'])