Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions instana/instrumentation/flask/vanilla.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
7 changes: 5 additions & 2 deletions instana/instrumentation/flask/with_blinker.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)

Expand Down