crassula/google-cloud-error-reporting-bundle

Symfony扩展包用于Google Cloud错误报告

v0.8.0 2021-04-12 11:27 UTC

This package is auto-updated.

Last update: 2024-09-12 19:04:24 UTC


README

此扩展包提供与Google Cloud Error Reporting的集成,以便在您的Symfony项目中使用。

注意: 此扩展包使用Google Cloud Error Reporting for PHP包,该包目前处于alpha阶段,因此预期会有BC不兼容性。

先决条件

此扩展包需要Symfony 3.3+。此外,您可能还需要安装grpc和protobuf PECL扩展。

安装

crassula/google-cloud-error-reporting-bundle添加到您的composer.json文件中

$ composer require crassula/google-cloud-error-reporting-bundle

在app/AppKernel.php中注册扩展包

public function registerBundles()
{
    return array(
        // ...
        new Crassula\Bundle\GoogleCloudErrorReportingBundle\CrassulaGoogleCloudErrorReportingBundle(),
    );
}

身份验证

有关客户端身份验证的信息,请参阅Google的身份验证指南。一旦身份验证成功,您就可以开始发送请求。

配置

在您的app/config/config.yml中进行最小配置

crassula_google_cloud_error_reporting:
    enabled: true
    project_id: project-12345
    service: app_name
    client_options:
        credentials: /etc/gcp_credentials.json

默认情况下,错误报告是禁用的,因此您需要明确启用您需要的地方(例如,在app/config/config_prod.yml中)。

要运行完整配置引用,请执行

$ bin/console config:dump-reference CrassulaGoogleCloudErrorReportingBundle

示例

use Crassula\Bundle\GoogleCloudErrorReportingBundle\Service\ErrorReporter;

try {
    $this->doFaultyOperation();
} catch (\Exception $e) {
    $container->get(ErrorReporter::class)->report($e);
}

您还可以作为第二个参数传递选项

注意事项

关于自动错误报告

当配置选项use_listeners启用时,扩展包会注册具有优先级2048kernel.exceptionconsole.error事件监听器。

错误在kernel.terminateconsole.terminate时报告。

此选项默认启用。

异常处理

报告器捕获并记录与Google Cloud Error Reporting包配置错误相关的异常。

许可证

此包可在MIT许可证下获得。