browser-sdk icon indicating copy to clipboard operation
browser-sdk copied to clipboard

💡 Discard errors coming from specific source files

Open vinnymac opened this issue 2 years ago • 3 comments

Is your feature request related to a problem? Please describe.

Currently my application configures RUM to discard a subset of errors by message and resource url. Pseudo code is something like the following.

import { datadogRum } from '@datadog/browser-rum';

datadogRum.init({
    beforeSend: (event, context) => {
        // discard a RUM error based on message
        if (event.type === 'error' && event.error.message.includes('patterns')) {
            return false
        }
        
       // discard a RUM error based on resource url
        if (event.type === 'error' && event.error.resource?.url.test(/pattern/)) {
          return false;
        }
    },
});

Unfortunately not every error has a resource url. Inspecting the events and context for errors that are sent in beforeSend, and while studying the source code in this repository, I did not find any mechanism to determine the source of the error. Additionally the original error isn't available so I can attempt to parse out the source. This means I receive much more in-actionable noise in RUM than desired from third party scripts.

Describe the solution you'd like

The Datadog RUM application error interface does show the source of an error when available, yet I don't see that same information in beforeSend so I can make a decision on whether or not to discard an error. Can we add a feature for filtering errors by URL? Or can we add these sources to the event objects so that developers can decide whether or not they want to keep errors for particular third parties?

Pseudo code for a solution might look something like

import { datadogRum } from '@datadog/browser-rum';

datadogRum.init({
    // URL patterns for errors that should not be sent to RUM
    denyUrls: [/pattern/],
    // URL patterns for errors that should be sent to RUM
    allowUrls: [/pattern/],
});


// Alternatively expose source on the error event
datadogRum.init({
    beforeSend: (event, context) => {
        // discard a RUM error based on source
        if (event.type === 'error' && event.error.source.test(/pattern/)) {
            return false
        }
    },
});

Describe alternatives you've considered

I've inspected the arguments of beforeSend, and haven't seen an alternative for determining the initiator for a particular error. Perhaps for a subset of errors it may be possible to parse this out of the stack trace, when available.

I read through these docs and did not see a way to configure this functionality.

Thanks

SDK Version CDN Sync with v5

Related issues https://github.com/DataDog/browser-sdk/issues/1616 https://github.com/DataDog/browser-sdk/issues/362

vinnymac avatar Oct 31 '23 17:10 vinnymac

Hi @vinnymac,

my application configures RUM to discard a subset of errors by message and resource url

The RUM SDK do not collect failed network calls as error events since the v3 (cf upgrade entry), so RUM error events do not have event.error.resource field anymore.

I did not find any mechanism to determine the source of the error.

We have an error.source property on RUM errors that allow to identify error coming from the source code, a browser report or an addError API call.

The Datadog RUM application error interface does show the source of an error when available [...] Can we add a feature for filtering errors by URL?

I am guessing that what you'd want is the error.file attribute, identifying from which application source file the error is coming. is that it?

bcaudan avatar Nov 02 '23 10:11 bcaudan

Hi @bcaudan,

Thanks for the quick reply, must be a carry over from our old v3 implementation before we migrated to v4. We upgraded to v5 in the last week, so we have been taking a closer look at how to fine tune the configuration on our site.

We have an error.source property on RUM errors that allow to identify error coming from the source code, a browser report or an addError API call.

I see source in the datadog RUM error tracking dashboard with a value of browser for third party scripts. That seems like the error.source_type property and not the error.source property. I wonder if error.source === 'network' might help with keeping the noise down?

I am guessing that what you'd want is the error.file attribute, identifying from which application source file the error is coming.

This sounds like it would solve the problem 👍🏼

vinnymac avatar Nov 02 '23 14:11 vinnymac

I see source in the datadog RUM error tracking dashboard with a value of browser for third party scripts.

the source property is used to differentiate between data coming from browser, android, iOS...

I wonder if error.source === 'network' might help with keeping the noise down?

Since v3, browser RUM SDK don't collect error.source === 'network', so it should not help.

I am guessing that what you'd want is the error.file attribute, identifying from which application source file the error is coming.

This sounds like it would solve the problem 👍🏼

Unfortunately, for now, the SDK don't have access to the unminified file where the error happened (error.file) and the datadog app don't have filtering capabilities for RUM events.
However, If the errors you want to discard comes from specific files, you could look for them inside the minified stacktrace error.stack.

bcaudan avatar Nov 06 '23 12:11 bcaudan