diff --git a/instana/instrumentation/flask/vanilla.py b/instana/instrumentation/flask/vanilla.py index 26d810ea..fdf65708 100644 --- a/instana/instrumentation/flask/vanilla.py +++ b/instana/instrumentation/flask/vanilla.py @@ -74,15 +74,18 @@ def after_request_with_instana(response): @wrapt.patch_function_wrapper('flask', 'Flask.handle_user_exception') def handle_user_exception_with_instana(wrapped, instance, argv, kwargs): exc = argv[0] + handler = instance._find_error_handler(exc) if hasattr(flask.g, 'scope'): scope = flask.g.scope span = scope.span if not hasattr(exc, 'code'): - span.log_exception(argv[0]) + span.log_exception(exc) span.set_tag(ext.HTTP_STATUS_CODE, 500) - scope.close() + # Issue 172 - leave scope open for downstream error handlers + if handler is None: + scope.close() return wrapped(*argv, **kwargs) diff --git a/instana/instrumentation/flask/with_blinker.py b/instana/instrumentation/flask/with_blinker.py index 77253b3b..75f4fe8b 100644 --- a/instana/instrumentation/flask/with_blinker.py +++ b/instana/instrumentation/flask/with_blinker.py @@ -86,6 +86,7 @@ def log_exception_with_instana(sender, exception, **extra): @wrapt.patch_function_wrapper('flask', 'Flask.handle_user_exception') def handle_user_exception_with_instana(wrapped, instance, argv, kwargs): exc = argv[0] + handler = instance._find_error_handler(exc) if hasattr(flask.g, 'scope'): scope = flask.g.scope @@ -94,8 +95,10 @@ def handle_user_exception_with_instana(wrapped, instance, argv, kwargs): if not hasattr(exc, 'code'): span.log_exception(exc) span.set_tag(ext.HTTP_STATUS_CODE, 500) - scope.close() - flask.g.scope = None + # Issue 172 - leave scope open for downstream error handlers + if handler is None: + scope.close() + flask.g.scope = None return wrapped(*argv, **kwargs)