1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Yiisoft\Yii\Sentry; |
6
|
|
|
|
7
|
|
|
use InvalidArgumentException; |
8
|
|
|
|
9
|
|
|
final class YiiSentryConfig |
10
|
|
|
{ |
11
|
14 |
|
public function __construct(protected array $config) |
12
|
|
|
{ |
13
|
|
|
} |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Check if a DSN was set in the config. |
17
|
|
|
*/ |
18
|
|
|
public function hasDsnSet(): bool |
19
|
|
|
{ |
20
|
|
|
$config = $this->getUserConfig(); |
21
|
|
|
|
22
|
|
|
return !empty($config['options']['dsn']); |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Retrieve the user configuration. |
27
|
|
|
*/ |
28
|
12 |
|
public function getUserConfig(): array |
29
|
|
|
{ |
30
|
12 |
|
$config = $this->config; |
31
|
|
|
|
32
|
12 |
|
return empty($config) ? [] : $config; |
33
|
|
|
} |
34
|
|
|
|
35
|
12 |
|
public function getOptions(): array |
36
|
|
|
{ |
37
|
12 |
|
if (empty($this->config['options'])) { |
38
|
|
|
return []; |
39
|
|
|
} |
40
|
12 |
|
return is_array($this->config['options']) |
41
|
12 |
|
? $this->config['options'] |
42
|
12 |
|
: throw new InvalidArgumentException('options must be an array'); |
43
|
|
|
} |
44
|
|
|
|
45
|
14 |
|
public function getTracing(): array |
46
|
|
|
{ |
47
|
14 |
|
if (empty($this->config['tracing'])) { |
48
|
2 |
|
return []; |
49
|
|
|
} |
50
|
12 |
|
return is_array($this->config['tracing']) |
51
|
12 |
|
? $this->config['tracing'] |
52
|
12 |
|
: throw new InvalidArgumentException('tracing must be an array'); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
public function getMaxGuzzleBodyTrace(): ?int |
56
|
|
|
{ |
57
|
|
|
return empty($this->getTracing()['guzzle_max_body']) ? null : (int)$this->getTracing()['guzzle_max_body']; |
58
|
|
|
} |
59
|
|
|
|
60
|
12 |
|
public function getLogLevel(): ?string |
61
|
|
|
{ |
62
|
12 |
|
return isset($this->config['log_level']) ? (string)$this->config['log_level'] : null; |
63
|
|
|
} |
64
|
|
|
|
65
|
14 |
|
public function getIntegrations(): array |
66
|
|
|
{ |
67
|
14 |
|
if (empty($this->config['integrations'])) { |
68
|
14 |
|
return []; |
69
|
|
|
} |
70
|
|
|
return is_array($this->config['integrations']) |
71
|
|
|
? $this->config['integrations'] |
72
|
|
|
: throw new InvalidArgumentException('integrations must be an array'); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* Checks if the config is set in such a way that performance tracing could be enabled. |
77
|
|
|
* |
78
|
|
|
* Because of `traces_sampler` being dynamic we can never be 100% confident but that is also not important. |
79
|
|
|
*/ |
80
|
12 |
|
public function couldHavePerformanceTracingEnabled(): bool |
81
|
|
|
{ |
82
|
12 |
|
$config = $this->getUserConfig(); |
83
|
|
|
|
84
|
12 |
|
return !empty($config['options']['traces_sample_rate']) |
85
|
12 |
|
|| !empty($config['options']['traces_sampler']); |
86
|
|
|
} |
87
|
|
|
} |
88
|
|
|
|