punktde / sentry-flow
使用 Raven 客户端将异常和附加数据发送到 Sentry 服务器。
5.0.0
2024-06-05 10:16 UTC
Requires
- neos/flow: ^5.0 || ^6.0 || ^7.0 || ^8.0 || ^9.0
- sentry/sentry: ^4.0
README
这是一个针对 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 配置根据状态码或异常类启用或禁用。