Skip to content

Commit b96d714

Browse files
mgr/mgr_util: log traceback when exception occurs in RTimer.run()
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 <[email protected]>
1 parent 21cf769 commit b96d714

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/pybind/mgr/mgr_util.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
from ipaddress import ip_address
2323
from threading import Lock, Condition
2424
from typing import no_type_check, NewType
25+
from traceback import format_exc as tb_format_exc
2526
import urllib
2627
from functools import wraps
2728
if sys.version_info >= (3, 3):
@@ -88,8 +89,9 @@ def run(self):
8889
while not self.finished.is_set():
8990
self.finished.wait(self.interval)
9091
self.function(*self.args, **self.kwargs)
91-
except Exception as e:
92-
logger.error("task exception: %s", e)
92+
except Exception:
93+
logger.error(f'exception encountered in RTimer instance "{self}":'
94+
f'\n{tb_format_exc()}')
9395
raise
9496

9597

0 commit comments

Comments
 (0)