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 all 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
### Fix

* Change order of event filtering mechanisms (#2001)
* Only send session update for dropped events if state changed (#2002)

## 6.0.0-beta.2

Expand Down
48 changes: 45 additions & 3 deletions sentry/src/main/java/io/sentry/SentryClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,10 @@ private boolean shouldApplyScopeData(
return SentryId.EMPTY_ID;
}

Session session = null;
@Nullable
Session sessionBeforeUpdate =
scope != null ? scope.withSession((@Nullable Session session) -> {}) : null;
@Nullable Session session = null;

if (event != null) {
session = updateSessionData(event, hint, scope);
Expand All @@ -146,6 +149,18 @@ private boolean shouldApplyScopeData(
}
}

final boolean shouldSendSessionUpdate =
shouldSendSessionUpdateForDroppedEvent(sessionBeforeUpdate, session);

if (event == null && !shouldSendSessionUpdate) {
options
.getLogger()
.log(
SentryLevel.DEBUG,
"Not sending session update for dropped event as it did not cause the session health to change.");
return SentryId.EMPTY_ID;
adinauer marked this conversation as resolved.
Show resolved Hide resolved
}

SentryId sentryId = SentryId.EMPTY_ID;
if (event != null && event.getEventId() != null) {
sentryId = event.getEventId();
Expand All @@ -156,8 +171,9 @@ private boolean shouldApplyScopeData(
scope != null && scope.getTransaction() != null
? scope.getTransaction().traceState()
: null;
final SentryEnvelope envelope =
buildEnvelope(event, getAttachments(scope, hint), session, traceState, null);
final boolean shouldSendAttachments = event != null;
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 @@ -172,6 +188,32 @@ private boolean shouldApplyScopeData(
return sentryId;
}

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

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

final boolean didSessionMoveToCrashedState =
sessionAfterUpdate.getStatus() == Session.State.Crashed
&& sessionBeforeUpdate.getStatus() != Session.State.Crashed;
if (didSessionMoveToCrashedState) {
return true;
}

final boolean didSessionMoveToErroredState =
sessionAfterUpdate.errorCount() > 0 && sessionBeforeUpdate.errorCount() <= 0;
if (didSessionMoveToErroredState) {
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
Loading