diff --git a/docs/platforms/android/configuration/app-not-respond.mdx b/docs/platforms/android/configuration/app-not-respond.mdx index 753d55041ebed2..e32eb5e81e88e0 100644 --- a/docs/platforms/android/configuration/app-not-respond.mdx +++ b/docs/platforms/android/configuration/app-not-respond.mdx @@ -1,7 +1,7 @@ --- title: Application Not Responding (ANR) sidebar_order: 4 -description: Learn how to turn off or specify ANR. +description: Learn how to turn off or configure ANR detection, profiling, and fingerprinting. og_image: /og-images/platforms-android-configuration-app-not-respond.png --- @@ -105,6 +105,77 @@ SentryAndroid.init(context) { options -> ![ANR Thread Dump](./img/app-not-respond-thread-dump.png) +## ANR Profiling (Experimental) + + + +ANR Profiling is available starting in SDK version `8.35.0`. This feature is experimental and may change in future versions. + + + + + +ANR profiles are powered by the Profiling platform and require a plan with profiling enabled. See the [pricing page](https://sentry.io/pricing/) for more details. + + + +The SDK can capture stack profiles for foreground ANRs of the main thread when an ANR is detected. A profile is a time-based view of your stack trace, showing which functions were executing and for how long. The captured profile is attached to the ANR event on the next app start, providing a flamegraph on the Sentry issue details page. This gives you deeper insight into what the main thread was doing at the time of the ANR. + +```mermaid +flowchart LR + A[App start] --> B + B[Main thread
blocked > 1s] --> C[Collect and store ANR profile to disk] + E[Next app start] --> F[Read
ApplicationExitInfo] --> G[Match stored
ANR profile] --> H[Attach ANR profile
to ANR event] +``` + +To enable ANR profiling, set the `anrProfilingSampleRate` to a value between `0.0` and `1.0`. This controls the probability of collecting a profile for each detected foreground ANR: + +```xml {filename:AndroidManifest.xml} + + + +``` + +```kotlin +SentryAndroid.init(context) { options -> + options.anrProfilingSampleRate = 1.0 +} +``` + +```java +SentryAndroid.init(context, options -> { + options.setAnrProfilingSampleRate(1.0); +}); +``` + +Once enabled, ANR events will include a profile section on the issue details page, showing a flamegraph of the main thread activity at the time of the ANR: + +![ANR Profile](./img/anr-profile.png) + +## ANR Fingerprinting + +The SDK assigns a static fingerprint to ANR events whose stack traces contain only system frames (for example, classes from `java.lang` or `android.os`). This groups noisy system-frame-only ANRs into a single issue, reducing noise in your issue stream. Foreground and background system-frame-only ANRs are grouped separately. + +ANR fingerprinting is enabled by default starting in SDK version `8.35.0`. To disable it: + +```xml {filename:AndroidManifest.xml} + + + +``` + +```kotlin +SentryAndroid.init(context) { options -> + options.isEnableAnrFingerprinting = false +} +``` + +```java +SentryAndroid.init(context, options -> { + options.setEnableAnrFingerprinting(false); +}); +``` + ## ANR Root Cause Analysis Sentry performs various root cause analyses to give you insights about why certain ANRs might appear. If a potential root cause is detected, it'll be displayed in a new section below the ANR stack trace. Sentry can detect the following root causes: diff --git a/docs/platforms/android/configuration/img/anr-profile.png b/docs/platforms/android/configuration/img/anr-profile.png new file mode 100644 index 00000000000000..1bdfabff7470fc Binary files /dev/null and b/docs/platforms/android/configuration/img/anr-profile.png differ diff --git a/docs/platforms/android/configuration/options.mdx b/docs/platforms/android/configuration/options.mdx index e2f827834d9aad..656f5dff93aabb 100644 --- a/docs/platforms/android/configuration/options.mdx +++ b/docs/platforms/android/configuration/options.mdx @@ -375,6 +375,20 @@ A boolean value that determines whether the app start process will be profiled. +## ANR Options + + + +A number between `0` and `1`, controlling the percentage chance a profile will be collected for each detected foreground ANR. (`0` represents 0% while `1` represents 100%.) The default is null (disabled). When set, the SDK captures a stack profile of the main thread at the time of ANR detection and attaches it to the ANR event on the next app start. + + + + + +When enabled, the SDK assigns a static fingerprint to ANR events whose stack traces contain only system frames. This groups noisy system-frame-only ANRs into a single issue, reducing noise. Foreground and background system-frame-only ANRs are grouped separately. + + + ## Transaction-Based Profiling Options This mode will eventually be deprecated, and it's recommended to upgrade to UI Profiling. The same behaviour, without the 30 seconds limitation, can be achieved with the `trace` profile lifecycle option. In order to upgrade to UI Profiling, you also need to remove the transaction-based options from your configuration. diff --git a/docs/platforms/android/index.mdx b/docs/platforms/android/index.mdx index ff78836ff873be..639cf134a48f5b 100644 --- a/docs/platforms/android/index.mdx +++ b/docs/platforms/android/index.mdx @@ -185,3 +185,4 @@ class MyActivity : AppCompatActivity() { - Learn about the features of Sentry's Android SDK - Learn how to enhance stack traces of your Sentry errors - Enrich events with additional context to make debugging simpler +- Diagnose ANRs with profiling and automatic fingerprinting