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