holidaypirates / bugsnag-lumen by holidaypirates

Bugsnag notifier for Lumen applications.
1,214
7
3
Package Data
Maintainer Username: holidaypirates
Maintainer Contact: notifiers@bugsnag.com (James Smith)
Package Create Date: 2015-05-10
Package Last Update: 2016-07-20
Language: PHP
License: MIT
Last Refreshed: 2020-10-23 15:29:52
Package Statistics
Total Downloads: 1,214
Monthly Downloads: 0
Daily Downloads: 0
Total Stars: 7
Total Watchers: 3
Total Forks: 0
Total Open Issues: 1

Bugsnag Notifier for Lumen

The Bugsnag Notifier for Lumen gives you instant notification of errors and exceptions in your Lumen PHP applications. (based on package for Laravel https://github.com/holidaypirates/bugsnag-lumen)

Bugsnag captures errors in real-time from your web, mobile and desktop applications, helping you to understand and resolve them as fast as possible. Create a free account to start capturing errors from your applications.

How to Install

  1. Install the holidaypirates/bugsnag-lumen package

    $ composer require "holidaypirates/bugsnag-lumen:1.*"
    
  2. Update bootstrap/app.php to activate Bugsnag

    # Copy config/bugsnag.php from package to project config, change vaules and register config file in `bootstrap/app.php`
    $app->configure('bugsnag');
    
    # Add `BugsnagLumenServiceProvider` to the `bootstrap/app.php`
    $app->register('HolidayPirates\BugsnagLumen\BugsnagLumenServiceProvider')
    
  3. Use the Bugsnag exception handler from App/Exceptions/Handler.php.

    # DELETE this line
    use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
    
    # ADD this line instead
    use HolidayPirates\BugsnagLumen\BugsnagExceptionHandler as ExceptionHandler
    

    After this change, your file should look like this:

    <?php namespace App\Exceptions;
    
    use Exception;
    use HolidayPirates\BugsnagLumen\BugsnagExceptionHandler as ExceptionHandler;
    
    class Handler extends ExceptionHandler {
        ...
    }
    
    

Configuration

  1. Create a file config/bugsnag.php that contains your API key:

  2. Configure your api_key:

    <?php # config/bugsnag.php
    
    return array(
        'api_key' => 'YOUR-API-KEY-HERE'
    );
    
  3. Optionally, you can add the notify_release_stages key to the same file above to define which Laravel environments will send Exceptions to Bugsnag.

    return array(
        'api_key' => 'YOUR-API-KEY-HERE',
        'notify_release_stages' => ['production', 'staging']
    );
    

Sending Custom Data With Exceptions

It is often useful to send additional meta-data about your app, such as information about the currently logged in user, along with any error or exceptions, to help debug problems.

To send custom data, you should define a before-notify function, adding an array of "tabs" of custom data to the $metaData parameter. For example:

app('bugsnag')->setBeforeNotifyFunction("before_bugsnag_notify");

function before_bugsnag_notify($error) {
    // Do any custom error handling here

    // Also add some meta data to each error
    $error->setMetaData(array(
        "user" => array(
            "name" => "James",
            "email" => "james@example.com"
        )
    ));
}

See the setBeforeNotifyFunction documentation on the bugsnag-php library for more information.

Sending Custom Errors or Non-Fatal Exceptions

You can easily tell Bugsnag about non-fatal or caught exceptions by calling app('bugsnag')->notifyException:

app('bugsnag')->notifyException(new Exception("Something bad happened"));

You can also send custom errors to Bugsnag with Bugsnag::notifyError:

app('bugsnag')->notifyError("ErrorType", "Something bad happened here too");

Both of these functions can also be passed an optional $metaData parameter, which should take the following format:

$metaData =  array(
    "user" => array(
        "name" => "James",
        "email" => "james@example.com"
    )
);

Error Reporting Levels

By default we'll use the value of error_reporting from your php.ini or any value you set at runtime using the error_reporting(...) function.

If you'd like to send different levels of errors to Bugsnag, you can call setErrorReportingLevel, for example:

app('bugsnag')->setErrorReportingLevel(E_ALL & ~E_NOTICE);

Additional Configuration

The Bugsnag PHP Client is available as Bugsnag, which allows you to set various configuration options, for example:

app('bugsnag')->setReleaseStage("production");

See the Bugsnag Notifier for PHP documentation for full configuration details.

Reporting Bugs or Feature Requests

Please report any bugs or feature requests on the github issues page for this project here:

https://github.com/holidaypirates/bugsnag-lumen/issues