When an exception occurs in class RTimer of mgr_util.py, only the
exception message is logged but not only this is insufficient for
debugging but also it is hard to spot in logs. This should not be the
case, especially for an occurring exception. Therefore, add code to log
traceback and exception name as well along with exception's message.
Log entry before this patch -
2024-09-27T00:22:38.656+0530
7f05c7e006c0 0 [volumes ERROR mgr_util] task exception: dummy exception for testing
Log entry with this patch -
2024-09-27T00:40:26.509+0530
7f61d64006c0 0 [volumes ERROR mgr_util] exception encountered in RTimer instance "<RTimer(Thread-7, started daemon
140058183075520)>":
Traceback (most recent call last):
File "/home/rishabh/repos/ceph/minor3/src/pybind/mgr/mgr_util.py", line 91, in run
self.function(*self.args, **self.kwargs)
File "/home/rishabh/repos/ceph/minor3/src/pybind/mgr/volumes/fs/stats_util.py", line 232, in _update_progress_bars
raise RuntimeError('dummy exception for testing')
RuntimeError: dummy exception for testing
Signed-off-by: Rishabh Dave <ridave@redhat.com>
from ipaddress import ip_address
from threading import Lock, Condition
from typing import no_type_check, NewType
+from traceback import format_exc as tb_format_exc
import urllib
from functools import wraps
if sys.version_info >= (3, 3):
while not self.finished.is_set():
self.finished.wait(self.interval)
self.function(*self.args, **self.kwargs)
- except Exception as e:
- logger.error("task exception: %s", e)
+ except Exception:
+ logger.error(f'exception encountered in RTimer instance "{self}":'
+ f'\n{tb_format_exc()}')
raise