Session tracker throttling not working with some cache drivers (eg. Redis)
itsgoingd opened this issue · 3 comments
Describe the bug
The session tracking implementation includes a throttling mechanism, where the sessions data is cached locally and submitted to Bugsnag only once every 30 seconds. This is very necessary as submitting the data to Bugsnag incurs a sizeable performance overhead on the request (in my case 300-600ms).
This mechanism unfortunately does not seem to work when using the Redis and possibly other cache backends in Laravel.
I've managed to trace the issue to this check in the bugsnag-php
library:
https://github.com/bugsnag/bugsnag-php/blob/master/src/SessionTracker.php#L428-L432
Redis and possibly other cache backends return all values as strings, which will fail this check. This causes 0 to be always returned, which effectively disables the throttling mechanism as we are unable to track the last sent timestamp.
A possible fix might be for example using is_numeric
and explicitly casting the return value to integer.
Steps to reproduce
- Setup an empty Laravel project w/ Bugsnag
- Enable auto-captured sessions
BUGSNAG_CAPTURE_SESSIONS=true
- Set cache backend to redis
CACHE_DRIVER=redis
- Watch sessions being submitted to Bugsnag on every request instead of once every 30 seconds
Environment
- Bugsnag version: v2.22.2
- PHP version: 8.0.10
- Composer version: 2.0.8
- Laravel version: v8.63.0
- Lumen version (if any):
Hey @itsgoingd - thanks for raising this, it does look like there could be an issue here. We're going to investigate this when priorities allow. I'll keep you updated on this thread 👍
A fix for this has been released in https://github.com/bugsnag/bugsnag-php/releases/tag/v3.27.0. You can run composer update bugsnag/bugsnag
to get this update. Thanks for raising the issue with us.
Thanks for getting the fix out so fast. ✌🏾