13
13
use Illuminate \Console \Events \CommandStarting ;
14
14
use Illuminate \Console \Events \CommandFinished ;
15
15
use Illuminate \Routing \Route ;
16
+ use RuntimeException ;
16
17
use Sentry \State \Scope ;
17
18
use Sentry \Breadcrumb ;
19
+ use Sentry \State \Hub ;
18
20
19
21
class EventHandler
20
22
{
@@ -98,6 +100,10 @@ public function subscribeAuthEvents(Dispatcher $events)
98
100
*/
99
101
public function __call ($ method , $ arguments )
100
102
{
103
+ if (!method_exists ($ this , $ method . 'handler ' )) {
104
+ throw new RuntimeException ('Missing event handler: ' . $ method . 'handler ' );
105
+ }
106
+
101
107
try {
102
108
call_user_func_array (array ($ this , $ method . 'handler ' ), $ arguments );
103
109
} catch (Exception $ exception ) {
@@ -132,6 +138,7 @@ protected function routerMatchedHandler(Route $route)
132
138
));
133
139
Integration::setTransaction ($ routeName );
134
140
}
141
+
135
142
/**
136
143
* Since Laravel 5.2
137
144
*
@@ -142,7 +149,6 @@ protected function routeMatchedHandler(RouteMatched $match)
142
149
$ this ->routerMatchedHandler ($ match ->route );
143
150
}
144
151
145
-
146
152
/**
147
153
* Since Laravel 5.2
148
154
*
@@ -202,6 +208,9 @@ protected function authenticatedHandler(Authenticated $event)
202
208
*/
203
209
protected function queueJobProcessingHandler (JobProcessing $ event )
204
210
{
211
+ // When a job starts, we want to push a new scope
212
+ Hub::getCurrent ()->pushScope ();
213
+
205
214
$ job = [
206
215
'job ' => $ event ->job ->getName (),
207
216
'queue ' => $ event ->job ->getQueue (),
@@ -223,6 +232,18 @@ protected function queueJobProcessingHandler(JobProcessing $event)
223
232
));
224
233
}
225
234
235
+
236
+ /**
237
+ * Since Laravel 5.2
238
+ *
239
+ * @param \Illuminate\Queue\Events\JobProcessed $event
240
+ */
241
+ protected function queueJobProcessedHandler (JobProcessed $ event )
242
+ {
243
+ // When a job finished, we want to pop the scope
244
+ Hub::getCurrent ()->popScope ();
245
+ }
246
+
226
247
/**
227
248
* Since Laravel 5.5
228
249
*
0 commit comments