laravelsentry

How to write custom message into Sentry with tag?


On Laravel 11 site I want to write message into sentry with tag "InvalidDataEvent" in event handler.

Googling I found page Laravel and Sentry: How to set a custom tag in Sentry?

and make in event handler :

public function handle(InvalidDataEvent $event): void
{
    $errorMessage = 'Invalid Data Event: ' . $event->message;
    if (app()->bound('sentry')) {
        app('sentry')->withScope(function (\Sentry\State\Scope $scope) use ($errorMessage): void {
            $scope->setLevel(\Sentry\Severity::warning());

            // ERROR POINTING AT ROW BELOW
            $scope->setTag('InvalidDataEvent', app(\Illuminate\Http\Request::class)->headers->get('InvalidDataEvent'));

            app('sentry')->captureException($errorMessage);
        });
    }
    /* Sentry\State\Scope::setTag(): Argument #2 ($value) must be of type string, null given, called in /Project/app/Listeners/InvalidDataListener.php on line 26 */

    if(App::isLocal()) {
        throw new \ErrorException($errorMessage);
    }

}

But error raised :

Sentry\State\Scope::setTag(): Argument #2 ($value) must be of type string, null given, called in /Project/app/Listeners/InvalidDataListener.php on line 26

a) Not sure what is $value var and how to fix it ?
b) how to convert string $errorMessage into Throwable class in line :

app('sentry')->captureException($errorMessage);

?

REMADE BLOCK:

I remade in event handler :

if (app()->bound('sentry')) {
    app('sentry')->withScope(function (\Sentry\State\Scope $scope) use ($errorMessage): void {


        $customEvent = app(Request::class)->headers->get('YOUR_CUSTOM_EVENT', 'DTag');
        \Log::info($customEvent); // In log file I see value "DTag" - so this code is run
        $scope->setTag('YOUR_CUSTOM_EVENT', $customEvent);


        app('sentry')->captureException(new \Exception($errorMessage));
    });
}

But in sentry.io/projects/myproject/ console I did not find any new events, only old events from yesterday which were defined in bootstrap/app.php:

return Application::configure(basePath: dirname(__DIR__))
    ->withRouting(
        web: __DIR__ . '/../routes/web.php',
        commands: __DIR__ . '/../routes/console.php',
        health: '/up',
    )

    ->withMiddleware(function (Middleware $middleware) {
        $middleware->alias([
            'checkAuthPermissions' => CheckAuthPermissionsMiddleware::class
        ]);
                })
    ->withExceptions(function (Exceptions $exceptions) {
        Integration::handles($exceptions);
    })->create();

after I have installed the package...

PS. Please point to related manuals - I searched without success...

"laravel/framework": "^11.9",
"sentry/sentry-laravel": "^4.7",

CHECKS BLOCK:

Sure in .env file I have :

SENTRY_LARAVEL_DSN=https://XXXX.ingest.us.sentry.io/XXX
SENTRY_TRACES_SAMPLE_RATE=1.0
VITE_SENTRY_DSN_PUBLIC="${SENTRY_LARAVEL_DSN}"

In config/sentry.php (I did not modify it yet):

<?php

/**
 * Sentry Laravel SDK configuration file.
 *
 * @see https://docs.sentry.io/platforms/php/guides/laravel/configuration/options/
 */
