Add opentracing spans to calls to external cache (#12380)
This commit is contained in:
parent
3a7e97c7ad
commit
d1cd96ce29
|
@ -0,0 +1 @@
|
||||||
|
Add opentracing spans to calls to external cache.
|
|
@ -289,6 +289,9 @@ class SynapseTags:
|
||||||
# Uniqueish ID of a database transaction
|
# Uniqueish ID of a database transaction
|
||||||
DB_TXN_ID = "db.txn_id"
|
DB_TXN_ID = "db.txn_id"
|
||||||
|
|
||||||
|
# The name of the external cache
|
||||||
|
CACHE_NAME = "cache.name"
|
||||||
|
|
||||||
|
|
||||||
class SynapseBaggage:
|
class SynapseBaggage:
|
||||||
FORCE_TRACING = "synapse-force-tracing"
|
FORCE_TRACING = "synapse-force-tracing"
|
||||||
|
|
|
@ -17,6 +17,7 @@ from typing import TYPE_CHECKING, Any, Optional
|
||||||
|
|
||||||
from prometheus_client import Counter, Histogram
|
from prometheus_client import Counter, Histogram
|
||||||
|
|
||||||
|
from synapse.logging import opentracing
|
||||||
from synapse.logging.context import make_deferred_yieldable
|
from synapse.logging.context import make_deferred_yieldable
|
||||||
from synapse.util import json_decoder, json_encoder
|
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)
|
logger.debug("Caching %s %s: %r", cache_name, key, encoded_value)
|
||||||
|
|
||||||
with response_timer.labels("set").time():
|
with opentracing.start_active_span(
|
||||||
return await make_deferred_yieldable(
|
"ExternalCache.set",
|
||||||
self._redis_connection.set(
|
tags={opentracing.SynapseTags.CACHE_NAME: cache_name},
|
||||||
self._get_redis_key(cache_name, key),
|
):
|
||||||
encoded_value,
|
with response_timer.labels("set").time():
|
||||||
pexpire=expiry_ms,
|
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]:
|
async def get(self, cache_name: str, key: str) -> Optional[Any]:
|
||||||
"""Look up a key/value in the named cache."""
|
"""Look up a key/value in the named cache."""
|
||||||
|
@ -108,10 +113,14 @@ class ExternalCache:
|
||||||
if self._redis_connection is None:
|
if self._redis_connection is None:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
with response_timer.labels("get").time():
|
with opentracing.start_active_span(
|
||||||
result = await make_deferred_yieldable(
|
"ExternalCache.get",
|
||||||
self._redis_connection.get(self._get_redis_key(cache_name, key))
|
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)
|
logger.debug("Got cache result %s %s: %r", cache_name, key, result)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue