PHPackages                             nadar/yii2-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. [Logging &amp; Monitoring](/categories/logging)
4. /
5. nadar/yii2-sentry

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

nadar/yii2-sentry
=================

Yii2 Sentry integration with log target support

1.0.3(4mo ago)1593↓42.3%MITPHPPHP ^8.4|^8.5CI passing

Since Jan 4Pushed 2mo agoCompare

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

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

Sentry for Yii2
===============

[](#sentry-for-yii2)

Yii2 Sentry integration with log target support for error tracking and monitoring.

[![Tests](https://github.com/nadar/yii2-sentry/actions/workflows/tests.yml/badge.svg)](https://github.com/nadar/yii2-sentry/actions/workflows/tests.yml)

Important

Yii might look inactive, but it is still used a lot. This Sentry extension is **actively supported**, works with **current PHP versions**, and supports the **latest Sentry SDK options**.

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

[](#requirements)

- PHP &gt;= 8.4
- Yii2 &gt;= 2.0
- Sentry PHP SDK &gt;= 4.9

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

[](#installation)

Install via Composer:

```
composer require nadar/yii2-sentry
```

Configuration
-------------

[](#configuration)

### Basic Configuration

[](#basic-configuration)

Configure the Sentry component in your application config:

```
return [
    'components' => [
        'sentry' => [
            'class' => 'Nadar\Sentry\Sentry',
            'dsn' => 'YOUR_SENTRY_DSN',
        ],
    ],
];
```

### Console Test Command (Optional)

[](#console-test-command-optional)

For console applications, you can add the Sentry test command to verify your integration:

```
return [
    'controllerMap' => [
        'sentry-test' => [
            'class' => 'Nadar\Sentry\SentryTestCommand',
        ],
    ],
];
```

Then test your Sentry integration by running:

```
php yii sentry-test
```

This will send various test events to Sentry including exceptions, messages with different severity levels, log events, and events with custom context data. Check your Sentry dashboard to verify the events appear correctly.

### Log Target Configuration

[](#log-target-configuration)

Add the Sentry log target to your log component:

```
return [
    'components' => [
        'log' => [
            'targets' => [
                [
                    'class' => 'Nadar\Sentry\SentryTarget',
                    'levels' => ['error', 'warning'],
                    'except' => [
                        'yii\web\HttpException:404',
                        'yii\web\HttpException:403',
                    ],
                    'logVars' => ['_GET', '_POST', '_SESSION', '_SERVER'],
                ],
            ],
        ],
    ],
];
```

### Verifying Installation

[](#verifying-installation)

After installing and configuring the package, you can verify that Sentry is working correctly:

1. **Configure the Sentry component** in your `config/console.php` (for console apps) or `config/web.php` (for web apps)
2. **Add the test command** to your console config (see Console Test Command section below)
3. **Run the test command**: ```
    php yii sentry-test
    ```
4. **Check your Sentry dashboard** at  to see the test events

The test command will send multiple test events including exceptions, messages, and events with custom context to help you verify your integration is working correctly.

Configuration Options
---------------------

[](#configuration-options)

### Sentry Component Options

[](#sentry-component-options)

- **dsn** (required): Your Sentry DSN (Data Source Name)
- **sampleRate**: Sample rate for error events (0.0 to 1.0, default: 1.0)
- **tracesSampleRate**: Sample rate for performance monitoring (0.0 to 1.0, default: 0.0)
- **sendDefaultPii**: Whether to send default PII (Personally Identifiable Information)
- **maxBreadcrumbs**: Maximum breadcrumbs (default: 100)
- **clientOptions**: Additional client options for Sentry SDK
- **extraCallback**: Global callback function to add extra data to all events (see below)

### Log Target Options

[](#log-target-options)

- **sentry**: The Sentry component ID (default: 'sentry')
- **levels**: Array of log levels to capture (e.g., \['error', 'warning'\])
- **except**: Array of patterns to exclude from logging (e.g., \['yii\\web\\HttpException:404'\])
- **logVars**: Array of context variables to log (e.g., \['\_GET', '\_POST', '\_SERVER'\])

Usage
-----

[](#usage)

### Manual Exception Capture

[](#manual-exception-capture)

You can manually capture exceptions or messages:

```
try {
    // Your code
} catch (\Exception $e) {
    Yii::$app->sentry->captureException($e);
}
```

### Manual Message Capture

[](#manual-message-capture)

```
Yii::$app->sentry->captureMessage('Something went wrong', 'error');
```

### Using Yii2 Logger

[](#using-yii2-logger)

The log target will automatically capture messages logged through Yii2's logger:

```
Yii::error('An error occurred');
Yii::warning('A warning message');
```

Extra Callbacks
---------------

[](#extra-callbacks)

Both the Sentry component and SentryTarget support `extraCallback` functions to add custom context data to events. When both callbacks are defined, they are merged together with the SentryTarget callback taking precedence.

Define a global `extraCallback` in the Sentry component to add context data to ALL events:

```
return [
    'components' => [
        'sentry' => [
            'class' => 'Nadar\Sentry\Sentry',
            'dsn' => 'YOUR_SENTRY_DSN',
            'extraCallback' => function () {
                return [
                    'server_id' => gethostname(),
                    'app_version' => '1.0.0',
                ];
            },
        ],
    ],
];
```

###  Health Score

44

—

FairBetter than 92% of packages

Maintenance80

Actively maintained with recent releases

Popularity20

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity56

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 80% 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 ~3 days

Total

4

Last Release

124d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/86184bf08843ed8fcc4aedb2fdecd8a9e832e47e89a7166cebfda529c176f5ce?d=identicon)[nadar](/maintainers/nadar)

---

Top Contributors

[![nadar](https://avatars.githubusercontent.com/u/3417221?v=4)](https://github.com/nadar "nadar (36 commits)")[![Copilot](https://avatars.githubusercontent.com/in/1143301?v=4)](https://github.com/Copilot "Copilot (9 commits)")

---

Tags

loggingsentryyii2error-tracking

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[sentry/sentry-laravel

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

1.3k114.3M154](/packages/sentry-sentry-laravel)[justbetter/magento2-sentry

Magento 2 Logger for Sentry

1851.5M3](/packages/justbetter-magento2-sentry)[stayallive/wp-sentry

A (unofficial) WordPress plugin to report PHP and JavaScript errors to Sentry.

379197.9k](/packages/stayallive-wp-sentry)[mito/yii2-sentry

Yii 2 extension for Sentry

92377.7k](/packages/mito-yii2-sentry)[lordsimal/cakephp-sentry

Sentry plugin for CakePHP

12270.3k](/packages/lordsimal-cakephp-sentry)

PHPackages © 2026

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