pluswerk / sentry
+Pluswerk TYPO3 扩展:Sentry 客户端
3.3.0
2024-04-19 06:25 UTC
Requires
- php: ~8.1.0 || ~8.2.0 || ~8.3.0
- composer-runtime-api: ^2
- ext-fileinfo: *
- http-interop/http-factory-guzzle: ^1.0
- sentry/sentry: ^3.22.1
- typo3/cms-core: ^11.5 || ^12.4
- typo3/cms-frontend: ^11.5 || ^12.4
Requires (Dev)
- pluswerk/grumphp-config: ^7
- saschaegerer/phpstan-typo3: ^1.10.0
- ssch/typo3-rector: ^2.4.0
- symfony/http-client: ^5.4 || ^6
README
Pluswerk TYPO3 Sentry PHP 客户端
功能
- 具有 LogWriter,可让您将任何日志条目写入 Sentry
- 记录所有由 TYPO3 错误处理捕获的异常。
- 记录所有由 TYPO3 生产异常处理器 ContentObject 捕获的异常。
- 这处理您网站中的
Oops, an error occurred! code: 2023080912232477707e9b
错误。 - 它以正常方式显示错误消息 + 代码后面只有一个 的链接。因此,普通用户将看不到链接。
- 链接将直接打开带有正确错误的 Sentry。
- 这处理您网站中的
快速入门
- 添加环境变量
SENTRY_DSN=https://dsn-to-your@sentry.io/instance
SENTRY_ORGANISATION=sentry
(可选):如果您的 Sentry 组织不同。在例如“Oops, an error occurred! Code: 2023080912232477707e9b”中使用。DISABLE_SENTRY
(可选):通过将此设置为 1 禁用 SentrySENTRY_QUEUE
(可选):通过将此设置为 1 启用队列系统SENTRY_ERRORS_TO_REPORT
(可选):要报告的错误作为数字,例如 E_REVOERABLE_ERROR 的 4096
- 将以下行添加到您的
AdditionalConfiguration.php
(new \Pluswerk\Sentry\Bootstrap())->initializeHandler();
- 如果您启用了 SENTRY_QUEUE
- 将
typo3 pluswerk:sentry:flush
添加到您的调度服务中 - 如果您想在运行命令时报告错误,请在命令之前添加环境变量
SENTRY_QUEUE=0 typo3 pluswerk:sentry:flush
- 将
设置
此扩展包含一些设置在 TYPO3 后端
force_disable_sentry
-> 强制通过在后台禁用 Sentry 覆盖 ENVenable_git_hash_releases
(默认为是)-> 自动跟踪具有当前 git 哈希的版本(仅在安装了 git 的情况下有效)
配置范围
有时可能需要另外配置 Sentry 事件的范围。
为此,可以使用方法 \Pluswerk\Sentry\Sentry::withScope($exception, $scopeCallback)
。
参数类似于 https://docs.sentry.io/platforms/php/enriching-events/scopes/#local-scopes
。第一个参数需要抛出异常,第二个是一个回调,您可以在其中应用自定义设置到 Sentry 范围。
在该回调中不需要额外写入 captureException
。
示例
Sentry::getInstance()->withScope($exception, fn(Scope $scope) => $scope->setTag('oops_code', $oopsCode));
SentryLogger
如果您想将所有来自 TYPO3 日志的警告记录到 Sentry,可以在 additional.php 中写入此内容。
$GLOBALS['TYPO3_CONF_VARS']['LOG']['writerConfiguration'][LogLevel::WARNING] = [ SyslogWriter::class => [], SentryLogger::class => [], ];