diff --git a/sentry_sdk/scope.py b/sentry_sdk/scope.py index 3081d95140..4a0fbcac28 100644 --- a/sentry_sdk/scope.py +++ b/sentry_sdk/scope.py @@ -919,6 +919,7 @@ def add_breadcrumb( new_crumb = crumb if before_breadcrumb is not None: + new_crumb = None with capture_internal_exceptions(): new_crumb = before_breadcrumb(crumb, hint) @@ -1480,7 +1481,7 @@ def run_error_processors(self, event: "Event", hint: "Hint") -> "Optional[Event] ) for error_processor in error_processors: - new_event = event + new_event = None with capture_internal_exceptions(): new_event = error_processor(event, exc_info) if new_event is None: @@ -1510,7 +1511,7 @@ def run_event_processors(self, event: "Event", hint: "Hint") -> "Optional[Event] ) for event_processor in event_processors: - new_event = event + new_event = None with capture_internal_exceptions(): new_event = event_processor(event, hint) if new_event is None: diff --git a/tests/test_basics.py b/tests/test_basics.py index d746146baa..38861c4cf9 100644 --- a/tests/test_basics.py +++ b/tests/test_basics.py @@ -214,7 +214,7 @@ def do_this(): @pytest.mark.tests_internal_exceptions def test_option_before_breadcrumb_exception(sentry_init, capture_events): - """Exceptions in before_breadcrumb are contained.""" + """Breadcrumb is dropped if before_breadcrumb raises an exception.""" def before_breadcrumb(crumb, hint): 1 / 0 @@ -234,10 +234,7 @@ def do_this(): (event,) = events assert event["exception"]["values"][0]["type"] == "ValueError" - (crumb,) = event["breadcrumbs"]["values"] - assert "timestamp" in crumb - assert crumb["message"] == "Hello" - assert crumb["type"] == "default" + assert event["breadcrumbs"]["values"] == [] def test_breadcrumb_arguments(sentry_init, capture_events): @@ -661,6 +658,49 @@ def foo(event, hint): sentry_sdk.scope.global_event_processors = old_processors +@pytest.mark.tests_internal_exceptions +def test_event_processor_exception_drops_event_and_records_client_report( + sentry_init, capture_events, capture_record_lost_event_calls +): + sentry_init(default_integrations=False) + events = capture_events() + record_lost_event_calls = capture_record_lost_event_calls() + + scope = sentry_sdk.get_isolation_scope() + + @scope.add_event_processor + def bad_processor(event, hint): + raise ValueError("processor error") + + capture_message("should be dropped") + + assert len(events) == 0 + assert ("event_processor", "error", None, 1) in record_lost_event_calls + + +@pytest.mark.tests_internal_exceptions +def test_error_processor_exception_drops_event( + sentry_init, capture_events, capture_record_lost_event_calls +): + sentry_init(default_integrations=False) + events = capture_events() + record_lost_event_calls = capture_record_lost_event_calls() + + scope = sentry_sdk.get_isolation_scope() + + @scope.add_error_processor + def bad_error_processor(event, exc_info): + raise ValueError("error processor error") + + try: + raise ValueError("original error") + except Exception: + capture_exception() + + assert len(events) == 0 + assert ("event_processor", "error", None, 1) in record_lost_event_calls + + @pytest.mark.tests_internal_exceptions def test_before_send_exception_records_callback_error( sentry_init, capture_events, capture_record_lost_event_calls