summary refs log tree commit diff
path: root/synapse
diff options
context:
space:
mode:
authorJorik Schellekens <joriks@matrix.org>2019-07-11 18:21:10 +0100
committerJorik Schellekens <joriks@matrix.org>2019-07-17 14:20:22 +0100
commit04c3bf430c985dc405f2793e68adcd070c837e9d (patch)
tree0f85082b7ed2eb8c0473ee9a62cb42f5219530d1 /synapse
parentGroup utils (diff)
downloadsynapse-04c3bf430c985dc405f2793e68adcd070c837e9d.tar.xz
Move opentracing setters
Diffstat (limited to 'synapse')
-rw-r--r--synapse/logging/opentracing.py122
1 files changed, 64 insertions, 58 deletions
diff --git a/synapse/logging/opentracing.py b/synapse/logging/opentracing.py
index c3ccf8a7d8..dc49fc3cd5 100644
--- a/synapse/logging/opentracing.py
+++ b/synapse/logging/opentracing.py
@@ -119,6 +119,8 @@ def init_tracer(config):
     tags = opentracing.tags
 
 
+##### Start spans and scopes
+
 # Could use kwargs but I want these to be explicit
 def start_active_span(
     operation_name,
@@ -161,64 +163,6 @@ def start_active_span_follows_from(operation_name, contexts):
         return scope
 
 
-@only_if_tracing
-def set_tag(key, value):
-    """Set's a tag on the active span"""
-    opentracing.tracer.active_span.set_tag(key, value)
-
-
-@only_if_tracing
-def log_kv(key_values, timestamp=None):
-    """Log to the active span"""
-    opentracing.tracer.active_span.log_kv(key_values, timestamp)
-
-
-# Note: we don't have a get baggage items because we're trying to hide all
-# scope and span state from synapse. I think this method may also be useless
-# as a result
-
-# I also thinks it's dangerous with respect to pii. If the whitelisting
-# is missconfigured or buggy span information will leak. This is no issue
-# if it's jaeger span id's but baggage can contain any arbitrary data. I would
-# suggest removing this.
-@only_if_tracing
-def set_baggage_item(key, value):
-    """Attach baggage to the active span"""
-    opentracing.tracer.active_span.set_baggage_item(key, value)
-
-
-@only_if_tracing
-def set_operation_name(operation_name):
-    """Sets the operation name of the active span"""
-    opentracing.tracer.active_span.set_operation_name(operation_name)
-
-
-@only_if_tracing
-def set_homeserver_whitelist(homeserver_whitelist):
-    """Sets the whitelist
-
-    Args:
-        homeserver_whitelist (iterable of strings): regex of whitelisted homeservers
-    """
-    global _homeserver_whitelist
-    if homeserver_whitelist:
-        # Makes a single regex which accepts all passed in regexes in the list
-        _homeserver_whitelist = re.compile(
-            "({})".format(")|(".join(homeserver_whitelist))
-        )
-
-
-@only_if_tracing
-def whitelisted_homeserver(destination):
-    """Checks if a destination matches the whitelist
-    Args:
-        destination (String)"""
-    global _homeserver_whitelist
-    if _homeserver_whitelist:
-        return _homeserver_whitelist.match(destination)
-    return False
-
-
 def start_active_span_from_context(
     headers,
     operation_name,
@@ -299,6 +243,68 @@ def start_active_span_from_edu(
     return scope
 
 
+###### Opentracing setters for tags, logs, etc
+
+
+@only_if_tracing
+def set_tag(key, value):
+    """Set's a tag on the active span"""
+    opentracing.tracer.active_span.set_tag(key, value)
+
+
+@only_if_tracing
+def log_kv(key_values, timestamp=None):
+    """Log to the active span"""
+    opentracing.tracer.active_span.log_kv(key_values, timestamp)
+
+
+# Note: we don't have a get baggage items because we're trying to hide all
+# scope and span state from synapse. I think this method may also be useless
+# as a result
+
+# I also thinks it's dangerous with respect to pii. If the whitelisting
+# is missconfigured or buggy span information will leak. This is no issue
+# if it's jaeger span id's but baggage can contain any arbitrary data. I would
+# suggest removing this.
+@only_if_tracing
+def set_baggage_item(key, value):
+    """Attach baggage to the active span"""
+    opentracing.tracer.active_span.set_baggage_item(key, value)
+
+
+@only_if_tracing
+def set_operation_name(operation_name):
+    """Sets the operation name of the active span"""
+    opentracing.tracer.active_span.set_operation_name(operation_name)
+
+
+@only_if_tracing
+def set_homeserver_whitelist(homeserver_whitelist):
+    """Sets the homeserver whitelist
+
+    Args:
+        homeserver_whitelist (iterable of strings): regex of whitelisted homeservers
+    """
+    global _homeserver_whitelist
+    if homeserver_whitelist:
+        # Makes a single regex which accepts all passed in regexes in the list
+        _homeserver_whitelist = re.compile(
+            "({})".format(")|(".join(homeserver_whitelist))
+        )
+
+
+@only_if_tracing
+def whitelisted_homeserver(destination):
+    """Checks if a destination matches the whitelist
+
+    Args:
+        destination (String)"""
+    global _homeserver_whitelist
+    if _homeserver_whitelist:
+        return _homeserver_whitelist.match(destination)
+    return False
+
+
 @only_if_tracing
 def inject_active_span_twisted_headers(headers, destination):
     """