def __call__(self): if not get_raven_config().enabled: return '' config = { 'dsn': self._get_dsn_without_private_key(), 'options': self._get_install_args(), 'user_context': reporter.prepare_user_infos( self.context, self.request, include_roles=False)} return 'var raven_config = {};'.format( json.dumps(config, sort_keys=True, indent=4))
def __call__(self): if not get_raven_config().enabled: return '' config = { 'dsn': self._get_dsn_without_private_key(), 'options': self._get_install_args(), 'user_context': reporter.prepare_user_infos(self.context, self.request, include_roles=False) } return 'var raven_config = {};'.format( json.dumps(config, sort_keys=True, indent=4))
def log_msg_to_sentry(message, context=None, request=None, url=None, data=None, extra=None, fingerprint=None, string_max_length=_marker): """A (hopefully) fail-safe function to log a message to Sentry. This is loosely based on ftw.raven's maybe_report_exception(), except that it can be used to simply log a free-form message and optionally some additional data, for cases where you don't have an actual exception. It also allows to specifiy a fingerprint to better control Sentry's grouping of messages. This still depends on ftw.raven for extraction of some additional info. If either ftw.raven isn't installed, or we can't get hold of a Sentry client, this function should abort gracefully, not log to Sentry, but also not cause any additional problems. This is why everything here is written in a very defensive way, we're being very paranoid and try hard not to cause any additional issues. """ if not FTW_RAVEN_AVAILABLE: log.warn('ftw.raven not installed, not logging to Sentry') return False try: client = get_raven_client() if client is None: log.warn('Could not get raven client, not logging to Sentry') return False if request is None: request = getRequest() if context is None: context = context_from_request(request) if url is None: url = url_from_request(request) try: data_dict = { 'request': prepare_request_infos(request), 'user': prepare_user_infos(context, request), 'extra': prepare_extra_infos(context, request), 'modules': prepare_modules_infos(), 'tags': get_default_tags(), } release = get_release() if release: data_dict['release'] = release if data is not None: data_dict.update(data) except: log.error('Error while preparing sentry data.') raise try: kwargs = dict( message=message, data=data_dict, extra=extra, stack=False, ) if fingerprint: kwargs['fingerprint'] = fingerprint with custom_string_max_length(client, string_max_length): client.captureMessage(**kwargs) except: log.error('Error while reporting to sentry.') raise except: try: get_raven_client().captureException( data={ 'extra': { 'raven_meta_error': 'Error occured while reporting' ' another error.' } }) except: log.error('Failed to report error occured while reporting error.') return False return True
def log_msg_to_sentry(message, context=None, request=None, url=None, data=None, extra=None, fingerprint=None, string_max_length=_marker): """A (hopefully) fail-safe function to log a message to Sentry. This is loosely based on ftw.raven's maybe_report_exception(), except that it can be used to simply log a free-form message and optionally some additional data, for cases where you don't have an actual exception. It also allows to specifiy a fingerprint to better control Sentry's grouping of messages. This still depends on ftw.raven for extraction of some additional info. If either ftw.raven isn't installed, or we can't get hold of a Sentry client, this function should abort gracefully, not log to Sentry, but also not cause any additional problems. This is why everything here is written in a very defensive way, we're being very paranoid and try hard not to cause any additional issues. """ if not FTW_RAVEN_AVAILABLE: log.warn('ftw.raven not installed, not logging to Sentry') return False try: client = get_raven_client() if client is None: log.warn('Could not get raven client, not logging to Sentry') return False if request is None: request = getRequest() if context is None: context = context_from_request(request) if url is None: url = url_from_request(request) try: data_dict = { 'request': prepare_request_infos(request), 'user': prepare_user_infos(context, request), 'extra': prepare_extra_infos(context, request), 'modules': prepare_modules_infos(), 'tags': get_default_tags(), } release = get_release() if release: data_dict['release'] = release if data is not None: data_dict.update(data) except: log.error('Error while preparing sentry data.') raise try: kwargs = dict( message=message, data=data_dict, extra=extra, stack=False, ) if fingerprint: kwargs['fingerprint'] = fingerprint with custom_string_max_length(client, string_max_length): client.captureMessage(**kwargs) except: log.error('Error while reporting to sentry.') raise except: try: get_raven_client().captureException( data={'extra': { 'raven_meta_error': 'Error occured while reporting' ' another error.'}}) except: log.error( 'Failed to report error occured while reporting error.') return False return True