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_ignore_messages_by_regex(self): regex = re.compile(r'cruel') def _ignore_cruel_world_substring(message, **kw): if regex.search(message): return False return message events.add_message_handler(_ignore_cruel_world_substring) self.assertFalse(events.on_message('hello cruel world')) self.assertIsNot(events.on_message('hello world'), False)
def _report_message(message, level, request, extra_data, payload_data): """ Called by report_message() wrapper """ if not _check_config(): return filtered_message = events.on_message(message, request=request, extra_data=extra_data, payload_data=payload_data, level=level) if filtered_message is False: return data = _build_base_data(request, level=level) # message data['body'] = { 'message': { 'body': filtered_message } } if extra_data: extra_data = extra_data data['body']['message'].update(extra_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, data.get('access_token')) return data['uuid']
def _report_message(message, level, request, extra_data, payload_data): """ Called by report_message() wrapper """ if not _check_config(): return filtered_message = events.on_message(message, request=request, extra_data=extra_data, payload_data=payload_data, level=level) if filtered_message is False: return data = _build_base_data(request, level=level) # message data['body'] = { 'message': { 'body': filtered_message } } if extra_data: extra_data = extra_data data['body']['message'].update(extra_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']