Bugsnag for Laravel and Lumen

repository·master·Indexed 21 days ago

https://github.com/bugsnag/bugsnag-laravel

An exception reporter for Laravel and Lumen applications that provides instant notification of errors and crashes, including support for handled exceptions and custom diagnostic data.

Tokens
4.5K
Snippets
15
Records
17
Agent score
73%

What's inside bugsnag-laravel

  1. Get started with Bugsnag for Laravel or Lumen

    master

    To integrate Bugsnag into your Laravel or Lumen application, follow these steps:

    1. Create a Bugsnag account: Sign up at bugsnag.com.
    2. Follow the official integration guide: Complete the specific setup instructions for your framework:
    3. Report handled exceptions: Use the Bugsnag::notify() method to manually report exceptions that you have caught in your code.
    4. Customize your integration: Use the available configuration options to fine-tune how errors are reported and what data is attached.
  2. Set up the Bugsnag Lumen 5.2 demo

    master

    To run the Lumen 5.2 demonstration application and see how errors are reported to the Bugsnag dashboard, follow these steps:

    1. Clone the repository and navigate to the specific Lumen 5.2 example directory:
      git clone https://github.com/bugsnag/bugsnag-laravel.git
      cd bugsnag-laravel/example/lumen-5.2
    2. Install the PHP dependencies using Composer:
      composer install
    3. Create your environment file from the example:
      cp .env.example .env
    4. Configure your Bugsnag API Key by setting the BUGSNAG_API_KEY environment variable in your .env file.
    5. Start the local development server:
      php -S localhost:8000 -t public/
    6. Access the demo at http://localhost:8000.
    git clone https://github.com/bugsnag/bugsnag-laravel.git
    cd bugsnag-laravel/example/lumen-5.2
    composer install
    cp .env.example .env
    # Set BUGSNAG_API_KEY in .env
    php -S localhost:8000 -t public/
  3. Set up the Bugsnag Laravel 5.2 demo application

    master

    To run the Laravel 5.2 demonstration project, clone the repository, install dependencies via Composer, and configure your environment variables. You must provide a valid BUGSNAG_API_KEY in your .env file to see errors reported in your Bugsnag dashboard.

    Follow these steps:

    1. Clone the repository and navigate to the specific Laravel 5.2 example directory:
      git clone https://github.com/bugsnag/bugsnag-laravel.git
      cd bugsnag-laravel/example/laravel-5.2
    2. Install PHP dependencies:
      composer install
    3. Create your environment file:
      cp .env.example .env
    4. Open .env and set BUGSNAG_API_KEY to your Bugsnag project's API Key.
    5. Generate the application key:
      php artisan key:generate
    6. Start the local development server:
      php artisan serve
    7. Access the application at http://localhost:8000.
    git clone https://github.com/bugsnag/bugsnag-laravel.git
    cd bugsnag-laravel/example/laravel-5.2
    composer install
    cp .env.example .env
    # Set BUGSNAG_API_KEY in .env
    php artisan key:generate
    php artisan serve
  4. Report handled exceptions using Bugsnag::notify()

    master

    While the package automatically reports unhandled exceptions and crashes, you can manually report exceptions that your application has caught (handled exceptions) using the Bugsnag::notify() method. This allows you to track errors that don't necessarily crash the application but still require attention.

    Bugsnag::notify($exception);
  5. Set up the Bugsnag Laravel 6 demo application

    master

    To run the Laravel 6 demonstration application, follow these steps to clone the repository, install dependencies, and configure your environment variables. You will need a Bugsnag account and an API Key to see errors reported in your dashboard.

    1. Clone the repository and navigate to the Laravel 6 example directory:
      git clone https://github.com/bugsnag/bugsnag-laravel.git
      cd bugsnag-laravel/example/laravel-6
    2. Install PHP dependencies using Composer:
      composer install
    3. Create your environment file:
      cp .env.example .env
    4. Configure your Bugsnag API Key in the .env file by setting the BUGSNAG_API_KEY variable.
    5. Generate the application key:
      php artisan key:generate
    6. Start the local development server:
      php artisan serve
    7. Access the application at http://localhost:8000.
    git clone https://github.com/bugsnag/bugsnag-laravel.git
    cd bugsnag-laravel/example/laravel-6
    composer install
    cp .env.example .env
    # Set BUGSNAG_API_KEY in .env
    php artisan key:generate
    php artisan serve
  6. Upgrade Bugsnag for Laravel 5.6

    master

    Laravel 5.6 introduced a new Monolog-based logging system that replaces the Illuminate\\Contracts\\Logging\\Log class with Illuminate\\Log\\LogManager. To upgrade Bugsnag, you must remove the old manual aliases and instead add Bugsnag as a channel to your logging stack.

    1. Remove old aliases

    In app/Providers/AppServiceProvider.php, remove the following lines from the register method:

    // Remove these if they exist:
    $this->app->alias('bugsnag.logger', \Illuminate\\Contracts\\Logging\\Log::class);
    $this->app->alias('bugsnag.logger', \Psr\\Log\\LoggerInterface::class);
    
    // Or if using the multi-logger, remove these:
    $this->app->alias('bugsnag.multi', \Illuminate\\Contracts\\Logging\\Log::class);
    $this->app->alias('bugsnag.multi', \Psr\\Log\\LoggerInterface::class);

    2. Configure the logging channel

    Add the bugsnag driver to your config/logging.php file by creating a new channel and adding it to your stack channel.

    // config/logging.php
    
    'channels' => [
        'stack' => [
            'driver' => 'stack',
            // Add bugsnag to the stack:
            'channels' => ['single', 'bugsnag'],
        ],
    
        // ...
    
        // Create a bugsnag logging channel:
        'bugsnag' => [
            'driver' => 'bugsnag',
        ],
    ],
  7. Set up the Bugsnag Lumen 6 demo

    master

    To run the Lumen 6 demonstration application and see how errors are reported to your Bugsnag dashboard, follow these steps:

    1. Clone the repository and navigate to the Lumen 6 example directory:
      git clone https://github.com/bugsnag/bugsnag-laravel.git
      cd bugsnag-laravel/example/lumen-6
    2. Install PHP dependencies using Composer:
      composer install
    3. Create your environment file from the example:
      cp .env.example .env
    4. Configure your Bugsnag API Key by setting the BUGSNAG_API_KEY environment variable in your .env file.
    5. Start the built-in PHP development server:
      php -S localhost:8000 -t public/
    6. Access the demo at http://localhost:8000.
    git clone https://github.com/bugsnag/bugsnag-laravel.git
    cd bugsnag-laravel/example/lumen-6
    composer install
    cp .env.example .env
    # Set BUGSNAG_API_KEY in .env
    php -S localhost:8000 -t public/
  8. Set up the Bugsnag Laravel 7 demo application

    master

    To run the Laravel 7 demonstration project, clone the repository, install dependencies via Composer, configure your environment variables, and start the local development server. You must provide a valid BUGSNAG_API_KEY in your .env file to see errors reported in your Bugsnag dashboard.

    # 1. Clone the repo and enter the directory
    git clone https://github.com/bugsnag/bugsnag-laravel.git
    cd bugsnag-laravel/example/laravel-7
    
    # 2. Install dependencies
    composer install
    
    # 3. Copy environment file
    cp .env.example .env
    
    # 4. Set BUGSNAG_API_KEY in .env with your project's API Key
    
    # 5. Generate application key
    php artisan key:generate
    
    # 6. Run the application
    php artisan serve
  9. Upgrade Bugsnag from 1.x to 2.x

    master

    When upgrading from version 1.x to 2.x, the primary change is that Bugsnag no longer automatically overrides your application's exception handler.

    To complete the upgrade, you must:

    1. Restore your original exception handler if it was previously overridden by Bugsnag.
    2. Bind the new logger to the container following the current integration guide.
    3. Re-publish the Bugsnag configuration file if you want to access the new configuration options available in 2.x.
  10. Set up the Bugsnag Lumen 5.8 demo application

    master

    To run the Lumen 5.8 demonstration application and see how errors are reported to the Bugsnag dashboard, follow these steps:

    1. Clone the repository and navigate to the specific Lumen 5.8 example directory:
      git clone https://github.com/bugsnag/bugsnag-laravel.git
      cd bugsnag-laravel/example/lumen-5.8
    2. Install PHP dependencies using Composer:
      composer install
    3. Configure environment variables: Copy the example environment file to .env:
      cp .env.example .env
    4. Provide your API Key: Open the .env file and set the BUGSNAG_API_KEY to your specific Bugsnag project's API Key.
    5. Start the local server: Run the built-in PHP server:
      php -S localhost:8000 -t public/
    6. Access the demo: Open http://localhost:8000 in your browser to view the example page.
    git clone https://github.com/bugsnag/bugsnag-laravel.git
    cd bugsnag-laravel/example/lumen-5.8
    composer install
    cp .env.example .env
    # Set BUGSNAG_API_KEY in .env
    php -S localhost:8000 -t public/
  11. Set up the Bugsnag Laravel 5.8 demo application

    master

    To run the local demonstration of Bugsnag integration with Laravel 5.8, follow these steps to clone the repository, install dependencies, and configure your environment variables. You will need a Bugsnag API Key from your Bugsnag dashboard to see errors reported in real-time.

    # 1. Clone the repo and enter the specific Laravel 5.8 example directory
    git clone https://github.com/bugsnag/bugsnag-laravel.git
    cd bugsnag-laravel/example/laravel-5.8
    
    # 2. Install PHP dependencies
    composer install
    
    # 3. Prepare the environment file
    cp .env.example .env
    
    # 4. Generate the Laravel application key
    php artisan key:generate
    
    # 5. Start the local development server
    php artisan serve
  12. Set up the Bugsnag Laravel 12 demo application

    master

    To run the Laravel 12 demonstration application, follow these steps to clone the repository, install dependencies, configure your environment, and initialize the database.

    1. Clone the repository and navigate to the Laravel 12 example directory:
      git clone https://github.com/bugsnag/bugsnag-laravel.git
      cd bugsnag-laravel/example/laravel-12
    2. Install PHP dependencies using Composer:
      composer install
    3. Create your environment file:
      cp .env.example .env
    4. Configure your Bugsnag API Key by setting the BUGSNAG_API_KEY environment variable in your .env file.
    5. Generate the Laravel application key:
      php artisan key:generate
    6. Initialize a SQLite database:
      touch database/database.sqlite
    7. Run database migrations:
      php artisan migrate
    8. Start the local development server:
      php artisan serve

    Once running, you can view the example page at http://localhost:8000.

    git clone https://github.com/bugsnag/bugsnag-laravel.git
    cd bugsnag-laravel/example/laravel-12
    composer install
    cp .env.example .env
    # Set BUGSNAG_API_KEY in .env
    php artisan key:generate
    touch database/database.sqlite
    php artisan migrate
    php artisan serve