Copy the latest compiled UMD package bundle from
https://unpkg.com/@airbrake/browser to
vendor/assets/javascripts/airbrake.js
in your project.
Then, add the following code to your Sprockets manifest:
//= require airbrake
var airbrake = new Airbrake.Notifier({
projectId: 1,
projectKey: 'FIXME'
});
airbrake.addFilter(function(notice) {
notice.context.environment = "<%= Rails.env %>";
return notice;
});
try {
throw new Error('Hello from Airbrake!');
} catch (err) {
airbrake.notify(err).then(function(notice) {
if (notice.id) {
console.log('notice id:', notice.id);
} else {
console.log('notify failed:', notice.error);
}
});
}
Add @airbrake/broswer
to your application.
yarn add @airbrake/browser
In your main application pack, import @airbrake/browser
and configure the client.
import { Notifier } from '@airbrake/browser';
const airbrake = new Notifier({
projectId: 1,
projectKey: 'FIXME'
});
airbrake.addFilter((notice) => {
notice.context.environment = process.env.RAILS_ENV;
return notice;
});
try {
throw new Error('Hello from Airbrake!');
} catch (err) {
airbrake.notify(err).then((notice) => {
if (notice.id) {
console.log('notice id:', notice.id);
} else {
console.log('notify failed:', notice.error);
}
});
}
You should now be able to capture JavaScript exceptions in your Ruby on Rails application.