mirror of
https://git.anonymousland.org/anonymousland/synapse.git
synced 2024-10-01 11:49:51 -04:00
Fix error reporting when using opentracing.trace
(#7961)
This commit is contained in:
parent
84d099ae11
commit
1ef9efc1e0
1
changelog.d/7961.bugfix
Normal file
1
changelog.d/7961.bugfix
Normal file
@ -0,0 +1 @@
|
|||||||
|
Fix a long standing bug where the tracing of async functions with opentracing was broken.
|
@ -737,24 +737,14 @@ def trace(func=None, opname=None):
|
|||||||
|
|
||||||
@wraps(func)
|
@wraps(func)
|
||||||
async def _trace_inner(*args, **kwargs):
|
async def _trace_inner(*args, **kwargs):
|
||||||
if opentracing is None:
|
with start_active_span(_opname):
|
||||||
return await func(*args, **kwargs)
|
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:
|
else:
|
||||||
# The other case here handles both sync functions and those
|
# The other case here handles both sync functions and those
|
||||||
# decorated with inlineDeferred.
|
# decorated with inlineDeferred.
|
||||||
@wraps(func)
|
@wraps(func)
|
||||||
def _trace_inner(*args, **kwargs):
|
def _trace_inner(*args, **kwargs):
|
||||||
if opentracing is None:
|
|
||||||
return func(*args, **kwargs)
|
|
||||||
|
|
||||||
scope = start_active_span(_opname)
|
scope = start_active_span(_opname)
|
||||||
scope.__enter__()
|
scope.__enter__()
|
||||||
|
|
||||||
@ -767,7 +757,6 @@ def trace(func=None, opname=None):
|
|||||||
return result
|
return result
|
||||||
|
|
||||||
def err_back(result):
|
def err_back(result):
|
||||||
scope.span.set_tag(tags.ERROR, True)
|
|
||||||
scope.__exit__(None, None, None)
|
scope.__exit__(None, None, None)
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
@ -116,6 +116,8 @@ class _LogContextScope(Scope):
|
|||||||
if self._enter_logcontext:
|
if self._enter_logcontext:
|
||||||
self.logcontext.__enter__()
|
self.logcontext.__enter__()
|
||||||
|
|
||||||
|
return self
|
||||||
|
|
||||||
def __exit__(self, type, value, traceback):
|
def __exit__(self, type, value, traceback):
|
||||||
if type == twisted.internet.defer._DefGen_Return:
|
if type == twisted.internet.defer._DefGen_Return:
|
||||||
super(_LogContextScope, self).__exit__(None, None, None)
|
super(_LogContextScope, self).__exit__(None, None, None)
|
||||||
|
Loading…
Reference in New Issue
Block a user