Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ignoreDuplicateErrors config flag #755

Merged
merged 2 commits into from
Jul 31, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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