2017 © Pedro Peláez
 

library sentry-laravel

Laravel integration for Sentry (https://sentry.io)

image

macromindonline/sentry-laravel

Laravel integration for Sentry (https://sentry.io)

  • Monday, November 13, 2017
  • by macromindonline
  • Repository
  • 1 Watchers
  • 0 Stars
  • 6 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 67 Forks
  • 0 Open issues
  • 18 Versions
  • 0 % Grown

The README.md

, (*1)

Sentry for Laravel

Build Status Total Downloads Downloads per month Latest stable version License, (*2)

Laravel integration for Sentry., (*3)

Installation

Laravel 5.x

Install the sentry/sentry-laravel package:, (*4)

$ composer require sentry/sentry-laravel

If you're on Laravel 5.4 or earlier, you'll need to add the following to your config/app.php:, (*5)

'providers' => array(
    // ...
    Sentry\SentryLaravel\SentryLaravelServiceProvider::class,
)

'aliases' => array(
    // ...
    'Sentry' => Sentry\SentryLaravel\SentryFacade::class,
)

Add Sentry reporting to app/Exceptions/Handler.php:, (*6)

public function report(Exception $exception)
{
    if (app()->bound('sentry') && $this->shouldReport($exception)) {
        app('sentry')->captureException($exception);
    }

    parent::report($exception);
}

Create the Sentry configuration file (config/sentry.php):, (*7)

$ php artisan vendor:publish --provider="Sentry\SentryLaravel\SentryLaravelServiceProvider"

Add your DSN to .env:, (*8)

SENTRY_DSN=https://public:secret@sentry.example.com/1

Laravel 4.x

Install the sentry/sentry-laravel package:, (*9)

$ composer require sentry/sentry-laravel

Add the Sentry service provider and facade in config/app.php:, (*10)

'providers' => array(
    // ...
    'Sentry\SentryLaravel\SentryLaravelServiceProvider',
)

'aliases' => array(
    // ...
    'Sentry' => 'Sentry\SentryLaravel\SentryFacade',
)

Create the Sentry configuration file (config/sentry.php):, (*11)

$ php artisan config:publish sentry/sentry-laravel

Lumen 5.x

Install the sentry/sentry-laravel package:, (*12)

$ composer require sentry/sentry-laravel

Register Sentry in bootstrap/app.php:, (*13)

$app->register('Sentry\SentryLaravel\SentryLumenServiceProvider');

# Sentry must be registered before routes are included
require __DIR__ . '/../app/Http/routes.php';

Add Sentry reporting to app/Exceptions/Handler.php:, (*14)

public function report(Exception $e)
{
    if (app()->bound('sentry') && $this->shouldReport($e)) {
        app('sentry')->captureException($e);
    }

    parent::report($e);
}

Create the Sentry configuration file (config/sentry.php):, (*15)

<?php

return array(
    'dsn' => '___DSN___',

    // capture release as git sha
    // 'release' => trim(exec('git log --pretty="%h" -n1 HEAD')),

    // Capture bindings on SQL queries
    'breadcrumbs.sql_bindings' => true,

    // Capture default user context
    'user_context' => true,
);

Testing with Artisan

You can test your configuration using the provided artisan command:, (*16)

$ php artisan sentry:test
[sentry] Client configuration:
-> server: https://app.getsentry.com/api/3235/store/
-> project: 3235
-> public_key: e9ebbd88548a441288393c457ec90441
-> secret_key: 399aaee02d454e2ca91351f29bdc3a07
[sentry] Generating test event
[sentry] Sending test event with ID: 5256614438cf4e0798dc9688e9545d94

Adding Context

The mechanism to add context will vary depending on which version of Laravel you're using, but the general approach is the same. Find a good entry point to your application in which the context you want to add is available, ideally early in the process., (*17)

In the following example, we'll use a middleware:, (*18)

namespace App\Http\Middleware;

use Closure;

class SentryContext
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request $request
     * @param  \Closure                 $next
     *
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        if (app()->bound('sentry')) {
            /** @var \Raven_Client $sentry */
            $sentry = app('sentry');

            // Add user context
            if (auth()->check()) {
                $sentry->user_context([...]);
            } else {
                $sentry->user_context(['id' => null]);
            }

            // Add tags context
            $sentry->tags_context([...]);
        }

        return $next($request);
    }
}

