forked from getsentry/sentry-symfony
/
Configuration.php
210 lines (200 loc) · 9.93 KB
/
Configuration.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
<?php
declare(strict_types=1);
namespace Sentry\SentryBundle\DependencyInjection;
use Doctrine\Bundle\DoctrineBundle\DoctrineBundle;
use Jean85\PrettyVersions;
use Sentry\Options;
use Sentry\SentryBundle\ErrorTypesParser;
use Sentry\Transport\TransportFactoryInterface;
use Symfony\Bundle\TwigBundle\TwigBundle;
use Symfony\Component\Cache\CacheItem;
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\ConfigurationInterface;
use Symfony\Component\HttpClient\HttpClient;
use Symfony\Component\Messenger\MessageBusInterface;
final class Configuration implements ConfigurationInterface
{
/**
* {@inheritdoc}
*/
public function getConfigTreeBuilder(): TreeBuilder
{
$treeBuilder = new TreeBuilder('sentry');
/** @var ArrayNodeDefinition $rootNode */
$rootNode = method_exists(TreeBuilder::class, 'getRootNode')
? $treeBuilder->getRootNode()
: $treeBuilder->root('sentry');
$rootNode
->children()
->scalarNode('dsn')
->info('If this value is not provided, the SDK will try to read it from the SENTRY_DSN environment variable. If that variable also does not exist, the SDK will just not send any events.')
->end()
->booleanNode('register_error_listener')->defaultTrue()->end()
->scalarNode('logger')
->info('The service ID of the PSR-3 logger used to log messages coming from the SDK client. Be aware that setting the same logger of the application may create a circular loop when an event fails to be sent.')
->defaultNull()
->end()
->scalarNode('transport_factory')
->info('The service ID of the transport factory used by the default SDK client.')
->defaultValue(TransportFactoryInterface::class)
->end()
->arrayNode('options')
->addDefaultsIfNotSet()
->fixXmlConfig('integration')
->fixXmlConfig('trace_propagation_target')
->fixXmlConfig('tag')
->fixXmlConfig('class_serializer')
->fixXmlConfig('prefix', 'prefixes')
->children()
->arrayNode('integrations')
->scalarPrototype()->end()
->end()
->booleanNode('default_integrations')->end()
->integerNode('send_attempts')->min(0)->end()
->arrayNode('prefixes')
->defaultValue(array_merge(['%kernel.project_dir%'], array_filter(explode(\PATH_SEPARATOR, get_include_path() ?: ''))))
->scalarPrototype()->end()
->end()
->floatNode('sample_rate')
->min(0.0)
->max(1.0)
->info('The sampling factor to apply to events. A value of 0 will deny sending any event, and a value of 1 will send all events.')
->end()
->floatNode('traces_sample_rate')
->min(0.0)
->max(1.0)
->info('The sampling factor to apply to transactions. A value of 0 will deny sending any transaction, and a value of 1 will send all transactions.')
->end()
->scalarNode('traces_sampler')->end()
->arrayNode('trace_propagation_targets')
->scalarPrototype()->end()
->beforeNormalization()->castToArray()->end()
->end()
->booleanNode('attach_stacktrace')->end()
->integerNode('context_lines')->min(0)->end()
->booleanNode('enable_compression')->end()
->scalarNode('environment')
->cannotBeEmpty()
->defaultValue('%kernel.environment%')
->end()
->scalarNode('logger')->end()
->scalarNode('release')
->cannotBeEmpty()
->defaultValue(PrettyVersions::getRootPackageVersion()->getPrettyVersion())
->end()
->scalarNode('server_name')->end()
->scalarNode('before_send')->end()
->arrayNode('tags')
->useAttributeAsKey('name')
->normalizeKeys(false)
->scalarPrototype()->end()
->end()
->scalarNode('error_types')
->beforeNormalization()
->always(\Closure::fromCallable([ErrorTypesParser::class, 'parse']))
->end()
->end()
->integerNode('max_breadcrumbs')
->min(0)
->max(Options::DEFAULT_MAX_BREADCRUMBS)
->end()
->variableNode('before_breadcrumb')->end()
->arrayNode('in_app_exclude')
->scalarPrototype()->end()
->beforeNormalization()->castToArray()->end()
->defaultValue([
'%kernel.cache_dir%',
'%kernel.build_dir%',
'%kernel.project_dir%/vendor',
])
->end()
->arrayNode('in_app_include')
->scalarPrototype()->end()
->beforeNormalization()->castToArray()->end()
->end()
->booleanNode('send_default_pii')->end()
->integerNode('max_value_length')->min(0)->end()
->scalarNode('http_proxy')->end()
->integerNode('http_connect_timeout')
->min(0)
->info('The maximum number of seconds to wait while trying to connect to a server. It works only when using the default transport.')
->end()
->integerNode('http_timeout')
->min(0)
->info('The maximum execution time for the request+response as a whole. It works only when using the default transport.')
->end()
->booleanNode('capture_silenced_errors')->end()
->enumNode('max_request_body_size')
->values([
'none',
'small',
'medium',
'always',
])
->end()
->arrayNode('class_serializers')
->useAttributeAsKey('class')
->normalizeKeys(false)
->scalarPrototype()->end()
->end()
->end()
->end()
->end();
$this->addMessengerSection($rootNode);
$this->addDistributedTracingSection($rootNode);
return $treeBuilder;
}
private function addMessengerSection(ArrayNodeDefinition $rootNode): void
{
$rootNode
->children()
->arrayNode('messenger')
->{interface_exists(MessageBusInterface::class) ? 'canBeDisabled' : 'canBeEnabled'}()
->children()
->booleanNode('capture_soft_fails')->defaultTrue()->end()
->end()
->end()
->end();
}
private function addDistributedTracingSection(ArrayNodeDefinition $rootNode): void
{
$rootNode
->children()
->arrayNode('tracing')
->canBeDisabled()
->addDefaultsIfNotSet()
->children()
->arrayNode('dbal')
->{class_exists(DoctrineBundle::class) ? 'canBeDisabled' : 'canBeEnabled'}()
->fixXmlConfig('connection')
->children()
->arrayNode('connections')
->scalarPrototype()->end()
->end()
->end()
->end()
->arrayNode('twig')
->{class_exists(TwigBundle::class) ? 'canBeDisabled' : 'canBeEnabled'}()
->end()
->arrayNode('cache')
->{class_exists(CacheItem::class) ? 'canBeDisabled' : 'canBeEnabled'}()
->end()
->arrayNode('http_client')
->{class_exists(HttpClient::class) ? 'canBeDisabled' : 'canBeEnabled'}()
->end()
->arrayNode('console')
->addDefaultsIfNotSet()
->fixXmlConfig('excluded_command')
->children()
->arrayNode('excluded_commands')
->scalarPrototype()->end()
->defaultValue(['messenger:consume'])
->end()
->end()
->end()
->end()
->end()
->end();
}
}