summary refs log tree commit diff
diff options
context:
space:
mode:
authorJorik Schellekens <joriks@matrix.org>2019-08-05 15:02:29 +0100
committerJorik Schellekens <joriks@matrix.org>2019-08-05 15:02:29 +0100
commit4f36a2dfeca8222898b9b1f5dbb12935a85e234c (patch)
tree45779970bbb21b01523b045dc6b7d5d55ff3f4c8
parentDocstrings shouldn't lie. (diff)
downloadsynapse-4f36a2dfeca8222898b9b1f5dbb12935a85e234c.tar.xz
Create and use a method to get the span context as a dict.
-rw-r--r--synapse/logging/opentracing.py25
-rw-r--r--synapse/storage/devices.py3
2 files changed, 26 insertions, 2 deletions
diff --git a/synapse/logging/opentracing.py b/synapse/logging/opentracing.py
index d2c209c471..bbc609a569 100644
--- a/synapse/logging/opentracing.py
+++ b/synapse/logging/opentracing.py
@@ -527,6 +527,31 @@ def inject_active_span_text_map(carrier, destination=None):
     )
 
 
+def get_active_span_text_map(destination=None):
+    """
+    Gets a span context as a dict. This can be used instead of injecting a span
+    into an empty carrier.
+
+    Args:
+        destination (str): the name of the remote server. The dict will only
+        contain a span context if the destination matches the homeserver_whitelist
+        or if destination is None.
+
+    Returns:
+        A dict containing the span context.
+    """
+
+    if not opentracing or (destination and not whitelisted_homeserver(destination)):
+        return {}
+
+    carrier = {}
+    opentracing.tracer.inject(
+        opentracing.tracer.active_span, opentracing.Format.TEXT_MAP, carrier
+    )
+
+    return carrier
+
+
 def active_span_context_as_string():
     """
     Returns:
diff --git a/synapse/storage/devices.py b/synapse/storage/devices.py
index 3b2e9c6699..724c5b7622 100644
--- a/synapse/storage/devices.py
+++ b/synapse/storage/devices.py
@@ -828,8 +828,7 @@ class DeviceStore(DeviceWorkerStore, BackgroundUpdateStore):
             ],
         )
 
-        context = {"opentracing": {}}
-        opentracing.inject_active_span_text_map(context["opentracing"])
+        context = {"opentracing": opentracing.get_active_span_text_map()}
 
         self._simple_insert_many_txn(
             txn,