evolcon/yii2-sentry
Composer 安装命令:
composer require evolcon/yii2-sentry
包简介
Yii2 sentry
README 文档
README
Installation
composer require evolcon/yii2-sentry:@dev
Add SentryComponent to the the application config:
'components' => [
'sentry' => [
'class' => evolcon\sentry\SentryComponent::class,
'dsn' => 'https://fsdhbk67bhkfa424eehb678agj66b7@sentry.io/2588150',
],
],
For disabling notification set false to attribute enabled
'components' => [
'sentry' => [
'class' => evolcon\sentry\SentryComponent::class,
'dsn' => 'https://fsdhbk67bhkfa424eehb678agj66b7@sentry.io/2588150',
'enabled' => false,
],
],
Add class SentryTarget attribute 'targets' for component 'log'
'components' => [
'log' => [
'traceLevel' => YII_DEBUG ? 3 : 0,
'flushInterval' => 1,
'targets' => [
[
'class' => evolcon\sentry\SentryTarget::class,
'exportInterval' => 1,
'levels' => ['error', 'warning'],
'except' => [
'yii\web\HttpException:429', // TooManyRequestsHttpException
'yii\web\HttpException:401', // UnauthorizedHttpException
],
'userData' => ['id', 'email', 'role'],
],
]
],
],
#User data collecting
Add userData attribute to SentryTarget and array list of attributes which are needed to be collected
'components' => [
'log' => [
'traceLevel' => YII_DEBUG ? 3 : 0,
'flushInterval' => 1,
'targets' => [
[
'class' => evolcon\sentry\SentryTarget::class,
'exportInterval' => 1,
'levels' => ['error', 'warning'],
'except' => [
'yii\web\HttpException:429', // TooManyRequestsHttpException
'yii\web\HttpException:401', // UnauthorizedHttpException
],
'userData' => ['id', 'email', 'role'],
],
]
],
],
By default sentry target uses 'user' component of the application. If you need to override component, configure attribute userComponent
NOTE: component must be an instance of \yii\web\User class
'components' => [
'log' => [
'traceLevel' => YII_DEBUG ? 3 : 0,
'flushInterval' => 1,
'targets' => [
[
'class' => evolcon\sentry\SentryTarget::class,
'userComponent' => 'user', //the component name
'userData' => ['id', 'email', 'role'],
],
]
],
],
Sometimes we need to separate logs for example to separate warning and error and send them to different projects in sentry.
For that we need to override SentryTarget's attribute sentryComponent , and set the component name which we needed
'components' => [
'sentryWarnings' => [
'class' => evolcon\sentry\SentryComponent::class,
'dsn' => 'https://fsdhbk67bhkfa424eehb678agj66b7@sentry.io/55555555',
],
'sentryErrors' => [
'class' => evolcon\sentry\SentryComponent::class,
'dsn' => 'https://fsdhbk67bhkfa424eehb678agj66b7@sentry.io/999999999',
],
'log' => [
'traceLevel' => YII_DEBUG ? 3 : 0,
'flushInterval' => 1,
'targets' => [
[
'class' => evolcon\sentry\SentryTarget::class,
'sentryComponent' => 'sentryWarnings',
'levels' => ['warning'], //only warnings
],
[
'class' => evolcon\sentry\SentryTarget::class,
'sentryComponent' => 'sentryErrors',
'levels' => ['error'], //only errors
],
]
],
],
Exception with tags
use evolcon\sentry\SilentException;
throw (new SilentException('Error message'))
->addTag('tagName', 'tagValue')
->addTag('tagName2', 'tagValue')
->addExtra('extraName', 'extraValue')
->addExtra('extraName2', 'extraValue');
Multiple tags and extra
throw (new SilentException('Error message'))
->addTags(['tagName' => 'tagValue', 'tagName2' => 'tagValue'])
->addExtras(['extraName' => 'extraValue', 'extraName2' => 'extraValue']);
Exception without throwing is need sometimes when we need to debug our code and keep project fault tolerant.
In this case you can create an instance of class SilentException and call method save()
try {
// my code
} catch(\Throwable $e) {
(new SilentException($e->getMessage()))
->addTags(['tagName' => 'tagValue', 'tagName2' => 'tagValue'])
->addExtras(['extraName' => 'extraValue', 'extraName2' => 'extraValue'])
->save(__METHOD__);
}
evolcon/yii2-sentry 适用场景与选型建议
evolcon/yii2-sentry 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 88 次下载、GitHub Stars 达 1, 最近一次更新时间为 2019 年 11 月 02 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「sentry」 「yii2」 「evolcon」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 evolcon/yii2-sentry 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 evolcon/yii2-sentry 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 evolcon/yii2-sentry 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Fork of a PHP client for Sentry (http://getsentry.com) that work also with php5.2
An implementation of the Sentry User Manager for Laravel.
A custom URL rule class for Yii 2 which allows to create translated URL rules
Simple Yii2 Sentry target for logging (http://getsentry.com)
Monitoring for scheduled jobs
Asynchronous Sentry for Symfony - Fire and forget
统计信息
- 总下载量: 88
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: Unknown
- 更新时间: 2019-11-02