123456 |
- {
- "html": "<div class=\"section\" id=\"installation\">\n<h2>Installation</h2>\n<p>There are various ways to install the PHP integration for Sentry. The\nrecommended way is to use <a class=\"reference external\" href=\"http://getcomposer.org/\">Composer</a>:</p>\n<div class=\"highlight-python\"><div class=\"highlight\" style=\"background: #ffffff\"><pre style=\"line-height: 125%\"><span></span>$ composer require "sentry/sentry"\n</pre></div>\n</div>\n<p>Alternatively you can manually install it:</p>\n<ol class=\"arabic\">\n<li><p class=\"first\">Download and extract the latest <a class=\"reference external\" href=\"https://github.com/getsentry/sentry-php/archive/master.zip\">sentry-php</a> archive\nto your PHP project.</p>\n</li>\n<li><p class=\"first\">Require the autoloader in your application:</p>\n<div class=\"highlight-php\"><div class=\"highlight\" style=\"background: #ffffff\"><pre style=\"line-height: 125%\"><span></span><span style=\"color: #2eb0f7\">require_once</span> <span style=\"color: #e8535a\">'/path/to/Raven/library/Raven/Autoloader.php'</span><span style=\"color: #111111\">;</span>\n<span style=\"color: #111111\">Raven_Autoloader</span><span style=\"color: #4b4f5c\">::</span><span style=\"color: #a47ac6\">register</span><span style=\"color: #111111\">();</span>\n</pre></div>\n</div>\n</li>\n</ol>\n</div>\n\n\n<div class=\"section\" id=\"laravel-5-x\">\n<h2>Laravel 5.x</h2>\n<p>Install the <code class=\"docutils literal\"><span class=\"pre\">sentry/sentry-laravel</span></code> package:</p>\n<div class=\"highlight-bash\"><div class=\"highlight\" style=\"background: #ffffff\"><pre style=\"line-height: 125%\"><span></span>$ composer require sentry/sentry-laravel\n</pre></div>\n</div>\n<p>If you’re on Laravel 5.4 or earlier, you’ll need to add the following to your <code class=\"docutils literal\"><span class=\"pre\">config/app.php</span></code> (for Laravel 5.5+ these will be auto-discovered by Laravel):</p>\n<div class=\"highlight-php\"><div class=\"highlight\" style=\"background: #ffffff\"><pre style=\"line-height: 125%\"><span></span><span style=\"color: #e8535a\">'providers'</span> <span style=\"color: #4b4f5c\">=></span> <span style=\"color: #2eb0f7\">array</span><span style=\"color: #111111\">(</span>\n <span style=\"color: #34c08b; font-style: italic\">// ...</span>\n <span style=\"color: #111111\">Sentry\\SentryLaravel\\SentryLaravelServiceProvider</span><span style=\"color: #4b4f5c\">::</span><span style=\"color: #a47ac6\">class</span><span style=\"color: #111111\">,</span>\n<span style=\"color: #111111\">)</span>\n\n<span style=\"color: #e8535a\">'aliases'</span> <span style=\"color: #4b4f5c\">=></span> <span style=\"color: #2eb0f7\">array</span><span style=\"color: #111111\">(</span>\n <span style=\"color: #34c08b; font-style: italic\">// ...</span>\n <span style=\"color: #e8535a\">'Sentry'</span> <span style=\"color: #4b4f5c\">=></span> <span style=\"color: #111111\">Sentry\\SentryLaravel\\SentryFacade</span><span style=\"color: #4b4f5c\">::</span><span style=\"color: #a47ac6\">class</span><span style=\"color: #111111\">,</span>\n<span style=\"color: #111111\">)</span>\n</pre></div>\n</div>\n<p>Add Sentry reporting to <code class=\"docutils literal\"><span class=\"pre\">App/Exceptions/Handler.php</span></code>:</p>\n<div class=\"highlight-php\"><div class=\"highlight\" style=\"background: #ffffff\"><pre style=\"line-height: 125%\"><span></span><span style=\"color: #2eb0f7\">public</span> <span style=\"color: #2eb0f7\">function</span> <span style=\"color: #111111\">report(Exception</span> <span style=\"color: #111111\">$exception)</span>\n<span style=\"color: #111111\">{</span>\n <span style=\"color: #2eb0f7\">if</span> <span style=\"color: #111111\">(app()</span><span style=\"color: #4b4f5c\">-></span><span style=\"color: #a47ac6\">bound</span><span style=\"color: #111111\">(</span><span style=\"color: #e8535a\">'sentry'</span><span style=\"color: #111111\">)</span> <span style=\"color: #4b4f5c\">&&</span> <span style=\"color: #111111\">$this</span><span style=\"color: #4b4f5c\">-></span><span style=\"color: #a47ac6\">shouldReport</span><span style=\"color: #111111\">($exception))</span> <span style=\"color: #111111\">{</span>\n <span style=\"color: #111111\">app(</span><span style=\"color: #e8535a\">'sentry'</span><span style=\"color: #111111\">)</span><span style=\"color: #4b4f5c\">-></span><span style=\"color: #a47ac6\">captureException</span><span style=\"color: #111111\">($exception);</span>\n <span style=\"color: #111111\">}</span>\n\n <span style=\"color: #2eb0f7\">parent</span><span style=\"color: #4b4f5c\">::</span><span style=\"color: #a47ac6\">report</span><span style=\"color: #111111\">($exception);</span>\n<span style=\"color: #111111\">}</span>\n</pre></div>\n</div>\n<p>Create the Sentry configuration file (<code class=\"docutils literal\"><span class=\"pre\">config/sentry.php</span></code>):</p>\n<div class=\"highlight-bash\"><div class=\"highlight\" style=\"background: #ffffff\"><pre style=\"line-height: 125%\"><span></span>$ php artisan vendor:publish --provider<span style=\"color: #4b4f5c\">=</span><span style=\"color: #e8535a\">"Sentry\\SentryLaravel\\SentryLaravelServiceProvider"</span>\n</pre></div>\n</div>\n<p>Add your DSN to <code class=\"docutils literal\"><span class=\"pre\">.env</span></code>:</p>\n<div class=\"highlight-bash\"><div class=\"highlight\" style=\"background: #ffffff\"><pre style=\"line-height: 125%\"><span></span><span style=\"color: #111111\">SENTRY_DSN</span><span style=\"color: #4b4f5c\">=</span>___DSN___\n</pre></div>\n</div>\n<p>Finally, if you wish to wire up User Feedback, you can do so by creating a custom\nerror view in <cite>resources/views/errors/500.blade.php</cite>.</p>\n<p>For Laravel 5 up to 5.4 you need to open up <code class=\"docutils literal\"><span class=\"pre\">App/Exceptions/Handler.php</span></code> and extend the\n<code class=\"docutils literal\"><span class=\"pre\">render</span></code> 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:</p>\n<div class=\"highlight-php\"><div class=\"highlight\" style=\"background: #ffffff\"><pre style=\"line-height: 125%\"><span></span><span style=\"color: #4b4f5c\"><?</span><span style=\"color: #111111\">php</span>\n\n<span style=\"color: #2eb0f7\">class</span> <span style=\"color: #111111\">Handler</span> <span style=\"color: #2eb0f7\">extends</span> <span style=\"color: #111111\">ExceptionHandler</span>\n<span style=\"color: #111111\">{</span>\n <span style=\"color: #2eb0f7\">public</span> <span style=\"color: #2eb0f7\">function</span> <span style=\"color: #111111\">report(Exception</span> <span style=\"color: #111111\">$exception)</span>\n <span style=\"color: #111111\">{</span>\n <span style=\"color: #2eb0f7\">if</span> <span style=\"color: #111111\">(app()</span><span style=\"color: #4b4f5c\">-></span><span style=\"color: #a47ac6\">bound</span><span style=\"color: #111111\">(</span><span style=\"color: #e8535a\">'sentry'</span><span style=\"color: #111111\">)</span> <span style=\"color: #4b4f5c\">&&</span> <span style=\"color: #111111\">$this</span><span style=\"color: #4b4f5c\">-></span><span style=\"color: #a47ac6\">shouldReport</span><span style=\"color: #111111\">($exception))</span> <span style=\"color: #111111\">{</span>\n <span style=\"color: #111111\">app(</span><span style=\"color: #e8535a\">'sentry'</span><span style=\"color: #111111\">)</span><span style=\"color: #4b4f5c\">-></span><span style=\"color: #a47ac6\">captureException</span><span style=\"color: #111111\">($exception);</span>\n <span style=\"color: #111111\">}</span>\n\n <span style=\"color: #2eb0f7\">parent</span><span style=\"color: #4b4f5c\">::</span><span style=\"color: #a47ac6\">report</span><span style=\"color: #111111\">($exception);</span>\n <span style=\"color: #111111\">}</span>\n\n <span style=\"color: #2eb0f7\">public</span> <span style=\"color: #2eb0f7\">function</span> <span style=\"color: #111111\">render($request,</span> <span style=\"color: #111111\">Exception</span> <span style=\"color: #111111\">$exception)</span>\n <span style=\"color: #111111\">{</span>\n <span style=\"color: #34c08b; font-style: italic\">// Convert all non-http exceptions to a proper 500 http exception</span>\n <span style=\"color: #34c08b; font-style: italic\">// if we don't do this exceptions are shown as a default template</span>\n <span style=\"color: #34c08b; font-style: italic\">// instead of our own view in resources/views/errors/500.blade.php</span>\n <span style=\"color: #2eb0f7\">if</span> <span style=\"color: #111111\">($this</span><span style=\"color: #4b4f5c\">-></span><span style=\"color: #a47ac6\">shouldReport</span><span style=\"color: #111111\">($exception)</span> <span style=\"color: #4b4f5c\">&&</span> <span style=\"color: #4b4f5c\">!</span><span style=\"color: #111111\">$this</span><span style=\"color: #4b4f5c\">-></span><span style=\"color: #a47ac6\">isHttpException</span><span style=\"color: #111111\">($exception)</span> <span style=\"color: #4b4f5c\">&&</span> <span style=\"color: #4b4f5c\">!</span><span style=\"color: #111111\">config(</span><span style=\"color: #e8535a\">'app.debug'</span><span style=\"color: #111111\">))</span> <span style=\"color: #111111\">{</span>\n <span style=\"color: #111111\">$exception</span> <span style=\"color: #4b4f5c\">=</span> <span style=\"color: #2eb0f7\">new</span> <span style=\"color: #111111\">HttpException(</span><span style=\"color: #45c2c9\">500</span><span style=\"color: #111111\">,</span> <span style=\"color: #e8535a\">'Whoops!'</span><span style=\"color: #111111\">);</span>\n <span style=\"color: #111111\">}</span>\n\n <span style=\"color: #2eb0f7\">return</span> <span style=\"color: #2eb0f7\">parent</span><span style=\"color: #4b4f5c\">::</span><span style=\"color: #a47ac6\">render</span><span style=\"color: #111111\">($request,</span> <span style=\"color: #111111\">$exception);</span>\n <span style=\"color: #111111\">}</span>\n<span style=\"color: #111111\">}</span>\n</pre></div>\n</div>\n<p>Next, create <code class=\"docutils literal\"><span class=\"pre\">resources/views/errors/500.blade.php</span></code>, and embed the feedback code:</p>\n<div class=\"highlight-html\"><div class=\"highlight\" style=\"background: #ffffff\"><pre style=\"line-height: 125%\"><span></span><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</pre></div>\n</div>\n<p>That’s it!</p>\n</div>\n",
- "link": "https://docs.getsentry.com/clients/php/integrations/laravel/",
- "id": "php-laravel",
- "name": "Laravel"
- }
|