From d3cbee047f4a0780d532abac32333d79e7f30a14 Mon Sep 17 00:00:00 2001 From: Aleksei Voronov Date: Fri, 7 Jul 2023 16:41:40 +0200 Subject: [PATCH] Log exceptions that happen when reporting metrics At the moment, if an exception happens inside report_now, it is wholly ignored This means that if there is a fault in the reporter, it may silently sit there, not reporting anything, without anyone's knowledge. Add some basic logging of caught exceptions so that they show up in user's logs and so that they are able to inspect problems when they arise. --- pyformance/reporters/reporter.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/pyformance/reporters/reporter.py b/pyformance/reporters/reporter.py index d2a4b62..f25eaea 100644 --- a/pyformance/reporters/reporter.py +++ b/pyformance/reporters/reporter.py @@ -1,9 +1,12 @@ +import logging import time from threading import Thread, Event import six from ..registry import global_registry, get_qualname +LOG = logging.getLogger(__name__) + class Reporter(object): def create_thread(self): # noinspection PyAttributeOutsideInit @@ -43,7 +46,8 @@ def _loop(self): while not self._stopped.is_set(): try: self.report_now(self.registry) - except: + except Exception as e: + LOG.error("Exception caught while reporting metrics", exc_info=e) pass next_loop_time += self.reporting_interval wait = max(0, next_loop_time - time.time())