classmarkets / raven-bundle
Display sentry event ids on error pages
Installs: 15 198
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 1
Forks: 2
Open Issues: 1
Type:symfony-bundle
Requires
- php: >= 7.1
- raven/raven: ~0.11
- symfony/framework-bundle: ~3.0|~4.0
- symfony/twig-bundle: ~3.0|~4.0
Requires (Dev)
- mockery/mockery: ~1.1.0
- phpunit/phpunit: ^6.1
- symfony/browser-kit: ~3.0|~4.0
- symfony/monolog-bridge: ~3.0|~4.0
- symfony/monolog-bundle: ~3.0
- symfony/templating: ^4.0
- symfony/yaml: ^4.0
This package is auto-updated.
Last update: 2020-08-13 13:00:37 UTC
README
Are you using sentry for exception monitoring in Symfony 2? Good! Now let's show meaningful error pages to your users.
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:
<h1>Oh no, something went wrong!</h1> {% 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:
<?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:
<?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:
monolog: raven: type: raven dsn: %sentry_dsn% level: error
Turn it into this:
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.
The important thing is that monolog.raven.client_id
equals
cm_raven.client_id
.
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.
How it works
There are two parts to this bundle. Remembering event ids and making them available to error pages.
The first part is easy. All we have to do is decorate a Raven_Client
service
with an event id recorder.
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).
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.
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).
To disable the exception listener configure
cm_raven: enable_exception_listener: false