Skip to content
This repository has been archived by the owner on Oct 23, 2023. It is now read-only.

Support partial exc_info using logger #1132

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion raven/handlers/logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ def _emit(self, record, **kwargs):

# If there's no exception being processed, exc_info may be a 3-tuple of None
# http://docs.python.org/library/sys.html#sys.exc_info
if record.exc_info and all(record.exc_info):
if record.exc_info and not all(x is None for x in record.exc_info):
# capture the standard message first so that we ensure
# the event is recorded as an exception, in addition to having our
# message interface attached
Expand Down
25 changes: 25 additions & 0 deletions tests/handlers/logging/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,31 @@ def test_logger_exc_info(self):
self.assertEqual(msg['message'], 'This is a test info with an exception')
self.assertEqual(msg['params'], ())

def test_logger_partial_exc_info(self):
try:
raise ValueError('This is a test ValueError')
except ValueError:
exc_info = sys.exc_info()
exc_info = (exc_info[0], exc_info[1], None)
record = self.make_record('This is a test info with an exception', exc_info=exc_info)
else:
self.fail('Should have raised an exception')

self.handler.emit(record)

self.assertEqual(len(self.client.events), 1)
event = self.client.events.pop(0)

self.assertEqual(event['message'], 'This is a test info with an exception')
assert 'exception' in event
exc = event['exception']['values'][-1]
self.assertEqual(exc['type'], 'ValueError')
self.assertEqual(exc['value'], 'This is a test ValueError')
self.assertTrue('sentry.interfaces.Message' in event)
msg = event['sentry.interfaces.Message']
self.assertEqual(msg['message'], 'This is a test info with an exception')
self.assertEqual(msg['params'], ())

def test_message_params(self):
record = self.make_record('This is a test of %s', args=('args',))
self.handler.emit(record)
Expand Down