Skip to content

Commit

Permalink
RUMM-2931 prevent reporting ANR when app is in background
Browse files Browse the repository at this point in the history
  • Loading branch information
xgouchet committed Jan 18, 2023
1 parent a54ed7a commit 9d3221b
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import com.datadog.android.core.internal.system.BuildSdkVersionProvider
import com.datadog.android.core.internal.system.DefaultBuildSdkVersionProvider
import com.datadog.android.core.internal.utils.devLogger
import com.datadog.android.rum.internal.RumFeature
import com.datadog.android.rum.internal.anr.ANRException
import com.datadog.android.rum.internal.domain.RumContext
import com.datadog.android.rum.internal.vitals.NoOpVitalMonitor
import com.datadog.android.rum.internal.vitals.VitalMonitor
Expand Down Expand Up @@ -120,6 +121,10 @@ internal class RumViewManagerScope(
event: RumRawEvent,
writer: DataWriter<Any>
) {
if (event is RumRawEvent.AddError && event.throwable is ANRException) {
// RUMM-2931 ignore ANR detected when the app is not in foreground
return
}
val isValidBackgroundEvent = event.javaClass in validBackgroundEventTypes
val isSilentOrphanEvent = event.javaClass in silentOrphanEventTypes

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ import android.util.Log
import com.datadog.android.core.internal.CoreFeature
import com.datadog.android.core.internal.net.FirstPartyHostDetector
import com.datadog.android.core.internal.system.BuildSdkVersionProvider
import com.datadog.android.rum.RumErrorSource
import com.datadog.android.rum.internal.RumFeature
import com.datadog.android.rum.internal.anr.ANRDetectorRunnable
import com.datadog.android.rum.internal.anr.ANRException
import com.datadog.android.rum.internal.domain.RumContext
import com.datadog.android.rum.internal.vitals.NoOpVitalMonitor
import com.datadog.android.rum.internal.vitals.VitalMonitor
Expand Down Expand Up @@ -355,6 +358,26 @@ internal class RumViewManagerScopeTest {
assertThat(testedScope.childrenScopes).hasSize(0)
}

@Test
fun `𝕄 not start a bg ViewScope 𝕎 handleEvent { app displayed, event is background ANR}`() {
// Given
testedScope.applicationDisplayed = true
val fakeEvent = RumRawEvent.AddError(
message = ANRDetectorRunnable.ANR_MESSAGE,
source = RumErrorSource.SOURCE,
stacktrace = null,
throwable = ANRException(Thread.currentThread()),
isFatal = false,
attributes = emptyMap()
)

// When
testedScope.handleEvent(fakeEvent, mockWriter)

// Then
assertThat(testedScope.childrenScopes).hasSize(0)
}

@Test
fun `𝕄 not start a bg ViewScope 𝕎 handleEvent { bg disabled, event is relevant }`(
forge: Forge
Expand Down

0 comments on commit 9d3221b

Please sign in to comment.