承接 classmarkets/raven-bundle 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

classmarkets/raven-bundle

最新稳定版本:3.0.0

Composer 安装命令:

composer require classmarkets/raven-bundle

包简介

Display sentry event ids on error pages

README 文档

README

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

统计信息

  • 总下载量: 15.2k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 2
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2014-11-06

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固