From bc68a7447ceca5a5a386dc0371e1357ad5c732d3 Mon Sep 17 00:00:00 2001 From: Wu Junmin Date: Fri, 18 Aug 2017 19:05:25 +0800 Subject: [PATCH] Extend stack to exc_info --- raven/events.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/raven/events.py b/raven/events.py index 775a5804c..697623dda 100644 --- a/raven/events.py +++ b/raven/events.py @@ -109,6 +109,28 @@ def _get_value(self, exc_type, exc_value, exc_traceback): 'stacktrace': stack_info, } + @staticmethod + def full_stacktrace(t, v, tb): + class FauxTb(object): + def __init__(self, tb_frame, tb_lineno, tb_next): + self.tb_frame = tb_frame + self.tb_lineno = tb_lineno + self.tb_next = tb_next + + def extend_tb(tb): + f = tb.tb_frame + lst = [] + while f is not None: + lst.append((f, f.f_lineno)) + f = f.f_back + head = tb + for tb_frame, tb_lineno in lst[1:]: + head = FauxTb(tb_frame, tb_lineno, head) + return head + + full_tb = extend_tb(tb) + return t, v, full_tb + def capture(self, exc_info=None, **kwargs): if not exc_info or exc_info is True: exc_info = sys.exc_info() @@ -116,6 +138,8 @@ def capture(self, exc_info=None, **kwargs): if not exc_info: raise ValueError('No exception found') + exc_info = self.full_stacktrace(*exc_info) + values = [] for exc_info in _chained_exceptions(exc_info): value = self._get_value(*exc_info)