1717use Illuminate \Queue \Events \JobProcessing ;
1818use Illuminate \Queue \Events \WorkerStopping ;
1919use Illuminate \Queue \QueueManager ;
20- use Laravel \Octane \Events as Octane ;
2120use Illuminate \Routing \Events \RouteMatched ;
2221use Illuminate \Routing \Route ;
22+ use Laravel \Octane \Events as Octane ;
23+ use Laravel \Sanctum \Events as Sanctum ;
2324use RuntimeException ;
2425use Sentry \Breadcrumb ;
2526use Sentry \SentrySdk ;
@@ -33,14 +34,14 @@ class EventHandler
3334 * @var array
3435 */
3536 protected static $ eventHandlerMap = [
36- 'router.matched ' => 'routerMatched ' , // Until Laravel 5.1
37- 'Illuminate\Routing\Events\RouteMatched ' => 'routeMatched ' , // Since Laravel 5.2
37+ 'router.matched ' => 'routerMatched ' , // Until Laravel 5.1
38+ 'Illuminate\Routing\Events\RouteMatched ' => 'routeMatched ' , // Since Laravel 5.2
3839
39- 'illuminate.query ' => 'query ' , // Until Laravel 5.1
40- 'Illuminate\Database\Events\QueryExecuted ' => 'queryExecuted ' , // Since Laravel 5.2
40+ 'illuminate.query ' => 'query ' , // Until Laravel 5.1
41+ 'Illuminate\Database\Events\QueryExecuted ' => 'queryExecuted ' , // Since Laravel 5.2
4142
42- 'illuminate.log ' => ' log ' , // Until Laravel 5.3
43- 'Illuminate\Log\Events\MessageLogged ' => 'messageLogged ' , // Since Laravel 5.4
43+ 'illuminate.log ' => ' log ' , // Until Laravel 5.3
44+ 'Illuminate\Log\Events\MessageLogged ' => 'messageLogged ' , // Since Laravel 5.4
4445
4546 'Illuminate\Console\Events\CommandStarting ' => 'commandStarting ' , // Since Laravel 5.5
4647 'Illuminate\Console\Events\CommandFinished ' => 'commandFinished ' , // Since Laravel 5.5
@@ -52,7 +53,8 @@ class EventHandler
5253 * @var array
5354 */
5455 protected static $ authEventHandlerMap = [
55- 'Illuminate\Auth\Events\Authenticated ' => 'authenticated ' , // Since Laravel 5.3
56+ 'Illuminate\Auth\Events\Authenticated ' => 'authenticated ' , // Since Laravel 5.3
57+ 'Laravel\Sanctum\Events\TokenAuthenticated ' => 'sanctumTokenAuthenticated ' , // Since Sanctum 2.13
5658 ];
5759
5860 /**
@@ -61,10 +63,10 @@ class EventHandler
6163 * @var array
6264 */
6365 protected static $ queueEventHandlerMap = [
64- 'Illuminate\Queue\Events\JobProcessing ' => 'queueJobProcessing ' , // Since Laravel 5.2
65- 'Illuminate\Queue\Events\JobProcessed ' => 'queueJobProcessed ' , // Since Laravel 5.2
66+ 'Illuminate\Queue\Events\JobProcessed ' => 'queueJobProcessed ' , // Since Laravel 5.2
67+ 'Illuminate\Queue\Events\JobProcessing ' => 'queueJobProcessing ' , // Since Laravel 5.2
68+ 'Illuminate\Queue\Events\WorkerStopping ' => 'queueWorkerStopping ' , // Since Laravel 5.2
6669 'Illuminate\Queue\Events\JobExceptionOccurred ' => 'queueJobExceptionOccurred ' , // Since Laravel 5.2
67- 'Illuminate\Queue\Events\WorkerStopping ' => 'queueWorkerStopping ' , // Since Laravel 5.2
6870 ];
6971
7072 /**
@@ -73,17 +75,17 @@ class EventHandler
7375 * @var array
7476 */
7577 protected static $ octaneEventHandlerMap = [
76- 'Laravel\Octane\Events\RequestReceived ' => 'octaneRequestReceived ' ,
78+ 'Laravel\Octane\Events\RequestReceived ' => 'octaneRequestReceived ' ,
7779 'Laravel\Octane\Events\RequestTerminated ' => 'octaneRequestTerminated ' ,
7880
79- 'Laravel\Octane\Events\TaskReceived ' => 'octaneTaskReceived ' ,
81+ 'Laravel\Octane\Events\TaskReceived ' => 'octaneTaskReceived ' ,
8082 'Laravel\Octane\Events\TaskTerminated ' => 'octaneTaskTerminated ' ,
8183
82- 'Laravel\Octane\Events\TickReceived ' => 'octaneTickReceived ' ,
84+ 'Laravel\Octane\Events\TickReceived ' => 'octaneTickReceived ' ,
8385 'Laravel\Octane\Events\TickTerminated ' => 'octaneTickTerminated ' ,
8486
8587 'Laravel\Octane\Events\WorkerErrorOccurred ' => 'octaneWorkerErrorOccurred ' ,
86- 'Laravel\Octane\Events\WorkerStopping ' => 'octaneWorkerStopping ' ,
88+ 'Laravel\Octane\Events\WorkerStopping ' => 'octaneWorkerStopping ' ,
8789 ];
8890
8991 /**
@@ -166,11 +168,11 @@ public function __construct(Container $container, array $config)
166168 {
167169 $ this ->container = $ container ;
168170
169- $ this ->recordSqlQueries = ($ config ['breadcrumbs.sql_queries ' ] ?? $ config ['breadcrumbs ' ]['sql_queries ' ] ?? true ) === true ;
170- $ this ->recordSqlBindings = ($ config ['breadcrumbs.sql_bindings ' ] ?? $ config ['breadcrumbs ' ]['sql_bindings ' ] ?? false ) === true ;
171- $ this ->recordLaravelLogs = ($ config ['breadcrumbs.logs ' ] ?? $ config ['breadcrumbs ' ]['logs ' ] ?? true ) === true ;
172- $ this ->recordQueueInfo = ($ config ['breadcrumbs.queue_info ' ] ?? $ config ['breadcrumbs ' ]['queue_info ' ] ?? true ) === true ;
173- $ this ->recordCommandInfo = ($ config ['breadcrumbs.command_info ' ] ?? $ config ['breadcrumbs ' ]['command_info ' ] ?? true ) === true ;
171+ $ this ->recordSqlQueries = ($ config ['breadcrumbs.sql_queries ' ] ?? $ config ['breadcrumbs ' ]['sql_queries ' ] ?? true ) === true ;
172+ $ this ->recordSqlBindings = ($ config ['breadcrumbs.sql_bindings ' ] ?? $ config ['breadcrumbs ' ]['sql_bindings ' ] ?? false ) === true ;
173+ $ this ->recordLaravelLogs = ($ config ['breadcrumbs.logs ' ] ?? $ config ['breadcrumbs ' ]['logs ' ] ?? true ) === true ;
174+ $ this ->recordQueueInfo = ($ config ['breadcrumbs.queue_info ' ] ?? $ config ['breadcrumbs ' ]['queue_info ' ] ?? true ) === true ;
175+ $ this ->recordCommandInfo = ($ config ['breadcrumbs.command_info ' ] ?? $ config ['breadcrumbs ' ]['command_info ' ] ?? true ) === true ;
174176 $ this ->recordOctaneTickInfo = ($ config ['breadcrumbs.octane_tick_info ' ] ?? $ config ['breadcrumbs ' ]['octane_tick_info ' ] ?? true ) === true ;
175177 $ this ->recordOctaneTaskInfo = ($ config ['breadcrumbs.octane_task_info ' ] ?? $ config ['breadcrumbs ' ]['octane_task_info ' ] ?? true ) === true ;
176178 }
@@ -419,10 +421,32 @@ private function addLogBreadcrumb(string $level, ?string $message, array $contex
419421 */
420422 protected function authenticatedHandler (Authenticated $ event )
421423 {
422- $ userData = [
424+ $ this -> configureUserScopeWithRequest ( [
423425 'id ' => $ event ->user ->getAuthIdentifier (),
424- ];
426+ ]);
427+ }
425428
429+ /**
430+ * Since Sanctum 2.13
431+ *
432+ * @param \Laravel\Sanctum\Events\TokenAuthenticated $event
433+ */
434+ protected function sanctumTokenAuthenticatedHandler (Sanctum \TokenAuthenticated $ event )
435+ {
436+ $ this ->configureUserScopeWithRequest ([
437+ 'id ' => $ event ->token ->tokenable ->getAuthIdentifier (),
438+ ]);
439+ }
440+
441+ /**
442+ * Configures the user scope with the user data and values from the HTTP request.
443+ *
444+ * @param array $userData
445+ *
446+ * @return void
447+ */
448+ private function configureUserScopeWithRequest (array $ userData ): void
449+ {
426450 try {
427451 /** @var \Illuminate\Http\Request $request */
428452 $ request = $ this ->container ->make ('request ' );
@@ -461,9 +485,9 @@ protected function queueJobProcessingHandler(JobProcessing $event)
461485 }
462486
463487 $ job = [
464- 'job ' => $ event ->job ->getName (),
465- 'queue ' => $ event ->job ->getQueue (),
466- 'attempts ' => $ event ->job ->attempts (),
488+ 'job ' => $ event ->job ->getName (),
489+ 'queue ' => $ event ->job ->getQueue (),
490+ 'attempts ' => $ event ->job ->attempts (),
467491 'connection ' => $ event ->connectionName ,
468492 ];
469493
0 commit comments