3
3
namespace App \Providers ;
4
4
5
5
use App \Support \GitHub ;
6
+ use Illuminate \Queue \Events \JobFailed ;
7
+ use Illuminate \Support \Facades \Queue ;
6
8
use Illuminate \Support \Facades \View ;
7
9
use Illuminate \Support \ServiceProvider ;
10
+ use Sentry \State \Scope ;
11
+
12
+ use function Sentry \captureException ;
13
+ use function Sentry \configureScope ;
8
14
9
15
class AppServiceProvider extends ServiceProvider
10
16
{
@@ -22,6 +28,8 @@ public function register(): void
22
28
public function boot (): void
23
29
{
24
30
$ this ->registerSharedViewVariables ();
31
+
32
+ $ this ->sendFailingJobsToSentry ();
25
33
}
26
34
27
35
private function registerSharedViewVariables (): void
@@ -35,4 +43,22 @@ private function registerSharedViewVariables(): void
35
43
View::share ('openCollectiveLink ' , 'https://opencollective.com/nativephp ' );
36
44
View::share ('githubLink ' , 'https://github.com/NativePHP ' );
37
45
}
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
+ }
38
64
}
0 commit comments