designcourse icon indicating copy to clipboard operation
designcourse copied to clipboard

`beforeSend` not firing

Open austinlogo opened this issue 1 year ago • 3 comments
trafficstars

Describe the bug `BeforeSend is being sent on init configurations, but we're still seeing the logs make their way through.

To Reproduce

Begin Logging with the following beforeSend config

datadogLogs.init({
      beforeSend: (event) => {
        if (event.message.includes('DD_LOGS is already initialized')) return false;
        if (event.http?.status_code === 0) {
          webLogger.log('swallowing event error', event);
          return false;
        }

        return true;
      },
    });

Expected behavior I would expect aborted requests with a 0 status code to not show up in the DD logs.

austinlogo avatar Feb 23 '24 23:02 austinlogo

Hello @austinlogo ! Thanks for reaching out.

I tried the code snippet you provided (I removed webLogger.log('swallowing event error', event);) and it is filtering out all the events that have 0 as a status_code.

Could you please check if you can reproduce it on your app ? You can use the browser-sdk extension to see which events (logs) are being sent.

Otherwise, we suspect that perhaps some old version of your app, still using the configuration without beforeSend, could be the origin of those event, or some error might be thrown when trying to log using webLogger when the status_code is 0.

N-Boutaib avatar Feb 26 '24 16:02 N-Boutaib

Hey @N-Boutaib, thanks for getting back. We looked into this more and still see it. Will the datadogLogs.init() update configurations if run again. We were also seeing Datadog Browser SDK: DD_RUM is already initialized. errors.

Questions:

  • Does the config update if run again (i.e. on refresh), if not How can we update the configurations?
  • Can we filter these out in the pipeline? We tried that but it seems like the pipeline is read-only.

image

austinlogo avatar Mar 08 '24 13:03 austinlogo

Does the config update if run again (i.e. on refresh), if not How can we update the configurations?

No, it won't. For beforeSend, you could use a reference like this:

let currentBeforeSend = (event) => { ... }
datadogLogs.init({
  beforeSend: (event) => currentBeforeSend(event)
})

// later
currentBeforeSend = (event) => { ...something else... }

Can we filter these out in the pipeline? We tried that but it seems like the pipeline is read-only.

You should be able to create a new pipeline, and use source:browser as a filter to focus on browser logs.

BenoitZugmeyer avatar Mar 11 '24 12:03 BenoitZugmeyer