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
4 changes: 3 additions & 1 deletion sentry_sdk/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
convert_types,
handle_in_app,
get_type_name,
capture_internal_exceptions,
logger,
)
from sentry_sdk.transport import make_transport
Expand Down Expand Up @@ -87,7 +88,8 @@ def _prepare_event(self, event, hint, scope):

before_send = self.options["before_send"]
if before_send is not None:
new_event = before_send(event)
with capture_internal_exceptions():
new_event = before_send(event, hint)
if new_event is None:
logger.info("before send dropped event (%s)", event)
event = new_event
Expand Down
2 changes: 1 addition & 1 deletion sentry_sdk/integrations/_wsgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ def close(self):


def _make_wsgi_event_processor(environ):
def event_processor(event):
def event_processor(event, hint):
with capture_internal_exceptions():
# if the code below fails halfway through we at least have some data
request_info = event.setdefault("request", {})
Expand Down
2 changes: 1 addition & 1 deletion sentry_sdk/integrations/django.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def sentry_patched_get_response(self, request):


def _make_event_processor(weak_request):
def event_processor(event):
def event_processor(event, hint):
# if the request is gone we are fine not logging the data from
# it. This might happen if the processor is pushed away to
# another thread.
Expand Down
4 changes: 2 additions & 2 deletions sentry_sdk/integrations/flask.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def _request_started(sender, **kwargs):
scope.add_event_processor(_make_request_event_processor(app, weak_request))


def event_processor(event):
def event_processor(event, hint):
request = getattr(_request_ctx_stack.top, "request", None)

if request:
Expand Down Expand Up @@ -109,7 +109,7 @@ def _capture_exception(sender, exception, **kwargs):


def _make_request_event_processor(app, weak_request):
def inner(event):
def inner(event, hint):
request = weak_request()

# if the request is gone we are fine not logging the data from
Expand Down
5 changes: 3 additions & 2 deletions sentry_sdk/scope.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from sentry_sdk.utils import logger
from sentry_sdk.utils import logger, capture_internal_exceptions


def _attr_setter(fn):
Expand Down Expand Up @@ -140,7 +140,8 @@ def _drop(event, cause, ty):
event = new_event

for processor in self._event_processors:
new_event = processor(event)
with capture_internal_exceptions():
new_event = processor(event, hint)
if new_event is None:
return _drop(event, processor, "event processor")
event = new_event
Expand Down
6 changes: 6 additions & 0 deletions sentry_sdk/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ class EventHint(object):
def __init__(self, exc_info=None):
self.exc_info = exc_info

@property
def exception(self):
"""Returns the exception value on the hint if there is one."""
if self.exc_info is not None:
return self.exc_info[1]

@classmethod
def with_exc_info(cls, exc_info=None):
"""Creates a hint with the exc info filled in."""
Expand Down
4 changes: 3 additions & 1 deletion tests/test_basics.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ def test_option_callback(sentry_init, capture_events):
drop_events = False
drop_breadcrumbs = False

def before_send(event):
def before_send(event, hint):
assert hint is not None
assert isinstance(hint.exception, ValueError)
if not drop_events:
event["extra"] = {"foo": "bar"}
return event
Expand Down