From ef9e926e552260042ac855fbeae9b4ef396254e2 Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Tue, 27 Apr 2021 14:15:35 +0100 Subject: Add opentracing spans to DB calls and measure blocks --- synapse/util/metrics.py | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'synapse/util/metrics.py') diff --git a/synapse/util/metrics.py b/synapse/util/metrics.py index 6d14351bd2..c6ff520b34 100644 --- a/synapse/util/metrics.py +++ b/synapse/util/metrics.py @@ -23,6 +23,7 @@ from synapse.logging.context import ( LoggingContext, current_context, ) +from synapse.logging.opentracing import start_active_span from synapse.metrics import InFlightGauge logger = logging.getLogger(__name__) @@ -102,6 +103,7 @@ class Measure: "name", "_logging_context", "start", + "_span", ] def __init__(self, clock, name: str): @@ -126,13 +128,18 @@ class Measure: self._logging_context = LoggingContext(str(curr_context), parent_context) self.start = None # type: Optional[int] + self._span = start_active_span(f"measure.{name}") + def __enter__(self) -> "Measure": if self.start is not None: raise RuntimeError("Measure() objects cannot be re-used") + self._span.__enter__() + self.start = self.clock.time() self._logging_context.__enter__() in_flight.register((self.name,), self._update_in_flight) + return self def __exit__(self, exc_type, exc_val, exc_tb): @@ -156,6 +163,8 @@ class Measure: except ValueError: logger.warning("Failed to save metrics! Usage: %s", usage) + self._span.__exit__(exc_type, exc_val, exc_tb) + def get_resource_usage(self) -> ContextResourceUsage: """Get the resources used within this Measure block -- cgit 1.5.1