Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions sentry_sdk/scope.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
50 changes: 45 additions & 5 deletions tests/test_basics.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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):
Expand Down Expand Up @@ -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
Expand Down
Loading