Skip to content

Commit b7443ca

Browse files
romtsnlizokmgetsantry[bot]
authored
feat(android): New ANRv2 options (#7246)
Co-authored-by: Liza Mock <[email protected]> Co-authored-by: getsantry[bot] <66042841+getsantry[bot]@users.noreply.github.com>
1 parent 432e903 commit b7443ca

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed
198 KB
Loading

src/platforms/android/configuration/app-not-respond.mdx

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ sidebar_order: 3
44
description: "Learn how to turn off or specify ANR."
55
---
66

7+
Application Not Responding (ANR) errors are triggered when the main UI thread of an application is blocked for more than five seconds. The Android SDK reports ANR errors as Sentry events. In addition, Sentry calculates [ANR rate](/platforms/android/performance/instrumentation/performance-metrics/#application-not-responding-anr-rate) based on these events and user sessions.
8+
9+
## ANR implementation details
10+
711
The Android SDK uses different implementations to detect ANRs, depending on what version of Android the device is running:
812

913
- Below Android 11: Running a Watchdog thread (v1)
@@ -54,8 +58,52 @@ and asynchronously sends ANR events to Sentry for each ANR in the history, enric
5458

5559
The integration reports ANR events with `mechanism:AppExitInfo`.
5660

61+
<Note>
62+
63+
If [ApplicationExitInfo#getTraceInputStream](<https://developer.android.com/reference/android/app/ApplicationExitInfo#getTraceInputStream()>) returns `null`, the SDK will no longer report an ANR event, since these events won't be actionable without it.
64+
65+
</Note>
66+
5767
![ANR](app-not-respond.png)
5868

69+
#### Historical ANRs
70+
71+
By default, the SDK only reports and enriches the latest ANR and it's the only one counted towards the ANR rate. However, there's also a `setReportHistoricalAnrs` option available in `SentryOptions`, which enables the SDK to report all ANRs from the [getHistoricalExitReasons](<https://developer.android.com/reference/android/app/ActivityManager?hl=en#getHistoricalProcessExitReasons(java.lang.String,%20int,%20int)>) list:
72+
73+
```kotlin
74+
SentryAndroid.init(context) { options ->
75+
options.isReportHistoricalAnrs = true
76+
}
77+
```
78+
79+
```java
80+
SentryAndroid.init(context) { options ->
81+
options.setReportHistoricalAnrs(true)
82+
}
83+
```
84+
85+
This option is useful after updating the SDK to the version where the new ANR implementation was introduced, in order to report all ANRs that took place prior to the SDK update. Other than that, the SDK will always pick up the latest ANR from the historical exit reasons list on next app restart, and there won't be any historical ANRs to report.
86+
87+
The integration reports ANR events with `mechanism:HistoricalAppExitInfo`.
88+
89+
#### Attaching Thread Dump
90+
91+
The SDK makes it possible to send the ANR thread dump from [ApplicationExitInfo#getTraceInputStream](<https://developer.android.com/reference/android/app/ApplicationExitInfo#getTraceInputStream()>) as an attachment. This is useful for performing deeper investigations using all available information from the OS (in addition to the SDK parsing the thread dump into threads with stack traces):
92+
93+
```kotlin
94+
SentryAndroid.init(context) { options ->
95+
options.isAttachAnrThreadDump = true
96+
}
97+
```
98+
99+
```java
100+
SentryAndroid.init(context) { options ->
101+
options.setAttachAnrThreadDump(true)
102+
}
103+
```
104+
105+
![ANR Thread Dump](app-not-respond-thread-dump.png)
106+
59107
## ANR Root Cause Analysis
60108

61109
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 stacktrace. Sentry can detect the following root causes:

0 commit comments

Comments
 (0)