PHPackages                             sheershoff/yii2-sentry-component - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Logging &amp; Monitoring](/categories/logging)
4. /
5. sheershoff/yii2-sentry-component

ActiveYii2-extension[Logging &amp; Monitoring](/categories/logging)

sheershoff/yii2-sentry-component
================================

A Yii2 component for Sentry allowing data arrays passing through Yii2 logging methods

1.0.8(9y ago)414.5k1MITPHPPHP &gt;=5.4.0

Since Feb 18Pushed 9y ago1 watchersCompare

[ Source](https://github.com/sheershoff/yii2-sentry)[ Packagist](https://packagist.org/packages/sheershoff/yii2-sentry-component)[ RSS](/packages/sheershoff-yii2-sentry-component/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (2)Versions (6)Used By (0)

Usage of this fork is strongly discouraged
==========================================

[](#usage-of-this-fork-is-strongly-discouraged)

This fork is abandoned and left for those who still uses it (if any at all). Stick to  instead.

Yii2 sentry component
=====================

[](#yii2-sentry-component)

Yii2 Sentry component allowing for unified array format passing parameters to Sentry log target and other log targets. The ability to pass arrays as the log message is suitable practice for those who want to use Logstash, ElasticSearch, etc. for getting statistical inferences of these data later on.

Install
-------

[](#install)

```
php composer.phar require sheershoff/yii2-sentry-component:dev-master

```

In config file:

```
'bootstrap' => ['log', 'raven'],
'components' => [
    'raven' => [
        'class' => 'sheershoff\sentry\ErrorHandler',
        'dsn' => '', // Sentry DSN
    ],
    'log' => [
        'targets' => [
            [
                'class' => 'sheershoff\sentry\Target',
                'levels' => ['error', 'warning'],
                'dsn' => '', // Sentry DSN
            ]
        ],
    ],
]
```

If application doesn't have `raven` component, the component will not try to send messages to sentry. This is useful for development environments, for example.

Usage
-----

[](#usage)

Exceptions and PHP errors are caught without effort. Standart `Yii::(error|warning|info|trace)` logging works as usual, but you also can use the following format:

```
Yii::warning([
    'msg' => 'SomeWarning', // event name that will be sent to Sentry
    'data' => [ // extra data for the event
        'userId' => Yii::$app->user->id,
        'someDataOnWarningSituation' => $controller->state,
        'modelThatCausedFailure' => $model->attributes,
    ],
], 'eventCategory');
```

Or you can replace this with `Log::warning` as in the exception example below, since the exception argument is not required. Notice that `eventCategory` is not sent to Sentry and is used only for log messages routing and filtering.

Wherever you need to log a caught exception with stacktrace and additional data, use

```
use sheershoff\sentry\Log;
// some code here
try{
    $model1->save();
}catch (\Exception $e){
    Log::warning([
        'msg' => 'ExceptionWarning', // event name that will be sent to Sentry
        'data' => [ // extra data for the event
            'userId' => Yii::$app->user->id,
            'someDataOnWarningSituation' => $controller->state,
            'modelThatCausedFailure' => $model->attributes,
        ],
    ], 'exceptionCategory', $e);
}
```

There are proxy methods in `Log` for the four Yii static methods: `error`, `warning`, `info`, `trace`. If `$e` is not null the component expects that it is an exception and after calling the corresponding Yii method also captures the exception for Sentry.

Also, the following use cases are possible:

```
SentryHelper::extraData($task->attributes);
throw new Exception('unknown task type');
```

Or just capture a message with full stacktrace:

```
try {
    throw new Exception('FAIL');
} catch (Exception $e) {
    SentryHelper::captureWithMessage('Fail to save model', $e);
}
```

Other log targets
-----------------

[](#other-log-targets)

To use the power of the component you should keep in mind that other log targets will receive arrays instead of strings in the log message. You can create a proxy class, redefining `formatMessage` method of the parent LogTarget, e.g.:

```
namespace common\components;
use Yii;
class SyslogJsonTarget extends \yii\log\SyslogTarget
{
	/**
	 * @inheritdoc
	 */
	public function formatMessage($message)
	{
		list($text, $level, $category, $timestamp) = $message;
		$level = \yii\log\Logger::getLevelName($level);
		if (!is_string($text)) {
			$text = \yii\helpers\Json::encode($text);
		} else {
			$text = \yii\helpers\Json::encode(['rawstring' => $text]);
		}
		$prefix = $this->getMessagePrefix($message);
		return "{$prefix}[$level][$category] $text";
	}
}
```

Data precautions
----------------

[](#data-precautions)

- Avoid passing resources and objects that can not be serialized in the array or rewrite formatMessage to handle that, e.g. trying to serialize PDO instance will raise fatal PHP error. Native Yii log targets will try to serialize that. One can check  to see how it sanitizes and handles these cases and use it's static methods.
- Also check how raven can filter out private data such as password or sensitive financial requisites.

Inspired by
-----------

[](#inspired-by)

-
-

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity24

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity62

Established project with proven stability

 Bus Factor1

Top contributor holds 65.2% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~116 days

Total

5

Last Release

3636d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/d2b71f46c0f8be2d70581785d84ea50e76b41d65141bfe4d55fb84ddcdaf041e?d=identicon)[sheershoff](/maintainers/sheershoff)

---

Top Contributors

[![m8rge](https://avatars.githubusercontent.com/u/575777?v=4)](https://github.com/m8rge "m8rge (15 commits)")[![sheershoff](https://avatars.githubusercontent.com/u/1510318?v=4)](https://github.com/sheershoff "sheershoff (7 commits)")[![ramm](https://avatars.githubusercontent.com/u/476076?v=4)](https://github.com/ramm "ramm (1 commits)")

---

Tags

logsentryyii2raven

### Embed Badge

![Health badge](/badges/sheershoff-yii2-sentry-component/health.svg)

```
[![Health](https://phpackages.com/badges/sheershoff-yii2-sentry-component/health.svg)](https://phpackages.com/packages/sheershoff-yii2-sentry-component)
```

###  Alternatives

[e96/yii2-sentry

A Yii2 client for Sentry (http://getsentry.com)

2960.4k](/packages/e96-yii2-sentry)[facile-it/sentry-module

This module allows integration of Sentry Client into laminas and mezzio

19372.5k](/packages/facile-it-sentry-module)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
