asminog/yii2-sentry

Yii2 logger for Sentry

Maintainers

👁 asminog

Package info

github.com/asminog/yii2-sentry

Type:yii2-extension

pkg:composer/asminog/yii2-sentry

Statistics

Installs: 71

Dependents: 0

Suggesters: 0

Stars: 3

Open Issues: 0

v1.2.0 2025-02-27 16:10 UTC

Requires

Suggests

None

Provides

None

Conflicts

None

Replaces

None

MIT 999b14bfb7b21de6383450b97c0bf0dfa4997bff

loggersentryyii2

This package is auto-updated.

Last update: 2026-06-27 19:34:38 UTC


README

👁 Latest Stable Version
👁 Test
👁 License
👁 PHP from Packagist
👁 Code Intelligence Status
👁 Scrutinizer code quality
👁 Downloads

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: 'auto'. 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 [].
 /* @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 [].
 /* @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