{ "html": "
There are various ways to install the PHP integration for Sentry. The\nrecommended way is to use Composer:
\n$ composer require "sentry/sentry"\n
Alternatively you can manually install it:
\nDownload and extract the latest sentry-php archive\nto your PHP project.
\nRequire the autoloader in your application:
\nrequire_once '/path/to/Raven/library/Raven/Autoloader.php';\nRaven_Autoloader::register();\n
Install the sentry/sentry-laravel
package:
$ composer require sentry/sentry-laravel\n
If you’re on Laravel 5.4 or earlier, you’ll need to add the following to your config/app.php
(for Laravel 5.5+ these will be auto-discovered by Laravel):
'providers' => array(\n // ...\n Sentry\\SentryLaravel\\SentryLaravelServiceProvider::class,\n)\n\n'aliases' => array(\n // ...\n 'Sentry' => Sentry\\SentryLaravel\\SentryFacade::class,\n)\n
Add Sentry reporting to App/Exceptions/Handler.php
:
public function report(Exception $exception)\n{\n if (app()->bound('sentry') && $this->shouldReport($exception)) {\n app('sentry')->captureException($exception);\n }\n\n parent::report($exception);\n}\n
Create the Sentry configuration file (config/sentry.php
):
$ php artisan vendor:publish --provider="Sentry\\SentryLaravel\\SentryLaravelServiceProvider"\n
Add your DSN to .env
:
SENTRY_DSN=___DSN___\n
Finally, if you wish to wire up User Feedback, you can do so by creating a custom\nerror view in resources/views/errors/500.blade.php.
\nFor Laravel 5 up to 5.4 you need to open up App/Exceptions/Handler.php
and extend the\nrender
method to make sure the 500 error is rendered as a view correctly, in 5.5+ this\nstep is not required anymore an you can skip ahead to the next one:
<?php\n\nclass Handler extends ExceptionHandler\n{\n public function report(Exception $exception)\n {\n if (app()->bound('sentry') && $this->shouldReport($exception)) {\n app('sentry')->captureException($exception);\n }\n\n parent::report($exception);\n }\n\n public function render($request, Exception $exception)\n {\n // Convert all non-http exceptions to a proper 500 http exception\n // if we don't do this exceptions are shown as a default template\n // instead of our own view in resources/views/errors/500.blade.php\n if ($this->shouldReport($exception) && !$this->isHttpException($exception) && !config('app.debug')) {\n $exception = new HttpException(500, 'Whoops!');\n }\n\n return parent::render($request, $exception);\n }\n}\n
Next, create resources/views/errors/500.blade.php
, and embed the feedback code:
<div class="content">\n <div class="title">Something went wrong.</div>\n\n @if(app()->bound('sentry') && !empty(Sentry::getLastEventID()))\n <div class="subtitle">Error ID: {{ Sentry::getLastEventID() }}</div>\n\n <!-- Sentry JS SDK 2.1.+ required -->\n <script src="https://cdn.ravenjs.com/3.3.0/raven.min.js"></script>\n\n <script>\n Raven.showReportDialog({\n eventId: '{{ Sentry::getLastEventID() }}',\n // use the public DSN (dont include your secret!)\n dsn: 'https://e9ebbd88548a441288393c457ec90441@sentry.io/3235',\n user: {\n 'name': 'Jane Bloggs',\n 'email': 'jane.doe@example.com',\n }\n });\n </script>\n @endif\n</div>\n
That’s it!
\n