bugsnag / bugsnag-laravel

BugSnag notifier for the Laravel PHP framework. Monitor and report Laravel errors.
https://docs.bugsnag.com/platforms/php/laravel/
MIT License
876 stars 129 forks source link

Ensure events are sent from queues when using Laravel Vapor #511

Closed imjoehaines closed 1 year ago

imjoehaines commented 1 year ago

Goal

Currently we never flush events in queued jobs when using Laravel Vapor because it does not call our shutdown function or fire the 'looping' event

To fix this, we need to:

  1. flush events in 'after' and 'exceptionOccurred' in order to send any events created during the execution of a job
  2. disable batch sending in 'after' and 'exceptionOccurred' so that any events created when a job finishes get sent synchronously. Otherwise we'd fail to send these events if the queue worker doesn't run another job
  3. Re-enable batch sending in 'before' if we previously disabled it. This allows users to get the performance benefits of batch sending while their job is running (though it's much less relevant in a queue process)

This ensures that events created in a job are sent (when we call flush) and events created after a job are sent (as they are sent synchronously)

This PR also fixes breadcrumbs leaking between jobs; they are now cleared in the 'before' event on Laravel Vapor

Testing

Unfortunately this can't really be tested (short of running Vapor on CI) because these changes are specific to the way queues workers behave on Vapor. Any unit test would only prove the code is run as written, not that this actually works when run on Vapor