return [

    // @see https://docs.sentry.io/product/sentry-basics/dsn-explainer/
    'dsn' => env('SENTRY_LARAVEL_DSN', env('SENTRY_DSN')),

    // @see https://spotlightjs.com/
    // 'spotlight' => env('SENTRY_SPOTLIGHT', false),

    // @see: https://docs.sentry.io/platforms/php/guides/laravel/configuration/options/#logger
    // 'logger' => Sentry\Logger\DebugFileLogger::class, // By default this will log to `storage_path('logs/sentry.log')`

    // The release version of your application
    // Example with dynamic git hash: trim(exec('git --git-dir ' . base_path('.git') . ' log --pretty="%h" -n1 HEAD'))
    'release' => env('SENTRY_RELEASE'),

    // When left empty or `null` the Laravel environment will be used (usually discovered from `APP_ENV` in your `.env`)
    'environment' => env('SENTRY_ENVIRONMENT'),

    // @see: https://docs.sentry.io/platforms/php/guides/laravel/configuration/options/#sample-rate
    'sample_rate' => env('SENTRY_SAMPLE_RATE') === null ? 1.0 : (float)env('SENTRY_SAMPLE_RATE'),

    // @see: https://docs.sentry.io/platforms/php/guides/laravel/configuration/options/#traces-sample-rate
    'traces_sample_rate' => env('SENTRY_TRACES_SAMPLE_RATE') === null ? null : (float)env('SENTRY_TRACES_SAMPLE_RATE'),

    // @see: https://docs.sentry.io/platforms/php/guides/laravel/configuration/options/#profiles-sample-rate
    'profiles_sample_rate' => env('SENTRY_PROFILES_SAMPLE_RATE') === null ? null : (float)env('SENTRY_PROFILES_SAMPLE_RATE'),

    // @see: https://docs.sentry.io/platforms/php/guides/laravel/configuration/options/#send-default-pii
    'send_default_pii' => env('SENTRY_SEND_DEFAULT_PII', false),

    // @see: https://docs.sentry.io/platforms/php/guides/laravel/configuration/options/#ignore-exceptions
    // 'ignore_exceptions' => [],

    // @see: https://docs.sentry.io/platforms/php/guides/laravel/configuration/options/#ignore-transactions
    'ignore_transactions' => [
        // Ignore Laravel's default health URL
        '/up',
    ],

    // Breadcrumb specific configuration
    'breadcrumbs' => [
        // Capture Laravel logs as breadcrumbs
        'logs' => env('SENTRY_BREADCRUMBS_LOGS_ENABLED', true),

        // Capture Laravel cache events (hits, writes etc.) as breadcrumbs
        'cache' => env('SENTRY_BREADCRUMBS_CACHE_ENABLED', true),

        // Capture Livewire components like routes as breadcrumbs
        'livewire' => env('SENTRY_BREADCRUMBS_LIVEWIRE_ENABLED', true),

        // Capture SQL queries as breadcrumbs
        'sql_queries' => env('SENTRY_BREADCRUMBS_SQL_QUERIES_ENABLED', true),

        // Capture SQL query bindings (parameters) in SQL query breadcrumbs
        'sql_bindings' => env('SENTRY_BREADCRUMBS_SQL_BINDINGS_ENABLED', false),

        // Capture queue job information as breadcrumbs
        'queue_info' => env('SENTRY_BREADCRUMBS_QUEUE_INFO_ENABLED', true),

        // Capture command information as breadcrumbs
        'command_info' => env('SENTRY_BREADCRUMBS_COMMAND_JOBS_ENABLED', true),

        // Capture HTTP client request information as breadcrumbs
        'http_client_requests' => env('SENTRY_BREADCRUMBS_HTTP_CLIENT_REQUESTS_ENABLED', true),

        // Capture send notifications as breadcrumbs
        'notifications' => env('SENTRY_BREADCRUMBS_NOTIFICATIONS_ENABLED', true),
    ],

    // Performance monitoring specific configuration
    'tracing' => [
        // Trace queue jobs as their own transactions (this enables tracing for queue jobs)
        'queue_job_transactions' => env('SENTRY_TRACE_QUEUE_ENABLED', true),

        // Capture queue jobs as spans when executed on the sync driver
        'queue_jobs' => env('SENTRY_TRACE_QUEUE_JOBS_ENABLED', true),

        // Capture SQL queries as spans
        'sql_queries' => env('SENTRY_TRACE_SQL_QUERIES_ENABLED', true),

        // Capture SQL query bindings (parameters) in SQL query spans
        'sql_bindings' => env('SENTRY_TRACE_SQL_BINDINGS_ENABLED', false),

        // Capture where the SQL query originated from on the SQL query spans
        'sql_origin' => env('SENTRY_TRACE_SQL_ORIGIN_ENABLED', true),

        // Define a threshold in milliseconds for SQL queries to resolve their origin
        'sql_origin_threshold_ms' => env('SENTRY_TRACE_SQL_ORIGIN_THRESHOLD_MS', 100),

        // Capture views rendered as spans
        'views' => env('SENTRY_TRACE_VIEWS_ENABLED', true),

        // Capture Livewire components as spans
        'livewire' => env('SENTRY_TRACE_LIVEWIRE_ENABLED', true),

        // Capture HTTP client requests as spans
        'http_client_requests' => env('SENTRY_TRACE_HTTP_CLIENT_REQUESTS_ENABLED', true),

        // Capture Laravel cache events (hits, writes etc.) as spans
        'cache' => env('SENTRY_TRACE_CACHE_ENABLED', true),

        // Capture Redis operations as spans (this enables Redis events in Laravel)
        'redis_commands' => env('SENTRY_TRACE_REDIS_COMMANDS', false),

        // Capture where the Redis command originated from on the Redis command spans
        'redis_origin' => env('SENTRY_TRACE_REDIS_ORIGIN_ENABLED', true),

        // Capture send notifications as spans
        'notifications' => env('SENTRY_TRACE_NOTIFICATIONS_ENABLED', true),

        // Enable tracing for requests without a matching route (404's)
        'missing_routes' => env('SENTRY_TRACE_MISSING_ROUTES_ENABLED', false),

        // Configures if the performance trace should continue after the response has been sent to the user until the application terminates
        // This is required to capture any spans that are created after the response has been sent like queue jobs dispatched using `dispatch(...)->afterResponse()` for example
        'continue_after_response' => env('SENTRY_TRACE_CONTINUE_AFTER_RESPONSE', true),

        // Enable the tracing integrations supplied by Sentry (recommended)
        'default_integrations' => env('SENTRY_TRACE_DEFAULT_INTEGRATIONS_ENABLED', true),
    ],

];

