Developed with love by KnpLabs Hire us for your project!
37

Evolution7BugsnagBundle

by evolution7

Symfony Bugsnag integration

Latest Stable Version Total Downloads Latest Unstable Version License

Evolution7BugsnagBundle

Enables Bugsnag integration into your Symfony application, using the bugsnag-php 2.x library from Bugsnag.

Installation

The recommended way of installing this bundle is using Composer.

Add this repository to your composer information using the following command

composer require "evolution7/bugsnag-bundle:~2.0"

Add the bundle to your AppKernel.php:

$bundles = array(
    //Other Bundles
    new Evolution7\BugsnagBundle\BugsnagBundle(),

Define your Bugsnag API key in the config.yml

bugsnag:
    api_key: YOUR-API-KEY

Usage

After the installation the bundle works without any additional settings required, but you can tweak some settings.

Enabled Stages

You can set for which Symfony environments (kernel.environment) you want Bugsnag to be enabled. This is done through the enabled_stages setting:

bugsnag:
    enabled_stages: [dev, prod, staging]

These environments should match the environment as set in your application's web/app.php, web/app_dev.php and/or app/console. The default is to report bugs for the prod environment only.

Notify Stages

You can set for which environments you want Bugsnag to get error reports. This is done with the notify_stages setting:

bugsnag:
    notify_stages: [development, staging, production]

The default is to report bugs in staging and production environments.

Proxy

If your server requires you to access Bugsnag through a proxy, you can set this up easily as well. Just use the following example to configure the settings you need in your config.yml:

bugsnag:
    proxy:
        host: www.bugsnag.com
        port: 42
        user: username
        password: password

The only of these settings that is mandatory is the host, all others can be left out if they aren't required.

AppVersion

If you tag your app releases with version numbers, Bugsnag can display these on your dashboard if you set this:

bugsnag:
    app_version: v1.2.3

Testing

Included in the bundle is a controller that will allow you to test if your site is hooked up correctly. Just add the following to your routing.yml:

evolution7_bugsnag_bundle:
    resource: "@BugsnagBundle/Resources/config/routing.yml"
    prefix:   /bugsnagtest

And then afterwards you can access your.domain/bugsnagtest/exception and your.domain/bugsnagtest/error which should then send errors to your configured Bugsnag project.

Advanced Usage

Release Stage Class

Bugsnag allows you to determine which release stage you are currently in, the Evolution7BugsnagBundle uses a ReleaseStage class for this which determines this based on the path. Depending on your setup you might want to have a different way of determining this, in which case it is possible to override this by providing your own ReleaseStage class.
You can implement a class that implements the Evolution7\BugsnagBundle\ReleaseStage\ReleaseStageInterface and provide its name as a parameter in your config.yml

bugsnag:
    release_stage:
        class: Your\Name\Space\ClassName

User Information

Bugsnag gives the possibility to give userdata as additional information to a request. If you give an id, name or email these fields will be searchable. Other fields are allowed
but not searchable - they will only be displayed. The bundle allows to set a user to array converter as a service which will be used to send user data.
The given service must be an instance of \Evolution7\BugsnagBundle\UserInterface

<?php
# src/AppBundle/BugsnagUser.php
namespace AppBundle;

use Evolution7\BugsnagBundle\UserInterface as BugsnagUserInterface;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
use Symfony\Component\Security\Core\User\UserInterface as SymfonyUserInterface;

class BugsnagUser implements BugsnagUserInterface
{
    /**
     * @var TokenStorageInterface
     */
    private $token;

    /**
     * @param TokenStorageInterface $token
     */
    public function __construct(TokenStorageInterface $token)
    {
        $this->token = $token->getToken();
    }

    /**
     * @inheritdoc
     */
    public function getUserAsArray()
    {
        if (
            is_null($this->token)
            || !$this->token->isAuthenticated()
            || !$this->token->getUser() instanceof SymfonyUserInterface
        ) {
            return [];
        }

        $user = $this->token->getUser();

        return [
            'id' => $user->getId(),
            'name' => $user->getUsername(),
            'email' => $user->getEmail()
        ];
    }
}
# services.yml
services:
  app.bugsnag_user:
    class: AppBundle\BugsnagUser
    arguments: [@security.token_storage]
# app/config/config.yml
bugsnag:
    user: app.bugsnag_user

Contributing

  • Fork it on Github
  • Commit and push until you are happy
  • Run the tests to make sure they all pass: composer install && ./vendor/bin/phpunit
  • Make a pull request
  • Thanks!

Acknowledgement

Parts of this code are based on the bugsnag-php-symfony Bundle

The MIT License

Copyright (c) 2013 Evolution 7 (http://www.evolution7.com.au)

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
bugsnag:
api_key: ~
app_version: ~
user: ~
enabled_stages:

# Default:
- prod
notify_stages:

# Defaults:
- staging
- production
release_stage:
class: ~
proxy:
host: ~
port: ~
user: ~
password: ~
  • Merge pull request #25 from revoltek-daniel/patch-1
    By web-flow, 3 years ago
  • Fix Symfony 3.1 yaml deprecation warning
    By web-flow, 4 years ago
  • Merge pull request #23 from desmax/patch-1
    By my2ter, 4 years ago
  • Fix symfony dependence
    By desmax, 4 years ago
  • Merge pull request #14 from JHGitty/patch-1
    By my2ter, 4 years ago
  • Merge pull request #18 from JHGitty/patch-3
    By my2ter, 4 years ago
  • Fix #13 #17
    By JHGitty, 4 years ago
  • Update composer.json requirements
    By JHGitty, 4 years ago
  • Fix broken tests introduced with RequestStack
    By Romain Palmas, 4 years ago
  • Limit composer's dependency symfony to ">=2.4.0"
    By Romain Palmas, 4 years ago
  • Merge pull request #12 from iagomelanias/master
    By my2ter, 4 years ago
  • Update request information
    By iagomelanias, 4 years ago
  • Fix dependency injection
    By iagomelanias, 4 years ago
  • Update routing parameter key
    By iagomelanias, 4 years ago
  • Update unit test
    By thoaionline, 4 years ago
  • Merge pull request #11 from DZunke/feature/users
    By thoaionline, 4 years ago
  • Rename get method in user interface to getUserAsArray
    By DZunke, 4 years ago
  • Fix example bugsnag user in readme
    By DZunke, 4 years ago
  • Implement service reader for userdata in trace
    By DZunke, 4 years ago
  • Add stat badges
    By thoaionline, 5 years ago
  • Add credit for @vicdelfant
    By thoaionline, 5 years ago
  • Release 1.3.0
    By thoaionline, 5 years ago
  • Merge pull request #10 from vicdelfant/master
    By thoaionline, 5 years ago
  • Emphasized the difference between the Bugsnag stage and Symfony environment
    By Vic D'Elfant, 5 years ago
  • Replaced tabs with 4 spaces as per PSR-2
    By Vic D'Elfant, 5 years ago
  • Introduced bugsnag.enabled_stages setting (replaces bugsnag.report_in_dev)
    By Vic D'Elfant, 5 years ago
  • Release 1.2.1
    By ArjenSchwarz, 5 years ago
  • Change CI build to use Docker containers
    By ArjenSchwarz, 5 years ago
  • Merge pull request #9 from dbtlr/master
    By ArjenSchwarz, 5 years ago
  • Make sure that json content types bass over their parameters properly.
    By dbtlr, 5 years ago