def process(self, **kwargs): """ Processes the message before passing it on to the server """ if kwargs.get('data'): # Ensure we're not changing the original data which was passed # to Sentry kwargs['data'] = kwargs['data'].copy() kwargs.setdefault('level', logging.ERROR) kwargs.setdefault('server_name', settings.NAME) # save versions of all installed apps if 'data' not in kwargs or '__sentry__' not in (kwargs['data'] or {}): if kwargs.get('data') is None: kwargs['data'] = {} kwargs['data']['__sentry__'] = {} versions = get_versions() kwargs['data']['__sentry__']['versions'] = versions # Shorten lists/strings for k, v in kwargs['data'].iteritems(): if k == '__sentry__': continue kwargs['data'][k] = shorten(v) if kwargs.get('view'): # get list of modules from right to left parts = kwargs['view'].split('.') module_list = \ ['.'.join(parts[:idx]) for idx in xrange(1, len(parts)+1)][::-1] version = None module = None for m in module_list: if m in versions: module = m version = versions[m] # store our "best guess" for application version if version: kwargs['data']['__sentry__'].update({ 'version': version, 'module': module, }) if 'checksum' not in kwargs: checksum = construct_checksum(**kwargs) else: checksum = kwargs['checksum'] for filter_ in get_filters(): kwargs = filter_(None).process(kwargs) or kwargs # create ID client-side so that it can be passed to application message_id = uuid.uuid4().hex kwargs['message_id'] = message_id # Make sure all data is coerced kwargs['data'] = transform(kwargs['data']) if 'timestamp' not in kwargs: kwargs['timestamp'] = datetime.datetime.now() self.send(**kwargs) return message_id
def create_from_record(self, record, **kwargs): """ Creates an error log for a ``logging`` module ``record`` instance. """ for k in ('url', 'view', 'data'): if not kwargs.get(k): kwargs[k] = record.__dict__.get(k) kwargs.update({ 'logger': record.name, 'level': record.levelno, 'message': force_unicode(record.msg), 'server_name': settings.NAME, }) # construct the checksum with the unparsed message kwargs['checksum'] = construct_checksum(**kwargs) # save the message with included formatting kwargs['message'] = record.getMessage() return self.process( traceback=record.exc_text, **kwargs )