airbrake

Ignore environments with Airbrake JS


We use Airbrake to track errors in our Rails application using the Ruby and JS versions of their SDK... but noticed that we're unable to ignore certain environments such as development and test in our JS code.

In our configuration we have:

var airbrake = new Airbrake.Notifier({
  host: '<%= Settings.airbrake_host %>',
  projectId: 1,
  projectKey: '<%= Settings.airbrake_key %>',
  environment: '<%= Rails.env %>',
  ignoreEnvironments: ['development', 'test'] // Not working???
});

We've based this on what we have for the Ruby-side:

Airbrake.configure do |config|
  config.host = Settings.airbrake_host
  config.project_id = 1
  config.project_key = Settings.airbrake_key
  config.environment = Rails.env
  config.ignore_environments = %w[development test]
end

Looking at the available options in the code: https://github.com/airbrake/airbrake-js/blob/master/packages/browser/src/options.ts it seems there's no ignoreEnvironments so that's why it's not working... is there a way to ignore environments? We don't want to have to wrap any calls to Airbrake with a conditional to check the environment.


Solution

  • One way I've found to handle this is to add a filter after the configuration that checks if the environment matches one of our ignored ones:

    airbrake.addFilter((notice) => {
      if (['development', 'test'].includes(notice.context.environment)) return null;
      return notice;
    });