In config/app.php - no "sentry" lines:

Sure I have cleared config.

bootstrap/app.php:

->withMiddleware(function (Middleware $middleware) {
    $middleware->alias([
        'checkAuthPermissions' => CheckAuthPermissionsMiddleware::class
    ]);
            })

->withExceptions(function (Exceptions $exceptions) {
    Integration::handles($exceptions);
})->create();


Which options Did I miss ?  Especailly in config/app.php ?

REMADE BLOCK # 2:

After I added Sentry alias into config/app.php file and ServiceProvider into bootstrap/providers.php file example :

Route::get('/check-sentry', function () {
    if (app()->bound('sentry')) {
        app('sentry')->captureException(new \Exception('There is a exception on Sentry check'));
    }
    return 'Sentry is working well';
});

works ok.

But when I try to add custom tag to this code :

Route::get('/check-sentry', function () {
    if (app()->bound('sentry')) {

        app('sentry')->withScope(function (\Sentry\State\Scope $scope) use ($errorMessage): void {
                $scope->setLevel(\Sentry\Severity::warning());

            $customEvent = app(Request::class)->headers->get('YOUR_CUSTOM_EVENT', 'DTag');
            $scope->setTag('YOUR_CUSTOM_EVENT', $customEvent);

            app('sentry')->captureException(new \Exception('There is a exception on Sentry check'));
        });

    }
    return 'Sentry is working well';
});

I got error :

