Skip to content
Merged
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
7 changes: 6 additions & 1 deletion instana/instrumentation/urllib3.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,13 @@

@wrapt.patch_function_wrapper('urllib3', 'PoolManager.urlopen')
def urlopen_with_instana(wrapped, instance, args, kwargs):
context = instana.internal_tracer.current_context()

# If we're not tracing, just return
if context is None:
return wrapped(*args, **kwargs)

try:
context = instana.internal_tracer.current_context()
span = instana.internal_tracer.start_span("urllib3", child_of=context)
span.set_tag(ext.HTTP_URL, args[1])
span.set_tag(ext.HTTP_METHOD, args[0])
Expand Down
5 changes: 4 additions & 1 deletion instana/tracer.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,10 @@ def start_span(
return self.current_span

def current_context(self):
return self.current_span.context
context = None
if self.current_span:
context = self.current_span.context
return context

def inject(self, span_context, format, carrier):
if format in self._propagators:
Expand Down
4 changes: 4 additions & 0 deletions tests/test_urllib3.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ def setUp(self):
self.http = urllib3.PoolManager()
self.recorder = tracer.recorder
self.recorder.clear_spans()
tracer.current_span = None

def tearDown(self):
""" Do nothing for now """
Expand All @@ -19,6 +20,9 @@ def test_vanilla_requests(self):
r = self.http.request('GET', 'http://127.0.0.1:5000/')
assert_equals(r.status, 200)

spans = self.recorder.queued_spans()
assert_equals(0, len(spans))

def test_get_request(self):
span = tracer.start_span("test")
r = self.http.request('GET', 'http://127.0.0.1:5000/')
Expand Down