Skip to content

Commit

Permalink
Merge pull request #2348 from HedvigInsurance/improvement/do-not-repo…
Browse files Browse the repository at this point in the history
…rt-cancelled-requests-as-RUM-errors

Filter out cancellation exceptions for RUM errors
  • Loading branch information
StylianosGakis authored Dec 12, 2024
2 parents e7443f3 + 7b74a76 commit 9be2bb2
Showing 1 changed file with 24 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@ import androidx.startup.Initializer
import com.datadog.android.Datadog
import com.datadog.android.DatadogSite
import com.datadog.android.core.configuration.Configuration
import com.datadog.android.event.EventMapper
import com.datadog.android.log.Logger
import com.datadog.android.log.Logs
import com.datadog.android.log.LogsConfiguration
import com.datadog.android.privacy.TrackingConsent
import com.datadog.android.rum.Rum
import com.datadog.android.rum.RumConfiguration
import com.datadog.android.rum.model.ErrorEvent
import com.datadog.android.rum.model.ErrorEvent.Category.EXCEPTION
import com.datadog.android.rum.tracking.ActivityViewTrackingStrategy
import com.datadog.android.trace.AndroidTracer
import com.datadog.android.trace.Trace
Expand Down Expand Up @@ -55,6 +58,7 @@ abstract class DatadogInitializer : Initializer<Unit>, KoinComponent {
val rumConfig = RumConfiguration.Builder(applicationId)
.trackLongTasks()
.trackFrustrations(true)
.setErrorEventMapper(cancellationFilteringErrorEventMapper)
.useViewTrackingStrategy(ActivityViewTrackingStrategy(true))
.build()
Rum.enable(rumConfig, sdkCore)
Expand Down Expand Up @@ -90,3 +94,23 @@ abstract class DatadogInitializer : Initializer<Unit>, KoinComponent {
Timber.plant(DatadogLoggingTree(logger))
}
}

/**
* Filters out errors that originate from a network request throwing an error when the exception is explicitly an
* IOException with the message "cancelled". These "errors" are just part of the normal app behavior, where we may leave
* a screen which was in the middle of a network request, and in the process of leaving we cancel the coroutineScope in
* which that work was being done in.
*/
private val cancellationFilteringErrorEventMapper = EventMapper<ErrorEvent> { errorEvent ->
val wasCancellationException = with(errorEvent.error) {
category == EXCEPTION &&
isCrash == false &&
type == "java.io.IOException" &&
stack?.startsWith("java.io.IOException: Canceled") == true
}
if (wasCancellationException) {
null
} else {
errorEvent
}
}

0 comments on commit 9be2bb2

Please sign in to comment.