[2024-08-13 09:23:13] local.ERROR: Undefined property: Illuminate\Support\Facades\Request::$headers {"userId":1,"exception":"[object] (ErrorException(code: 0): Undefined property: Illuminate\\Support\\Facades\\Request::$headers at laravel-serializable-closure://function () {
    if (\\app()->bound('sentry')) {

        \\app('sentry')->withScope(function (\\Sentry\\State\\Scope $scope): void {
                $scope->setLevel(\\Sentry\\Severity::warning());
            $customEvent = \\app(\\Request::class)->headers->get('YOUR_CUSTOM_EVENT', 'DTag');
            $scope->setTag('YOUR_CUSTOM_EVENT', $customEvent);

            \\app('sentry')->captureException(new \\Exception('There is a exception on Sentry check'));
        });

    }
    return 'Sentry is working well';
}:7)
[stacktrace]
#0 /projectPath/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php(256): Illuminate\\Foundation\\Bootstrap\\HandleExceptions->handleError()
#1 laravel-serializable-closure://function () {
    if (\\app()->bound('sentry')) {

        \\app('sentry')->withScope(function (\\Sentry\\State\\Scope $scope): void {
                $scope->setLevel(\\Sentry\\Severity::warning());
            $customEvent = \\app(\\Request::class)->headers->get('YOUR_CUSTOM_EVENT', 'DTag');
            $scope->setTag('YOUR_CUSTOM_EVENT', $customEvent);

            \\app('sentry')->captureException(new \\Exception('There is a exception on Sentry check'));
        });

    }
    return 'Sentry is working well';
}(7): Illuminate\\Foundation\\Bootstrap\\HandleExceptions->Illuminate\\Foundation\\Bootstrap\\{closure}()
#2 /projectPath/vendor/sentry/sentry/src/State/Hub.php(97): Illuminate\\Routing\\RouteFileRegistrar::{closure}()
#3 laravel-serializable-closure://function () {
    if (\\app()->bound('sentry')) {

        \\app('sentry')->withScope(function (\\Sentry\\State\\Scope $scope): void {
                $scope->setLevel(\\Sentry\\Severity::warning());
            $customEvent = \\app(\\Request::class)->headers->get('YOUR_CUSTOM_EVENT', 'DTag');
            $scope->setTag('YOUR_CUSTOM_EVENT', $customEvent);

            \\app('sentry')->captureException(new \\Exception('There is a exception on Sentry check'));
        });

    }
    return 'Sentry is working well';
}(5): Sentry\\State\\Hub->withScope()
#4 /projectPath/vendor/laravel/framework/src/Illuminate/Routing/CallableDispatcher.php(40): Illuminate\\Routing\\RouteFileRegistrar::{closure}()
#5 /projectPath/vendor/sentry/sentry-laravel/src/Sentry/Laravel/Tracing/Routing/TracingCallableDispatcherTracing.php(21): Illuminate\\Routing\\CallableDispatcher->dispatch()
#6 /projectPath/vendor/sentry/sentry-laravel/src/Sentry/Laravel/Tracing/Routing/TracingRoutingDispatcher.php(34): Sentry\\Laravel\\Tracing\\Routing\\TracingCallableDispatcherTracing->Sentry\\Laravel\\Tracing\\Routing\\{closure}()
#7 /projectPath/vendor/sentry/sentry-laravel/src/Sentry/Laravel/Tracing/Routing/TracingCallableDispatcherTracing.php(20): Sentry\\Laravel\\Tracing\\Routing\\TracingRoutingDispatcher->wrapRouteDispatch()
#8 /projectPath/vendor/laravel/framework/src/Illuminate/Routing/Route.php(238): Sentry\\Laravel\\Tracing\\Routing\\TracingCallableDispatcherTracing->dispatch()
#9 /projectPath/vendor/laravel/framework/src/Illuminate/Routing/Route.php(209): Illuminate\\Routing\\Route->runCallable()
#10 /projectPath/vendor/laravel/framework/src/Illuminate/Routing/Router.php(808): Illuminate\\Routing\\Route->run()
#11 /projectPath/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(144): Illuminate\\Routing\\Router->Illuminate\\Routing\\{closure}()
#12 /projectPath/vendor/laravel/framework/src/Illuminate/Routing/Middleware/SubstituteBindings.php(50): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#13 /projectPath/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(183): Illuminate\\Routing\\Middleware\\SubstituteBindings->handle()
#14 /projectPath/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/VerifyCsrfToken.php(88): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#15 /projectPath/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(183): Illuminate\\Foundation\\Http\\Middleware\\VerifyCsrfToken->handle()
#16 /projectPath/vendor/laravel/framework/src/Illuminate/View/Middleware/ShareErrorsFromSession.php(49): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#17 /projectPath/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(183): Illuminate\\View\\Middleware\\ShareErrorsFromSession->handle()
#18 /projectPath/vendor/laravel/framework/src/Illuminate/Session/Middleware/StartSession.php(121): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#19 /projectPath/vendor/laravel/framework/src/Illuminate/Session/Middleware/StartSession.php(64): Illuminate\\Session\\Middleware\\StartSession->handleStatefulRequest()
#20 /projectPath/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(183): Illuminate\\Session\\Middleware\\StartSession->handle()
#21 /projectPath/vendor/laravel/framework/src/Illuminate/Cookie/Middleware/AddQueuedCookiesToResponse.php(37): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#22 /projectPath/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(183): Illuminate\\Cookie\\Middleware\\AddQueuedCookiesToResponse->handle()
#23 /projectPath/vendor/laravel/framework/src/Illuminate/Cookie/Middleware/EncryptCookies.php(75): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#24 /projectPath/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(183): Illuminate\\Cookie\\Middleware\\EncryptCookies->handle()
#25 /projectPath/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(119): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#26 /projectPath/vendor/laravel/framework/src/Illuminate/Routing/Router.php(807): Illuminate\\Pipeline\\Pipeline->then()
#27 /projectPath/vendor/laravel/framework/src/Illuminate/Routing/Router.php(786): Illuminate\\Routing\\Router->runRouteWithinStack()
#28 /projectPath/vendor/laravel/framework/src/Illuminate/Routing/Router.php(750): Illuminate\\Routing\\Router->runRoute()
#29 /projectPath/vendor/laravel/framework/src/Illuminate/Routing/Router.php(739): Illuminate\\Routing\\Router->dispatchToRoute()
#30 /projectPath/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(201): Illuminate\\Routing\\Router->dispatch()
#31 /projectPath/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(144): Illuminate\\Foundation\\Http\\Kernel->Illuminate\\Foundation\\Http\\{closure}()
#32 /projectPath/vendor/sentry/sentry-laravel/src/Sentry/Laravel/Http/FlushEventsMiddleware.php(13): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#33 /projectPath/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(183): Sentry\\Laravel\\Http\\FlushEventsMiddleware->handle()
#34 /projectPath/vendor/sentry/sentry-laravel/src/Sentry/Laravel/Http/SetRequestIpMiddleware.php(45): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#35 /projectPath/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(183): Sentry\\Laravel\\Http\\SetRequestIpMiddleware->handle()
#36 /projectPath/vendor/sentry/sentry-laravel/src/Sentry/Laravel/Http/SetRequestMiddleware.php(31): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#37 /projectPath/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(183): Sentry\\Laravel\\Http\\SetRequestMiddleware->handle()
#38 /projectPath/vendor/livewire/livewire/src/Features/SupportDisablingBackButtonCache/DisableBackButtonCacheMiddleware.php(19): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#39 /projectPath/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(183): Livewire\\Features\\SupportDisablingBackButtonCache\\DisableBackButtonCacheMiddleware->handle()
#40 /projectPath/vendor/barryvdh/laravel-debugbar/src/Middleware/InjectDebugbar.php(59): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#41 /projectPath/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(183): Barryvdh\\Debugbar\\Middleware\\InjectDebugbar->handle()
#42 /projectPath/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php(21): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#43 /projectPath/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/ConvertEmptyStringsToNull.php(31): Illuminate\\Foundation\\Http\\Middleware\\TransformsRequest->handle()
#44 /projectPath/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(183): Illuminate\\Foundation\\Http\\Middleware\\ConvertEmptyStringsToNull->handle()
#45 /projectPath/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php(21): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#46 /projectPath/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TrimStrings.php(51): Illuminate\\Foundation\\Http\\Middleware\\TransformsRequest->handle()
#47 /projectPath/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(183): Illuminate\\Foundation\\Http\\Middleware\\TrimStrings->handle()
#48 /projectPath/vendor/laravel/framework/src/Illuminate/Http/Middleware/ValidatePostSize.php(27): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#49 /projectPath/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(183): Illuminate\\Http\\Middleware\\ValidatePostSize->handle()
#50 /projectPath/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/PreventRequestsDuringMaintenance.php(110): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#51 /projectPath/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(183): Illuminate\\Foundation\\Http\\Middleware\\PreventRequestsDuringMaintenance->handle()
#52 /projectPath/vendor/laravel/framework/src/Illuminate/Http/Middleware/HandleCors.php(49): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#53 /projectPath/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(183): Illuminate\\Http\\Middleware\\HandleCors->handle()
#54 /projectPath/vendor/laravel/framework/src/Illuminate/Http/Middleware/TrustProxies.php(57): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#55 /projectPath/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(183): Illuminate\\Http\\Middleware\\TrustProxies->handle()
#56 /projectPath/vendor/sentry/sentry-laravel/src/Sentry/Laravel/Tracing/Middleware.php(86): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#57 /projectPath/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(183): Sentry\\Laravel\\Tracing\\Middleware->handle()
#58 /projectPath/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(119): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#59 /projectPath/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(176): Illuminate\\Pipeline\\Pipeline->then()
#60 /projectPath/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(145): Illuminate\\Foundation\\Http\\Kernel->sendRequestThroughRouter()
#61 /projectPath/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(1188): Illuminate\\Foundation\\Http\\Kernel->handle()
#62 /projectPath/public/index.php(17): Illuminate\\Foundation\\Application->handleRequest()
#63 {main}
"}

PS. I try to add error message and tag in one request... Is it correct?


Solution

  • Your setTag doesnt work may be due to sometimes InvalidDataEvent value doesnt available in the request. so in order to resolve you can pass the default value to your InvalidDataEvent

    $customEvent = app(Request::class)->headers->get('YOUR_CUSTOM_EVENT', 'DTag');
    
    $scope->setTag('YOUR_CUSTOM_EVENT', $customEvent);
    

    If the Invalid Data Event is missing then it will use DTag

    and then generate a thrwable exception from a error message

    $throwableException = new \Exception($errorMessage);
    
    app('sentry')->captureException($throwableException);
    

    config/app.php

    'providers' => [
        Sentry\Laravel\ServiceProvider::class,
    ],
    
    'aliases' => [
        'Sentry' => Sentry\Laravel\Facade::class,
    ],
    

    Check sentry using route

    Route::get('/check-sentry', function () {
        if (app()->bound('sentry')) {
            app('sentry')->captureException(new \Exception('There is a exception on Sentry check'));
        }
        return 'Sentry is working well';
    });