Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only send session update for dropped events if state changed #2002

Merged
merged 21 commits into from
May 3, 2022
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
2a7b969
Change order of filtering mechanisms and add early return
adinauer Apr 22, 2022
45629e7
Only send session update for dropped events if state changed
adinauer Apr 22, 2022
9f6f2ba
Extract variable for throwable
adinauer Apr 26, 2022
e9bb239
Merge branch 'fix/event-drop-session-update-inconsistencies' into fix…
adinauer Apr 26, 2022
540df58
Merge branch '6.x.x' into fix/event-drop-session-update-inconsistencies
adinauer Apr 26, 2022
c5eff6c
Add changelog
adinauer Apr 26, 2022
7db9dae
Merge branch 'fix/event-drop-session-update-inconsistencies' into fix…
adinauer Apr 26, 2022
cde0fce
Add changelog
adinauer Apr 26, 2022
c885d69
Rename method
adinauer Apr 26, 2022
5832a4b
Rename things
adinauer Apr 26, 2022
1f51c55
Make var final
adinauer Apr 26, 2022
eaecfba
Merge branch 'fix/event-drop-session-update-inconsistencies' into fix…
adinauer Apr 26, 2022
05aa2ad
Apply suggestions from code review
adinauer Apr 26, 2022
89145b8
Update sentry/src/main/java/io/sentry/SentryClient.java
adinauer Apr 26, 2022
8488bc8
Add tests to verify order, session updates and sending
adinauer Apr 29, 2022
af302a1
Merge branch 'fix/event-drop-session-update-inconsistencies-extra' of…
adinauer Apr 29, 2022
a85eca4
Merge branch '6.x.x' into fix/event-drop-session-update-inconsistencies
adinauer May 3, 2022
bba94ea
Merge branch 'fix/event-drop-session-update-inconsistencies' into fix…
adinauer May 3, 2022
8b0321a
Add debug log for dropped events ...
adinauer May 3, 2022
b7ea25e
Merge branch '6.x.x' into fix/event-drop-session-update-inconsistenci…
adinauer May 3, 2022
949d248
Fix merge mistake
adinauer May 3, 2022
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
## Unreleased

* Fix: Allow disabling sending of client reports via Android Manifest and external options (#2007)
* Fix: Change order of event filtering mechanisms (#2001)
* Fix: Only send session update for dropped events if state changed (#2002)

## 6.0.0-alpha.6

Expand Down
87 changes: 63 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) {
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,7 +111,25 @@ private boolean shouldApplyScopeData(

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

Session session = null;
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;
}

@Nullable
Session oldSession =
adinauer marked this conversation as resolved.
Show resolved Hide resolved
scope != null ? scope.withSession((@Nullable Session session) -> {}) : null;
@Nullable Session session = null;

if (event != null) {
session = updateSessionData(event, hint, scope);
Expand All @@ -115,28 +149,10 @@ 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);
boolean shouldSendSessionUpdate = shouldSendSessionUpdateForDroppedEvent(oldSession, session);

if (event == null) {
options.getLogger().log(SentryLevel.DEBUG, "Event was dropped by beforeSend");
options
.getClientReportRecorder()
.recordLostEvent(DiscardReason.BEFORE_SEND, DataCategory.Error);
}
if (event == null && !shouldSendSessionUpdate) {
return SentryId.EMPTY_ID;
adinauer marked this conversation as resolved.
Show resolved Hide resolved
}

SentryId sentryId = SentryId.EMPTY_ID;
Expand All @@ -149,8 +165,9 @@ private boolean shouldApplyScopeData(
scope != null && scope.getTransaction() != null
? scope.getTransaction().traceState()
: null;
final SentryEnvelope envelope =
buildEnvelope(event, getAttachments(scope, hint), session, traceState, null);
boolean shouldSendAttachments = event != null;
adinauer marked this conversation as resolved.
Show resolved Hide resolved
List<Attachment> attachments = shouldSendAttachments ? getAttachments(scope, hint) : null;
final SentryEnvelope envelope = buildEnvelope(event, attachments, session, traceState, null);

if (envelope != null) {
transport.send(envelope, hint);
Expand All @@ -165,6 +182,28 @@ private boolean shouldApplyScopeData(
return sentryId;
}

private boolean shouldSendSessionUpdateForDroppedEvent(
adinauer marked this conversation as resolved.
Show resolved Hide resolved
@Nullable Session oldSession, @Nullable Session newSession) {
if (newSession == null) {
return false;
}

if (oldSession == null) {
return true;
}

if (newSession.getStatus() == Session.State.Crashed
&& oldSession.getStatus() != Session.State.Crashed) {
return true;
}

if (newSession.errorCount() > 0 && oldSession.errorCount() <= 0) {
return true;
}

return false;
}

private @Nullable List<Attachment> getAttachments(
final @Nullable Scope scope, final @NotNull Map<String, Object> hint) {
List<Attachment> attachments = null;
Expand Down