summary refs log tree commit diff
path: root/synapse
diff options
context:
space:
mode:
authorErik Johnston <erik@matrix.org>2022-04-07 13:18:29 +0100
committerGitHub <noreply@github.com>2022-04-07 13:18:29 +0100
commitd1cd96ce2966bc5bd268eac56a485e785779e9e0 (patch)
treefc2663cc7ce2d4ef3f9905be68dd487639657960 /synapse
parentPoetry: use locked environment in Docker images (#12385) (diff)
downloadsynapse-d1cd96ce2966bc5bd268eac56a485e785779e9e0.tar.xz
Add opentracing spans to calls to external cache (#12380)
Diffstat (limited to 'synapse')
-rw-r--r--synapse/logging/opentracing.py3
-rw-r--r--synapse/replication/tcp/external_cache.py31
2 files changed, 23 insertions, 11 deletions
diff --git a/synapse/logging/opentracing.py b/synapse/logging/opentracing.py
index 3ebed5c161..f86ee9aac7 100644
--- a/synapse/logging/opentracing.py
+++ b/synapse/logging/opentracing.py
@@ -289,6 +289,9 @@ class SynapseTags:
     # Uniqueish ID of a database transaction
     DB_TXN_ID = "db.txn_id"
 
+    # The name of the external cache
+    CACHE_NAME = "cache.name"
+
 
 class SynapseBaggage:
     FORCE_TRACING = "synapse-force-tracing"
diff --git a/synapse/replication/tcp/external_cache.py b/synapse/replication/tcp/external_cache.py
index bf7d017968..a448dd7eb1 100644
--- a/synapse/replication/tcp/external_cache.py
+++ b/synapse/replication/tcp/external_cache.py
@@ -17,6 +17,7 @@ from typing import TYPE_CHECKING, Any, Optional
 
 from prometheus_client import Counter, Histogram
 
+from synapse.logging import opentracing
 from synapse.logging.context import make_deferred_yieldable
 from synapse.util import json_decoder, json_encoder
 
@@ -93,14 +94,18 @@ class ExternalCache:
 
         logger.debug("Caching %s %s: %r", cache_name, key, encoded_value)
 
-        with response_timer.labels("set").time():
-            return await make_deferred_yieldable(
-                self._redis_connection.set(
-                    self._get_redis_key(cache_name, key),
-                    encoded_value,
-                    pexpire=expiry_ms,
+        with opentracing.start_active_span(
+            "ExternalCache.set",
+            tags={opentracing.SynapseTags.CACHE_NAME: cache_name},
+        ):
+            with response_timer.labels("set").time():
+                return await make_deferred_yieldable(
+                    self._redis_connection.set(
+                        self._get_redis_key(cache_name, key),
+                        encoded_value,
+                        pexpire=expiry_ms,
+                    )
                 )
-            )
 
     async def get(self, cache_name: str, key: str) -> Optional[Any]:
         """Look up a key/value in the named cache."""
@@ -108,10 +113,14 @@ class ExternalCache:
         if self._redis_connection is None:
             return None
 
-        with response_timer.labels("get").time():
-            result = await make_deferred_yieldable(
-                self._redis_connection.get(self._get_redis_key(cache_name, key))
-            )
+        with opentracing.start_active_span(
+            "ExternalCache.get",
+            tags={opentracing.SynapseTags.CACHE_NAME: cache_name},
+        ):
+            with response_timer.labels("get").time():
+                result = await make_deferred_yieldable(
+                    self._redis_connection.get(self._get_redis_key(cache_name, key))
+                )
 
         logger.debug("Got cache result %s %s: %r", cache_name, key, result)