From 1ef9efc1e07d3b7339249a79cd379105f1f335ea Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Mon, 27 Jul 2020 16:20:24 +0100 Subject: [PATCH] Fix error reporting when using `opentracing.trace` (#7961) --- changelog.d/7961.bugfix | 1 + synapse/logging/opentracing.py | 13 +------------ synapse/logging/scopecontextmanager.py | 2 ++ 3 files changed, 4 insertions(+), 12 deletions(-) create mode 100644 changelog.d/7961.bugfix diff --git a/changelog.d/7961.bugfix b/changelog.d/7961.bugfix new file mode 100644 index 000000000..b21f8e1f1 --- /dev/null +++ b/changelog.d/7961.bugfix @@ -0,0 +1 @@ +Fix a long standing bug where the tracing of async functions with opentracing was broken. diff --git a/synapse/logging/opentracing.py b/synapse/logging/opentracing.py index 210151757..21dbd9f41 100644 --- a/synapse/logging/opentracing.py +++ b/synapse/logging/opentracing.py @@ -737,24 +737,14 @@ def trace(func=None, opname=None): @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__() @@ -767,7 +757,6 @@ def trace(func=None, opname=None): return result def err_back(result): - scope.span.set_tag(tags.ERROR, True) scope.__exit__(None, None, None) return result diff --git a/synapse/logging/scopecontextmanager.py b/synapse/logging/scopecontextmanager.py index dc3ab00cb..026854b4c 100644 --- a/synapse/logging/scopecontextmanager.py +++ b/synapse/logging/scopecontextmanager.py @@ -116,6 +116,8 @@ class _LogContextScope(Scope): 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)