Movatterモバイル変換


[0]ホーム

URL:


Laravel

Laravel is a PHP web application framework with expressive, elegant syntax. Learn how to set it up with Sentry.

Install thesentry/sentry-laravel package:

Copied
composer require sentry/sentry-laravel

Enable capturing unhandled exception to report to Sentry by making the following change to yourbootstrap/app.php:

bootstrap/app.php
Copied
<?phpuseIlluminate\Foundation\Application;useIlluminate\Foundation\Configuration\Exceptions;useIlluminate\Foundation\Configuration\Middleware;useSentry\Laravel\Integration;returnApplication::configure(basePath:dirname(__DIR__))->withRouting(web:__DIR__.'/../routes/web.php',commands:__DIR__.'/../routes/console.php',health:'/up',)->withMiddleware(function(Middleware$middleware){//})->withExceptions(function(Exceptions$exceptions){Integration::handles($exceptions);})->create();

Alternatively, you can configure Sentry as aLaravel Log Channel.

Configure the Sentry DSN with this command:

Copied
php artisan sentry:publish--dsn=https://examplePublicKey@o0.ingest.sentry.io/0

It creates the config file (config/sentry.php) and adds theDSN to your.env file.

.env
Copied
SENTRY_LARAVEL_DSN=https://examplePublicKey@o0.ingest.sentry.io/0

In order to receive stack trace arguments in your errors, make sure to setzend.exception_ignore_args: Off in your php.ini

You can test your configuration using the providedsentry:test artisan command:

Copied
php artisan sentry:test

You can verify that Sentry is capturing errors in your Laravel application by creating a route that will throw an exception:

routes/web.php
Copied
Route::get('/debug-sentry',function(){thrownewException('My first Sentry error!');});

Visiting this route will trigger an exception that will be captured by Sentry.

Settraces_sample_rate inconfig/sentry.php orSENTRY_TRACES_SAMPLE_RATE in your.env to a value greater than0.0. Setting a value greater than0.0 will enable Tracing,null (the default) will disable Tracing.

.env
Copied
# Be sure to lower this value in production otherwise you could burn through your quota quickly.SENTRY_TRACES_SAMPLE_RATE=1.0

The example configuration above will transmit 100% of captured traces. Be sure to lower this value in production or you could use up your quota quickly.

You can also be more granular with the sample rate by using thetraces_sampler option. Learn more inUsing Sampling to Filter Transaction Events.

Performance data is transmitted using a new event type called "transactions", which you can learn about inDistributed Tracing.

When Sentry is installed in your application, it will also be active when you are developing or running tests.

You most likely don't want errors to be sent to Sentry when you are developing or running tests. To avoid this, set the DSN value tonull to disable sending errors to Sentry.

You can also do this by not definingSENTRY_LARAVEL_DSN in your.env or by defining it asSENTRY_LARAVEL_DSN=null.

If you do leave Sentry enabled when developing or running tests, it's possible for it to have a negative effect on the performance of your application or test suite.

If you're using Laravel's Forge platform to provision and deploy your PHP application, you can create a Sentry organization throughForge.

Sentry and Forge

Was this helpful?
Help improve this content
Our documentation is open source and available on GitHub. Your contributions are welcome, whether fixing a typo (drat!) or suggesting an update ("yeah, this would be better").

[8]ページ先頭

©2009-2025 Movatter.jp