-
-
Notifications
You must be signed in to change notification settings - Fork 84
Add cookbook page about sentry integration #134
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
vjik
left a comment
There was a problem hiding this 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]>
I haven't tried this service. |
|
@xepozz I did. It is 100% compatible. |
|
@samdark merge? |
|
Oh looks config package was modified from article writing date. I will check one more time and back. |
|
@xepozz any updates? |
|
This one should be updated/merged. Can do translation later. |
xepozz
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Поддерживается*
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)

Added cookbook page about integration with Sentry.
Todo: