From 8038eff3232ffd1df8f14ba7aa9bbc90bce26696 Mon Sep 17 00:00:00 2001 From: David Cramer Date: Mon, 19 Oct 2015 15:04:49 -0700 Subject: [PATCH] Add support for in_app on exception frames --- raven/base.py | 12 ++++++-- raven/contrib/django/client.py | 19 ++++--------- tests/base/tests.py | 50 ++++++++++++++++++++++++++++++++++ 3 files changed, 66 insertions(+), 15 deletions(-) diff --git a/raven/base.py b/raven/base.py index 8d037eaa..f258aa2b 100644 --- a/raven/base.py +++ b/raven/base.py @@ -327,8 +327,8 @@ class Client(object): 'stacktrace': stack_info, }) - if 'stacktrace' in data and self.include_paths: - for frame in data['stacktrace']['frames']: + if self.include_paths: + for frame in self._iter_frames(data): if frame.get('in_app') is not None: continue @@ -531,6 +531,14 @@ class Client(object): """ return self.remote.is_active() + def _iter_frames(self, data): + if 'stacktrace' in data: + for frame in data['stacktrace']['frames']: + yield frame + if 'exception' in data: + for frame in data['exception']['values'][0]['stacktrace']['frames']: + yield frame + def _successful_send(self): self.state.set_success() diff --git a/raven/contrib/django/client.py b/raven/contrib/django/client.py index 9dbb82dd..80494141 100644 --- a/raven/contrib/django/client.py +++ b/raven/contrib/django/client.py @@ -108,20 +108,13 @@ class DjangoClient(Client): def build_msg(self, *args, **kwargs): data = super(DjangoClient, self).build_msg(*args, **kwargs) - stacks = [ - data.get('stacktrace'), - ] - if 'exception' in data: - stacks.append(data['exception']['values'][0]['stacktrace']) + for frame in self._iter_frames(data): + module = frame.get('module') + if not module: + continue - for stacktrace in filter(bool, stacks): - for frame in stacktrace['frames']: - module = frame.get('module') - if not module: - continue - - if module.startswith('django.'): - frame['in_app'] = False + if module.startswith('django.'): + frame['in_app'] = False if not self.site and 'django.contrib.sites' in settings.INSTALLED_APPS: try: diff --git a/tests/base/tests.py b/tests/base/tests.py index e360b2fe..1b1851ac 100644 --- a/tests/base/tests.py +++ b/tests/base/tests.py @@ -455,3 +455,53 @@ class ClientTest(TestCase): client = Client('sync+http://public:secret@example.com/1') assert type(client.remote.get_transport()) is HTTPTransport + + def test_marks_in_app_frames_for_stacktrace(self): + client = TempStoreClient( + include_paths=['foo'], + exclude_paths=['foo.bar'], + ) + client.captureMessage('hello', data={ + 'stacktrace': { + 'frames': [ + {'module': 'foo'}, + {'module': 'bar'}, + {'module': 'foo.bar'}, + {'module': 'foo.baz'}, + ] + } + }) + + event = client.events.pop(0) + frames = event['stacktrace']['frames'] + assert frames[0]['in_app'] + assert not frames[1]['in_app'] + assert not frames[2]['in_app'] + assert frames[3]['in_app'] + + def test_marks_in_app_frames_for_exception(self): + client = TempStoreClient( + include_paths=['foo'], + exclude_paths=['foo.bar'], + ) + client.captureMessage('hello', data={ + 'exception': { + 'values': [{ + 'stacktrace': { + 'frames': [ + {'module': 'foo'}, + {'module': 'bar'}, + {'module': 'foo.bar'}, + {'module': 'foo.baz'}, + ] + } + }] + } + }) + + event = client.events.pop(0) + frames = event['exception']['values'][0]['stacktrace']['frames'] + assert frames[0]['in_app'] + assert not frames[1]['in_app'] + assert not frames[2]['in_app'] + assert frames[3]['in_app']