statikbe/craft-sentry

Craft CMS 的 Sentry.io 集成

安装数: 9,482

依赖项: 1

推荐者: 0

安全性: 0

星标: 2

关注者: 10

分支: 1

开放问题: 0

类型:craft-plugin

5.0.0 2024-03-26 20:12 UTC

This package is auto-updated.

Last update: 2024-08-26 21:02:02 UTC


README

Sentry.io 对 Craft CMS 的集成。灵感来源于 born05/craft-sentry,但有所创新。

安装

要安装此插件,请在您的终端中遵循以下说明。

cd /path/to/project
composer require statikbe/craft-sentry
./craft plugin/install craft-sentry

配置

创建一个 config/craft-sentry.php 配置文件,内容如下

<?php

return [
    'enabled'       => true,
    'anonymous'     => true,
    'clientDsn'     => getenv('SENTRY_DSN') ?: 'https://example@sentry.io/123456789',
    'excludedCodes' => ['400', '404', '429'],
    'release'       => getenv('SENTRY_RELEASE') ?: null,
];

用法

要使 Sentry 记录您的异常,您实际上不需要做任何事情。安装插件并添加您的 DSN 即可。

当您编写自己的自定义代码并抛出自定义异常时,您可能还想捕获这些异常并将它们发送到 Sentry。可以这样做

<?php

use statikbe\sentry\Sentry;
use yii\base\InvalidConfigException; // Don't copy this line, it's just here to make the example theoractically correct ;) 

try {
    throw new InvalidConfigException("Something went wrong here...");
} catch (Exception $e) {
    Sentry::handleException($e);
}

该插件适用于抛出在 Web 请求和控制台请求中的异常。对于 Web 请求,会包含错误发生的 URL。

Statik.be 提供