Skip to content

Commit 578029d

Browse files
committed
Add English translation
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)
1 parent ab4e22f commit 578029d

File tree

3 files changed

+119
-9
lines changed

3 files changed

+119
-9
lines changed

cookbook/en/README.md

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,6 @@ This book conforms to the [Terms of Yii Documentation](https://www.yiiframework.
1212

1313
---
1414

15-
[Preface](preface.md)
16-
17-
## Getting started
18-
19-
## Organizing code
20-
15+
- [Preface](preface.md)
2116
- [Structuring code by use-case with vertical slices](organizing-code/structuring-by-use-case-with-vertical-slices.md)
17+
- [Sentry integration](sentry-integration.md)

cookbook/en/sentry-integration.md

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
# Sentry integration
2+
3+
## What is Sentry
4+
5+
[Sentry](https://sentry.io/) is a tool for monitoring and debugging application stability and performance.
6+
Sentry gives you access to the events that you send there from your application.
7+
8+
Most often, Sentry is used for monitoring errors (exceptions).
9+
You can enrich errors with context to better understand the problem:
10+
- Request arguments
11+
- Tags for grouping exceptions
12+
- Environment state: environment variables, application state, and other global attributes
13+
14+
You can find the full list of features on the official website: https://sentry.io/welcome/
15+
16+
## Installation
17+
18+
### Install the package
19+
20+
Install the required package `yiisoft/yii-sentry` with the following command:
21+
22+
```shell
23+
composer require yiisoft/yii-sentry --prefer-dist
24+
```
25+
26+
### Install an HTTP driver
27+
28+
The [`getsentry/sentry-php`](https://github.com/getsentry/sentry-php) library requires the `php-http/httplug` package and any HTTP driver.
29+
In the example below we’ll use the Guzzle adapter.
30+
31+
> You can find the list of all adapters on [this page](https://docs.php-http.org/en/latest/clients.html#clients-adapters).
32+
33+
To install the packages, run the following command:
34+
35+
```shell
36+
composer require php-http/httplug php-http/guzzle7-adapter --prefer-dist
37+
```
38+
39+
## Configuration
40+
41+
### Get and store the token
42+
43+
Next, configure the application.
44+
45+
First, register at [Sentry](https://sentry.io) and create a project.
46+
47+
Then, in the project settings on the “General Settings” tab, find the “Security Token” field and copy its value.
48+
49+
Now put this token into the package configuration. By default, the config is located at `config/packages/yiisoft/yii-sentry/config/params.php`.
50+
Set the copied token as the value of the array element at `yiisoft/yii-sentry` => `options` => `dsn`. Example:
51+
52+
```diff
53+
'yiisoft/yii-sentry' => [
54+
'enabled' => true,
55+
'options' => [
56+
- 'dsn' => '',
57+
+ 'dsn' => 'TOKEN',
58+
],
59+
],
60+
```
61+
62+
### Configure the HTTP client
63+
64+
After installing the HTTP client, configure it.
65+
66+
Create the file `config/common/sentry.php` and put the following code into it:
67+
68+
```php
69+
<?php
70+
71+
declare(strict_types=1);
72+
73+
return [
74+
\Http\Client\HttpClient::class => \GuzzleHttp\Client::class,
75+
\Http\Client\HttpAsyncClient::class => [
76+
'class' => \Http\Adapter\Guzzle7\Client::class,
77+
'__construct()' => [
78+
\Yiisoft\Factory\Definition\Reference::to(\Http\Client\HttpClient::class),
79+
],
80+
],
81+
];
82+
```
83+
84+
# Integration
85+
86+
### Web
87+
88+
Sentry support for `web` is implemented as middleware.
89+
90+
That means you only need to add `SentryMiddleware` to the global middleware list in `config/web/application.php`:
91+
92+
```diff
93+
return [
94+
Yiisoft\Yii\Web\Application::class => [
95+
'__construct()' => [
96+
'dispatcher' => DynamicReference::to(static function (Injector $injector) {
97+
return ($injector->make(MiddlewareDispatcher::class))
98+
->withMiddlewares(
99+
[
100+
Router::class,
101+
SubFolder::class,
102+
+ SentryMiddleware::class,
103+
ErrorCatcher::class,
104+
]
105+
);
106+
}),
107+
'fallbackHandler' => Reference::to(NotFoundHandler::class),
108+
],
109+
],
110+
];
111+
```
112+
113+
### Console
114+
115+
Sentry supports `console` via a handler for the [ConsoleEvents::ERROR](https://symfony.com/doc/current/components/console/events.html#the-consoleevents-error-event) event.
116+
117+
The package provides a configuration file that automatically subscribes the application to this event.

cookbook/ru/README.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,5 @@
99

1010
---
1111

12-
Оглавление
13-
---------------
14-
1512
[Вступление](preface.md)
1613
[Интеграция с Sentry](sentry-integration.md)

0 commit comments

Comments
 (0)