punktde/sentry-flow

使用 Raven 客户端将异常和附加数据发送到 Sentry 服务器。

安装次数: 64,947

依赖项: 1

建议者: 0

安全: 0

星标: 4

关注者: 8

分支: 2

开放问题: 0

类型:neos-package

5.0.0 2024-06-05 10:16 UTC

README

Latest Stable Version Total Downloads License

这是 Flow 框架的 Sentry 客户端软件包。

有关 Sentry 的更多信息,请访问 https://sentry.io

安装

$ composer require punktde/sentry-flow

兼容性矩阵

配置

将以下内容添加到您的 Settings.yaml 中,并用您的项目 DSN(Sentry 项目的 API 密钥)替换 dsn 设置

PunktDe:
  Sentry:
    Flow:
      dsn: 'https://public_key@your-sentry-server.com/project-id'

您还可以设置 Sentry 环境,以通过例如 dev-/staging-/live-system 筛选异常。设置环境变量 SENTRY_ENVIRONMENT 或将其值添加到您的 Settings.yaml

PunktDe:
  Sentry:
    Flow:
      environment: 'live'

此外,您还可以设置 Sentry 发布版本,以帮助识别第一次发生错误时使用的发布版本。默认情况下,会搜索以 RELEASE_ 开头的文件,并使用 RELEASE_ 后的值用于 Sentry。作为替代,您可以覆盖基于文件的发布编号,并设置环境变量 SENTRY_RELEASE 或将其值添加到您的 Settings.yaml

PunktDe:
  Sentry:
    Flow:
      release: '5.0.3'

如果您需要使用自定义传输,例如将 sentry 报告写入文件,您必须实现 Sentry\TransportInterface

<?php
declare(strict_types=1);

namespace Vendor\Package\Sentry\Transport;

use Sentry\Event;
use Sentry\Exception\JsonException;
use Sentry\Transport\TransportInterface;
use Sentry\Util\JSON;

class FileWriterTransport implements TransportInterface
{
    /**
     * @param Event $event
     *
     * @return string|null Returns the ID of the event or `null` if it failed to be sent
     *
     * @throws JsonException
     */
    public function send(Event $event): ?string
    {
        if (file_put_contents('My\Path\And\FileName', JSON::encode($event)) !== false) {
            return $event->getId();
        }
        return null;
    }
}

然后配置要使用的类

PunktDe:
  Sentry:
    Flow:
      transportClass: '\Vendor\Package\Sentry\Transport\FileWriterTransport'

用法

Sentry 将记录所有启用了渲染选项 logException 的异常。这可以根据 Flow 配置通过状态码或异常类启用或禁用。