PHPackages                             yii2-extensions/sentry - 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. [Debugging &amp; Profiling](/categories/debugging)
4. /
5. yii2-extensions/sentry

ActiveYii2-extension[Debugging &amp; Profiling](/categories/debugging)

yii2-extensions/sentry
======================

Yii2 logger for Sentry

1.1.0(3w ago)33BSD-3-ClausePHPPHP &gt;=8.4CI passing

Since Apr 20Pushed 3w agoCompare

[ Source](https://github.com/yii2-extensions/sentry)[ Packagist](https://packagist.org/packages/yii2-extensions/sentry)[ RSS](/packages/yii2-extensions-sentry/feed)WikiDiscussions main Synced 1w ago

READMEChangelog (2)Dependencies (6)Versions (5)Used By (0)

    ![Yii Framework](https://camo.githubusercontent.com/6f0a7c6c5e9ed8d389db5c82af26a2f70418756b736357378178997e52296488/68747470733a2f2f7777772e7969696672616d65776f726b2e636f6d2f696d6167652f64657369676e2f6c6f676f2f796969335f66756c6c5f666f725f6461726b2e737667)

Sentry
======

[](#sentry)

 [ ![PHPUnit](https://camo.githubusercontent.com/ed344d66566aa4da61c3b40ac1de970d06d30a72f164069474a7ff22ec759f37/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f796969322d657874656e73696f6e732f73656e7472792f6275696c642e796d6c3f7374796c653d666f722d7468652d6261646765266c6f676f3d676974687562266c6162656c3d504850556e6974) ](https://github.com/yii2-extensions/sentry/actions/workflows/build.yml) [ ![CodeCoverage](https://camo.githubusercontent.com/6d1f33a98c986a54bd2b7d2f0d6be2fdfeeac1e5d4b9ba45a29595df6a4f29dd/68747470733a2f2f696d672e736869656c64732e696f2f636f6465636f762f632f6769746875622f796969322d657874656e73696f6e732f73656e7472792e7376673f7374796c653d666f722d7468652d6261646765266c6f676f3d636f6465636f76266c6f676f436f6c6f723d7768697465266c6162656c3d436f766572616765) ](https://codecov.io/github/yii2-extensions/sentry) [ ![PHPStan](https://camo.githubusercontent.com/7c457564378c9ed3f28d3b8e3e0fe9368200103a7b7a05764bc592d66d711bf2/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f796969322d657874656e73696f6e732f73656e7472792f7374617469632e796d6c3f7374796c653d666f722d7468652d6261646765266c6f676f3d676974687562266c6162656c3d5048505374616e) ](https://github.com/yii2-extensions/sentry/actions/workflows/static.yml)

Note

Continued development of

Requirements
------------

[](#requirements)

- PHP &gt;= 8.4
- `ext-excimer` for profiling metrics

Installation
------------

[](#installation)

```
composer require yii2-extensions/sentry
```

Add target class in the application config:

```
return [
    'components' => [
        'log' => [
            'traceLevel' => YII_DEBUG ? 3 : 0,
            'targets' => [
                [
                    'class' => '\yii2\extensions\sentry\SentryTarget',
                    'dsn' => 'https://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
-----

[](#usage)

Writing simple message:

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

Writing messages with extra data:

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

### Extra callback

[](#extra-callback)

`extraCallback` property can modify extra's data as callable function:

```
    'targets' => [
        [
            'class' => '\yii2\extensions\sentry\SentryTarget',
            'dsn' => 'https://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

[](#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

### Additional context

[](#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
----------

[](#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',
```

Performance and profiling
-------------------------

[](#performance-and-profiling)

You can send data to Sentry to obtain **Performance** and **Profiling** metrics for your application.

```
'targets' => [
    [
        'class' => SentryTarget::class,
        'tracing' => true,
        'clientOptions' => [
            'traces_sample_rate' => 1.0,
            'profiles_sample_rate' => 1.0,
        ],
    ],
],
```

### Enable tracing

[](#enable-tracing)

```
'clientOptions' => [
    'traces_sample_rate' => 1.0,
],
```

### Enable profiling

[](#enable-profiling)

[![image](./support/profiling.png)](./support/profiling.png)

Note

For the profiler to work, the [Excimer](https://pecl.php.net/package/excimer) extension must be installed.

```
'clientOptions' => [
    // Set a sampling rate for profiling - this is relative to traces_sample_rate
    'profiles_sample_rate' => 1.0,
],
```

###  Health Score

43

—

FairBetter than 89% of packages

Maintenance95

Actively maintained with recent releases

Popularity7

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity54

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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 ~29 days

Total

2

Last Release

21d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/524d2b46690f41fce7188d369488a35e7624e6c5a264d82aacd08548bfd156ab?d=identicon)[terabytesoftw](/maintainers/terabytesoftw)

---

Top Contributors

[![s1lver](https://avatars.githubusercontent.com/u/4567634?v=4)](https://github.com/s1lver "s1lver (15 commits)")

---

Tags

performanceprofilingsentryyii2issues

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[sentry/sentry-laravel

Laravel SDK for Sentry (https://sentry.io)

1.4k122.6M183](/packages/sentry-sentry-laravel)[craftcms/cms

Craft CMS

3.6k3.6M2.9k](/packages/craftcms-cms)[noisebynorthwest/php-spx

A simple &amp; straight-to-the-point PHP profiling extension with its built-in web UI

2.6k1.3k](/packages/noisebynorthwest-php-spx)[wikimedia/arc-lamp

Flame graphs and log processing for PHP stack traces.

434.6k](/packages/wikimedia-arc-lamp)

PHPackages © 2026

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