1. In the All options for configuring your application, the Yii2 framework is not available, so you can only select PHP, as shown in Figure 1.

2. Install the PHP integration for Sentry. The recommended method is to use Composer, but I decided not to use this approach for now, as shown in Figure 2.
3. Searching for yii2 sentry on GitHub, I decided to implement this based on hellowearemito/yii2-sentry, as shown in Figure 3.

3. Searching for yii2 sentry on GitHub, I decided to implement this based on hellowearemito/yii2-sentry, as shown in Figure 3.

4. Open the URL: https://github.com/hellowearemito/yii2-sentry and 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 development environment configuration file by editing \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 production environment configuration file by editing \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 by editing \api\config\main.php.
'components' => [
'log' => [
'traceLevel' => YII_DEBUG ? 3 : 0,
'targets' => [
'sentry' => [
'class' => 'mito\sentry\Target',
'levels' => ['error', 'warning'],
],
],
],
],
8. Initialize by selecting the development environment and edit \api\config\main-local.php, as shown in Figure 5.

init
0
yes
All
9. The private DSN value needs to be copied from the Configuration section at /settings/sentry/pcs-api/install/php/, as shown in Figure 6.

10. Make a GET request to the API, which returns a 302 response, as shown in Figure 7.

{
"name": "Found",
"message": "框架服务控制台HTTP请求失败:登录超时",
"code": 20039,
"status": 302,
"type": "yii\\web\\HttpException"
}
11. Check the Unresolved Issues, which are the unresolved problems. As expected, the corresponding log has been sent to Sentry, as shown in Figure 8.

12. Initialize by selecting the production environment and edit \api\config\main-local.php, as shown in Figure 9.

init
1
yes
All
13. Make a GET request to the API, which returns a 404 response, as shown in Figure 10.

{
"name": "Not Found",
"message": "用户ID:10,不存在",
"code": 20002,
"status": 404
}
14. Check the Unresolved Issues, which are the unresolved problems. As expected, the corresponding log has been sent to Sentry, as shown in Figure 11.

15. After initializing by selecting the development environment, do not edit \api\config\main-local.php, as shown in Figure 12.

16. Make a GET request to the API, which returns a 404 response, as shown in Figure 13.

{
"name": "Not Found",
"message": "用户ID:11,不存在",
"code": 20002,
"status": 404,
"type": "yii\\web\\NotFoundHttpException"
}
17. Check the Unresolved Issues, which are the unresolved problems. As expected, the corresponding log was not sent to Sentry because Sentry has been disabled, as shown in Figure 14.

18. Repeat steps 15, 16, and 17 again, selecting the production environment in step 15. I found that the corresponding log was not sent to Sentry, as expected, because Sentry has been disabled, as shown in Figure 15.

