i22

Symfony 的 Airbrake.io 集成

v2.0.7 2017-11-02 10:07 UTC

README

Latest Stable Version Dependencies Status

Airbrake.io 和 Errbit 集成于 Symfony。

注意

本项目是基于 eymengunay/EoAirbrakeBundle 的分支(非常感谢)。我们曾大量使用它来完成我们的项目,但遗憾的是它已不再活跃维护。因此,我们决定分支它并进行一些改进。例如,在 twig 2.0+ 中,当前的 twig 扩展已被弃用,需要替换。此外,我们还将从 dbtlr/php-airbrake 切换到官方的 airbrake/airbrake-php。

先决条件

本捆绑包版本需要 Symfony 3.2+

安装

步骤 1:使用 composer 下载 AirbrakeBundle

在您的 composer.json 中添加 AirbrakeBundle

{
    "require": {
        "i22/airbrake-bundle": "~2.0"
    }
}

现在通过运行以下命令告诉 composer 下载捆绑包

$ php composer.phar update i22/airbrake-bundle

Composer 将将捆绑包安装到您的项目 vendor/i22 目录。

步骤 2:启用捆绑包

在内核中启用捆绑包

<?php
// app/AppKernel.php

public function registerBundles()
{
    $bundles = array(
        // ...
        new I22\AirbrakeBundle\I22AirbrakeBundle(),
    );
}

步骤 3:配置 I22AirbrakeBundle

现在您已正确安装和启用 I22AirbrakeBundle,下一步是配置捆绑包以适应您应用程序的特定需求。

将以下配置添加到您的 config.yml 文件中

# app/config/config.yml
i22_airbrake:
    project_id: PROJECT-ID
    api_key: YOUR-API-KEY

步骤 4(可选):添加主机配置以指向类似于 Errbit 的自托管解决方案

# app/config/config.yml
i22_airbrake:
    ...
    host: YOUR-ERRBIT-HOST
    ...

步骤 5(可选):添加 I22AirbrakeBundle 路由以模拟错误异常

如果您想模拟异常并测试您的配置,您可以在应用程序中添加以下路由。

# app/config/routing.yml
i22_airbrake_simulate:
    pattern: /airbrake/simulate
    defaults:  { _controller:  I22AirbrakeBundle:Simulate:index }

现在您可以从: http://your-project.domain/airbrake/simulate 访问示例控制器

配置参考

i22_airbrake:

    # This parameter is required
    # For Errbit the exact value of project_id doesn't matter
    project_id:: YOUR-PROJECT-ID

    # Omit this key if you need to enable/disable the bundle temporarily 
    # If not given, this bundle will ignore all exceptions and won't send any data to remote.
    api_key: YOUR-API-KEY

    # By default, the notifier uses a socket connection to send the exceptions to Airbrake, 
    # which WON'T wait for a response back from the server. 
    # If this is not derisable for your application, you can pass async: false 
    # and the notifier will send an syncronous notification using cURL.
    async: true

    # If you are using your own hosted implementation of 
    # Airbrake (such as Errbit) you will have to specify your custom host name.
    host: errbit.example.com

    # You might want to ignore some exceptions such as http not found, access denied etc.
    # By default this bundle ignores all HttpException instances. (includes HttpNotFoundException, AccessDeniedException)
    # To log all exceptions leave this array empty.
    ignored_exceptions: ["Symfony\Component\HttpKernel\Exception\HttpException"]

    # If you want to force override of whether or not to use SSL you can set secure to true/false whether or not to use SSL you can set secure to true/false
    # By default secure is set to true
    secure: true

用法

配置完成后,捆绑包将自动将异常/错误发送到 Airbrake 服务器。

记录 JavaScript 错误

EoAirbrakeBundle 包含一个用于 Airbrake JavaScript 通知器的 twig 扩展。要在客户端开始记录异常,您必须在您的基模板中添加 {{ airbrake_notifier() }} 函数。

<!doctype html>
<html lang="en">
    <head>
        <title>Hello World</title>
        <!-- Airbrake notifier -->
        {{ airbrake_notifier() }}
    </head>
...

许可

本捆绑包受 MIT 许可证保护。请参阅捆绑包中的完整许可证。

Resources/meta/LICENSE

报告问题或功能请求

与此捆绑包相关的问题和功能请求在GitHub问题跟踪器中跟踪:https://github.com/i22-digitalagentur/AirbrakeBundle