|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Health monitoring for Yii2 applications |
|
4
|
|
|
* |
|
5
|
|
|
* @link https://github.com/hiqdev/yii2-monitoring |
|
6
|
|
|
* @package yii2-monitoring |
|
7
|
|
|
* @license BSD-3-Clause |
|
8
|
|
|
* @copyright Copyright (c) 2017, HiQDev (http://hiqdev.com/) |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
use hiqdev\yii2\monitoring\Module; |
|
12
|
|
|
use hiqdev\yii2\monitoring\Component; |
|
13
|
|
|
use hiqdev\yii2\monitoring\targets\EmailTarget; |
|
14
|
|
|
use hiqdev\yii2\monitoring\targets\RedirectTarget; |
|
15
|
|
|
use hiqdev\yii2\monitoring\targets\SentryTarget; |
|
16
|
|
|
|
|
17
|
|
|
$env = defined('YII_ENV') ? YII_ENV : 'prod'; |
|
18
|
|
|
$debug = defined('YII_DEBUG') && YII_DEBUG; |
|
19
|
|
|
|
|
20
|
|
|
return array_filter([ |
|
21
|
|
|
'bootstrap' => [ |
|
22
|
|
|
'monitoring' => 'monitoring', |
|
23
|
|
|
], |
|
24
|
|
|
'container' => [ |
|
25
|
|
|
'singletons' => [ |
|
26
|
|
|
\Sentry\State\HubInterface::class => fn () => \Sentry\SentrySdk::getCurrentHub(), |
|
|
|
|
|
|
27
|
|
|
], |
|
28
|
|
|
], |
|
29
|
|
|
'components' => array_filter([ |
|
30
|
|
|
'log' => [ |
|
31
|
|
|
'targets' => [ |
|
32
|
|
|
'monitoring' => [ |
|
33
|
|
|
'__class' => RedirectTarget::class, |
|
34
|
|
|
'levels' => ['error'], |
|
35
|
|
|
'targets' => array_keys(array_filter([ |
|
36
|
|
|
'sentry' => $params['sentry.dsn'] && $params['sentry.enabled'], |
|
37
|
|
|
'email' => $env === 'prod' && $params['monitoring.email.to'], |
|
38
|
|
|
])), |
|
39
|
|
|
], |
|
40
|
|
|
], |
|
41
|
|
|
], |
|
42
|
|
|
'monitoring' => [ |
|
43
|
|
|
'__class' => Component::class, |
|
44
|
|
|
], |
|
45
|
|
|
]), |
|
46
|
|
|
'modules' => [ |
|
47
|
|
|
'monitoring' => [ |
|
48
|
|
|
'__class' => Module::class, |
|
49
|
|
|
'flag' => $params['monitoring.flag'], |
|
50
|
|
|
'targets' => [ |
|
51
|
|
|
'email' => array_filter([ |
|
52
|
|
|
'__class' => EmailTarget::class, |
|
53
|
|
|
'view' => '@vendor/hiqdev/yii2-monitoring/src/views/mail/error.php', |
|
54
|
|
|
'from' => $params['monitoring.email.from'] ?: $params['adminEmail'], |
|
55
|
|
|
'to' => $params['monitoring.email.to'] ?: $params['adminEmail'], |
|
56
|
|
|
'subject' => $params['monitoring.email.subject'], |
|
57
|
|
|
]), |
|
58
|
|
|
'sentry' => [ |
|
59
|
|
|
'__class' => SentryTarget::class, |
|
60
|
|
|
], |
|
61
|
|
|
], |
|
62
|
|
|
], |
|
63
|
|
|
], |
|
64
|
|
|
]); |
|
65
|
|
|
|