Skip to content

Commit

Permalink
Merge pull request #754 from rollbar/wj-diagnostic-anonymous
Browse files Browse the repository at this point in the history
Add diagnostic key for anonymous errors
  • Loading branch information
waltjones authored Jul 25, 2019
2 parents b144a0f + 55d2d7c commit 0d0a01f
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/browser/rollbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,9 @@ Rollbar.prototype.handleAnonymousErrors = function() {
return;
}

// Allow this to be tracked later.
error._isAnonymous = true;

// url, lineno, colno shouldn't be needed for these errors.
// If that changes, update this accordingly, using the unused
// _stack param as needed (rather than parse error.toString()).
Expand Down Expand Up @@ -475,6 +478,7 @@ function addTransformsToNotifier(notifier, gWindow) {
.addTransform(transforms.scrubPayload)
.addTransform(sharedTransforms.userTransform(logger))
.addTransform(sharedTransforms.addConfiguredOptions)
.addTransform(sharedTransforms.addDiagnosticKeys)
.addTransform(sharedTransforms.itemToPayload);
}

Expand Down
13 changes: 12 additions & 1 deletion src/transforms.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,22 @@ function addConfiguredOptions(item, options, callback) {
callback(null, item);
}

function addDiagnosticKeys(item, options, callback) {
var diagnostic = {}

if (_.get(item, 'err._isAnonymous')) {
diagnostic.isAnonymous = true;
}
item.data.notifier.diagnostic = _.merge(item.data.notifier.diagnostic, diagnostic);
callback(null, item);
}

module.exports = {
itemToPayload: itemToPayload,
addTelemetryData: addTelemetryData,
addMessageWithError: addMessageWithError,
userTransform: userTransform,
addConfigToPayload: addConfigToPayload,
addConfiguredOptions: addConfiguredOptions
addConfiguredOptions: addConfiguredOptions,
addDiagnosticKeys: addDiagnosticKeys
};
2 changes: 2 additions & 0 deletions test/browser.rollbar.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,7 @@ describe('options.captureUncaught', function() {

expect(body.access_token).to.eql('POST_CLIENT_ITEM_TOKEN');
expect(body.data.body.trace.exception.message).to.eql('test error');
expect(body.data.notifier.diagnostic.isAnonymous).to.not.be.ok();

server.requests.length = 0;

Expand Down Expand Up @@ -350,6 +351,7 @@ describe('options.captureUncaught', function() {

expect(body.access_token).to.eql('POST_CLIENT_ITEM_TOKEN');
expect(body.data.body.trace.exception.message).to.eql('anon error');
expect(body.data.notifier.diagnostic.isAnonymous).to.eql(true);

// karma doesn't unload the browser between tests, so the onerror handler
// will remain installed. Unset captureUncaught so the onerror handler
Expand Down

0 comments on commit 0d0a01f

Please sign in to comment.