summary refs log tree commit diff
path: root/synapse/util/logcontext.py
diff options
context:
space:
mode:
authorRichard van der Hoff <richard@matrix.org>2019-06-24 10:01:16 +0100
committerRichard van der Hoff <richard@matrix.org>2019-06-24 10:01:16 +0100
commitdc94773e600fef29cf88d304ffb1515b145aea13 (patch)
tree488a53672280947136aaaf5895abd86d939453fd /synapse/util/logcontext.py
parentMerge branch 'develop' into rav/cleanup_metrics (diff)
downloadsynapse-dc94773e600fef29cf88d304ffb1515b145aea13.tar.xz
Avoid raising exceptions in metrics
Sentry will catch the errors if they happen, so that should be good enough, and
woun't make things explode if we hit the error condition.
Diffstat (limited to 'synapse/util/logcontext.py')
-rw-r--r--synapse/util/logcontext.py22
1 files changed, 14 insertions, 8 deletions
diff --git a/synapse/util/logcontext.py b/synapse/util/logcontext.py
index 10022ff620..6b0d2deea0 100644
--- a/synapse/util/logcontext.py
+++ b/synapse/util/logcontext.py
@@ -374,20 +374,26 @@ class LoggingContext(object):
 
         # sanity check
         if utime_delta < 0:
-            raise ValueError("utime went backwards! %f < %f" % (
-                current.ru_utime, self.usage_start.ru_utime,
-            ))
+            logger.error(
+                "utime went backwards! %f < %f",
+                current.ru_utime,
+                self.usage_start.ru_utime,
+            )
+            utime_delta = 0
 
         if stime_delta < 0:
-            raise ValueError("stime went backwards! %f < %f" % (
-                current.ru_stime, self.usage_start.ru_stime,
-            ))
+            logger.error(
+                "stime went backwards! %f < %f",
+                current.ru_stime,
+                self.usage_start.ru_stime,
+            )
+            stime_delta = 0
 
         return utime_delta, stime_delta
 
     def add_database_transaction(self, duration_sec):
         if duration_sec < 0:
-            raise ValueError('DB txn time can only be non-negative')
+            raise ValueError("DB txn time can only be non-negative")
         self._resource_usage.db_txn_count += 1
         self._resource_usage.db_txn_duration_sec += duration_sec
 
@@ -399,7 +405,7 @@ class LoggingContext(object):
                 connection
         """
         if sched_sec < 0:
-            raise ValueError('DB scheduling time can only be non-negative')
+            raise ValueError("DB scheduling time can only be non-negative")
         self._resource_usage.db_sched_duration_sec += sched_sec
 
     def record_event_fetch(self, event_count):