From 8fbd5d753017f9616418cf3f97467acd21b527f7 Mon Sep 17 00:00:00 2001 From: Peter Giacomo Lombardo Date: Tue, 27 Feb 2018 13:25:53 +0100 Subject: [PATCH] Add more safeties in KV collection & processing --- instana/instrumentation/urllib3.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/instana/instrumentation/urllib3.py b/instana/instrumentation/urllib3.py index 371db35c..f7b1f0f3 100644 --- a/instana/instrumentation/urllib3.py +++ b/instana/instrumentation/urllib3.py @@ -10,13 +10,14 @@ import urllib3 # noqa def collect(instance, args, kwargs): + """ Build and return a fully qualified URL for this request """ try: kvs = {} kvs['host'] = instance.host kvs['port'] = instance.port - if len(args) is 2: + if args is not None and len(args) is 2: kvs['method'] = args[0] kvs['path'] = args[1] else: @@ -45,8 +46,10 @@ def urlopen_with_instana(wrapped, instance, args, kwargs): span = instana.internal_tracer.start_span("urllib3", child_of=context) kvs = collect(instance, args, kwargs) - span.set_tag(ext.HTTP_URL, kvs['url']) - span.set_tag(ext.HTTP_METHOD, kvs['method']) + if 'url' in kvs: + span.set_tag(ext.HTTP_URL, kvs['url']) + if 'method' in kvs: + span.set_tag(ext.HTTP_METHOD, kvs['method']) instana.internal_tracer.inject(span.context, opentracing.Format.HTTP_HEADERS, kwargs["headers"]) rv = wrapped(*args, **kwargs)