Add support for in_app on exception frames
This commit is contained in:
parent
42dbe37095
commit
8038eff323
|
@ -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()
|
||||
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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']
|
||||
|
|
Loading…
Reference in New Issue