Skip to content

Commit

Permalink
Reduce rollbar noise
Browse files Browse the repository at this point in the history
connects soxhub/qa#1301

Adds callback option to configure which errors get
sent to rollbar
  • Loading branch information
galnoy committed Jun 20, 2017
1 parent b1ac3d2 commit babff20
Show file tree
Hide file tree
Showing 6 changed files with 237 additions and 40 deletions.
4 changes: 4 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
node_modules
db
config
bin
53 changes: 53 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
{
"rules": {
"indent": [
2,
"tab"
],
"linebreak-style": [
2,
"unix"
],
"semi": [
2,
"always"
],
"no-unused-vars": [
2,
{"args": "after-used",
"argsIgnorePattern": "^_"}
],
"one-var": [
2,
"never"
],
"no-multiple-empty-lines": [
1,
{"max": 1}
],
"padded-blocks": [
1,
"never"
],
"no-trailing-spaces": [
1,
{ "skipBlankLines": true }
],
"no-spaced-func": [
2
],
"strict": ["error"]

},
"parserOptions": {
"ecmaVersion": 8
},
"env": {
"es6": true,
"node": true
},
"globals": {
"requireRoot": true
},
"extends": "eslint:recommended"
}
33 changes: 19 additions & 14 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,19 @@
* *******************************************************************/

// Load modules
var Rollbar = require('rollbar');
var util = require('util');
const Rollbar = require('rollbar');
const util = require('util');

exports.register = function (server, options, next) {
var preError = options.preError || function preError(err) { return err; };
// The sanitize function is called with the exception that will be sent
// to rollbar. Its cleaned output will be sent to rollbar instead of
// the original exception.
var sanitize = options.sanitize || function identity(err) { return err; };

// The filter function will be called before sending any 4XX response
// to rollbar. If a truthy value is returned, the error will be
// forwarded to rollbar; when false, the error is not sent to rollbar.
var filter = options.filter || function never_filter() { return true; };

var rollbarOpts = options;
rollbarOpts.environment = rollbarOpts.environment || process.env.NODE_ENV;
Expand All @@ -47,19 +55,15 @@ exports.register = function (server, options, next) {
var rollbarAccessToken = rollbarOpts.accessToken;
rollbarOpts.enabled = !!rollbarAccessToken;

var rollbar = new Rollbar({
accessToken: rollbarOpts.accessToken,
environment: rollbarOpts.environment,
handleUncaughtExceptions: rollbarOpts.handleUncaughtExceptions,
enabled: rollbarOpts.enabled
});

var rollbar = new Rollbar(rollbarOpts);

server.ext('onPreResponse', function onPreResponse(request, next) {
var response = preError(request.response);
if (response && response.isBoom) {
rollbar.error(response, request, response.output, logError);
}
let response = request.response;

response.isBoom &&
filter(response) &&
rollbar.error(sanitize(response), request, response.output, logError);

next.continue();
});

Expand All @@ -75,6 +79,7 @@ exports.register = function (server, options, next) {

server.expose('rollbar', rollbar);

next();
};

exports.register.attributes = {
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "rollbar-hapi",
"version": "0.0.9",
"version": "0.0.10",
"description": "A Hapi plugin for rollbar painless integration",
"author": "Evangelos Pappas <[email protected]>",
"engine": "node >= 0.10.x",
Expand Down
Loading

0 comments on commit babff20

Please sign in to comment.