Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Commit

Permalink
Fix error reporting when using opentracing.trace (#7961)
Browse files Browse the repository at this point in the history
  • Loading branch information
erikjohnston authored Jul 27, 2020
1 parent 84d099a commit 1ef9efc
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 12 deletions.
1 change: 1 addition & 0 deletions changelog.d/7961.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix a long standing bug where the tracing of async functions with opentracing was broken.
13 changes: 1 addition & 12 deletions synapse/logging/opentracing.py
Original file line number Diff line number Diff line change
Expand Up @@ -737,24 +737,14 @@ def decorator(func):

@wraps(func)
async def _trace_inner(*args, **kwargs):
if opentracing is None:
with start_active_span(_opname):
return await func(*args, **kwargs)

with start_active_span(_opname) as scope:
try:
return await func(*args, **kwargs)
except Exception:
scope.span.set_tag(tags.ERROR, True)
raise

else:
# The other case here handles both sync functions and those
# decorated with inlineDeferred.
@wraps(func)
def _trace_inner(*args, **kwargs):
if opentracing is None:
return func(*args, **kwargs)

scope = start_active_span(_opname)
scope.__enter__()

Expand All @@ -767,7 +757,6 @@ def call_back(result):
return result

def err_back(result):
scope.span.set_tag(tags.ERROR, True)
scope.__exit__(None, None, None)
return result

Expand Down
2 changes: 2 additions & 0 deletions synapse/logging/scopecontextmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ def __enter__(self):
if self._enter_logcontext:
self.logcontext.__enter__()

return self

def __exit__(self, type, value, traceback):
if type == twisted.internet.defer._DefGen_Return:
super(_LogContextScope, self).__exit__(None, None, None)
Expand Down

0 comments on commit 1ef9efc

Please sign in to comment.