forked from MirrorHub/synapse
Fix the trace function for async functions. (#7872)
Co-authored-by: Richard van der Hoff <1389908+richvdh@users.noreply.github.com>
This commit is contained in:
parent
1ec2961b3b
commit
d1d5fa66e4
2 changed files with 43 additions and 25 deletions
1
changelog.d/7872.bugfix
Normal file
1
changelog.d/7872.bugfix
Normal file
|
@ -0,0 +1 @@
|
||||||
|
Fix a long standing bug where the tracing of async functions with opentracing was broken.
|
|
@ -733,6 +733,23 @@ def trace(func=None, opname=None):
|
||||||
|
|
||||||
_opname = opname if opname else func.__name__
|
_opname = opname if opname else func.__name__
|
||||||
|
|
||||||
|
if inspect.iscoroutinefunction(func):
|
||||||
|
|
||||||
|
@wraps(func)
|
||||||
|
async def _trace_inner(*args, **kwargs):
|
||||||
|
if opentracing is None:
|
||||||
|
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)
|
@wraps(func)
|
||||||
def _trace_inner(*args, **kwargs):
|
def _trace_inner(*args, **kwargs):
|
||||||
if opentracing is None:
|
if opentracing is None:
|
||||||
|
|
Loading…
Reference in a new issue