Skip to content

Commit 7e41f79

Browse files
authored
Merge pull request #64 from instana/safer-kv-referencing
Urllib3: More safeties in KV collection & processing
2 parents a77f7c8 + 8fbd5d7 commit 7e41f79

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

instana/instrumentation/urllib3.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,14 @@
1010
import urllib3 # noqa
1111

1212
def collect(instance, args, kwargs):
13+
""" Build and return a fully qualified URL for this request """
1314
try:
1415
kvs = {}
1516

1617
kvs['host'] = instance.host
1718
kvs['port'] = instance.port
1819

19-
if len(args) is 2:
20+
if args is not None and len(args) is 2:
2021
kvs['method'] = args[0]
2122
kvs['path'] = args[1]
2223
else:
@@ -45,8 +46,10 @@ def urlopen_with_instana(wrapped, instance, args, kwargs):
4546
span = instana.internal_tracer.start_span("urllib3", child_of=context)
4647

4748
kvs = collect(instance, args, kwargs)
48-
span.set_tag(ext.HTTP_URL, kvs['url'])
49-
span.set_tag(ext.HTTP_METHOD, kvs['method'])
49+
if 'url' in kvs:
50+
span.set_tag(ext.HTTP_URL, kvs['url'])
51+
if 'method' in kvs:
52+
span.set_tag(ext.HTTP_METHOD, kvs['method'])
5053

5154
instana.internal_tracer.inject(span.context, opentracing.Format.HTTP_HEADERS, kwargs["headers"])
5255
rv = wrapped(*args, **kwargs)

0 commit comments

Comments
 (0)