-
-
Notifications
You must be signed in to change notification settings - Fork 475
feat(core): [Unhandled Sessions 1] Add Unhandled session state and non-terminating error flag #5919
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
Open
Open
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
a4cf413
collection: Unhandled Sessions
buenaflor 3829c2e
feat(core): Add Unhandled session state and pending-unhandled marker
buenaflor 5a1130d
ref: rename pendingUnhandled to nonTerminatingUnhandledError
buenaflor 6441148
ref: drop public setter for the non-terminating unhandled error flag
buenaflor 5977515
ref: initialize the non-terminating flag through a private constructor
buenaflor 1f50e9d
ref: prefix the non-terminating flag field with has
buenaflor c7e399e
ref: drop comments that restate the code in Session
buenaflor e35da15
test: move Session serialization cases out of SessionTest
buenaflor c5e821c
test: remove SessionTest
buenaflor a03e0e5
docs(session): describe hasNonTerminatingUnhandledError on the field
buenaflor f067d22
docs(session): capitalise the hasNonTerminatingUnhandledError comment
buenaflor 007d3ed
ref(session): drop the private canonical constructor
buenaflor a7064ec
test(session): use Truth in the new session serialization tests
buenaflor e7d8759
test(session): cover the unhandled flag through the previous-session โฆ
buenaflor 03457a7
test(session): cover the unhandled session shape with a JSON fixture
buenaflor 0798336
docs(session): Clarify Unhandled state and hybrid-only recording
buenaflor 23f6118
docs(session): Reword Unhandled status javadoc
buenaflor bb42dc7
ref(session): Clear the unhandled marker for any terminal status
buenaflor e9b3b14
ref(session): Name the terminal-status check
buenaflor cfb652e
Revert "ref(session): Name the terminal-status check"
buenaflor 5faaac8
changelog
buenaflor File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,7 +21,13 @@ public enum State { | |
| Ok, | ||
| Exited, | ||
| Crashed, | ||
| Abnormal | ||
| Abnormal, | ||
| /** | ||
| * Final status when an unhandled error did not kill the process, such as a Flutter exception. | ||
| * The session stays {@link #Ok} until {@link Session#end()}. Native crashes still end as {@link | ||
| * #Crashed}. | ||
| */ | ||
| Unhandled | ||
| } | ||
|
|
||
| /** started timestamp */ | ||
|
|
@@ -66,6 +72,9 @@ public enum State { | |
| /** the Abnormal mechanism, e.g. what was the reason for session to become abnormal (ANR) */ | ||
| private @Nullable String abnormalMechanism; | ||
|
|
||
| /** Whether an unhandled error occurred that did not terminate the process */ | ||
| private boolean hasNonTerminatingUnhandledError; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this should be volatile, but it's not done anywhere else in this class, so good to keep it as-is. |
||
|
|
||
| /** The session lock, ops should be atomic */ | ||
| private final @NotNull AutoClosableReentrantLock sessionLock = new AutoClosableReentrantLock(); | ||
|
|
||
|
|
@@ -188,6 +197,45 @@ public int errorCount() { | |
| return abnormalMechanism; | ||
| } | ||
|
|
||
| /** | ||
| * Whether the session experienced an unhandled error that did <em>not</em> terminate the process, | ||
| * e.g. an unhandled Flutter exception, and so finalizes as {@link State#Unhandled} rather than | ||
| * {@link State#Exited}. A native crash is also unhandled, but it kills the process and ends the | ||
| * session as {@link State#Crashed} instead. | ||
| * | ||
| * <p>Never sent as a status while the session is alive; it is only persisted with the session. | ||
| */ | ||
| @ApiStatus.Internal | ||
| public boolean hasNonTerminatingUnhandledError() { | ||
|
buenaflor marked this conversation as resolved.
|
||
| return hasNonTerminatingUnhandledError; | ||
| } | ||
|
|
||
| /** | ||
| * Records that an active session experienced an unhandled error which did not terminate the | ||
|
buenaflor marked this conversation as resolved.
|
||
| * process, counting the error and advancing the session's sequence without ending it. On {@link | ||
| * #end()} the session is finalized as {@link State#Unhandled} unless a terminal status such as | ||
| * {@link State#Crashed} or {@link State#Abnormal} took over first. | ||
| * | ||
| * <p>Hybrid SDKs whose unhandled errors do not kill the process. Native Java/Android capture | ||
| * should not call this. | ||
| * | ||
| * @return whether the session was updated, i.e. false if it had already reached a terminal state | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nice! |
||
| */ | ||
| @ApiStatus.Internal | ||
| public boolean recordNonTerminatingUnhandledError() { | ||
| try (final @NotNull ISentryLifecycleToken ignored = sessionLock.acquire()) { | ||
| if (status != State.Ok) { | ||
| return false; | ||
| } | ||
| hasNonTerminatingUnhandledError = true; | ||
| errorCount.incrementAndGet(); | ||
| init = null; | ||
| timestamp = DateUtils.getCurrentDateTime(); | ||
| sequence = getSequenceTimestamp(timestamp); | ||
| return true; | ||
| } | ||
| } | ||
|
|
||
| @SuppressWarnings({"JdkObsolete", "JavaUtilDate"}) | ||
| public @Nullable Date getTimestamp() { | ||
| return timestamp; | ||
|
|
@@ -209,7 +257,7 @@ public void end(final @Nullable Date timestamp) { | |
|
|
||
| // at this state it might be Crashed already, so we don't check for it. | ||
| if (status == State.Ok) { | ||
| status = State.Exited; | ||
| status = hasNonTerminatingUnhandledError ? State.Unhandled : State.Exited; | ||
| } | ||
|
|
||
| if (timestamp != null) { | ||
|
sentry[bot] marked this conversation as resolved.
|
||
|
|
@@ -262,6 +310,11 @@ public boolean update( | |
| boolean sessionHasBeenUpdated = false; | ||
| if (status != null) { | ||
| this.status = status; | ||
| // the flag only decides how an Ok session is finalized, so an explicit terminal status | ||
| // such as a crash or an ANR takes precedence over a non-terminating error. | ||
| if (status != State.Ok) { | ||
| hasNonTerminatingUnhandledError = false; | ||
| } | ||
| sessionHasBeenUpdated = true; | ||
| } | ||
|
|
||
|
sentry[bot] marked this conversation as resolved.
|
||
|
|
@@ -318,21 +371,24 @@ private long getSequenceTimestamp(final @NotNull Date timestamp) { | |
| */ | ||
| @SuppressWarnings("MissingOverride") | ||
| public @NotNull Session clone() { | ||
| return new Session( | ||
| status, | ||
| started, | ||
| timestamp, | ||
| errorCount.get(), | ||
| distinctId, | ||
| sessionId, | ||
| init, | ||
| sequence, | ||
| duration, | ||
| ipAddress, | ||
| userAgent, | ||
| environment, | ||
| release, | ||
| abnormalMechanism); | ||
| final @NotNull Session session = | ||
| new Session( | ||
| status, | ||
| started, | ||
| timestamp, | ||
| errorCount.get(), | ||
| distinctId, | ||
| sessionId, | ||
| init, | ||
| sequence, | ||
| duration, | ||
| ipAddress, | ||
| userAgent, | ||
| environment, | ||
| release, | ||
| abnormalMechanism); | ||
| session.hasNonTerminatingUnhandledError = hasNonTerminatingUnhandledError; | ||
| return session; | ||
| } | ||
|
|
||
| // JsonSerializable | ||
|
|
@@ -354,6 +410,7 @@ public static final class JsonKeys { | |
| public static final String IP_ADDRESS = "ip_address"; | ||
| public static final String USER_AGENT = "user_agent"; | ||
| public static final String ABNORMAL_MECHANISM = "abnormal_mechanism"; | ||
| public static final String NON_TERMINATING_UNHANDLED_ERROR = "non_terminating_unhandled_error"; | ||
| } | ||
|
|
||
| @Override | ||
|
|
@@ -384,6 +441,9 @@ public void serialize(final @NotNull ObjectWriter writer, final @NotNull ILogger | |
| if (abnormalMechanism != null) { | ||
| writer.name(JsonKeys.ABNORMAL_MECHANISM).value(logger, abnormalMechanism); | ||
| } | ||
| if (hasNonTerminatingUnhandledError) { | ||
| writer.name(JsonKeys.NON_TERMINATING_UNHANDLED_ERROR).value(hasNonTerminatingUnhandledError); | ||
| } | ||
|
buenaflor marked this conversation as resolved.
|
||
| writer.name(JsonKeys.ATTRS); | ||
| writer.beginObject(); | ||
| writer.name(JsonKeys.RELEASE).value(logger, release); | ||
|
|
@@ -440,6 +500,7 @@ public static final class Deserializer implements JsonDeserializer<Session> { | |
| String environment = null; | ||
| String release = null; // @NotNull | ||
| String abnormalMechanism = null; | ||
| boolean hasNonTerminatingUnhandledError = false; | ||
|
|
||
| Map<String, Object> unknown = null; | ||
| while (reader.peek() == JsonToken.NAME) { | ||
|
|
@@ -483,6 +544,12 @@ public static final class Deserializer implements JsonDeserializer<Session> { | |
| case JsonKeys.ABNORMAL_MECHANISM: | ||
| abnormalMechanism = reader.nextStringOrNull(); | ||
| break; | ||
| case JsonKeys.NON_TERMINATING_UNHANDLED_ERROR: | ||
| final Boolean hasNonTerminatingUnhandledErrorValue = reader.nextBooleanOrNull(); | ||
| hasNonTerminatingUnhandledError = | ||
| hasNonTerminatingUnhandledErrorValue != null | ||
| && hasNonTerminatingUnhandledErrorValue; | ||
| break; | ||
| case JsonKeys.ATTRS: | ||
| reader.beginObject(); | ||
| while (reader.peek() == JsonToken.NAME) { | ||
|
|
@@ -542,6 +609,7 @@ public static final class Deserializer implements JsonDeserializer<Session> { | |
| environment, | ||
| release, | ||
| abnormalMechanism); | ||
| session.hasNonTerminatingUnhandledError = hasNonTerminatingUnhandledError; | ||
| session.setUnknown(unknown); | ||
| reader.endObject(); | ||
| return session; | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.