Displaying the error ID

When something goes wrong and you get a customer email in your inbox it would be nice if they could give you some kind of identitifier for the error they are seeing., (*19)

Luckily Sentry provides you with just that by adding one of the following options to your error view., (*20)

// Using the Sentry facade
$errorID = Sentry::getLastEventID();

// Or without the Sentry facade (Lumen)
$errorID = app('sentry')->getLastEventID();

This could look something like this in for example your resources/views/error/500.blade.php:, (*21)

@if(!empty(Sentry::getLastEventID()))
    <p>Please send this ID with your support request: {{ Sentry::getLastEventID() }}.</p>
@endif

This ID can be searched for in the Sentry interface allowing you to find the error quickly., (*22)

Contributing

Dependencies are managed through composer:, (*23)

$ composer install

Tests can then be run via phpunit:, (*24)

$ vendor/bin/phpunit

Community

The Versions

13/11 2017

dev-master

9999999-dev https://sentry.io

Laravel integration for Sentry (https://sentry.io)

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

laravel logging errors sentry

31/08 2017

dev-laravel-4-x

dev-laravel-4-x https://sentry.io

Laravel integration for Sentry (https://sentry.io)

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

laravel logging errors sentry

11/08 2017

dev-releases/0.8.x

dev-releases/0.8.x https://sentry.io

Laravel integration for Sentry (https://sentry.io)

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

laravel logging errors sentry

11/08 2017

0.8.0

0.8.0.0 https://sentry.io

Laravel integration for Sentry (https://sentry.io)

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

laravel logging errors sentry

21/04 2017

dev-releases/0.7.x

dev-releases/0.7.x https://sentry.io

Laravel integration for Sentry (https://sentry.io)

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

laravel logging errors sentry

21/04 2017

0.7.0

0.7.0.0 https://sentry.io

Laravel integration for Sentry (https://sentry.io)

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

laravel logging errors sentry

17/03 2017

dev-releases/0.4.x

dev-releases/0.4.x http://getsentry.com

Laravel integration for Sentry (http://getsentry.com)

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

laravel logging errors sentry

09/02 2017

dev-releases/0.6.x

dev-releases/0.6.x https://sentry.io

Laravel integration for Sentry (https://sentry.io)

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

laravel logging errors sentry

09/02 2017

0.6.1

0.6.1.0 https://sentry.io

Laravel integration for Sentry (https://sentry.io)

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

laravel logging errors sentry

24/01 2017

0.6.0

0.6.0.0 https://sentry.io

Laravel integration for Sentry (https://sentry.io)

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

laravel logging errors sentry

09/12 2016

dev-releases/0.5.x

dev-releases/0.5.x https://sentry.io

Laravel integration for Sentry (https://sentry.io)

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

laravel logging errors sentry

09/12 2016

0.5.0

0.5.0.0 https://sentry.io

Laravel integration for Sentry (https://sentry.io)

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

laravel logging errors sentry

30/09 2016

0.4.1

0.4.1.0 http://getsentry.com

Laravel integration for Sentry (http://getsentry.com)

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

laravel logging errors sentry

30/09 2016

0.4.0

0.4.0.0 http://getsentry.com

Laravel integration for Sentry (http://getsentry.com)

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

laravel logging errors sentry

06/05 2016

0.3.0

0.3.0.0 http://getsentry.com

Laravel integration for Sentry (http://getsentry.com)

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

laravel logging errors sentry

04/05 2016

0.2.0

0.2.0.0 http://getsentry.com

Laravel integration for Sentry (http://getsentry.com)

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

laravel logging errors sentry

27/04 2016

0.1.1

0.1.1.0 http://getsentry.com

Laravel integration for Sentry (http://getsentry.com)

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

laravel logging errors sentry

27/04 2016

0.1.0

0.1.0.0 http://getsentry.com

Laravel integration for Sentry (http://getsentry.com)

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

laravel logging errors sentry