Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Raven Bundle Laravel Package

classmarkets/raven-bundle

View on GitHub
Deep Wiki
Context7

raven-bundle

Build Status Scrutinizer Code Quality

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
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
comsave/common
alecsammon/php-raml-parser
chrome-php/wrench
lendable/composer-license-checker
typhoon/reflection
mesilov/moneyphp-percentage
mike42/gfx-php
bookdown/themes
aura/view
aura/html
aura/cli
povils/phpmnd
nayjest/manipulator
omnipay/tests
psr-mock/http-message-implementation
psr-mock/http-factory-implementation
psr-mock/http-client-implementation
voku/email-check
voku/urlify
rtheunissen/guzzle-log-middleware