集成

了解 Sentry 提供的自动集成及其配置方法。

这些集成默认启用,并集成到标准库或解释器本身。它们有文档说明,以便您了解它们的功能并在出现问题时禁用它们。

要禁用系统集成,在调用 \Sentry\init() 时设置 default_integrations => false

此集成捕获所有全局未捕获的异常,并在发生错误时发出事件。

为此,它确保 Sentry 的 ErrorHandler 已注册,并将其添加为异常监听器的回调。

此集成钩入全局 PHP error_handler,并在发生错误时发出事件。

为此,它确保 Sentry 的 ErrorHandler 已注册,并将其添加为错误监听器的回调。默认情况下,ErrorHandler 保留 16 KiB 的内存来处理致命错误。在处理内存不足错误时,ErrorHandler 还会将 memory_limit 额外增加 5 MiB,以确保有足够的空间将内存不足事件发送到 Sentry。此更改仅执行一次,且仅影响内存不足错误的处理。

要更改用于致命错误处理的内存量或在处理内存不足错误时 memory_limit 增加的量,您可以在调用 \Sentry\init(...) 之前自行注册致命错误处理程序:

Copied
// The amount of reserved memory every request (in bytes), this has to be a positive integer amount of bytes. Defaults to 16 KiB
$errorHandler = \Sentry\ErrorHandler::registerOnceFatalErrorHandler(16 * 1024);
// The amount of memory in bytes to increase the `memory_limit` to when handling a out of memory error, can also be set to `null` to disable increasing the `memory_limit`. Defaults to 5 MiB
$errorHandler->setMemoryLimitIncreaseOnOutOfMemoryErrorInBytes(5 * 1024 * 1024);

对于某些框架或项目,官方和第三方用户提供了特定的集成,这些集成会自动注册错误处理程序。请参阅它们的文档。

默认情况下,error_types 选项默认为 error_reporting() 函数返回的值,这可能会在运行时更改。或者,您可以通过在 \Sentry\init() 中将其值设置为 PHP E* 常量的位掩码来设置为固定值。在这种情况下,Sentry 只会记录那些特定类型的错误,而不管当前的报告级别。

此集成捕获所有致命错误并发出相应的事件。

为此,它确保 Sentry 的 ErrorHandler

此集成向事件添加请求数据:

  • HTTP 方法
  • URL(包括查询字符串)
  • 主体(默认情况下仅在主体小于 10Kb 时)

如果启用了 send_default_pii 选项,它还将发送以下 PII:

  • IP 地址
  • Cookies
  • Headers

此集成将事件的 transaction 属性设置为原始事件有效负载中找到的值,或如果存在则设置为 PATH_INFO 服务器变量的值。

此集成读取引发错误的代码行周围的代码片段。

此集成用 PHP 运行时和服务器操作系统信息填充事件数据。

此集成记录与事件详细信息一起安装的所有 Composer 包的版本;根项目也包含在内。

您可以在不禁用默认集成的情况下使用 integrations 选项自定义集成列表。对于高级需求,您可以传递一个可调用对象,但在大多数情况下,固定集成列表即可工作。

在下面的示例中,所有集成都已启用,除了 ExceptionListenerIntegration

Copied
\Sentry\init([
    'dsn' => 'https://examplePublicKey@o0.ingest.sentry.io/0',
    'integrations' => static function (array $integrations) {
        $integrations = array_filter($integrations, static function (\Sentry\Integration\IntegrationInterface $integration) {
            // Check if the integration if an instance of the exception listener and return false to remove it from the array
            if ($integration instanceof \Sentry\Integration\ExceptionListenerIntegration) {
                return false;
            }

            return true;
        });

        return $integrations;
    },
]);