diff options
author | Erik Johnston <erik@matrix.org> | 2023-07-12 14:46:42 +0100 |
---|---|---|
committer | Erik Johnston <erik@matrix.org> | 2023-07-12 14:46:42 +0100 |
commit | e7176e81205b0350270ba12e9538550a7de5f019 (patch) | |
tree | 78f5c3a991102964f921f5c70ed9310b1e2f55d5 | |
parent | Fix running with an empty experimental features section. (#15925) (diff) | |
download | synapse-e7176e81205b0350270ba12e9538550a7de5f019.tar.xz |
Add prometheus exemplars support
-rw-r--r-- | synapse/http/request_metrics.py | 3 | ||||
-rw-r--r-- | synapse/logging/opentracing.py | 10 |
2 files changed, 12 insertions, 1 deletions
diff --git a/synapse/http/request_metrics.py b/synapse/http/request_metrics.py index 2b6d113544..4acb30e1db 100644 --- a/synapse/http/request_metrics.py +++ b/synapse/http/request_metrics.py @@ -21,6 +21,7 @@ from typing import Dict, Mapping, Set, Tuple from prometheus_client.core import Counter, Histogram from synapse.logging.context import current_context +from synapse.logging.opentracing import get_prometheus_exemplar from synapse.metrics import LaterGauge logger = logging.getLogger(__name__) @@ -193,7 +194,7 @@ class RequestMetrics: response_count.labels(self.method, self.name, tag).inc() response_timer.labels(self.method, self.name, tag, response_code_str).observe( - time_sec - self.start_ts + time_sec - self.start_ts, exemplar=get_prometheus_exemplar() ) resource_usage = context.get_resource_usage() diff --git a/synapse/logging/opentracing.py b/synapse/logging/opentracing.py index be910128aa..f5e4993fab 100644 --- a/synapse/logging/opentracing.py +++ b/synapse/logging/opentracing.py @@ -672,6 +672,16 @@ def active_span() -> Optional["opentracing.Span"]: return opentracing.tracer.active_span +def get_prometheus_exemplar() -> Optional[Dict[str, str]]: + span = active_span() + if not span: + return None + + trace_id = getattr(span, "trace_id", None) + + return trace_id + + @ensure_active_span("set a tag") def set_tag(key: str, value: Union[str, bool, int, float]) -> None: """Sets a tag on the active span""" |