Sentry-javascript: Filtering Chrome extension ReportingObserver events?

Created on 22 Sep 2018  路  6Comments  路  Source: getsentry/sentry-javascript

Package + Version

  • [x] @sentry/browser
  • [ ] @sentry/node
  • [ ] raven-js
  • [ ] raven-node _(raven for node)_
  • [ ] other:

Version:

4.0.4

Description

Is it possible to filter out ReportingObserver events from Chrome extensions like we can with regular Sentry errors? We just got one like:

{
anticipatedRemoval: 2019-03-12T04:00:00.000Z, 
columnNumber: 307, 
id: ElementCreateShadowRoot, 
lineNumber: 2, 
message: [Filtered], 
sourceFile: chrome-extension://mgijmajocgfcbeboacabfgobmjgjcoja/content.min.js
}

Most helpful comment

Worth noting here that #1713 removed ReportingObserver from the defaults, so starting with v4.3.0+ this shouldn't be an issue anymore 馃槃

All 6 comments

Yes, ReportingObserver events are the very same events you'd get for regular exceptions. You can use eventProcessing to filter one you don't need - https://github.com/getsentry/sentry-javascript/blob/9c131a04dec99fd9716d3b9e850082680f21e497/packages/browser/src/integrations/reportingobserver.ts#L94-L127

init({
  dsn: '__DSN__',
  beforeSend(event) {
    // Detect if we got a ReportingObserver event
    if (event.message && event.message.startsWith('ReportingObserver')) {
      // And check if the observer's report had a body, if so, check whether sourceFile points to chrome-extension. If so, drop the event.
      if (event.extra.body && event.extra.body.sourceFile && event.extra.body.sourceFile.startsWith('chrome-extension')) return null;
    }
    // Otherwise, just let it through
    return event;
  }
})

Or see this comment to see how to do it as a separate event processor - https://github.com/getsentry/sentry-javascript/issues/1329#issuecomment-423979370

Hope that helps. Cheers!

I appreciate the snippet, but am concerned that I could not find this in the docs: https://docs.sentry.io/search/?platform=browser&q=beforesend

Thanks for the snippet but I think there should be a correction:

 beforeSend(event) {
    // Detect if we got a ReportingObserver event
    if (event.message && event.message.startsWith('ReportingObserver')) {
      // And check if the observer's report had a body, if so, check whether sourceFile points to chrome-extension. If so, drop the event.
      if (
        event.extra.body &&
+        event.extra.body.sourceFile &&
        event.extra.body.sourceFile.startsWith('chrome-extension')
      ) {
        return null;
      }
    }
    // Otherwise, just let it through
    return event;
  }

without it I'm currently getting the error Cannot read property 'startsWith' of undefined

You're right. Updated :) Thanks!

Worth noting here that #1713 removed ReportingObserver from the defaults, so starting with v4.3.0+ this shouldn't be an issue anymore 馃槃

Was this page helpful?
0 / 5 - 0 ratings