Skip to content

Commit 598157d

Browse files
committed
send failing jobs to sentry
1 parent 0d645be commit 598157d

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

app/Providers/AppServiceProvider.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,14 @@
33
namespace App\Providers;
44

55
use App\Support\GitHub;
6+
use Illuminate\Queue\Events\JobFailed;
7+
use Illuminate\Support\Facades\Queue;
68
use Illuminate\Support\Facades\View;
79
use Illuminate\Support\ServiceProvider;
10+
use Sentry\State\Scope;
11+
12+
use function Sentry\captureException;
13+
use function Sentry\configureScope;
814

915
class 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

Comments
 (0)