17
17
use Illuminate \Queue \Events \JobProcessing ;
18
18
use Illuminate \Queue \Events \WorkerStopping ;
19
19
use Illuminate \Queue \QueueManager ;
20
- use Laravel \Octane \Events as Octane ;
21
20
use Illuminate \Routing \Events \RouteMatched ;
22
21
use Illuminate \Routing \Route ;
22
+ use Laravel \Octane \Events as Octane ;
23
+ use Laravel \Sanctum \Events as Sanctum ;
23
24
use RuntimeException ;
24
25
use Sentry \Breadcrumb ;
25
26
use Sentry \SentrySdk ;
@@ -33,14 +34,14 @@ class EventHandler
33
34
* @var array
34
35
*/
35
36
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
38
39
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
41
42
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
44
45
45
46
'Illuminate\Console\Events\CommandStarting ' => 'commandStarting ' , // Since Laravel 5.5
46
47
'Illuminate\Console\Events\CommandFinished ' => 'commandFinished ' , // Since Laravel 5.5
@@ -52,7 +53,8 @@ class EventHandler
52
53
* @var array
53
54
*/
54
55
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
56
58
];
57
59
58
60
/**
@@ -61,10 +63,10 @@ class EventHandler
61
63
* @var array
62
64
*/
63
65
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
66
69
'Illuminate\Queue\Events\JobExceptionOccurred ' => 'queueJobExceptionOccurred ' , // Since Laravel 5.2
67
- 'Illuminate\Queue\Events\WorkerStopping ' => 'queueWorkerStopping ' , // Since Laravel 5.2
68
70
];
69
71
70
72
/**
@@ -73,17 +75,17 @@ class EventHandler
73
75
* @var array
74
76
*/
75
77
protected static $ octaneEventHandlerMap = [
76
- 'Laravel\Octane\Events\RequestReceived ' => 'octaneRequestReceived ' ,
78
+ 'Laravel\Octane\Events\RequestReceived ' => 'octaneRequestReceived ' ,
77
79
'Laravel\Octane\Events\RequestTerminated ' => 'octaneRequestTerminated ' ,
78
80
79
- 'Laravel\Octane\Events\TaskReceived ' => 'octaneTaskReceived ' ,
81
+ 'Laravel\Octane\Events\TaskReceived ' => 'octaneTaskReceived ' ,
80
82
'Laravel\Octane\Events\TaskTerminated ' => 'octaneTaskTerminated ' ,
81
83
82
- 'Laravel\Octane\Events\TickReceived ' => 'octaneTickReceived ' ,
84
+ 'Laravel\Octane\Events\TickReceived ' => 'octaneTickReceived ' ,
83
85
'Laravel\Octane\Events\TickTerminated ' => 'octaneTickTerminated ' ,
84
86
85
87
'Laravel\Octane\Events\WorkerErrorOccurred ' => 'octaneWorkerErrorOccurred ' ,
86
- 'Laravel\Octane\Events\WorkerStopping ' => 'octaneWorkerStopping ' ,
88
+ 'Laravel\Octane\Events\WorkerStopping ' => 'octaneWorkerStopping ' ,
87
89
];
88
90
89
91
/**
@@ -166,11 +168,11 @@ public function __construct(Container $container, array $config)
166
168
{
167
169
$ this ->container = $ container ;
168
170
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 ;
174
176
$ this ->recordOctaneTickInfo = ($ config ['breadcrumbs.octane_tick_info ' ] ?? $ config ['breadcrumbs ' ]['octane_tick_info ' ] ?? true ) === true ;
175
177
$ this ->recordOctaneTaskInfo = ($ config ['breadcrumbs.octane_task_info ' ] ?? $ config ['breadcrumbs ' ]['octane_task_info ' ] ?? true ) === true ;
176
178
}
@@ -419,10 +421,32 @@ private function addLogBreadcrumb(string $level, ?string $message, array $contex
419
421
*/
420
422
protected function authenticatedHandler (Authenticated $ event )
421
423
{
422
- $ userData = [
424
+ $ this -> configureUserScopeWithRequest ( [
423
425
'id ' => $ event ->user ->getAuthIdentifier (),
424
- ];
426
+ ]);
427
+ }
425
428
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
+ {
426
450
try {
427
451
/** @var \Illuminate\Http\Request $request */
428
452
$ request = $ this ->container ->make ('request ' );
@@ -461,9 +485,9 @@ protected function queueJobProcessingHandler(JobProcessing $event)
461
485
}
462
486
463
487
$ 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 (),
467
491
'connection ' => $ event ->connectionName ,
468
492
];
469
493
0 commit comments