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

[PLAT-8277] Add maxEvents error message and update tests #1739

Merged
merged 2 commits into from
May 18, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
- Small performance improvements to `Bugnag.start`
[bugsnag-android#1680](https://github.com/bugsnag/bugsnag-android/pull/1680)
- (plugin-react|plugin-vue|plugin-react-navigation|plugin-react-native-navigation) Set `@bugsnag/core` to be an optional peer dependency to avoid unmet peer dependency warnings [#1735](https://github.com/bugsnag/bugsnag-js/pull/1735)
- (plugin-simple-throttle) Warning message added when error handler has exceeded `maxEvents` [#1739](https://github.com/bugsnag/bugsnag-js/pull/1739)

## v7.16.4 (2022-05-03)

Expand Down
14 changes: 11 additions & 3 deletions packages/plugin-simple-throttle/test/throttle.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,19 @@ import plugin from '../'
import Client from '@bugsnag/core/client'

describe('plugin: throttle', () => {
const payloads = []
const c = new Client({ apiKey: 'aaaa-aaaa-aaaa-aaaa' }, undefined, [plugin])
const mockWarn = jest.fn()
c._logger.warn = mockWarn
c._setDelivery(client => ({ sendEvent: (payload) => payloads.push(payload), sendSession: () => {} }))

it('prevents more than maxEvents being sent', () => {
const payloads = []
const c = new Client({ apiKey: 'aaaa-aaaa-aaaa-aaaa' }, undefined, [plugin])
c._setDelivery(client => ({ sendEvent: (payload) => payloads.push(payload), sendSession: () => {} }))
for (let i = 0; i < 100; i++) c.notify(new Error('This is fail'))
expect(payloads.length).toBe(10)
expect(mockWarn).toHaveBeenCalledTimes(90)
})

it('logs an appropriate error message', () => {
expect(mockWarn).toHaveBeenCalledWith('Cancelling event send due to maxEvents per session limit of 10 being reached')
})
})
5 changes: 4 additions & 1 deletion packages/plugin-simple-throttle/throttle.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ module.exports = {
// add onError hook
client.addOnError((event) => {
// have max events been sent already?
if (n >= client._config.maxEvents) return false
if (n >= client._config.maxEvents) {
client._logger.warn(`Cancelling event send due to maxEvents per session limit of ${client._config.maxEvents} being reached`)
return false
}
n++
})

Expand Down