Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 72 additions & 1 deletion docs/platforms/android/configuration/app-not-respond.mdx
Original file line number Diff line number Diff line change
@@ -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
---

Expand Down Expand Up @@ -105,6 +105,77 @@ SentryAndroid.init(context) { options ->

![ANR Thread Dump](./img/app-not-respond-thread-dump.png)

## ANR Profiling (Experimental)

<Alert>

ANR Profiling is available starting in SDK version `8.35.0`. This feature is experimental and may change in future versions.

</Alert>

<Alert>

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.

</Alert>

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<br>blocked > 1s] --> C[Collect and store ANR profile to disk]
E[Next app start] --> F[Read<br>ApplicationExitInfo] --> G[Match stored<br>ANR profile] --> H[Attach ANR profile<br>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}
<application>
<meta-data android:name="io.sentry.anr.profiling.sample-rate" android:value="1.0" />
</application>
```

```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}
<application>
<meta-data android:name="io.sentry.anr.enable-fingerprinting" android:value="false" />
</application>
```

```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:
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 14 additions & 0 deletions docs/platforms/android/configuration/options.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,20 @@ A boolean value that determines whether the app start process will be profiled.

</SdkOption>

## ANR Options

<SdkOption name="anrProfilingSampleRate" type="float" defaultValue="null" availableSince="8.35.0">

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.

</SdkOption>

<SdkOption name="enableAnrFingerprinting" type="bool" defaultValue="true" availableSince="8.35.0">

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.

</SdkOption>

## Transaction-Based Profiling Options

This mode will eventually be deprecated, and it's recommended to upgrade to <PlatformLink to="/configuration/options/#ui-profiling-options">UI Profiling</PlatformLink>. The same behaviour, without the 30 seconds limitation, can be achieved with the `trace` <PlatformLink to="/configuration/options/#profile-lifecycle">profile lifecycle</PlatformLink> option. In order to upgrade to UI Profiling, you also need to remove the transaction-based options from your configuration.
Expand Down
1 change: 1 addition & 0 deletions docs/platforms/android/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -185,3 +185,4 @@ class MyActivity : AppCompatActivity() {
- <PlatformLink to="/features">Learn about the features of Sentry's Android SDK</PlatformLink>
- <PlatformLink to="/enhance-errors">Learn how to enhance stack traces of your Sentry errors</PlatformLink>
- <PlatformLink to="/enriching-events">Enrich events with additional context to make debugging simpler</PlatformLink>
- <PlatformLink to="/configuration/app-not-respond">Diagnose ANRs</PlatformLink> with profiling and automatic fingerprinting
Loading