rollbar.js icon indicating copy to clipboard operation
rollbar.js copied to clipboard

ignoredMessages not getting ignored

Open wulffeld opened this issue 1 year ago • 6 comments

With this configuration the ignoredMessages are getting ignored and not sent to rollbar however if I leave out the checkIgnore option they will be sent to rollbar. That's not what the docs say I think or am I misunderstanding them?

Using latest rollbar.js. I've tested several times back and forth to verify this.

    var _rollbarConfig = {
      accessToken: "redacted",
      captureUncaught: true,
      captureUnhandledRejections: true,
      ignoredMessages: [
        /All ins elements in the DOM with class=adsbygoogle already have ads in them/i,
        /Uncaught TagError: adsbygoogle\.push\(\) error: All 'ins' elements in the DOM with class=adsbygoogle already have ads in them/i,
        /Uncaught TagError: adsbygoogle\.push\(\) error: No slot size for availableWidth=0/i
      ],
      checkIgnore: function(isUncaught, args, payload) {
        return this.ignoredMessages.some(function(ignoredMessage) {
          return ignoredMessage.test(args[0]);
        });
      },
      payload: {
        environment: "production"
      }
    };

wulffeld avatar Apr 25 '24 12:04 wulffeld

The ignoredMessages handler in Rollbar.js uses RegExp() to compile the expression, and uses 'gi' flags in the 2nd argument. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp

It looks like either your literal expressions are getting converted to strings, or RegExp() errors on the i flag.

I think you'll get the expected result with strings like: "All ins elements in the DOM with class=adsbygoogle already have ads in them"

waltjones avatar Apr 25 '24 14:04 waltjones

@waltjones Thanks however I tried with strings as well. This config will not block any exception:

  var _rollbarConfig = {
    accessToken: "...",
    captureUncaught: true,
    captureUnhandledRejections: true,
    ignoredMessages: [
      "All ins elements in the DOM with class=adsbygoogle already have ads in them",
      "Uncaught TagError: adsbygoogle\.push\(\) error: All 'ins' elements in the DOM with class=adsbygoogle already have ads in them",
      "Uncaught TagError: adsbygoogle\.push\(\) error: No slot size for availableWidth=0",
      "Script error."
    ],
    payload: {
      environment: "production"
    }
  };

unless I add:

  checkIgnore: function(isUncaught, args, payload) {
    return this.ignoredMessages.some(function(msg) {
      return args[0] && args[0].indexOf(msg) === 0;
    });
  },

🤯

wulffeld avatar Apr 25 '24 20:04 wulffeld

+1 on this issue. We're facing the same at my company.

arturbani avatar Nov 20 '24 01:11 arturbani

We're having the same issue.

aaronabf avatar Dec 13 '24 23:12 aaronabf

@waltjones I'm fairly confident there is a bug in the rollbar SDK.

aaronabf avatar Dec 13 '24 23:12 aaronabf

I'm pretty sure I know what your issue could be.

The args parameter passed to checkIgnore is actually an iArguments from whatever the rollbar client was called with. Now when rollbar is handling uncaught errors, it calls the log method with 3 arguments: the first being a string, the second is the error, and the third (I think) is a Promise or context from where the error originated.

In your checkIgnore handler you're only looking at args[0], and my guess is going to be if you log out args that the error you want to ignore is actually in the next index.

Hope that helps.

mathewbyrne avatar Feb 06 '25 01:02 mathewbyrne