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
|
|
|
* Retrieve the user configuration. |
17
|
|
|
*/ |
18
|
12 |
|
public function getUserConfig(): array |
19
|
|
|
{ |
20
|
12 |
|
$config = $this->config; |
21
|
|
|
|
22
|
12 |
|
return empty($config) ? [] : $config; |
23
|
|
|
} |
24
|
|
|
|
25
|
12 |
|
public function getOptions(): array |
26
|
|
|
{ |
27
|
12 |
|
if (empty($this->config['options'])) { |
28
|
|
|
return []; |
29
|
|
|
} |
30
|
12 |
|
return is_array($this->config['options']) |
31
|
12 |
|
? $this->config['options'] |
32
|
12 |
|
: throw new InvalidArgumentException('options must be an array'); |
33
|
|
|
} |
34
|
|
|
|
35
|
14 |
|
public function getTracing(): array |
36
|
|
|
{ |
37
|
14 |
|
if (empty($this->config['tracing'])) { |
38
|
2 |
|
return []; |
39
|
|
|
} |
40
|
12 |
|
return is_array($this->config['tracing']) |
41
|
12 |
|
? $this->config['tracing'] |
42
|
12 |
|
: throw new InvalidArgumentException('tracing must be an array'); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
public function getMaxGuzzleBodyTrace(): ?int |
46
|
|
|
{ |
47
|
|
|
return empty($this->getTracing()['guzzle_max_body']) ? null : (int)$this->getTracing()['guzzle_max_body']; |
48
|
|
|
} |
49
|
|
|
|
50
|
12 |
|
public function getLogLevel(): ?string |
51
|
|
|
{ |
52
|
12 |
|
return isset($this->config['log_level']) ? (string)$this->config['log_level'] : null; |
53
|
|
|
} |
54
|
|
|
|
55
|
14 |
|
public function getIntegrations(): array |
56
|
|
|
{ |
57
|
14 |
|
if (empty($this->config['integrations'])) { |
58
|
14 |
|
return []; |
59
|
|
|
} |
60
|
|
|
return is_array($this->config['integrations']) |
61
|
|
|
? $this->config['integrations'] |
62
|
|
|
: throw new InvalidArgumentException('integrations must be an array'); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* Checks if the config is set in such a way that performance tracing could be enabled. |
67
|
|
|
* |
68
|
|
|
* Because of `traces_sampler` being dynamic we can never be 100% confident but that is also not important. |
69
|
|
|
*/ |
70
|
12 |
|
public function couldHavePerformanceTracingEnabled(): bool |
71
|
|
|
{ |
72
|
12 |
|
$config = $this->getUserConfig(); |
73
|
|
|
|
74
|
12 |
|
return !empty($config['options']['traces_sample_rate']) || !empty($config['options']['traces_sampler']); |
75
|
|
|
} |
76
|
|
|
} |
77
|
|
|
|