-
Notifications
You must be signed in to change notification settings - Fork 205
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
Enable automatic session tracking by default #314
Conversation
…e state of autoCaptureSessions
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Short and sweet 🎉
autoCaptureSessions = false; | ||
} | ||
this.endpoint = notify; | ||
this.sessionEndpoint = sessions; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if invalidSessionsEndpoint
is true, then shouldn't this be set to null? Whether to send a session could then be determined by whether the endpoint is null rather than adding a new property.
It would also reduce the odds of unexpected behavior if Bugsnag.setAutoCaptureSessions()
is called after configuration.
… flag when checking whether to
Refactored to check that Also, here is the related Docs PR: https://github.com/bugsnag/docs.bugsnag.com/pull/720 |
} | ||
|
||
config.setSendThreads(data.getBoolean(MF_SEND_THREADS, true)); | ||
config.setPersistUserBetweenSessions( | ||
data.getBoolean(MF_PERSIST_USER_BETWEEN_SESSIONS, false)); | ||
config.setAutoCaptureSessions(data.getBoolean(MF_AUTO_CAPTURE_SESSIONS, false)); | ||
|
||
if (data.containsKey(MF_AUTO_CAPTURE_SESSIONS)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the advantage of this over the previous with the default set to true
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method no longer requires any knowledge of whether sessions should be automatically captured or not, and relies on Configuration
instead to specify a sensible default.
if (invalidSessionsEndpoint) { | ||
Logger.warn("The session tracking endpoint has not been set. " | ||
+ "Session tracking is disabled"); | ||
autoCaptureSessions = false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this require a this.
prefixing it as below?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not necessarily required but I think that's a good suggestion as it makes the semantics clearer that autoCaptureSessions
is a field, and would be more consistent with the rest of the method.
} else { | ||
this.sessionEndpoint = sessions; | ||
} | ||
this.autoCaptureSessions = !invalidSessionsEndpoint; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this is being set in the if/else above, does it need to be set again here? It may end up being set to true
after it's been manually disabled.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Both are not required, I've removed autoCaptureSessions = false
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There could be an issue where someone sets autoCaptureSessions
to false, then inputs a valid sessions endpoint. The:
this.autoCaptureSessions = !invalidSessionsEndpoint;
would then incorrectly set the autoCaptureSessions
back to true, overriding the user's configuration. Is that a possibility?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point - I've added an explicit test case for this scenario.
@@ -64,6 +64,11 @@ | |||
* @param user the session user (if any) | |||
*/ | |||
void startNewSession(@NonNull Date date, @Nullable User user, boolean autoCaptured) { | |||
if (configuration.getSessionEndpoint() == null) { | |||
Logger.warn("The session tracking endpoint has not been set. " |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should have mentioned this earlier, sorry - Should this warning be a one-time thing? We could end up adding a lot of logger noise.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Logger
class will automatically disable itself in production if that's a concern? The default implementation of session tracking waits at least 30 seconds before starting a new session on Android, so for the default use case I'd imagine this message would only be logged once or twice.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess that's ok, are there any similar cases already present in the notifier?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one is somewhat similar.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean for the logging repeatedly when in debug mode?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Cawllec it's not particularly easy to test log messages in Android unfortunately
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added one suggestion and one question
* | ||
* @throws IllegalArgumentException if the notify endpoint is empty or null | ||
*/ | ||
@SuppressWarnings("ConstantConditions") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might be worth adding a comment on the reasoning behind suppressing specific warnings
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added an inline comment
*/ | ||
@SuppressWarnings("ConstantConditions") | ||
public void setEndpoints(@NonNull String notify, @NonNull String sessions) | ||
throws IllegalArgumentException { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems like a big change in behavior? The other methods on configuration just accept whatever was set
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IIRC the design doc for this change states that we should throw an exception if notify
is not a valid URL, and log a warning if sessions
is not. The rationale being that the notifier can't really do anything useful if the notify endpoint has been misconfigured, but can still send errors if session tracking is not in use. I think it makes sense to fail fast in this instance if a programmer supplies an invalid value.
Looks good, just the CI that's not working ATM. |
CI has passed now (the test flakiness seems to be back on Travis) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM assuming @martin308 and @kattrali are now happy
* | ||
* @throws IllegalArgumentException if the notify endpoint is empty or null | ||
*/ | ||
@SuppressWarnings("ConstantConditions") // ignore checkstyle nullability warnings |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was thinking more along the lines of the reasoning behind suppressing it. I'm not sure what this does exactly but here is a possibly terrible example "Suppress this warning as we know that the "notify" parameter can be null due to this amazing reason... but we can ignore it because of some other scenario..."
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've removed this annotation as it appears it's no longer needed. I believe it was originally included because a null check was performed on notify
and sessions
, which are annotated as non-null. Checkstyle picks up the nullability annotation, but unfortunately this isn't enforced by the compiler for Java, so it made sense to perform a null check.
This code now uses TextUtils.isEmpty
, which also checks for an empty string along with null, which isn't a constant condition.
CHANGELOG.md
Outdated
@@ -1,5 +1,13 @@ | |||
# Changelog | |||
|
|||
## 4.X.X (TBD) | |||
|
|||
**Note**: this release alters the behaviour of the notifier to track session automatically. If you |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm reusing this copy for the js changelog and noticed a little typo:
- track session automatically
+ track sessions automatically
…scenarios Create additional E2E scenarios for Unity SO file upload
Goal
Enables automatic tracking of sessions by default, and adds a new API for setting the notify/session endpoints which deprecates the old method.
Design
This should prevent the unintentional scenario where a user sets the notify endpoint with a sessions endpoint.
Changeset
Added
config.setEndpoints(String notify, String sessions)
Changed
Deprecation notice for:
config.setEndpoint
config.setSessionsEndpoint
client.setEndpoint
Manifest meta-data parsing logic
Tests
An additional Mazerunner test for ensuring a session is automatically tracked on app launch, and unit tests for ensuring:
This doesn't automatically test that configuring endpoint without session endpoint logs a warning, as this is difficult to achieve on Android.
Discussion
Outstanding Questions
The deprecated options are not aliased onto the new API - I believe this is ok.
N.B. CI may currently fail due to unrelated flaky tests which are addressed in a separate PR.
Review
For the submitter, initial self-review:
For the pull request reviewer(s), this changeset has been reviewed for: