1313use Illuminate \Console \Events \CommandStarting ;
1414use Illuminate \Console \Events \CommandFinished ;
1515use Illuminate \Routing \Route ;
16+ use RuntimeException ;
1617use Sentry \State \Scope ;
1718use Sentry \Breadcrumb ;
19+ use Sentry \State \Hub ;
1820
1921class EventHandler
2022{
@@ -98,6 +100,10 @@ public function subscribeAuthEvents(Dispatcher $events)
98100 */
99101 public function __call ($ method , $ arguments )
100102 {
103+ if (!method_exists ($ this , $ method . 'handler ' )) {
104+ throw new RuntimeException ('Missing event handler: ' . $ method . 'handler ' );
105+ }
106+
101107 try {
102108 call_user_func_array (array ($ this , $ method . 'handler ' ), $ arguments );
103109 } catch (Exception $ exception ) {
@@ -132,6 +138,7 @@ protected function routerMatchedHandler(Route $route)
132138 ));
133139 Integration::setTransaction ($ routeName );
134140 }
141+
135142 /**
136143 * Since Laravel 5.2
137144 *
@@ -142,7 +149,6 @@ protected function routeMatchedHandler(RouteMatched $match)
142149 $ this ->routerMatchedHandler ($ match ->route );
143150 }
144151
145-
146152 /**
147153 * Since Laravel 5.2
148154 *
@@ -202,6 +208,9 @@ protected function authenticatedHandler(Authenticated $event)
202208 */
203209 protected function queueJobProcessingHandler (JobProcessing $ event )
204210 {
211+ // When a job starts, we want to push a new scope
212+ Hub::getCurrent ()->pushScope ();
213+
205214 $ job = [
206215 'job ' => $ event ->job ->getName (),
207216 'queue ' => $ event ->job ->getQueue (),
@@ -223,6 +232,18 @@ protected function queueJobProcessingHandler(JobProcessing $event)
223232 ));
224233 }
225234
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+
226247 /**
227248 * Since Laravel 5.5
228249 *
0 commit comments