Skip to content
Draft
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 as non-fatal ANR events: hangs that recover, and hangs that still block the main thread after 8 s, 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 fatal ANR that was already reported as a non-fatal ANR is not reported a second time ([#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()
}
}
}
Loading