Implementation of Sentry 9 Integration with Yii 2 Advanced Project Template
1. In the ALL option for configuring your application, there is no Yii2 framework, only PHP can be selected, as shown in Figure 1
2. Install PHP integration for Sentry. The recommended method is to use composer, but decided not to use this scheme for the time being, as shown in Figure 2
3. Search yii2 sentry in github, and decide to implement it based on hellowearemito/yii2-sentry, as shown in Figure 3
3. Search yii2 sentry in github, and decide to implement it based on hellowearemito/yii2-sentry, as shown in Figure 3
4. Open the URL:https://github.com/hellowearemito/yii2-sentry, execute the command, as shown in Figure 4
composer require --prefer-dist mito/yii2-sentry "~1.0.0"
5. After installing the extension, set the configuration in the configuration file of the development environment, edit \environments\dev\api\config\main-local.php
return [
'components' => [
'request' => [
// !!! insert a secret key in the following (if it is empty) - this is required by cookie validation
'cookieValidationKey' => '',
],
'sentry' => [
'class' => 'mito\sentry\Component',
'enabled' => false, // 设置为 false 以跳过收集错误,即禁用 Sentry,默认:true
'dsn' => 'YOUR-PRIVATE-DSN', // 私有 DSN
'environment' => 'development', // 环境,development:开发环境;production:生产环境,默认:production
'jsNotifier' => false, // 收集 JS 错误,默认:false
'jsOptions' => [ // raven-js 配置参数
'whitelistUrls' => [ // 收集JS错误的网址
'http://api.gitlab-php-yii2-app-advanced-cmc.localhost',
],
],
],
],
];
6. After installing the extension, set the configuration in the configuration file of the production environment, edit \environments\prod\api\config\main-local.php
return [
'components' => [
'request' => [
// !!! insert a secret key in the following (if it is empty) - this is required by cookie validation
'cookieValidationKey' => '',
],
'sentry' => [
'class' => 'mito\sentry\Component',
'enabled' => false, // 设置为 false 以跳过收集错误,即禁用 Sentry,默认:true
'dsn' => 'YOUR-PRIVATE-DSN', // 私有 DSN
'environment' => 'production', // 环境,development:开发环境;production:生产环境,默认:production
'jsNotifier' => false, // 收集 JS 错误,默认:false
'jsOptions' => [ // raven-js 配置参数
'whitelistUrls' => [ // 收集JS错误的网址
'http://api.gitlab-php-yii2-app-advanced-cmc.localhost',
],
],
],
],
];
7. Configure the log component to support sending logs to Sentry, edit \api\config\main.php
'components' => [
'log' => [
'traceLevel' => YII_DEBUG ? 3 : 0,
'targets' => [
'sentry' => [
'class' => 'mito\sentry\Target',
'levels' => ['error', 'warning'],
],
],
],
],
8. Initialize and select the development environment, edit \api\config\main-local.php, as shown in Figure 5
init
0
yes
All
9. The value of the private DSN needs to be copied from the configuration of /settings/sentry/pcs-api/install/php/, as shown in Figure 6
10. GET request interface, response 302, as shown in Figure 7
{
"name": "Found",
"message": "框架服务控制台HTTP请求失败:登录超时",
"code": 20039,
"status": 302,
"type": "yii\\web\\HttpException"
}
11. Check unresolved issues, that is, the unresolved problem, in line with the expectations, the corresponding log has been sent to Sentry, as shown in Figure 8
12. Initialize and select the production environment, edit \api\config\main-local.php, as shown in Figure 9
init
1
yes
All
13. GET request interface, response 404, as shown in Figure 10
{
"name": "Not Found",
"message": "用户ID:10,不存在",
"code": 20002,
"status": 404
}
14. Check the unresolved issues, that is, the unresolved problem, in line with the expectations, the corresponding log has been sent to Sentry, as shown in Figure 11
15. After initialization and selecting the development environment, do not edit \api\config\main-local.php, as shown in Figure 12
16. GET request interface, response 404, as shown in Figure 13
{
"name": "Not Found",
"message": "用户ID:11,不存在",
"code": 20002,
"status": 404,
"type": "yii\\web\\NotFoundHttpException"
}
17. Check unresolved issues, that is, the unresolved problem, which is in line with the expectations, the corresponding log is not sent to sentry, because sentry is disabled, as shown in Figure 14
18. Repeat steps 15, 16, and 17 again, and select the production environment in the environment of step 15, and find that the corresponding log is not sent to Sentry, which is in line with expectations, because Sentry has been disabled, as shown in Figure 15














