def send_exception(exc_type, exc_value, exc_traceback): logging.error(exc_value) try: value = exc_value payload = { u'event_id': generate_random_key(32), u'platform': u'python', u'culpit': u'-', u'timestamp': unicode(datetime.utcnow()), u'dist': Config.build(), u'tags': sys_info(), u'user': { u'id': Config.user_id(), }, u"exception": { u"values": [{ u"type": exc_type.__name__, u"value": unicode(value), u"stacktrace": { u"frames": list( imap( lambda f: { u'filename': f[0], u'lineno': f[1] + 1, u'function': f[2] }, traceback.extract_tb(exc_traceback))) } }] } } async_post(STORE_URL, headers={ u"X-Sentry-Auth": AUTH.format(timestamp=int(time.time())) }, json=payload) except Exception, sending_exception: # raise sending_exception print u"Could not send:(" print sending_exception logging.error(sending_exception)
def capture_exception(): logging.info("Capturing exception") exc_type, exc_value, exc_traceback = sys.exc_info() logging.error(exc_value) try: payload = { 'event_id': generate_random_key(32), 'platform': 'python', 'culpit': '-', 'timestamp': str(datetime.utcnow()), 'dist': Config.build(), 'tags': sys_info(), 'user': { 'id': _try_user_id(), }, "exception": { "values": [{ "type": exc_type.__name__, "value": ", ".join(exc_value.args), "stacktrace": { "frames": list( map( lambda f: { 'filename': f[0], 'lineno': f[1] + 1, 'function': f[2] }, traceback.extract_tb(exc_traceback))) } }] } } async_post( STORE_URL, headers={"X-Sentry-Auth": AUTH.format(timestamp=int(time.time()))}, json=payload) except Exception as sending_exception: print(sending_exception) # raise sending_exception logging.error(sending_exception)
def log_event(self, event): if event is not None and type(event) == list: if self.is_logging: result = async_post(self.api_uri, data=event) return result