asminog / yii2-sentry
Yii2 logger for Sentry
Installs: 65
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 3
Forks: 0
Open Issues: 0
Type:yii2-extension
Requires
- php: ^7.1
- sentry/sdk: ^2.1
- yiisoft/yii2: ^2.0
Requires (Dev)
- codeception/codeception: ^3.0
This package is auto-updated.
Last update: 2024-12-22 17:03:06 UTC
README
Installation
composer require asminog/yii2-sentry
Add target class in the application config:
return [ 'components' => [ 'log' => [ 'traceLevel' => YII_DEBUG ? 3 : 0, 'targets' => [ [ 'class' => 'asminog\yii2sentry\SentryTarget', 'levels' => ['error', 'warning'], 'dsn' => 'https://88e88888888888888eee888888eee8e8@sentry.io/1', // release option for project, default: null. Use "auto" to get it from git exec('git log --pretty="%H" -n1 HEAD') 'release' => 'my-project-name@2.3.12', // Options for sentry client 'options' => [], // Collect additional context from $_GLOBALS, default: ['_SESSION', 'argv']. To switch off set false. /* @see https://docs.sentry.io/enriching-error-data/context/?platform=php#extra-context 'collectContext' => ['_SERVER', '_COOKIE', '_SESSION', 'argv'], // user attributes to collect, default: ['id', 'username', 'email']. To switch off set false. /* @see https://docs.sentry.io/enriching-error-data/context/?platform=php#capturing-the-user */ 'collectUserAttributes' => ['userId', 'userName', 'email'], // add something to extra using extraCallback, default: null 'extraCallback' => function ($message, $extra) { $extra['YII_ENV'] = YII_ENV; return $extra; } ], ], ], ], ];
Usage
Writing simple message:
\Yii::error('message', 'category');
Writing messages with extra data:
\Yii::warning([ 'msg' => 'message', 'extra' => 'value', ], 'category');
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
About
Inspired by notamedia/yii2-sentry