Skip to content

Instantly share code, notes, and snippets.

@mmcdaris
Last active August 29, 2015 14:27
Show Gist options
  • Save mmcdaris/3b783be00539b0c5157e to your computer and use it in GitHub Desktop.
Save mmcdaris/3b783be00539b0c5157e to your computer and use it in GitHub Desktop.
airbrake-js filter: Don't send project root in backtrace lines

I was playing with the airbrake-js requirejs example and trying to filter out project_root from backtrace lines

Here is my airbrake-js addFilter for filtering out project root

airbrake.addFilter(function(notice) {
  var projectRoot = 'PROJECT_ROOT';
  for (i = 0; i < notice.errors.length; i++) {
    for(j = 0; j < notice.errors[i].backtrace.length; j++) {
      notice.errors[i].backtrace[j].file = notice.errors[i].backtrace[j].file.replace(projectRoot, '')
    };
  };
                                                                                                       
  return notice;
});

Also this gist has my full app.js if you want to mess around with it.

require.config({
paths: {
airbrakeJs: 'node_modules/airbrake-js/dist'
}
});
require(['airbrakeJs/client', 'airbrakeJs/instrumentation/jquery'],
function (AirbrakeClient, instrumentJQuery) {
var airbrake = new AirbrakeClient({
projectId: 5555555, projectKey: '5555555555555'
});
airbrake.addFilter(function(notice) {
var projectRoot = "PROJECT_ROOT";
for (i = 0; i < notice.errors.length; i++) {
for(j = 0; j < notice.errors[i].backtrace.length; j++) {
notice.errors[i].backtrace[j].file = notice.errors[i].backtrace[j].file.replace(projectRoot, '')
};
};
return notice;
});
try {
throw new Error('Hellooooo');
} catch (err) {
promise = airbrake.notify({
error: err,
params: {make_a: "point"}
});
promise.then(function(notice) {
console.log("https://airbrake.io/locate/" + notice.id);
});
}
if (window.jQuery) {
instrumentJQuery(airbrake, jQuery);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment