summary refs log tree commit diff
path: root/synapse
diff options
context:
space:
mode:
authorJorik Schellekens <joriks@matrix.org>2019-07-05 14:27:43 +0100
committerJorik Schellekens <joriks@matrix.org>2019-07-17 14:18:29 +0100
commit342840f8841336c2a543b22d14b15ccb0d02e18b (patch)
tree015da1830800348cfe1729a897e02dfb93679220 /synapse
parentTry catch wrapping to make sure the span is finished (diff)
downloadsynapse-342840f8841336c2a543b22d14b15ccb0d02e18b.tar.xz
Use the new clean contexts
Diffstat (limited to 'synapse')
-rw-r--r--synapse/logging/opentracing.py24
1 files changed, 6 insertions, 18 deletions
diff --git a/synapse/logging/opentracing.py b/synapse/logging/opentracing.py
index e185f8cf97..b6b69f7bc5 100644
--- a/synapse/logging/opentracing.py
+++ b/synapse/logging/opentracing.py
@@ -369,15 +369,9 @@ def trace_defered_function(func):
     @wraps(func)
     @defer.inlineCallbacks
     def f(self, *args, **kwargs):
-        # Start scope
-        TracerUtil.start_active_span(func.__name__)
-        try:
+        with start_active_span(func.__name__):
             r = yield func(self, *args, **kwargs)
-        except:
-            raise
-        finally:
-            TracerUtil.close_active_span()
-        defer.returnValue(r)
+            defer.returnValue(r)
 
     return f
 
@@ -388,14 +382,9 @@ def trace_defered_function_using_operation_name(name):
         @defer.inlineCallbacks
         def f(self, *args, **kwargs):
             # Start scope
-            TracerUtil.start_active_span(name)
-            try:
+            with start_active_span(name):
                 r = yield func(self, *args, **kwargs)
-            except:
-                raise
-            finally:
-                TracerUtil.close_active_span()
-            defer.returnValue(r)
+                defer.returnValue(r)
 
         return f
 
@@ -435,12 +424,11 @@ def wrap_in_span(func):
     if not TracerUtil._opentracing:
         return func
 
-    span = TracerUtil._opentracing.tracer.start_span(
-        func.__name__, child_of=TracerUtil._opentracing.tracer.active_span
-    )
+    parent_span = opentracing.tracer.active_span
 
     @wraps(func)
     def f(self, *args, **kwargs):
+        span = opentracing.tracer.start_span(func.__name__, child_of=parent_span)
         try:
             return func(self, *args, **kwargs)
         except Exception as e: