summary refs log tree commit diff
diff options
context:
space:
mode:
authorJorik Schellekens <joriks@matrix.org>2019-07-17 13:55:53 +0100
committerJorik Schellekens <joriks@matrix.org>2019-07-17 14:20:22 +0100
commitd67376f7fc4161b8d59d9449a4377469b33932f6 (patch)
treeb832723b326e0a6efd98ca1ec765c7f61a61e216
parentBetter inner function names (diff)
downloadsynapse-d67376f7fc4161b8d59d9449a4377469b33932f6.tar.xz
Better decorator names
-rw-r--r--docs/opentracing.rst12
-rw-r--r--synapse/logging/opentracing.py37
2 files changed, 27 insertions, 22 deletions
diff --git a/docs/opentracing.rst b/docs/opentracing.rst
index 02eba904db..c8133a8fb2 100644
--- a/docs/opentracing.rst
+++ b/docs/opentracing.rst
@@ -116,13 +116,13 @@ function becomes the operation name for the span.
 .. code-block:: python
 
    # Start a span using 'normal_function' as the operation name
-   @trace_function
+   @trace
    def normal_function(*args, **kwargs):
        # Does all kinds of cool and expected things
        return something_usual_and_useful
 
    # Start a span using 'deferred_function' as the operation name
-   @trace_defered_function
+   @trace_deferred
    # Yes, there is a typo in the lib. I will fix this
    def deferred_function(*args, **kwargs):
        # We start
@@ -131,17 +131,17 @@ function becomes the operation name for the span.
        defer.returnValue(something_usual_and_useful)
 
 Operation names can be explicitely set for functions by using
-``trace_function_using_operation_name`` and
-``trace_defered_function_using_operation_name``
+``trace_using_operation_name`` and
+``trace_deferred_using_operation_name``
 
 .. code-block:: python
 
-   @trace_function_using_operation_name("A *much* better operation name")
+   @trace_using_operation_name("A *much* better operation name")
    def normal_function(*args, **kwargs):
        # Does all kinds of cool and expected things
        return something_usual_and_useful
 
-   @trace_defered_function_using_operation_name("An operation name that fixes the typo!")
+   @trace_deferred_using_operation_name("An operation name that fixes the typo!")
    # Yes, there is a typo in the lib. I will fix this
    def deferred_function(*args, **kwargs):
        # We start
diff --git a/synapse/logging/opentracing.py b/synapse/logging/opentracing.py
index 008e16fac0..bd53f2365e 100644
--- a/synapse/logging/opentracing.py
+++ b/synapse/logging/opentracing.py
@@ -424,7 +424,7 @@ def extract_text_map(carrier):
     return opentracing.tracer.extract(opentracing.Format.TEXT_MAP, carrier)
 
 
-def trace_defered_function(func):
+def trace_deferred(func):
     """Decorator to trace a defered function. Sets the operation name to that of the
     function's."""
 
@@ -457,50 +457,55 @@ def trace_servlet(servlet_name, func):
 def trace_defered_function(func):
     @wraps(func)
     @defer.inlineCallbacks
-    def _trace_defered_function_inner(self, *args, **kwargs):
+    def _trace_deferred_inner(self, *args, **kwargs):
         with start_active_span(func.__name__):
             r = yield func(self, *args, **kwargs)
             defer.returnValue(r)
 
-    return _trace_defered_function_inner
+    return _trace_deferred_inner
+
 
+def trace_deferred_using_operation_name(name):
+    """Decorator to trace a defered function. Explicitely sets the operation_name to name"""
 
-def trace_defered_function_using_operation_name(name):
-    def trace_defered_function(func):
+    def trace_deferred(func):
         @wraps(func)
         @defer.inlineCallbacks
-        def _trace_defered_function_inner(self, *args, **kwargs):
+        def _trace_deferred_inner(self, *args, **kwargs):
             # Start scope
             with start_active_span(name):
                 r = yield func(self, *args, **kwargs)
                 defer.returnValue(r)
 
-        return _trace_defered_function_inner
+        return _trace_deferred_inner
 
-    return trace_defered_function
+    return trace_deferred
 
 
-def trace_function(func):
+def trace(func):
+    """Decorator to trace a normal function. Sets the operation name to that of the
+    function's."""
+
     @wraps(func)
-    def _trace_function_inner(self, *args, **kwargs):
+    def _trace_inner(self, *args, **kwargs):
         with start_active_span(func.__name__):
             return func(self, *args, **kwargs)
 
-    return _trace_function_inner
+    return _trace_inner
 
 
-def trace_function_using_operation_name(operation_name):
+def trace_using_operation_name(operation_name):
     """Decorator to trace a function. Explicitely sets the operation_name to name"""
 
-    def trace_function(func):
+    def trace(func):
         @wraps(func)
-        def _trace_function_inner(self, *args, **kwargs):
+        def _trace_inner(self, *args, **kwargs):
             with start_active_span(operation_name):
                 return func(self, *args, **kwargs)
 
-        return _trace_function_inner
+        return _trace_inner
 
-    return trace_function
+    return trace
 
 
 def tag_args(func):