def test_filter_by_level(self):
        self.assertFalse(events.on_exception_info((None, 123, None), level='ignored'))
        self.assertIsNot(events.on_exception_info((None, 123, None), level='error'), False)

        self.assertFalse(events.on_message('hello world', level='ignored'))
        self.assertIsNot(events.on_message('hello world', level='error'), False)

        self.assertFalse(events.on_payload({}, level='ignored'))
        self.assertIsNot(events.on_message({}, level='error'), False)
    def test_rollbar_ignored_exception(self):
        class IgnoredException(Exception):
            _rollbar_ignore = True

        class NotIgnoredException(Exception):
            _rollbar_ignore = False

        self.assertFalse(events.on_exception_info((None, IgnoredException(), None)))
        self.assertIsNot(events.on_exception_info((None, NotIgnoredException(), None)), False)
Exemple #3
0
    def test_ignore_by_setting_rollbar_ignore(self):
        class NotIgnoredByDefault(Exception):
            pass

        def _ignore_if_cruel_world_filter(exc_info, **kw):
            cls, exc, trace = exc_info
            if 'cruel world' in str(exc):
                exc._rollbar_ignore = True

            return exc_info

        events.add_exception_info_handler(_ignore_if_cruel_world_filter, pos=0)

        self.assertIsNot(events.on_exception_info((None, NotIgnoredByDefault('hello world'), None)), False)
        self.assertFalse(events.on_exception_info((None, NotIgnoredByDefault('hello cruel world'), None)))
Exemple #4
0
def _report_exc_info(exc_info, request, extra_data, payload_data, level=None):
    """
    Called by report_exc_info() wrapper
    """

    if not _check_config():
        return

    filtered_level = _filtered_level(exc_info[1])
    if level is None:
        level = filtered_level

    filtered_exc_info = events.on_exception_info(exc_info,
                                                 request=request,
                                                 extra_data=extra_data,
                                                 payload_data=payload_data,
                                                 level=level)

    if filtered_exc_info is False:
        return

    cls, exc, trace = filtered_exc_info

    data = _build_base_data(request)
    if level is not None:
        data['level'] = level

    # walk the trace chain to collect cause and context exceptions
    trace_chain = _walk_trace_chain(cls, exc, trace)

    extra_trace_data = None
    if len(trace_chain) > 1:
        data['body'] = {
            'trace_chain': trace_chain
        }
        if payload_data and ('body' in payload_data) and ('trace' in payload_data['body']):
            extra_trace_data = payload_data['body']['trace']
            del payload_data['body']['trace']
    else:
        data['body'] = {
            'trace': trace_chain[0]
        }

    if extra_data:
        extra_data = extra_data
        if not isinstance(extra_data, dict):
            extra_data = {'value': extra_data}
        if extra_trace_data:
            extra_data = dict_merge(extra_data, extra_trace_data)
        data['custom'] = extra_data
    if extra_trace_data and not extra_data:
        data['custom'] = extra_trace_data

    _add_request_data(data, request)
    _add_person_data(data, request)
    _add_lambda_context_data(data)
    data['server'] = _build_server_data()

    if payload_data:
        data = dict_merge(data, payload_data)

    payload = _build_payload(data)
    send_payload(payload, data.get('access_token'))

    return data['uuid']
Exemple #5
0
def _report_exc_info(exc_info, request, extra_data, payload_data, level=None):
    """
    Called by report_exc_info() wrapper
    """

    if not _check_config():
        return

    filtered_level = _filtered_level(exc_info[1])
    if level is None:
        level = filtered_level

    filtered_exc_info = events.on_exception_info(exc_info,
                                                 request=request,
                                                 extra_data=extra_data,
                                                 payload_data=payload_data,
                                                 level=level)

    if filtered_exc_info is False:
        return

    cls, exc, trace = filtered_exc_info

    data = _build_base_data(request)
    if level is not None:
        data['level'] = level

    # walk the trace chain to collect cause and context exceptions
    trace_chain = _walk_trace_chain(cls, exc, trace)

    extra_trace_data = None
    if len(trace_chain) > 1:
        data['body'] = {
            'trace_chain': trace_chain
        }
        if payload_data and ('body' in payload_data) and ('trace' in payload_data['body']):
            extra_trace_data = payload_data['body']['trace']
            del payload_data['body']['trace']
    else:
        data['body'] = {
            'trace': trace_chain[0]
        }

    if extra_data:
        extra_data = extra_data
        if not isinstance(extra_data, dict):
            extra_data = {'value': extra_data}
        if extra_trace_data:
            extra_data = dict_merge(extra_data, extra_trace_data)
        data['custom'] = extra_data
    if extra_trace_data and not extra_data:
        data['custom'] = extra_trace_data

    request = _get_actual_request(request)
    _add_request_data(data, request)
    _add_person_data(data, request)
    _add_lambda_context_data(data)
    data['server'] = _build_server_data()

    if payload_data:
        data = dict_merge(data, payload_data)

    payload = _build_payload(data)
    send_payload(payload, payload.get('access_token'))

    return data['uuid']