Installing airbrake-js in a Rails application

Features

  • Easy and flexible installation options including NPM, Bower and a public CDN
  • Send uncaught errors to Airbrake or manually using a try/catch
  • Add custom parameters to your errors for more context
  • Private sourcemap support
  • Control which errors you send with customizable filtering options

Getting started

Usage with Ruby on Rails

In order to include airbrake-js into your Ruby on Rails application, place this in your Gemfile:

# somewhere in Gemfile
source 'https://rails-assets.org' do
  gem 'rails-assets-airbrake-js-client'
end

And then place the following code into your application.js:

//= require airbrake-js-client

var airbrake = new airbrakeJs.Client({projectId: 1, projectKey: 'FIXME'});
airbrake.addFilter(function(notice) {
  notice.context.environment = "<%= Rails.env %>";
  return notice;
});

try {
  throw new Error('hello from airbrake-js');
} catch (err) {
  var promise = airbrake.notify(err);
  promise.then(function(notice) {
    console.log("notice id", notice.id);
  });
}

You should now be able to capture JavaScript exceptions in your Ruby on Rails application.

Going Further

Installation and configuration is just the beginning. The airbrake-js notifier supports many other advanced uses and options including:

Please visit the airbrake-js GitHub repo for more usage and configuration examples.