-
-
Notifications
You must be signed in to change notification settings - Fork 451
[QA] Fix potential ANRs due to default integrations #3778
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
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
d7e2ffc
Fix don't register any full drawn listeners if feature is not enabled
markushi fd2bc62
Offload app components breadcrumbs to background thread
markushi 7561fe4
Offload system events breadcrumbs to background thread
markushi 0870f09
Update Changelog
markushi e2cb750
Merge branch 'main' into feat/background-breadcrumbs
markushi 4ffe903
Fix flaky tests
markushi 41b11a9
Remove session breadcrumbs
markushi 40cbfea
Fix tests
markushi 0a924a0
Merge branch 'feat/background-breadcrumbs' of github.com:getsentry/se…
markushi e524d07
Address PR feedback
markushi 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
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 |
---|---|---|
|
@@ -6,7 +6,6 @@ | |
import io.sentry.IHub; | ||
import io.sentry.SentryLevel; | ||
import io.sentry.Session; | ||
import io.sentry.android.core.internal.util.BreadcrumbFactory; | ||
import io.sentry.transport.CurrentDateProvider; | ||
import io.sentry.transport.ICurrentDateProvider; | ||
import java.util.Timer; | ||
|
@@ -90,7 +89,6 @@ private void startSession() { | |
if (lastUpdatedSession == 0L | ||
|| (lastUpdatedSession + sessionIntervalMillis) <= currentTimeMillis) { | ||
if (enableSessionTracking) { | ||
addSessionBreadcrumb("start"); | ||
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. 💯 |
||
hub.startSession(); | ||
} | ||
hub.getOptions().getReplayController().start(); | ||
|
@@ -125,7 +123,6 @@ private void scheduleEndSession() { | |
@Override | ||
public void run() { | ||
if (enableSessionTracking) { | ||
addSessionBreadcrumb("end"); | ||
hub.endSession(); | ||
} | ||
hub.getOptions().getReplayController().stop(); | ||
|
@@ -157,11 +154,6 @@ private void addAppBreadcrumb(final @NotNull String state) { | |
} | ||
} | ||
|
||
private void addSessionBreadcrumb(final @NotNull String state) { | ||
final Breadcrumb breadcrumb = BreadcrumbFactory.forSession(state); | ||
hub.addBreadcrumb(breadcrumb); | ||
} | ||
|
||
@TestOnly | ||
@Nullable | ||
TimerTask getTimerTask() { | ||
|
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 |
---|---|---|
|
@@ -31,12 +31,13 @@ | |
public final class NetworkBreadcrumbsIntegration implements Integration, Closeable { | ||
|
||
private final @NotNull Context context; | ||
|
||
private final @NotNull BuildInfoProvider buildInfoProvider; | ||
|
||
private final @NotNull ILogger logger; | ||
private final @NotNull Object lock = new Object(); | ||
private volatile boolean isClosed; | ||
private @Nullable SentryOptions options; | ||
|
||
@TestOnly @Nullable NetworkBreadcrumbsNetworkCallback networkCallback; | ||
@TestOnly @Nullable volatile NetworkBreadcrumbsNetworkCallback networkCallback; | ||
|
||
public NetworkBreadcrumbsIntegration( | ||
final @NotNull Context context, | ||
|
@@ -63,40 +64,74 @@ public void register(final @NotNull IHub hub, final @NotNull SentryOptions optio | |
"NetworkBreadcrumbsIntegration enabled: %s", | ||
androidOptions.isEnableNetworkEventBreadcrumbs()); | ||
|
||
this.options = options; | ||
|
||
if (androidOptions.isEnableNetworkEventBreadcrumbs()) { | ||
|
||
// The specific error is logged in the ConnectivityChecker method | ||
if (buildInfoProvider.getSdkInfoVersion() < Build.VERSION_CODES.LOLLIPOP) { | ||
networkCallback = null; | ||
logger.log(SentryLevel.DEBUG, "NetworkBreadcrumbsIntegration requires Android 5+"); | ||
if (buildInfoProvider.getSdkInfoVersion() < Build.VERSION_CODES.N) { | ||
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. I've changed this to |
||
logger.log(SentryLevel.DEBUG, "NetworkCallbacks need Android N+."); | ||
return; | ||
} | ||
|
||
networkCallback = | ||
new NetworkBreadcrumbsNetworkCallback(hub, buildInfoProvider, options.getDateProvider()); | ||
final boolean registered = | ||
AndroidConnectionStatusProvider.registerNetworkCallback( | ||
context, logger, buildInfoProvider, networkCallback); | ||
try { | ||
options | ||
.getExecutorService() | ||
.submit( | ||
new Runnable() { | ||
@Override | ||
public void run() { | ||
// in case integration is closed before the task is executed, simply return | ||
if (isClosed) { | ||
return; | ||
} | ||
|
||
// The specific error is logged in the ConnectivityChecker method | ||
if (!registered) { | ||
networkCallback = null; | ||
logger.log(SentryLevel.DEBUG, "NetworkBreadcrumbsIntegration not installed."); | ||
return; | ||
synchronized (lock) { | ||
networkCallback = | ||
new NetworkBreadcrumbsNetworkCallback( | ||
hub, buildInfoProvider, options.getDateProvider()); | ||
|
||
final boolean registered = | ||
AndroidConnectionStatusProvider.registerNetworkCallback( | ||
context, logger, buildInfoProvider, networkCallback); | ||
if (registered) { | ||
logger.log(SentryLevel.DEBUG, "NetworkBreadcrumbsIntegration installed."); | ||
addIntegrationToSdkVersion(getClass()); | ||
} else { | ||
logger.log( | ||
SentryLevel.DEBUG, "NetworkBreadcrumbsIntegration not installed."); | ||
// The specific error is logged by AndroidConnectionStatusProvider | ||
} | ||
} | ||
} | ||
}); | ||
} catch (Throwable t) { | ||
logger.log(SentryLevel.ERROR, "Error submitting NetworkBreadcrumbsIntegration task.", t); | ||
} | ||
logger.log(SentryLevel.DEBUG, "NetworkBreadcrumbsIntegration installed."); | ||
addIntegrationToSdkVersion(getClass()); | ||
} | ||
} | ||
|
||
@Override | ||
public void close() throws IOException { | ||
if (networkCallback != null) { | ||
AndroidConnectionStatusProvider.unregisterNetworkCallback( | ||
context, logger, buildInfoProvider, networkCallback); | ||
logger.log(SentryLevel.DEBUG, "NetworkBreadcrumbsIntegration remove."); | ||
isClosed = true; | ||
|
||
try { | ||
Objects.requireNonNull(options, "Options is required") | ||
.getExecutorService() | ||
.submit( | ||
() -> { | ||
synchronized (lock) { | ||
if (networkCallback != null) { | ||
AndroidConnectionStatusProvider.unregisterNetworkCallback( | ||
context, logger, buildInfoProvider, networkCallback); | ||
logger.log(SentryLevel.DEBUG, "NetworkBreadcrumbsIntegration removed."); | ||
} | ||
networkCallback = null; | ||
} | ||
}); | ||
} catch (Throwable t) { | ||
logger.log(SentryLevel.ERROR, "Error submitting NetworkBreadcrumbsIntegration task.", t); | ||
} | ||
networkCallback = null; | ||
} | ||
|
||
@SuppressLint("ObsoleteSdkInt") | ||
|
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.
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 added this, as otherwise we'd add a new listener inside FullyDisplayedReporter without ever clearing that list.