Skip to content
Open
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
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@

## Unreleased

### Features

- Report main-thread hangs that recover as non-fatal ANR events, from Android 11 (API 30). Enable it with `options.nonFatalAnrSampleRate` (manifest: `io.sentry.anr.non-fatal.sample-rate`), and set the minimum hang duration with `options.nonFatalAnrThresholdMs` (default 700 ms, manifest: `io.sentry.anr.non-fatal.threshold-ms`). A hang that does not recover is reported only as a fatal ANR ([#6726](https://github.com/getsentry/sentry-java/pull/6726))

### Improvements

- ANR profiling: the profile now starts when the main thread has been blocked for 300 ms instead of 1 s, so it also shows the beginning of the hang ([#6725](https://github.com/getsentry/sentry-java/pull/6725))

### Fixes

- Kotlin now sees `Attachment.getBytes()`, `Device.getArchs()`, `Spring.getActiveProfiles()` and `JsonSerializationUtils.bytesFrom(...)` as nullable, because `@Nullable` now annotates the returned array instead of its elements ([#6558](https://github.com/getsentry/sentry-java/pull/6558))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,9 @@
<meta-data
android:name="io.sentry.anr.profiling.sample-rate"
android:value="1.0" />
<meta-data
android:name="io.sentry.anr.non-fatal.sample-rate"
android:value="1.0" />
<meta-data
android:name="io.sentry.anr.enable-fingerprinting"
android:value="true" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,19 @@ fun ErrorsScreen() {
}
}
}
item {
SentryTraced("non_fatal_anr") {
OutlinedButton(
onClick = {
tagSampleAction("non_fatal_anr")
Thread.sleep(2000)
},
modifier = Modifier,
) {
Text("Non-fatal ANR (2 s)", maxLines = 2, overflow = TextOverflow.Ellipsis)
}
}
}
item {
SentryTraced("native_anr") {
OutlinedButton(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package io.sentry.uitest.android

import androidx.test.core.app.launchActivity
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.SdkSuppress
import io.sentry.SentryLevel
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertNotNull
import kotlin.test.assertTrue
import org.junit.runner.RunWith

@RunWith(AndroidJUnit4::class)
@SdkSuppress(minSdkVersion = 30)
class NonFatalAnrTest : BaseUiTest() {
@Test
fun blockingMainThreadSendsOneNonFatalAnrEvent() {
initSentry(true) { it.nonFatalAnrSampleRate = 1.0 }
relayIdlingResource.increment()

launchActivity<EmptyActivity>().onActivity { Thread.sleep(2000) }

relay.assert {
assertFirstEnvelope {
val event = it.assertEvent()
it.assertNoOtherItems()

assertEquals(SentryLevel.ERROR, event.level)
val mechanismTypes = event.exceptions?.mapNotNull { e -> e.mechanism?.type }
assertTrue(mechanismTypes?.contains("NonFatalANR") == true, "mechanisms: $mechanismTypes")
assertTrue(event.exceptions!!.all { e -> e.mechanism?.isHandled == true })

val context = event.contexts["non_fatal_anr"] as Map<*, *>
val durationMs = assertNotNull(context["duration_ms"] as? Number)
assertTrue(durationMs.toLong() >= 700, "duration_ms: $durationMs")
}
assertNoOtherEnvelopes()
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

UI test flakes on extra ANR envelopes

Medium Severity

blockingMainThreadSendsOneNonFatalAnrEvent increments the relay idling resource once and requires exactly one envelope after launching EmptyActivity and sleeping 2s on the main thread. Hang detection starts at onStart and can already report a non-fatal ANR if AppCompat startup blocks the main thread for the 700 ms threshold, then the sleep sends a second event. waitUntilIdle can return after the first envelope, so assertNoOtherEnvelopes races and the extra decrement can corrupt CountingIdlingResource.

Fix in Cursor Fix in Web

Triggered by project rule: PR Review Guidelines for Cursor Bugbot

Reviewed by Cursor Bugbot for commit 72aa113. Configure here.

}
}
Loading