DataDog / dd-sdk-android

Datadog SDK for Android (Compatible with Kotlin and Java)
Apache License 2.0
154 stars 60 forks source link

Drop errors based on their Exception #1560

Closed orafaaraujo closed 1 year ago

orafaaraujo commented 1 year ago

Hi,

I'm trying to drop some errors, but they continue to appear in the Dashboards.

I'm using a custom TracedRequestListener on DatadogInterceptor and TracingInterceptor.

DatadogInterceptor(
    firstPartyHosts = tracedHosts,
    tracedRequestListener = customTracedRequestListener,
)

TracingInterceptor(
    tracedHosts = tracedHosts,
    tracedRequestListener = customTracedRequestListener,
)

private val customTracedRequestListener = object : TracedRequestListener {
    override fun onRequestIntercepted(
        request: Request,
        span: Span,
        response: Response?,
        throwable: Throwable?,
    ) {
        if (throwable is IOException) {
            (span as? DDSpan?)?.drop()
        }
    }
}

I aim to remove all java.io.IOException: Canceled generated from Coroutines when the user leaves the screen in a middle of a request. Those exceptions are expected, so we do not want to send them to Datadog.

Am I missing something? What's the correct approach in this situation?

Thank you

Additional context

0xnm commented 1 year ago

Hello @orafaaraujo!

Can you please tell us which dashboard are you checking? Is it RUM or Traces (APM)?

Please also share the SDK version used.

orafaaraujo commented 1 year ago

Hey @0xnm

It's on the RUM dashboard.

I'm using the SDK version 1.19.3, plugin version 1.10.0.

0xnm commented 1 year ago

TracedRequestListener works with spans, which are used for distributed tracing (APM) in case of OkHttp instrumentation.

For your use-case, since it is RUM, you may use setRumErrorEventMapper and return null in the implementation for the events which you want to drop based on your criteria.

orafaaraujo commented 1 year ago

Hey @0xnm

Now it's working like a charm. Thank you for your help on that. Have a nice weekend!