diff --git a/instana/instrumentation/flask/vanilla.py b/instana/instrumentation/flask/vanilla.py index 30c887aa..6a2dee5c 100644 --- a/instana/instrumentation/flask/vanilla.py +++ b/instana/instrumentation/flask/vanilla.py @@ -112,7 +112,10 @@ def handle_user_exception_with_instana(wrapped, instance, argv, kwargs): if hasattr(response, 'headers'): tracer.inject(scope.span.context, opentracing.Format.HTTP_HEADERS, response.headers) - response.headers.add('Server-Timing', "intid;desc=%s" % scope.span.context.trace_id) + if hasattr(response.headers, 'add'): + response.headers.add('Server-Timing', "intid;desc=%s" % scope.span.context.trace_id) + elif type(response.headers) is dict or hasattr(response.headers, "__dict__"): + response.headers['Server-Timing'] = "intid;desc=%s" % scope.span.context.trace_id scope.close() flask.g.scope = None diff --git a/instana/instrumentation/flask/with_blinker.py b/instana/instrumentation/flask/with_blinker.py index 1a4879f2..5d3e68a3 100644 --- a/instana/instrumentation/flask/with_blinker.py +++ b/instana/instrumentation/flask/with_blinker.py @@ -102,13 +102,17 @@ def handle_user_exception_with_instana(wrapped, instance, argv, kwargs): if hasattr(response, 'headers'): tracer.inject(scope.span.context, opentracing.Format.HTTP_HEADERS, response.headers) - response.headers.add('Server-Timing', "intid;desc=%s" % scope.span.context.trace_id) + if hasattr(response.headers, 'add'): + response.headers.add('Server-Timing', "intid;desc=%s" % scope.span.context.trace_id) + elif type(response.headers) is dict or hasattr(response.headers, "__dict__"): + response.headers['Server-Timing'] = "intid;desc=%s" % scope.span.context.trace_id scope.close() flask.g.scope = None - return response except Exception as e: logger.debug("handle_user_exception_with_instana:", exc_info=True) + finally: + return response def teardown_request_with_instana(*argv, **kwargs):