-
-
Notifications
You must be signed in to change notification settings - Fork 201
Open
Description
How do you use Sentry?
Sentry SaaS (sentry.io)
SDK version
Laravel SDK Version 4.19.0 PHP SDK Version 4.18.1
Laravel version
11.46.1
Steps to reproduce
-
Install Laravel and Sentry
composer require sentry/sentry-laravel -
Set a non-closure callback for before_send in config/sentry.php
'before_send' => ['App\Helpers\Sentry', 'beforeCall'] -
Create the callback class with strict type hints
<?php
namespace App\Helpers;
class Sentry
{
/**
* Create a new class instance.
*/
public static function beforeCall(?\Sentry\Event $event, ?\Sentry\EventHint $hint): ?\Sentry\Event
{
dd(1);
if ($hint === null) {
return $event;
}
if (!isset($hint->exception) || !method_exists($hint->exception, 'getTrace')) {
return $event;
}
$isJob = false;
foreach ($hint->exception->getTrace() as $trace) {
$isJob = isset($trace['class']) && str_contains($trace['class'], 'App\\Jobs\\');
if ($isJob) {
break;
}
}
// If it's a job, sample ~10%
if ($isJob && mt_rand(1, 100) > env('SENTRY_JOB_SAMPLE_RATE', 0.1) * 100) {
return null;
}
return $event;
}
}
- Trigger any exception
→ Sentry receives the event correctly.
- Run Laravel optimization
php artisan optimize
- Trigger the same exception again
→ Sentry does not send the event anymore.
→ The before_send callback is silently skipped.
(bypasses the beforeCall callback at step 4 and shows the exception directly)
- Clear optimization
php artisan optimize:clear
→ Sentry starts working normally again.
Expected result
The before_send callback should execute normally even when configuration is cached.
Running php artisan optimize should not disable or bypass the callback.
Actual result
After running php artisan optimize, the callback is not executed.
No events are sent to Sentry.
Clearing the optimization cache restores normal behavior.
Metadata
Metadata
Assignees
Projects
Status
No status