Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you raise a python exception and include additional data for Sentry?

Sentry can detect additional data associated with an exception such as:

enter image description here

How do you raise such an exception from Python (it's a Django app) with your own additional data fields?.

like image 804
AJP Avatar asked Apr 11 '13 14:04

AJP


1 Answers

I log exceptions using the logging library so after debugging the code a bit, I noticed the extra parameter:

import logging
logger = logging.getLogger('my_app_name')

def do_something():

    try:
        #do some stuff here that might break

    except Exception, e:
        logger.error(e, exc_info=1, extra={'extra-data': 'blah', })

Passing exc_info=1 is the same as calling logger.exception. However, exception() does not accept kwargs, which are required for using the extra parameter.

These values will show up in the 'Additional Data' section of the Sentry Error dashboard.

like image 62
wes Avatar answered Sep 17 '22 19:09

wes