notamedia/yii2-sentry
Composer 安装命令:
composer require notamedia/yii2-sentry
包简介
Yii2 logger for Sentry
README 文档
README
Installation
composer require notamedia/yii2-sentry
Add target class in the application config:
return [ 'components' => [ 'log' => [ 'traceLevel' => YII_DEBUG ? 3 : 0, 'targets' => [ [ 'class' => 'notamedia\sentry\SentryTarget', 'dsn' => 'http://2682ybvhbs347:235vvgy465346@sentry.io/1', 'levels' => ['error', 'warning'], // Write the context information (the default is true): 'context' => true, // Additional options for `Sentry\init`: 'clientOptions' => ['release' => 'my-project-name@2.3.12'] ], ], ], ], ];
Usage
Writing simple message:
\Yii::error('message', 'category');
Writing messages with extra data:
\Yii::warning([ 'msg' => 'message', 'extra' => 'value', ], 'category');
Extra callback
extraCallback property can modify extra's data as callable function:
'targets' => [ [ 'class' => 'notamedia\sentry\SentryTarget', 'dsn' => 'http://2682ybvhbs347:235vvgy465346@sentry.io/1', 'levels' => ['error', 'warning'], 'context' => true, // Write the context information. The default is true. 'extraCallback' => function ($message, $extra) { // some manipulation with data $extra['some_data'] = \Yii::$app->someComponent->someMethod(); return $extra; } ], ],
Tags
Writing messages with additional tags. If need to add additional tags for event, add tags key in message. Tags are various key/value pairs that get assigned to an event, and can later be used as a breakdown or quick access to finding related events.
Example:
\Yii::warning([ 'msg' => 'message', 'extra' => 'value', 'tags' => [ 'extraTagKey' => 'extraTagValue', ] ], 'category');
More about tags see https://docs.sentry.io/learn/context/#tagging-events
Additional context
You can add additional context (such as user information, fingerprint, etc) by calling \Sentry\configureScope() before logging.
For example in main configuration on beforeAction event (real place will dependant on your project):
return [ // ... 'on beforeAction' => function (\yii\base\ActionEvent $event) { /** @var \yii\web\User $user */ $user = Yii::$app->has('user', true) ? Yii::$app->get('user', false) : null; if ($user && ($identity = $user->getIdentity(false))) { \Sentry\configureScope(function (\Sentry\State\Scope $scope) use ($identity) { $scope->setUser([ // User ID and IP will be added by logger automatically 'username' => $identity->username, 'email' => $identity->email, ]); }); } return $event->isValid; }, // ... ];
Log levels
Yii2 log levels converts to Sentry levels:
\yii\log\Logger::LEVEL_ERROR => 'error',
\yii\log\Logger::LEVEL_WARNING => 'warning',
\yii\log\Logger::LEVEL_INFO => 'info',
\yii\log\Logger::LEVEL_TRACE => 'debug',
\yii\log\Logger::LEVEL_PROFILE_BEGIN => 'debug',
\yii\log\Logger::LEVEL_PROFILE_END => 'debug',
notamedia/yii2-sentry 适用场景与选型建议
notamedia/yii2-sentry 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2.09M 次下载、GitHub Stars 达 127, 最近一次更新时间为 2015 年 12 月 29 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「sentry」 「yii2」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 notamedia/yii2-sentry 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 notamedia/yii2-sentry 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 notamedia/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
统计信息
- 总下载量: 2.09M
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 128
- 点击次数: 21
- 依赖项目数: 6
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2015-12-29