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

Consider using a more accurate ANR tracking implementation #1796

Closed
vibin opened this issue Nov 5, 2021 · 8 comments · Fixed by #2697
Closed

Consider using a more accurate ANR tracking implementation #1796

vibin opened this issue Nov 5, 2021 · 8 comments · Fixed by #2697
Labels
enhancement New feature or request Platform: Android

Comments

@vibin
Copy link

vibin commented Nov 5, 2021

Hi, i'm currently evaluating Bugsnag and Sentry and one of the differences i've observed in the SDK is that Bugsnag uses a SIGQUIT signal handler to get called by OS when ANR occurs, as opposed to Sentry, which uses the watchdog approach.

I have used https://github.com/SalomonBrys/ANR-WatchDog in production before and while it's a useful library, I saw that it reports many false-positives compared to Play Console, especially in case of ANRs in BroadcastReceivers.

SIGQUIT approach is also not perfect, though. It doesn't track background ANRs: bugsnag/bugsnag-android#1377

There's a third approach to track ANRs and Crashlytics' Alpha version seems to be using it (tracks both foreground and background ANRs): getHistoricalProcessExitReasons on Android 11 and above only, sadly.

Any thoughts?

@bruno-garcia
Copy link
Member

Thanks you for bringing this up. It makes sense and perhaps we should consider an approach for Android 11+ only and keep the current as-is. Additionally, there's the possibility of relying on SIGQUIT through our NDK support which will also require some discussions internally.

@marandaneto
Copy link
Contributor

I've tested the 3rd option 2y ago and it worked really well, indeed, https://github.com/marandaneto/android-exit-reasons-api-sample
the approach we could take is, enable the watchdog when Android <= 10 and use the new API when Android >= 11.

the new API returns a InputStream tho, so it requires us converting this info into a SentryEvent https://developer.android.com/reference/kotlin/android/app/ApplicationExitInfo#gettraceinputstream

@marandaneto
Copy link
Contributor

sample_anr.txt

@marandaneto
Copy link
Contributor

Let's use the new API for Android >= 11 and keep the watch dog approach for back compatibility.

@marandaneto marandaneto moved this from Needs Discussion to Backlog in Mobile & Cross Platform SDK Dec 15, 2021
@marandaneto
Copy link
Contributor

@marandaneto
Copy link
Contributor

Update the docs after doing this, the docs should state the behavior for older and newer OS versions.

@marandaneto
Copy link
Contributor

marandaneto commented Nov 15, 2022

@marandaneto
Copy link
Contributor

The current ANRWatchDog approach actually could be improved using the setMessageLogging method, right now we keep posting something to the main thread so we can check the delay of being executed.
setMessageLogging is a callback that calls the Printer interface before and after something is executed in the looper.

Example:

2023-04-17 11:20:16.125 27155-27155 Sentry io.sentry.samples.android D Printer ANR: >>>>> Dispatching to Handler (android.view.ViewRootImpl$ViewRootHandler) {f45b933} android.graphics.HardwareRendererObserver$$ExternalSyntheticLambda0@846f00e: 0
2023-04-17 11:20:16.125 27155-27155 Sentry io.sentry.samples.android D Printer ANR: <<<<< Finished to Handler (android.view.ViewRootImpl$ViewRootHandler) {f45b933} android.graphics.HardwareRendererObserver$$ExternalSyntheticLambda0@846f00e
2023-04-17 11:20:16.133 27155-27155 Sentry io.sentry.samples.android D Printer ANR: >>>>> Dispatching to Handler (android.view.Choreographer$FrameHandler) {b5bbc0} android.view.Choreographer$FrameDisplayEventReceiver@315a0f9: 0
2023-04-17 11:20:16.135 27155-27155 Sentry io.sentry.samples.android D Printer ANR: <<<<< Finished to Handler (android.view.Choreographer$FrameHandler) {b5bbc0} android.view.Choreographer$FrameDisplayEventReceiver@315a0f9

We could have a SentryPrinter interface that keeps track of how long it takes to execute each task and raise an issue if necessary individually, the stack trace will be more accurate most likely as well.
This approach has a side effect tho, in case you execute plenty of small tasks, one after the other, all in the main thread, we'd need to find a way to sum them up, because the main thread is still somehow blocked.

@github-project-automation github-project-automation bot moved this from In Progress to Done in Mobile & Cross Platform SDK May 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request Platform: Android
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

4 participants