Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Filter out cancellation exceptions for RUM errors #2348

Merged
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
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
}
}
Loading