m12 / flow-rollbar
Rollbar.com 错误报告,适用于 Flow/Neos 项目
Requires
- neos/utility-arrays: *
- rollbar/rollbar: ~0.18.2
- typo3/eel: *
- typo3/flow: *
This package is not auto-updated.
Last update: 2024-09-14 19:04:15 UTC
README
将错误和未处理的异常报告给您的 Flow/Neos 项目的 Rollbar.com 服务。
在生产环境中特别有用,您不希望有任何异常或错误未被注意。
特性
- 错误和异常日志记录
- 在服务器端(PHP,包括 Web 请求和 CLI 请求)
- 在前端(JS)对于公共站点和 Neos 管理区域(内容模块和其他模块,如媒体、工作空间等)
- 默认情况下仅针对生产环境启用,也可以为开发环境启用。
- 发送环境和当前认证的账户标识符(如果存在)。
- 在 Flow 3.3、Neos 2.3 和 PHP 7.0 上测试过(应该可以在 PHP 5.6 上工作)。
安装
使用 composer 安装
composer require m12/flow-rollbar
配置
在 Configuration/Settings.yaml
中配置您的设置。您可以禁用前端 JavaScript 的 Rollbar 错误报告,或为 prod/dev 环境启用/禁用它。
以下为默认设置:
M12:
Rollbar:
# Enables Rollbar reporting for Production context
enableForProduction: true
# Enables Rollbar reporting for Development context
enableForDevelopment: false
# Enables Rollbar on the front-end, in the browser
# @see rollbarJsSettings below
enableForFrontend: true
# Server-side configuration
#
# You can add here any setting option described in rollbar-php
# docs: https://github.com/rollbar/rollbar-php
#
# Note: the `root`, `environment` and `person_fn` options are automatically filled.
rollbarSettings:
access_token: your POST_SERVER_ITEM access token here
batch_size: 10
# Front-end side configuration
#
# You can add here any option available in
# https://rollbar.com/docs/notifier/rollbar.js/ .
#
# Note: the `payload.environment` and `payload.person` options are automatically filled.
rollbarJsSettings:
accessToken: your POST_CLIENT_ITEM access token here
captureUncaught: true
captureUnhandledRejections: true
payload: {}
# Path to Rollbar html/js template
templatePath: 'resource://M12.Rollbar/Private/Templates/Rollbar.html'
# Assuming FLOW_CONTEXT contains sub-context, should it be sent in the `environment` key?
# When set to false *and* sub-context *is* present, whole FLOW_CONTEXT will be sent as a separate metadata.
includeSubContextInEnvironment: false
服务器端错误报告
在 rollbarSettings
中配置它。您至少需要提供 API 访问令牌应用程序(您的 Rollbar 应用的 post_server_item
)。您可以在 rollbar-php 文档中添加任何设置选项:[https://github.com/rollbar/rollbar-php](https://github.com/rollbar/rollbar-php)。
前端(javascript)错误报告
在 rollbarJsSettings
中配置它。至少需要提供 accessToken
值(您的 Rollbar 应用的 post_client_item
)。您可以在 rollbar JS 文档中添加任何设置选项:[https://rollbar.com/docs/notifier/rollbar.js/](https://rollbar.com/docs/notifier/rollbar.js/)。
Neos
Neos 的前端集成是开箱即用的,适用于公共站点以及所有 Neos CMS 管理区域(内容模块和其他子模块,例如媒体、历史记录等)。
要仅在 Neos CMS 管理面板上启用 Rollbar,您可以在您的 .ts 代码中添加以下行
prototype(TYPO3.Neos:Page) {
head {
rollbar = TYPO3.TypoScript:Template {
@if.onlyRenderWhenNotInLiveWorkspace = ${node.context.workspace.name != 'live'}
}
}
}
注意:前端实现的实现可能有点棘手。视图被配置为覆盖 Neos 的 Default.html
布局,以在所有 Neos 后端(子)模块上渲染 Rollbar 配置和 JS 片段。如果您已经覆盖了默认的 Neos 布局,请注意这一点。除此之外,我们还有一些 .ts 代码(自动包含)来将 Rollbar 片段添加到页面的 HEAD 部分,无论是在 Neos 内容模块中还是在实时网站上。
Flow
前端集成需要在您的模板(或布局中,这样它就可以在所有不同的视图中共享)中添加 Rollbar 片段。
使用 <rollbar:renderRollbar />
标签将 Rollbar 片段添加到您的前端布局代码中。请记住,在文件的顶部添加 rollbar
命名空间。
Rollbar 建议将其添加到 HEAD 部分的顶部,至少在其他任何 .js 代码之前。您的代码可能看起来像这样
{namespace rollbar=M12\Rollbar\ViewHelpers}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<rollbar:renderRollbar />
...
</head>
作者
作者:Marcin Ryzycki (marcin@m12.io)
许可
MIT