arueckauer/mezzio-sentry-delegator

Mezzio Delegator 和 Sentry 错误监听器

1.5.0 2024-08-21 16:10 UTC

This package is auto-updated.

Last update: 2024-09-21 16:21:19 UTC


README

Mezzio Delegator 和 Sentry 错误监听器

本软件包为 Sentry 提供初始化包装,并通过 Stratigility ErrorHandler 中间件的 ErrorListener 在 Sentry 中捕获可抛出对象(Throwable)的能力。Stratigility ErrorHandler 中间件 的文档。

安装

通过 Composer

composer require arueckauer/mezzio-sentry-delegator

配置

在项目的配置中提供 Sentry 的 dsn 以及可能的其它 配置选项,例如 config/autoload/services.local.php。前往 PHP 配置文档 选择项目的 dsn。

<?php

declare(strict_types = 1);

use Sentry\Options as SentryOptions;

return [
    // [..]
    SentryOptions::class => [
        'dsn' => 'https://<key>@<account-id>.ingest.sentry.io/<project-id>',
    ],
];

初始化 Sentry

要初始化 Sentry,将以下行添加到 public/index.php 中的匿名函数。

(new MezzioSentryDelegator\SentryInitializer())($container);

通过连接委托器附加监听器

在项目的配置中声明委托器依赖项,例如 config/autoload/dependencies.global.php

<?php

declare(strict_types = 1);

use MezzioSentryDelegator\Delegator;
use Laminas\Stratigility\Middleware\ErrorHandler;

class ConfigProvider
{
    public function __invoke() : array
    {
        return [
            'dependencies' => [
                'delegators' => [
                    ErrorHandler::class => [
                        Delegator::class,
                    ],
                ],
            ],
        ];
    }
}