Skip to content

Commit e29648b

Browse files
committed
Report violation on performance span instead
1 parent 325cf23 commit e29648b

File tree

1 file changed

+29
-15
lines changed

1 file changed

+29
-15
lines changed

src/Sentry/Laravel/Integration.php

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -216,29 +216,43 @@ public function __construct(?callable $callback)
216216

217217
public function __invoke(Model $model, string $relation): void
218218
{
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+
],
224228
]);
229+
}
225230

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+
// });
236249

237250
// Forward the violation to the next handler if there is one
238251
if ($this->callback !== null) {
239252
call_user_func($this->callback, $model, $relation);
240253
}
241254
}
255+
242256
};
243257
}
244258

0 commit comments

Comments
 (0)