Skip to content

Commit

Permalink
Merge pull request #755 from rollbar/wj-transmit-duplicate-errors
Browse files Browse the repository at this point in the history
Add ignoreDuplicateErrors config flag
  • Loading branch information
waltjones authored Jul 31, 2019
2 parents fa6d04f + ea85092 commit c90c91b
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 4 deletions.
3 changes: 2 additions & 1 deletion src/browser/rollbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,8 @@ var defaultOptions = {
sendConfig: false,
includeItemsInTelemetry: true,
captureIp: true,
inspectAnonymousErrors: true
inspectAnonymousErrors: true,
ignoreDuplicateErrors: true
};

module.exports = Rollbar;
3 changes: 2 additions & 1 deletion src/react-native/rollbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,8 @@ Rollbar.defaultOptions = {
enabled: true,
transmit: true,
sendConfig: false,
includeItemsInTelemetry: true
includeItemsInTelemetry: true,
ignoreDuplicateErrors: true
};

module.exports = Rollbar;
2 changes: 1 addition & 1 deletion src/rollbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ Rollbar.prototype._log = function(defaultLevel, item) {
callback = item.callback;
delete item.callback;
}
if (this._sameAsLastError(item)) {
if (this.options.ignoreDuplicateErrors && this._sameAsLastError(item)) {
if (callback) {
var error = new Error('ignored identical item');
error.item = item;
Expand Down
3 changes: 2 additions & 1 deletion src/server/rollbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -624,7 +624,8 @@ Rollbar.defaultOptions = {
captureEmail: false,
captureUsername: false,
captureIp: true,
captureLambdaTimeouts: true
captureLambdaTimeouts: true,
ignoreDuplicateErrors: true
};

module.exports = Rollbar;
73 changes: 73 additions & 0 deletions test/browser.rollbar.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,79 @@ describe('options.captureUncaught', function() {

done();
});

it('should ignore duplicate errors by default', function(done) {
var server = window.server;
stubResponse(server);
server.requests.length = 0;

var options = {
accessToken: 'POST_CLIENT_ITEM_TOKEN',
captureUncaught: true
};
var rollbar = new Rollbar(options);

var element = document.getElementById('throw-error');

// generate same error twice
element.click();
element.click();
server.respond();

// transmit only once
expect(server.requests.length).to.eql(1);

var body = JSON.parse(server.requests[0].requestBody);

expect(body.access_token).to.eql('POST_CLIENT_ITEM_TOKEN');
expect(body.data.body.trace.exception.message).to.eql('test error');

// karma doesn't unload the browser between tests, so the onerror handler
// will remain installed. Unset captureUncaught so the onerror handler
// won't affect other tests.
rollbar.configure({
captureUncaught: false
});

done();
});

it('should transmit duplicate errors when set in config', function(done) {
var server = window.server;
stubResponse(server);
server.requests.length = 0;

var options = {
accessToken: 'POST_CLIENT_ITEM_TOKEN',
captureUncaught: true,
ignoreDuplicateErrors: false
};
var rollbar = new Rollbar(options);

var element = document.getElementById('throw-error');

// generate same error twice
element.click();
element.click();
server.respond();

// transmit both errors
expect(server.requests.length).to.eql(2);

var body = JSON.parse(server.requests[0].requestBody);

expect(body.access_token).to.eql('POST_CLIENT_ITEM_TOKEN');
expect(body.data.body.trace.exception.message).to.eql('test error');

// karma doesn't unload the browser between tests, so the onerror handler
// will remain installed. Unset captureUncaught so the onerror handler
// won't affect other tests.
rollbar.configure({
captureUncaught: false
});

done();
})
});

describe('options.captureUnhandledRejections', function() {
Expand Down

0 comments on commit c90c91b

Please sign in to comment.