@@ -111,14 +111,24 @@ public function onKernelException(GetResponseForExceptionEvent $event): void
111
111
return ;
112
112
}
113
113
114
+ $ this ->eventDispatcher ->dispatch (SentrySymfonyEvents::PRE_CAPTURE , $ event );
115
+ $ this ->client ->captureException ($ exception , $ this ->getExceptionData ());
116
+ }
117
+
118
+ /**
119
+ * Additional attributes to pass with this event (see Sentry docs).
120
+ *
121
+ * @return array
122
+ */
123
+ protected function getExceptionData ()
124
+ {
114
125
$ data = ['tags ' => []];
115
126
$ request = $ this ->requestStack ->getCurrentRequest ();
116
127
if ($ request instanceof Request) {
117
128
$ data ['tags ' ]['route ' ] = $ request ->attributes ->get ('_route ' );
118
129
}
119
130
120
- $ this ->eventDispatcher ->dispatch (SentrySymfonyEvents::PRE_CAPTURE , $ event );
121
- $ this ->client ->captureException ($ exception , $ data );
131
+ return $ data ;
122
132
}
123
133
124
134
/**
@@ -188,9 +198,11 @@ protected function shouldExceptionCaptureBeSkipped(\Throwable $exception): bool
188
198
}
189
199
190
200
/**
191
- * @param UserInterface | object | string $user
201
+ * Additional user data
202
+ *
203
+ * @return array
192
204
*/
193
- protected function setUserValue ( $ user )
205
+ protected function getUserData ( )
194
206
{
195
207
$ data = [];
196
208
@@ -199,20 +211,28 @@ protected function setUserValue($user)
199
211
$ data ['ip_address ' ] = $ request ->getClientIp ();
200
212
}
201
213
214
+ return $ data ;
215
+ }
216
+
217
+ /**
218
+ * @param UserInterface | object | string $user
219
+ */
220
+ protected function setUserValue ($ user )
221
+ {
202
222
if ($ user instanceof UserInterface) {
203
- $ this ->client ->set_user_data ($ user ->getUsername (), null , $ data );
223
+ $ this ->client ->set_user_data ($ user ->getUsername (), null , $ this -> getUserData () );
204
224
205
225
return ;
206
226
}
207
227
208
228
if (is_string ($ user )) {
209
- $ this ->client ->set_user_data ($ user , null , $ data );
229
+ $ this ->client ->set_user_data ($ user , null , $ this -> getUserData () );
210
230
211
231
return ;
212
232
}
213
233
214
234
if (is_object ($ user ) && method_exists ($ user , '__toString ' )) {
215
- $ this ->client ->set_user_data ((string )$ user , null , $ data );
235
+ $ this ->client ->set_user_data ((string )$ user , null , $ this -> getUserData () );
216
236
}
217
237
}
218
238
}
0 commit comments