From 73338ac7e326970134d912cd60bafa8eab4e2b94 Mon Sep 17 00:00:00 2001 From: Philip Jenvey Date: Tue, 13 Feb 2018 14:50:57 -0800 Subject: [PATCH] fix: reverse our filled in stack trace order frames should be sorted from oldest to newest despite raven's iter_stack_frames Closes #1134 --- autopush/logging.py | 6 ++++-- autopush/tests/test_logging.py | 11 ++++++----- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/autopush/logging.py b/autopush/logging.py index 5bae3fab..07fd56d6 100644 --- a/autopush/logging.py +++ b/autopush/logging.py @@ -142,8 +142,10 @@ def raven_log(self, event): extra = dict() tb = f.getTracebackObject() if not tb: - # include the current stack for at least some context - stack = list(iter_stack_frames())[4:] # approx. + # include the current stack for at least some + # context. sentry's expecting that "Frames should be + # sorted from oldest to newest." + stack = reversed(list(iter_stack_frames())[5:]) # approx. extra = dict(no_failure_tb=True) extra.update( log_format=event.get('log_format'), diff --git a/autopush/tests/test_logging.py b/autopush/tests/test_logging.py index b12a775f..e23610ab 100644 --- a/autopush/tests/test_logging.py +++ b/autopush/tests/test_logging.py @@ -99,11 +99,12 @@ def check(): return assert len(logged) == 1 - # Ensure a top level stacktrace was included - stacktrace = logged[0]['stacktrace'] - assert any( - filename == f['abs_path'] and testname == f['function'] - for f in stacktrace['frames']) + # Ensure a stacktrace was included w/ the current frame as + # the last entry + frames = logged[0]['stacktrace']['frames'] + last = frames[-1] + assert last['abs_path'] == filename + assert last['function'] == testname self._port.stopListening() pl.stop()