Add opentracing spans to calls to external cache (#12380)

pull/12410/head
Erik Johnston 2022-04-07 13:18:29 +01:00 committed by GitHub
parent 3a7e97c7ad
commit d1cd96ce29
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 24 additions and 11 deletions

1
changelog.d/12380.misc Normal file
View File

@ -0,0 +1 @@
Add opentracing spans to calls to external cache.

View File

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

View File

@ -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,6 +94,10 @@ class ExternalCache:
logger.debug("Caching %s %s: %r", cache_name, key, encoded_value)
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(
@ -108,6 +113,10 @@ class ExternalCache:
if self._redis_connection is None:
return None
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))