Skip to content

Conversation

@xepozz
Copy link
Member

@xepozz xepozz commented Aug 25, 2021

Added cookbook page about integration with Sentry.

Todo:

  • Translate it into English.

@xepozz xepozz marked this pull request as ready for review October 10, 2021 11:13
@xepozz xepozz requested a review from a team October 10, 2021 11:13
@xepozz xepozz added the status:code review The pull request needs review. label Oct 10, 2021
Copy link
Member

@vjik vjik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Может быть ещё добавить информацию про аналоги Sentry, которые можно использовать с помощью этой же библиотеки? Например, GlitchTip.

Co-authored-by: Sergei Predvoditelev <[email protected]>
@xepozz
Copy link
Member Author

xepozz commented Oct 24, 2021

Может быть ещё добавить информацию про аналоги Sentry, которые можно использовать с помощью этой же библиотеки? Например, GlitchTip.

I haven't tried this service.

@samdark
Copy link
Member

samdark commented Oct 24, 2021

@xepozz I did. It is 100% compatible.

@samdark samdark added status:under development Someone is working on a pull request. and removed status:code review The pull request needs review. labels Oct 27, 2021
@xepozz
Copy link
Member Author

xepozz commented Mar 5, 2022

@samdark merge?

@xepozz
Copy link
Member Author

xepozz commented Mar 5, 2022

Oh looks config package was modified from article writing date. I will check one more time and back.

@samdark
Copy link
Member

samdark commented Mar 30, 2022

@xepozz any updates?

@samdark
Copy link
Member

samdark commented Mar 5, 2023

This one should be updated/merged. Can do translation later.

Copy link
Member Author

@xepozz xepozz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Поддерживается*

@xepozz
Copy link
Member Author

xepozz commented Mar 5, 2023

Поддерживается*

Oh sorry I meant this line
image

samdark added 3 commits March 6, 2023 09:07
diff --git c/cookbook/en/README.md i/cookbook/en/README.md
index 7d4ad10..6e50ac3 100644
--- c/cookbook/en/README.md
+++ i/cookbook/en/README.md
@@ -12,10 +12,6 @@ This book conforms to the [Terms of Yii Documentation](https://www.yiiframework.

 ---

-[Preface](preface.md)
-
-## Getting started
-
-## Organizing code
-
+- [Preface](preface.md)
 - [Structuring code by use-case with vertical slices](organizing-code/structuring-by-use-case-with-vertical-slices.md)
+- [Sentry integration](sentry-integration.md)
diff --git c/cookbook/en/sentry-integration.md i/cookbook/en/sentry-integration.md
new file mode 100644
index 0000000..67fec61
--- /dev/null
+++ i/cookbook/en/sentry-integration.md
@@ -0,0 +1,117 @@
+# Sentry Integration
+
+## What is Sentry
+
+[Sentry](https://sentry.io/) is a tool for monitoring and debugging application stability and performance.
+Sentry gives you access to the events that you send there from your application.
+
+Most often, Sentry is used for monitoring errors (exceptions).
+You can enrich errors with context to better understand the problem:
+- Request arguments
+- Tags for grouping exceptions
+- Environment state: environment variables, application state, and other global attributes
+
+You can find the full list of features on the official website: https://sentry.io/welcome/
+
+## Installation
+
+### Install the package
+
+Install the required package `yiisoft/yii-sentry` with the following command:
+
+```shell
+composer require yiisoft/yii-sentry --prefer-dist
+```
+
+### Install an HTTP driver
+
+The [`getsentry/sentry-php`](https://github.com/getsentry/sentry-php) library requires the `php-http/httplug` package and any HTTP driver.
+In the example below we’ll use the Guzzle adapter.
+
+> You can find the list of all adapters on [this page](https://docs.php-http.org/en/latest/clients.html#clients-adapters).
+
+To install the packages, run the following command:
+
+```shell
+composer require php-http/httplug php-http/guzzle7-adapter --prefer-dist
+```
+
+## Configuration
+
+### Get and store the token
+
+Next, configure the application.
+
+First, register at [Sentry](https://sentry.io) and create a project.
+
+Then, in the project settings on the “General Settings” tab, find the “Security Token” field and copy its value.
+
+Now put this token into the package configuration. By default, the config is located at `config/packages/yiisoft/yii-sentry/config/params.php`.
+Set the copied token as the value of the array element at `yiisoft/yii-sentry` => `options` => `dsn`. Example:
+
+```diff
+'yiisoft/yii-sentry' => [
+    'enabled' => true,
+    'options' => [
+-        'dsn' => '',
++        'dsn' => 'TOKEN',
+    ],
+],
+```
+
+### Configure the HTTP client
+
+After installing the HTTP client, configure it.
+
+Create the file `config/common/sentry.php` and put the following code into it:
+
+```php
+<?php
+
+declare(strict_types=1);
+
+return [
+    \Http\Client\HttpClient::class => \GuzzleHttp\Client::class,
+    \Http\Client\HttpAsyncClient::class => [
+        'class' => \Http\Adapter\Guzzle7\Client::class,
+        '__construct()' => [
+            \Yiisoft\Factory\Definition\Reference::to(\Http\Client\HttpClient::class),
+        ],
+    ],
+];
+```
+
+# Integration
+
+### Web
+
+Sentry support for `web` is implemented as middleware.
+
+That means you only need to add `SentryMiddleware` to the global middleware list in `config/web/application.php`:
+
+```diff
+return [
+    Yiisoft\Yii\Web\Application::class => [
+        '__construct()' => [
+            'dispatcher' => DynamicReference::to(static function (Injector $injector) {
+                return ($injector->make(MiddlewareDispatcher::class))
+                    ->withMiddlewares(
+                        [
+                            Router::class,
+                            SubFolder::class,
++                            SentryMiddleware::class,
+                            ErrorCatcher::class,
+                        ]
+                    );
+            }),
+            'fallbackHandler' => Reference::to(NotFoundHandler::class),
+        ],
+    ],
+];
+```
+
+### Console
+
+Sentry supports `console` via a handler for the [ConsoleEvents::ERROR](https://symfony.com/doc/current/components/console/events.html#the-consoleevents-error-event) event.
+
+The package provides a configuration file that automatically subscribes the application to this event.
diff --git c/cookbook/ru/README.md i/cookbook/ru/README.md
index 87d1f5b..1a24a7d 100644
--- c/cookbook/ru/README.md
+++ i/cookbook/ru/README.md
@@ -9,8 +9,5 @@

 ---

-Оглавление
----------------
-
 [Вступление](preface.md)
 [Интеграция с Sentry](sentry-integration.md)
@samdark samdark merged commit 8ab2b84 into master Aug 26, 2025
2 of 5 checks passed
@samdark samdark deleted the cookbook-sentry branch August 26, 2025 19:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status:under development Someone is working on a pull request.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants