33namespace App \Providers ;
44
55use App \Support \GitHub ;
6+ use Illuminate \Queue \Events \JobFailed ;
7+ use Illuminate \Support \Facades \Queue ;
68use Illuminate \Support \Facades \View ;
79use Illuminate \Support \ServiceProvider ;
10+ use Sentry \State \Scope ;
11+
12+ use function Sentry \captureException ;
13+ use function Sentry \configureScope ;
814
915class AppServiceProvider extends ServiceProvider
1016{
@@ -22,6 +28,8 @@ public function register(): void
2228 public function boot (): void
2329 {
2430 $ this ->registerSharedViewVariables ();
31+
32+ $ this ->sendFailingJobsToSentry ();
2533 }
2634
2735 private function registerSharedViewVariables (): void
@@ -35,4 +43,22 @@ private function registerSharedViewVariables(): void
3543 View::share ('openCollectiveLink ' , 'https://opencollective.com/nativephp ' );
3644 View::share ('githubLink ' , 'https://github.com/NativePHP ' );
3745 }
46+
47+ private function sendFailingJobsToSentry (): void
48+ {
49+ Queue::failing (static function (JobFailed $ event ) {
50+ if (app ()->bound ('sentry ' )) {
51+ configureScope (function (Scope $ scope ) use ($ event ): void {
52+ $ scope ->setContext ('job ' , [
53+ 'connection ' => $ event ->connectionName ,
54+ 'queue ' => $ event ->job ->getQueue (),
55+ 'name ' => $ event ->job ->resolveName (),
56+ 'payload ' => $ event ->job ->payload (),
57+ ]);
58+ });
59+
60+ captureException ($ event ->exception );
61+ }
62+ });
63+ }
3864}
0 commit comments