Skip to content

Commit 7c1d628

Browse files
committed
Make urllib3 childof current span; Add tests to validate
1 parent 34ea942 commit 7c1d628

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

instana/instrumentation/urllib3.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
@wrapt.patch_function_wrapper('urllib3', 'PoolManager.urlopen')
99
def urlopen_with_instana(wrapped, instance, args, kwargs):
1010
try:
11-
span = instana.internal_tracer.start_span("urllib3")
11+
context = instana.internal_tracer.current_context()
12+
span = instana.internal_tracer.start_span("urllib3", child_of=context)
1213
span.set_tag(ext.HTTP_URL, args[1])
1314
span.set_tag(ext.HTTP_METHOD, args[0])
1415

@@ -31,3 +32,6 @@ def urlopen_with_instana(wrapped, instance, args, kwargs):
3132
else:
3233
span.finish()
3334
return rv
35+
36+
37+
instana.log.debug("Instrumenting urllib3")

tests/test_urllib3.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ def test_get_request(self):
4040
assert_equals(None, second_span.error)
4141
assert_equals(None, second_span.ec)
4242

43+
assert_equals(second_span.t, first_span.t)
44+
assert_equals(second_span.p, first_span.s)
45+
4346
def test_put_request(self):
4447
span = tracer.start_span("test")
4548
r = self.http.request('PUT', 'http://127.0.0.1:5000/notfound')
@@ -60,6 +63,9 @@ def test_put_request(self):
6063
assert_equals(None, second_span.error)
6164
assert_equals(None, second_span.ec)
6265

66+
assert_equals(second_span.t, first_span.t)
67+
assert_equals(second_span.p, first_span.s)
68+
6369
def test_5xx_request(self):
6470
span = tracer.start_span("test")
6571
r = self.http.request('GET', 'http://127.0.0.1:5000/504')
@@ -80,6 +86,9 @@ def test_5xx_request(self):
8086
assert_equals(True, second_span.error)
8187
assert_equals(1, second_span.ec)
8288

89+
assert_equals(second_span.t, first_span.t)
90+
assert_equals(second_span.p, first_span.s)
91+
8392
def test_exception_logging(self):
8493
span = tracer.start_span("test")
8594
try:
@@ -104,6 +113,9 @@ def test_exception_logging(self):
104113
assert_equals(True, second_span.error)
105114
assert_equals(1, second_span.ec)
106115

116+
assert_equals(second_span.t, first_span.t)
117+
assert_equals(second_span.p, first_span.s)
118+
107119
def test_client_error(self):
108120
span = tracer.start_span("test")
109121

@@ -130,3 +142,6 @@ def test_client_error(self):
130142
assert_equals("GET", second_span.data.http.method)
131143
assert_equals(True, second_span.error)
132144
assert_equals(1, second_span.ec)
145+
146+
assert_equals(second_span.t, first_span.t)
147+
assert_equals(second_span.p, first_span.s)

0 commit comments

Comments
 (0)