Skip to content

Commit

Permalink
Change order of event filtering mechanisms (#2001)
Browse files Browse the repository at this point in the history
* Change order of filtering mechanisms and add early return

* Extract variable for throwable

* Add changelog

* Make var final
  • Loading branch information
adinauer authored May 3, 2022
1 parent 4781d52 commit 4fd621e
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 24 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## Unreleased

### Fix

* Change order of event filtering mechanisms (#2001)

## 6.0.0-beta.2

* Fix: Android profiling initializes on first profile start (#2009)
Expand Down
55 changes: 31 additions & 24 deletions sentry/src/main/java/io/sentry/SentryClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,22 @@ private boolean shouldApplyScopeData(

options.getLogger().log(SentryLevel.DEBUG, "Capturing event: %s", event.getEventId());

if (event != null) {
final Throwable eventThrowable = event.getThrowable();
if (eventThrowable != null && options.containsIgnoredExceptionForType(eventThrowable)) {
options
.getLogger()
.log(
SentryLevel.DEBUG,
"Event was dropped as the exception %s is ignored",
eventThrowable.getClass());
options
.getClientReportRecorder()
.recordLostEvent(DiscardReason.EVENT_PROCESSOR, DataCategory.Error);
return SentryId.EMPTY_ID;
}
}

if (shouldApplyScopeData(event, hint)) {
// Event has already passed through here before it was cached
// Going through again could be reading data that is no longer relevant
Expand All @@ -95,6 +111,21 @@ private boolean shouldApplyScopeData(

event = processEvent(event, hint, options.getEventProcessors());

if (event != null) {
event = executeBeforeSend(event, hint);

if (event == null) {
options.getLogger().log(SentryLevel.DEBUG, "Event was dropped by beforeSend");
options
.getClientReportRecorder()
.recordLostEvent(DiscardReason.BEFORE_SEND, DataCategory.Error);
}
}

if (event == null) {
return SentryId.EMPTY_ID;
}

Session session = null;

if (event != null) {
Expand All @@ -115,30 +146,6 @@ private boolean shouldApplyScopeData(
}
}

if (event != null) {
if (event.getThrowable() != null
&& options.containsIgnoredExceptionForType(event.getThrowable())) {
options
.getLogger()
.log(
SentryLevel.DEBUG,
"Event was dropped as the exception %s is ignored",
event.getThrowable().getClass());
options
.getClientReportRecorder()
.recordLostEvent(DiscardReason.EVENT_PROCESSOR, DataCategory.Error);
return SentryId.EMPTY_ID;
}
event = executeBeforeSend(event, hint);

if (event == null) {
options.getLogger().log(SentryLevel.DEBUG, "Event was dropped by beforeSend");
options
.getClientReportRecorder()
.recordLostEvent(DiscardReason.BEFORE_SEND, DataCategory.Error);
}
}

SentryId sentryId = SentryId.EMPTY_ID;
if (event != null && event.getEventId() != null) {
sentryId = event.getEventId();
Expand Down

0 comments on commit 4fd621e

Please sign in to comment.