From f5f14f88a60b9a33c6c02f52cc71ce7397854ac1 Mon Sep 17 00:00:00 2001 From: Peter Giacomo Lombardo Date: Wed, 2 Sep 2020 11:16:19 +0200 Subject: [PATCH] Celery: Add tag parsing safety --- instana/instrumentation/celery/hooks.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/instana/instrumentation/celery/hooks.py b/instana/instrumentation/celery/hooks.py index 7045dfc8..4f62d9e6 100644 --- a/instana/instrumentation/celery/hooks.py +++ b/instana/instrumentation/celery/hooks.py @@ -18,7 +18,10 @@ def add_broker_tags(span, broker_url): try: url = parse.urlparse(broker_url) - span.set_tag("scheme", url.scheme) + + # Add safety for edge case where scheme may not be a string + url_scheme = str(url.scheme) + span.set_tag("scheme", url_scheme) if url.hostname is None: span.set_tag("host", 'localhost') @@ -27,15 +30,15 @@ def add_broker_tags(span, broker_url): if url.port is None: # Set default port if not specified - if url.scheme == 'redis': + if url_scheme == 'redis': span.set_tag("port", "6379") - elif 'amqp' in url.scheme: + elif 'amqp' in url_scheme: span.set_tag("port", "5672") - elif 'sqs' in url.scheme: + elif 'sqs' in url_scheme: span.set_tag("port", "443") else: span.set_tag("port", str(url.port)) - except: + except Exception: logger.debug("Error parsing broker URL: %s" % broker_url, exc_info=True) @signals.task_prerun.connect