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

SentryBundle

by hautelook

HautelookSentryBundle

Bundle to use hautelook/sentry-client, which is a guzzle based sentry
client.

Installation

I recommend to only add the bundle in the production environment

class AppKernel extends Kernel
{
    public function registerBundles()
    {
        ...

        if (in_array($this->getEnvironment(), array('prod'))) {
            $bundles[] = new Hautelook\SentryBundle\HautelookSentryBundle();
        }

        ...
    }
}

Example configuration

hautelook_sentry:
    client_options:
        dsn: %sentry.dsn%

        # you probabled do not want to log 404 exceptions
        ignored_exceptions:
            Symfony\Component\HttpKernel\Exception\NotFoundHttpException: true

        # add customs data/tags
        command:
            params:
                tags: {}

    error_handler: true # enables exception, error, fatal errors capture

    # this will remove delpoyments dates etc from stack traces files
    # without this sentry will fail to group exceptions happening on different capistrano deployments
    files_base_path: %kernel.root_dir%/../

Usage

Enabling the error handler will cover what you want out of this bundle is most cases, however you can capture messages
or exception manually:

if ($container->has('hautelook_sentry.client')) {
    $container->get('hautelook_sentry.client')->captureException($e);
    $container->get('hautelook_sentry.client')->capture(array(
        'message' => 'sup ?',
    ));
}

Note that you have to catch yourself any exception that may happen when using the client directly.

Add capistrano revision to exceptions

imports:
    - { resource: revision.php }

hautelook_sentry:
    client_options:
        command:
            params:
                tags:
                    revision: %revision%
<?php
// app/config/revision.php

$revision = 'unknown';
if (file_exists($revisionFile = __DIR__ . '/../../REVISION')) {
    $revision = file_get_contents($revisionFile);
}

$container->setParameter('revision', $revision);

Config reference

# Default configuration for extension with alias: "hautelook_sentry"
hautelook_sentry:
    error_handler:
        enabled:                    false
        exception:                  true
        error:                      true
        fatal_error:                true
        throw_handler_exceptions:   false # By default any exception in the handler will be catched and ignored. Set to true to debug connection errors etc.
    files_base_path:      ~
    client_options:       # Required
        public_key:           ~ # Required
        secret_key:           ~ # Required
        project_id:           ~ # Required
        protocol:             https
        host:                 app.getsentry.com
        path:                 /
        port:                 ~
        dsn:                  ~
        exception_factory:    ~
        request:
            options:              [] # guzzle request options
        curl:
            options:              [] # guzzle curl options
        command:
            params:
                level:                ~
                logger:               ~
                platform:             ~
                tags:                 []
                extra:                []
                server_name:          localhost.localdomain
        ignored_exceptions:   []
Copyright (c) 2013 Adrien Brault <adrien.brault@gmail.com>

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.