2017 © Pedro Peláez
 

yii2-extension yii2-sentry

Yii2 logger for Sentry

image

notamedia/yii2-sentry

Yii2 logger for Sentry

  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 12 Forks
  • 2 Open issues
  • 10 Versions
  • 21 % Grown

The README.md

Sentry logger for Yii2

Build Status Latest Stable Version Total Downloads License, (*1)

Installation

composer require notamedia/yii2-sentry

Add target class in the application config:, (*2)

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:, (*3)

\Yii::error('message', 'category');

Writing messages with extra data:, (*4)

\Yii::warning([
    'msg' => 'message',
    'extra' => 'value',
], 'category');

Extra callback

extraCallback property can modify extra's data as callable function:, (*5)

    '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., (*6)

Example:, (*7)

\Yii::warning([
    'msg' => 'message',
    'extra' => 'value',
    'tags' => [
        'extraTagKey' => 'extraTagValue',
    ]
], 'category');

More about tags see https://docs.sentry.io/learn/context/#tagging-events, (*8)

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):, (*9)

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:, (*10)

\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',

The Versions

24/10 2017

dev-master

9999999-dev

Yii2 logger for Sentry

  Sources   Download

MIT

The Requires

 

The Development Requires

yii2 sentry

24/08 2017

1.3.0

1.3.0.0

Yii2 logger for Sentry

  Sources   Download

MIT

The Requires

 

The Development Requires

yii2 sentry

26/07 2017

1.3.0-beta

1.3.0.0-beta

Yii2 logger for Sentry

  Sources   Download

MIT

The Requires

 

The Development Requires

yii2 sentry

28/01 2017

1.2.1

1.2.1.0

Yii2 logger for Sentry

  Sources   Download

MIT

The Requires

 

The Development Requires

yii2 sentry

30/11 2016

1.2.0

1.2.0.0

Yii2 logger for Sentry

  Sources   Download

MIT

The Requires

 

yii2 sentry

03/10 2016

1.1.2

1.1.2.0

Yii2 logger for Sentry

  Sources   Download

MIT

The Requires

 

yii2 sentry

05/09 2016

1.1.1

1.1.1.0

Yii2 logger for Sentry

  Sources   Download

MIT

The Requires

 

yii2 sentry

08/04 2016

1.1.0

1.1.0.0

Yii2 logger for Sentry

  Sources   Download

MIT

The Requires

 

yii2 sentry

04/01 2016

1.0.0

1.0.0.0

Yii2 logger for Sentry

  Sources   Download

MIT

The Requires

 

yii2 sentry

29/12 2015

1.0.0-beta

1.0.0.0-beta

Yii2 logger for Sentry

  Sources   Download

MIT

The Requires

 

yii2 sentry