summary refs log tree commit diff
path: root/synapse/util/metrics.py
diff options
context:
space:
mode:
authorPatrick Cloke <clokep@users.noreply.github.com>2021-01-05 08:06:55 -0500
committerGitHub <noreply@github.com>2021-01-05 08:06:55 -0500
commit06fefe0bb19d5ef0a5873ea5697e2018ce9e6026 (patch)
tree7f890b4ecaf561d5bdf31494423fc6839f0e0b36 /synapse/util/metrics.py
parentImplement MSC2176: Updated redaction rules (#8984) (diff)
downloadsynapse-06fefe0bb19d5ef0a5873ea5697e2018ce9e6026.tar.xz
Add type hints to the logging context code. (#8939)
Diffstat (limited to 'synapse/util/metrics.py')
-rw-r--r--synapse/util/metrics.py10
1 files changed, 9 insertions, 1 deletions
diff --git a/synapse/util/metrics.py b/synapse/util/metrics.py
index ffdea0de8d..24123d5cc4 100644
--- a/synapse/util/metrics.py
+++ b/synapse/util/metrics.py
@@ -108,7 +108,15 @@ class Measure:
     def __init__(self, clock, name):
         self.clock = clock
         self.name = name
-        parent_context = current_context()
+        curr_context = current_context()
+        if not curr_context:
+            logger.warning(
+                "Starting metrics collection from sentinel context: metrics will be lost"
+            )
+            parent_context = None
+        else:
+            assert isinstance(curr_context, LoggingContext)
+            parent_context = curr_context
         self._logging_context = LoggingContext(
             "Measure[%s]" % (self.name,), parent_context
         )