Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Add opentracing spans to calls to external cache #12380

Merged
merged 6 commits into from
Apr 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/12380.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add opentracing spans to calls to external cache.
3 changes: 3 additions & 0 deletions synapse/logging/opentracing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
31 changes: 20 additions & 11 deletions synapse/replication/tcp/external_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

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

Expand Down Expand Up @@ -93,25 +94,33 @@ async def set(self, cache_name: str, key: str, value: Any, expiry_ms: int) -> No

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."""

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)

Expand Down