Skip to content

Commit 6fdeaa0

Browse files
committed
Listen for queue events
1 parent 856170b commit 6fdeaa0

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

src/Sentry/SentryLaravel/SentryLaravelEventHandler.php

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
use Illuminate\Routing\Route;
88
use Illuminate\Log\Events\MessageLogged;
99
use Illuminate\Auth\Events\Authenticated;
10+
use Illuminate\Queue\Events\JobProcessed;
11+
use Illuminate\Queue\Events\JobProcessing;
1012
use Illuminate\Routing\Events\RouteMatched;
1113
use Illuminate\Contracts\Events\Dispatcher;
1214
use Illuminate\Database\Events\QueryExecuted;
@@ -27,6 +29,9 @@ class SentryLaravelEventHandler
2729

2830
'illuminate.log' => 'log', // Until Laravel 5.3
2931
'Illuminate\Log\Events\MessageLogged' => 'messageLogged', // Since Laravel 5.4
32+
33+
'Illuminate\Queue\Events\JobProcessed' => 'queueJobProcessed', // since Laravel 5.2
34+
'Illuminate\Queue\Events\JobProcessing' => 'queueJobProcessing', // since Laravel 5.2
3035
);
3136

3237
/**
@@ -234,4 +239,42 @@ protected function authenticatedHandler(Authenticated $event)
234239
'id' => $event->user->getAuthIdentifier(),
235240
));
236241
}
242+
243+
/**
244+
* Since Laravel 5.2
245+
*
246+
* @param \Illuminate\Queue\Events\JobProcessed $event
247+
*/
248+
protected function queueJobProcessedHandler(JobProcessed $event)
249+
{
250+
$this->client->sendUnsentErrors();
251+
252+
$this->client->breadcrumbs->reset();
253+
}
254+
255+
/**
256+
* Since Laravel 5.2
257+
*
258+
* @param \Illuminate\Queue\Events\JobProcessing $event
259+
*/
260+
protected function queueJobProcessingHandler(JobProcessing $event)
261+
{
262+
$job = [
263+
'job' => $event->job->getName(),
264+
'queue' => $event->job->getQueue(),
265+
'attempts' => $event->job->attempts(),
266+
'connection' => $event->connectionName,
267+
];
268+
269+
// Resolve name exists only from Laravel 5.3+
270+
if (method_exists($event->job, 'resolveName')) {
271+
$job['resolved'] = $event->job->resolveName();
272+
}
273+
274+
$this->client->breadcrumbs->record([
275+
'category' => 'queue.job',
276+
'message' => 'Processing queue job',
277+
'data' => $job,
278+
]);
279+
}
237280
}

0 commit comments

Comments
 (0)