@@ -216,29 +216,43 @@ public function __construct(?callable $callback)
216
216
217
217
public function __invoke (Model $ model , string $ relation ): void
218
218
{
219
- SentrySdk::getCurrentHub ()->withScope (function (Scope $ scope ) use ($ model , $ relation ) {
220
- $ scope ->setContext ('violation ' , [
221
- 'model ' => get_class ($ model ),
222
- 'relation ' => $ relation ,
223
- 'origin ' => $ this ->resolveEventOrigin (),
219
+ $ currentSpan = SentrySdk::getCurrentHub ()->getSpan ();
220
+
221
+ if ($ currentSpan !== null ) {
222
+ $ currentSpan ->setData ([
223
+ 'lazy_loading_violation ' => [
224
+ 'model ' => get_class ($ model ),
225
+ 'relation ' => $ relation ,
226
+ 'origin ' => $ this ->resolveEventOrigin (),
227
+ ],
224
228
]);
229
+ }
225
230
226
- SentrySdk::getCurrentHub ()->captureEvent (
227
- tap (Event::createEvent (), static function (Event $ event ) {
228
- $ event ->setLevel (Severity::warning ());
229
- }),
230
- EventHint::fromArray ([
231
- 'exception ' => new LazyLoadingViolationException ($ model , $ relation ),
232
- 'mechanism ' => new ExceptionMechanism (ExceptionMechanism::TYPE_GENERIC , true ),
233
- ])
234
- );
235
- });
231
+ // @TODO: We are currently reporting the violation on the current span, but we might want to give users the option to report it as a separate event?
232
+ // SentrySdk::getCurrentHub()->withScope(function (Scope $scope) use ($model, $relation) {
233
+ // $scope->setContext('violation', [
234
+ // 'model' => get_class($model),
235
+ // 'relation' => $relation,
236
+ // 'origin' => $this->resolveEventOrigin(),
237
+ // ]);
238
+ //
239
+ // SentrySdk::getCurrentHub()->captureEvent(
240
+ // tap(Event::createEvent(), static function (Event $event) {
241
+ // $event->setLevel(Severity::warning());
242
+ // }),
243
+ // EventHint::fromArray([
244
+ // 'exception' => new LazyLoadingViolationException($model, $relation),
245
+ // 'mechanism' => new ExceptionMechanism(ExceptionMechanism::TYPE_GENERIC, true),
246
+ // ])
247
+ // );
248
+ // });
236
249
237
250
// Forward the violation to the next handler if there is one
238
251
if ($ this ->callback !== null ) {
239
252
call_user_func ($ this ->callback , $ model , $ relation );
240
253
}
241
254
}
255
+
242
256
};
243
257
}
244
258
0 commit comments