示例#1
0
    def _get_install_args(self):
        args = {}

        release = reporter.get_release()
        if release:
            args['release'] = release

        if hasattr(socket, 'gethostname'):
            args['serverName'] = socket.gethostname()

        tags = reporter.get_default_tags()
        if tags:
            args['tags'] = tags

        return args
示例#2
0
    def _get_install_args(self):
        args = {}

        release = reporter.get_release()
        if release:
            args['release'] = release

        if hasattr(socket, 'gethostname'):
            args['serverName'] = socket.gethostname()

        tags = reporter.get_default_tags()
        if tags:
            args['tags'] = tags

        return args
示例#3
0
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
示例#4
0
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