rollbar / rollbar.js

Error tracking and logging from Javascript to Rollbar
https://docs.rollbar.com/docs/javascript
MIT License
566 stars 212 forks source link

Fixed telemetry queue shorten calculation on reconfigure. #1105

Closed danielmorell closed 1 year ago

danielmorell commented 1 year ago

Description of the change

I am working on implementing Telemetry in the PHP SDK and using JS as a reference implementation. I found what looks like bug in the telemetry queue size calculation when telemetry is reconfigured here:

https://github.com/rollbar/rollbar.js/blob/e964ecbdb16a4d2b8b5feaa8b70a2ec327648ed0/src/telemetry.js#L12-L23

Specifically, deleteCount = this.maxQueueSize - newMaxEvents; looks a little suspicious. If the previous max was 100 and the new max is 80 our delete count would be 20.

We then would remove 20 items from the beginning of the queue without checking the length of the queue. So, if 10 items where in the queue we would effectively empty it. Even thought our new max is 80 and the current length of 10 is well under that.

This PR fixes that by using at the length of the queue instead of the maxQueueSize property.

Type of change

Related issues

None

Checklists

Development

Code review