2017 © Pedro Peláez
 

symfony-bundle raven-bundle

Display sentry event ids on error pages

image

classmarkets/raven-bundle

Display sentry event ids on error pages

  • Thursday, April 26, 2018
  • by pschultz
  • Repository
  • 1 Watchers
  • 1 Stars
  • 13,737 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 2 Forks
  • 1 Open issues
  • 10 Versions
  • 1 % Grown

The README.md

raven-bundle

Build Status Scrutinizer Code Quality, (*1)

Are you using sentry for exception monitoring in Symfony 2? Good! Now let's show meaningful error pages to your users., (*2)

Sentry generates ids for each event it receives. This bundle adds a Twig function that let's you access those event ids in error page templates:, (*3)




Oh no, something went wrong!

{% if exception is defined %} {% set eventId = sentry_event_id(exception) %} {% if eventId is not empty %} <p> The good news is that our team has been notified and is probably working on a solution already. </p> <p> Error Code: <code>{{ eventId }}</code> </p> {% endif %} {% endif %}

You can also lookup event ids wherever the DIC is available like this:, (*4)

<?php

$container->get('cm_raven.sentry_event_recorder')->getEventIdForException($exception);

Installation

The usual. Install it with composer require classmarkets/raven-bundle ~1.0.0 and add it to the kernel:, (*5)

<?php

    public function registerBundles()
    {
        $bundles = array(
            // ...
            new \Classmarkets\RavenBundle\CMRavenBundle(),
        );
    }

Configuration

Quickstart

Assuming you are using Monolog's raven handler already, and have not changed the twig.exception_listener service, you already have something like this:, (*6)

monolog:
    raven:
        type:  raven
        dsn: %sentry_dsn%
        level: error

Turn it into this:, (*7)

monolog:
    raven:
        type:  raven
        dsn: "" # some versions of the monolog bundle require the dsn key to
                # be present (even if it is empty)
        client_id: raven
        level: error

cm_raven:
    client_id: raven

services:
    raven:
        class: Raven_Client
        arguments: [ %sentry_dsn% ]

If you already have monolog.raven.client_id configured, omit the extra service definition., (*8)

The important thing is that monolog.raven.client_id equals cm_raven.client_id., (*9)

If you are not using monolog, find the id for the service that provides the Raven_Client instance, and set cm_raven.client_id to that id., (*10)

How it works

There are two parts to this bundle. Remembering event ids and making them available to error pages., (*11)

The first part is easy. All we have to do is decorate a Raven_Client service with an event id recorder., (*12)

The second part is tricky because the original exception doesn't make it into the template engine. Instead, it gets converted into a FlattenException. This FlattenException is unknown to our event recorder (because it only saw the original exception)., (*13)

The FlattenException gets created by some protected method in the twig.exception_listener service. To solve our problem, we replace that service to associate the FlattenException with the same event id as the original exception., (*14)

If your application already has a custom twig.exception_listener service, disable our implementation and call @cm_raven.sentry_event_recorder::addExceptionAlias($originalException, $flattenException) yourself (see ExceptionListener.php)., (*15)

To disable the exception listener configure, (*16)

cm_raven:
    enable_exception_listener: false

The Versions

26/04 2018

dev-master

9999999-dev

Display sentry event ids on error pages

  Sources   Download

MIT

The Requires

 

The Development Requires

by Peter Schultz

bundle symfony raven sentry

26/04 2018
26/04 2018
26/04 2018

dev-symfony3

dev-symfony3

Display sentry event ids on error pages

  Sources   Download

MIT

The Requires

 

The Development Requires

by Peter Schultz

bundle symfony raven sentry

13/04 2016

dev-update-raven

dev-update-raven

Display sentry event ids on error pages

  Sources   Download

MIT

The Requires

 

The Development Requires

by Peter Schultz

bundle symfony raven sentry

13/04 2016

dev-update-tests

dev-update-tests

Display sentry event ids on error pages

  Sources   Download

MIT

The Requires

 

The Development Requires

by Peter Schultz

bundle symfony raven sentry

17/12 2015

1.0.3

1.0.3.0

Display sentry event ids on error pages

  Sources   Download

MIT

The Requires

 

The Development Requires

by Peter Schultz

bundle symfony raven sentry

07/12 2014

1.0.2

1.0.2.0

Display sentry event ids on error pages

  Sources   Download

MIT

The Requires

 

The Development Requires

by Peter Schultz

bundle symfony raven sentry

07/11 2014

1.0.1

1.0.1.0

Display sentry event ids on error pages

  Sources   Download

MIT

The Requires

 

The Development Requires

by Peter Schultz

bundle symfony raven sentry

06/11 2014

1.0.0

1.0.0.0

Display sentry event ids on error pages

  Sources   Download

MIT

The Requires

 

The Development Requires

by Peter Schultz

bundle symfony raven sentry