|
5 | 5 | use Illuminate\Contracts\Container\BindingResolutionException;
|
6 | 6 | use Illuminate\Contracts\Events\Dispatcher;
|
7 | 7 | use Illuminate\Contracts\Http\Kernel as HttpKernelInterface;
|
| 8 | +use Illuminate\Console\Scheduling\Event as LaravelEvent; |
8 | 9 | use Illuminate\Foundation\Application as Laravel;
|
9 | 10 | use Illuminate\Foundation\Http\Kernel as HttpKernel;
|
10 | 11 | use Illuminate\Log\LogManager;
|
11 | 12 | use RuntimeException;
|
| 13 | +use Sentry\CheckIn; |
| 14 | +use Sentry\CheckInStatus; |
12 | 15 | use Sentry\ClientBuilder;
|
13 | 16 | use Sentry\ClientBuilderInterface;
|
| 17 | +use Sentry\Event as SentryEvent; |
14 | 18 | use Sentry\Integration as SdkIntegration;
|
15 | 19 | use Sentry\Laravel\Console\PublishCommand;
|
16 | 20 | use Sentry\Laravel\Console\TestCommand;
|
@@ -59,6 +63,7 @@ public function boot(): void
|
59 | 63 | $this->bindEvents();
|
60 | 64 |
|
61 | 65 | $this->setupFeatures();
|
| 66 | + $this->setupCronMonitoring(); |
62 | 67 |
|
63 | 68 | if ($this->app->bound(HttpKernelInterface::class)) {
|
64 | 69 | /** @var \Illuminate\Foundation\Http\Kernel $httpKernel */
|
@@ -143,6 +148,45 @@ protected function setupFeatures(): void
|
143 | 148 | }
|
144 | 149 | }
|
145 | 150 |
|
| 151 | + /** |
| 152 | + * Setup Cron Monitoring. |
| 153 | + */ |
| 154 | + private function setupCronMonitoring(): void |
| 155 | + { |
| 156 | + LaravelEvent::macro('sentryMonitor', function (string $monitorSlug) { |
| 157 | + $hub = SentrySdk::getCurrentHub(); |
| 158 | + $checkIn = new CheckIn( |
| 159 | + $monitorSlug, |
| 160 | + CheckInStatus::inProgress() |
| 161 | + ); |
| 162 | + |
| 163 | + /** @var \Illuminate\Console\Scheduling\Event $this */ |
| 164 | + return $this |
| 165 | + ->before(function () use ($hub, $checkIn) { |
| 166 | + $event = SentryEvent::createCheckIn(); |
| 167 | + $event->setCheckIn($checkIn); |
| 168 | + |
| 169 | + $hub->captureEvent($event); |
| 170 | + }) |
| 171 | + ->onSuccess(function () use ($hub, $checkIn) { |
| 172 | + $checkIn->setStatus(CheckInStatus::ok()); |
| 173 | + |
| 174 | + $event = SentryEvent::createCheckIn(); |
| 175 | + $event->setCheckIn($checkIn); |
| 176 | + |
| 177 | + $hub->captureEvent($event); |
| 178 | + }) |
| 179 | + ->onFailure(function () use ($hub, $checkIn) { |
| 180 | + $checkIn->setStatus(CheckInStatus::error()); |
| 181 | + |
| 182 | + $event = SentryEvent::createCheckIn(); |
| 183 | + $event->setCheckIn($checkIn); |
| 184 | + |
| 185 | + $hub->captureEvent($event); |
| 186 | + }); |
| 187 | + }); |
| 188 | + } |
| 189 | + |
146 | 190 | /**
|
147 | 191 | * Register the artisan commands.
|
148 | 192 | */
|
|
0 commit comments