Skip to content

Commit

Permalink
fix: Ensure breadcrumbs behave correctly
Browse files Browse the repository at this point in the history
Now that leaveBreadcrumb() doesn't have the check of enabledBreadcrumbTypes, the notifier needs to
check if "error" breadcrumbs are desired before adding them. Additionally this commit forces Node
not to leave any breadcrumbs at all, until they are switched on.
  • Loading branch information
bengourley committed Apr 2, 2020
1 parent 7a62ec4 commit ffb6afa
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 6 deletions.
14 changes: 8 additions & 6 deletions packages/core/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -301,12 +301,14 @@ class Client {
return cb(null, event)
}

// only leave a crumb for the error if actually got sent
Client.prototype.leaveBreadcrumb.call(this, event.errors[0].errorClass, {
errorClass: event.errors[0].errorClass,
errorMessage: event.errors[0].errorMessage,
severity: event.severity
}, 'error')
if (includes(this._config.enabledBreadcrumbTypes, 'error')) {
// only leave a crumb for the error if actually got sent
Client.prototype.leaveBreadcrumb.call(this, event.errors[0].errorClass, {
errorClass: event.errors[0].errorClass,
errorMessage: event.errors[0].errorMessage,
severity: event.severity
}, 'error')
}

if (originalSeverity !== event.severity) {
event._handledState.severityReason = { type: 'userCallbackSetSeverity' }
Expand Down
15 changes: 15 additions & 0 deletions packages/core/test/client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,21 @@ describe('@bugsnag/core/client', () => {
expect(client._breadcrumbs.length).toBe(1)
expect(client._breadcrumbs[0].type).toBe('manual')
})

it('only leaves an error breadcrumb if enabledBreadcrumbTypes contains "error"', (done) => {
const client = new Client({
apiKey: 'API_KEY_YEAH',
enabledBreadcrumbTypes: []
})
client._setDelivery(client => ({
sendSession: () => {},
sendEvent: (payload, cb) => cb(null)
}))
client.notify(new Error('oh no'), () => {}, () => {
expect(client._breadcrumbs.length).toBe(0)
done()
})
})
})

describe('startSession()', () => {
Expand Down
2 changes: 2 additions & 0 deletions packages/node/src/notifier.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ const Bugsnag = {
bugsnag._logger.warn('Breadcrumbs are not supported in Node.js yet')
}

bugsnag._config.enabledBreadcrumbTypes = []

return bugsnag
},
start: (opts) => {
Expand Down

0 comments on commit ffb6afa

Please sign in to comment.