Skip to content

Commit 9e40753

Browse files
authored
Merge pull request #68 from michaelzangerle/bugfix/configuration
[BUGFIX] fixes the configuration tree
2 parents 00a6dbb + bc0b730 commit 9e40753

File tree

4 files changed

+475
-112
lines changed

4 files changed

+475
-112
lines changed

README.md

Lines changed: 63 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -54,96 +54,121 @@ class AppKernel extends Kernel
5454

5555
### Step 3: Configure the SDK
5656

57-
Add your DSN to ``app/config/config.yml``:
57+
Add your [Sentry DSN](https://docs.sentry.io/quickstart/#configure-the-dsn) value of your project to ``app/config/config.yml``.
58+
Leaving this value empty will effectively disable Sentry reporting.
5859

5960
```yaml
60-
6161
sentry:
6262
dsn: "https://public:[email protected]/1"
6363
```
6464
65-
## Configuration
66-
67-
The following can be configured via ``app/config/config.yml``:
65+
### Configuration
6866
69-
### app_path
67+
The following can be configured via ``app/config/config.yml``.
7068
71-
The base path to your application. Used to trim prefixes and mark frames as part of your application.
69+
#### Skip some exceptions
7270
7371
```yaml
7472
sentry:
75-
app_path: "/path/to/myapp"
73+
skip_capture:
74+
- "Symfony\\Component\\HttpKernel\\Exception\\HttpExceptionInterface"
7675
```
7776
78-
### dsn
77+
#### Listeners' priority
7978
80-
[Sentry DSN](https://docs.sentry.io/quickstart/#configure-the-dsn) value of your project.
81-
Leaving this value empty will effectively disable Sentry reporting.
79+
You can change the priority of the 3 default listeners of this bundle with the `listener_priorities` key of your config.
80+
The default value is `0`, and here are the 3 possible sub-keys:
81+
82+
```yaml
83+
listener_priorities:
84+
request: 0
85+
kernel_exception: 0
86+
console_exception: 0
87+
```
88+
89+
... respectively for the `onKernelRequest`, `onKernelException` and `onConsoleException` events.
90+
91+
#### Deprecated configuration options
92+
93+
In previous releases of this bundle, some of the previous options where set outside of the options level of the configuration file. Those still work but are deprecated, and they will be dropped in the 2.x release, so you are advised to abandon them; to provide forward compatibility, they can be used alongside the standard syntax, but values must match. This is a list of those options:
8294

8395
```yaml
8496
sentry:
85-
dsn: "https://public:[email protected]/1"
97+
app_path: ~
98+
environment: ~
99+
error_types: ~
100+
prefixes: ~
101+
release: ~
102+
excluded_app_paths: ~
86103
```
87104

88-
### environment
105+
#### Options
89106

90-
The environment your code is running in (e.g. production).
107+
In the following section you will find some of the available options you can configure. All available options and a more detailed description of each can be found [here](https://docs.sentry.io/clients/php/config/).
108+
109+
##### app_path
110+
111+
The base path to your application. Used to trim prefixes and mark frames as part of your application.
91112

92113
```yaml
93114
sentry:
94-
environment: "%kernel.environment%"
115+
options:
116+
app_path: "/path/to/myapp"
95117
```
96118

97-
### release
119+
##### environment
98120

99-
The version of your application. Often this is the git sha.
121+
The environment your code is running in (e.g. production).
100122

101123
```yaml
102124
sentry:
103-
release: "beeee2a06521a60e646bbb8fe38702e61e4929bf"
125+
options:
126+
environment: "%kernel.environment%"
104127
```
105128

106-
### prefixes
129+
##### release
107130

108-
A list of prefixes to strip from filenames. Often these would be vendor/include paths.
131+
The version of your application. Often this is the git sha.
109132

110133
```yaml
111134
sentry:
112-
prefixes:
113-
- /usr/lib/include
135+
options:
136+
release: "beeee2a06521a60e646bbb8fe38702e61e4929bf"
114137
```
115138

116-
### skip some exceptions
139+
##### prefixes
140+
141+
A list of prefixes to strip from filenames. Often these would be vendor/include paths.
117142

118143
```yaml
119144
sentry:
120-
skip_capture:
121-
- "Symfony\\Component\\HttpKernel\\Exception\\HttpExceptionInterface"
145+
options:
146+
prefixes:
147+
- /usr/lib/include
122148
```
123149

124-
### error types
150+
##### error types
125151

126152
Define which error types should be reported.
127153

128154
```yaml
129155
sentry:
130-
error_types: E_ALL & ~E_DEPRECATED & ~E_NOTICE
156+
options:
157+
error_types: E_ALL & ~E_DEPRECATED & ~E_NOTICE
131158
```
132159

133-
### Listeners' priority
160+
##### tags
134161

135-
You can change the priority of the 3 default listeners of this bundle with the `listener_priorities` key of your config.
136-
The default value is `0`, and here are the 3 possible sub-keys:
162+
Define tags for the logged errors.
137163

138164
```yaml
139-
listener_priorities:
140-
request: 0
141-
kernel_exception: 0
142-
console_exception: 0
165+
sentry:
166+
options:
167+
tags:
168+
tag1: tagvalue
169+
tag2: tagvalue
143170
```
144171

145-
... respectively for the `onKernelRequest`, `onKernelException` and `onConsoleException` events.
146-
147172
## Customization
148173

149174
It is possible to customize the configuration of the user context, as well
@@ -160,7 +185,8 @@ property in your Sentry configuration, e.g.:
160185

161186
```yaml
162187
sentry:
163-
exception_listener: AppBundle\EventListener\MySentryExceptionListener
188+
options:
189+
exception_listener: AppBundle\EventListener\MySentryExceptionListener
164190
```
165191

166192
... and then define the custom `ExceptionListener`, e.g.:
@@ -284,4 +310,3 @@ app.my_sentry_event_subscriber:
284310
[Packagist link]: https://packagist.org/packages/sentry/sentry-symfony
285311
[Master build link]: https://travis-ci.org/getsentry/sentry-symfony
286312
[Master scrutinizer link]: https://scrutinizer-ci.com/g/getsentry/sentry-symfony/?branch=master
287-

src/Sentry/SentryBundle/DependencyInjection/Configuration.php

Lines changed: 66 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace Sentry\SentryBundle\DependencyInjection;
44

5+
use Raven_Compat;
6+
use Sentry\SentryBundle\SentryBundle;
57
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
68
use Symfony\Component\Config\Definition\ConfigurationInterface;
79

@@ -14,6 +16,8 @@ class Configuration implements ConfigurationInterface
1416
{
1517
/**
1618
* {@inheritDoc}
19+
* @throws \InvalidArgumentException
20+
* @throws \RuntimeException
1721
*/
1822
public function getConfigTreeBuilder()
1923
{
@@ -35,9 +39,68 @@ public function getConfigTreeBuilder()
3539
->defaultNull()
3640
->end()
3741
->arrayNode('options')
38-
->treatNullLike(array())
39-
->prototype('scalar')->end()
40-
->defaultValue(array())
42+
->addDefaultsIfNotSet()
43+
->children()
44+
->scalarNode('logger')->defaultValue('php')->end()
45+
->scalarNode('server')->defaultNull()->end()
46+
->scalarNode('secret_key')->defaultNull()->end()
47+
->scalarNode('public_key')->defaultNull()->end()
48+
->scalarNode('project')->defaultValue(1)->end()
49+
->booleanNode('auto_log_stacks')->defaultFalse()->end()
50+
->scalarNode('name')->defaultValue(Raven_Compat::gethostname())->end()
51+
->scalarNode('site')->defaultNull()->end()
52+
->arrayNode('tags')
53+
->prototype('scalar')->end()
54+
->end()
55+
->scalarNode('release')->defaultNull()->end()
56+
->scalarNode('environment')->defaultValue('%kernel.environment%')->end()
57+
->scalarNode('sample_rate')->defaultValue(1)->end()
58+
->booleanNode('trace')->defaultTrue()->end()
59+
->scalarNode('timeout')->defaultValue(2)->end()
60+
->scalarNode('message_limit')->defaultValue(\Raven_Client::MESSAGE_LIMIT)->end()
61+
->arrayNode('exclude')
62+
->prototype('scalar')->end()
63+
->end()
64+
->scalarNode('http_proxy')->defaultNull()->end()
65+
->arrayNode('extra')
66+
->prototype('scalar')->end()
67+
->end()
68+
->scalarNode('curl_method')->defaultValue('sync')->end()
69+
->scalarNode('curl_path')->defaultValue('curl')->end()
70+
->booleanNode('curl_ipv4')->defaultTrue()->end()
71+
->scalarNode('ca_cert')->defaultNull()->end()
72+
->booleanNode('verify_ssl')->defaultTrue()->end()
73+
->scalarNode('curl_ssl_version')->defaultNull()->end()
74+
->scalarNode('trust_x_forwarded_proto')->defaultFalse()->end()
75+
->scalarNode('mb_detect_order')->defaultNull()->end()
76+
->arrayNode('error_types')
77+
->prototype('scalar')->end()
78+
->end()
79+
->scalarNode('app_path')->defaultValue('%kernel.root_dir%/..')->end()
80+
->arrayNode('excluded_app_paths')
81+
->defaultValue(
82+
array(
83+
'%kernel.root_dir%/../vendor',
84+
'%kernel.root_dir%/../app/cache',
85+
'%kernel.root_dir%/../var/cache',
86+
)
87+
)
88+
->prototype('scalar')->end()
89+
->end()
90+
->arrayNode('prefixes')
91+
->defaultValue(array('%kernel.root_dir%/..'))
92+
->prototype('scalar')->end()
93+
->end()
94+
->booleanNode('install_default_breadcrumb_handlers')->defaultTrue()->end()
95+
->booleanNode('install_shutdown_handler')->defaultTrue()->end()
96+
->arrayNode('processors')
97+
->defaultValue(array('Raven_SanitizeDataProcessor'))
98+
->prototype('scalar')->end()
99+
->end()
100+
->arrayNode('processorOptions')
101+
->prototype('scalar')->end()
102+
->end()
103+
->end()
41104
->end()
42105
->scalarNode('error_types')
43106
->defaultNull()
@@ -50,7 +113,6 @@ public function getConfigTreeBuilder()
50113
->end()
51114
->end()
52115
->arrayNode('skip_capture')
53-
->treatNullLike(array())
54116
->prototype('scalar')->end()
55117
->defaultValue(array('Symfony\Component\HttpKernel\Exception\HttpExceptionInterface'))
56118
->end()
@@ -59,12 +121,10 @@ public function getConfigTreeBuilder()
59121
->end()
60122
->arrayNode('prefixes')
61123
->prototype('scalar')->end()
62-
->treatNullLike(array())
63124
->defaultValue(array('%kernel.root_dir%/..'))
64125
->end()
65126
->arrayNode('excluded_app_paths')
66127
->prototype('scalar')->end()
67-
->treatNullLike(array())
68128
->defaultValue(array(
69129
'%kernel.root_dir%/../vendor',
70130
'%kernel.root_dir%/../app/cache',

src/Sentry/SentryBundle/DependencyInjection/SentryExtension.php

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Sentry\SentryBundle\DependencyInjection;
44

5+
use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException;
56
use Symfony\Component\DependencyInjection\ContainerBuilder;
67
use Symfony\Component\Config\FileLocator;
78
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
@@ -16,6 +17,8 @@ class SentryExtension extends Extension
1617
{
1718
/**
1819
* {@inheritDoc}
20+
*
21+
* @throws InvalidConfigurationException
1922
*/
2023
public function load(array $configs, ContainerBuilder $container)
2124
{
@@ -31,5 +34,57 @@ public function load(array $configs, ContainerBuilder $container)
3134
foreach ($config['listener_priorities'] as $key => $priority) {
3235
$container->setParameter('sentry.listener_priorities.' . $key, $priority);
3336
}
37+
38+
// TODO Can be removed when deprecated config options are removed
39+
$this->checkConfigurationOnForInvalidSettings($config, $container);
40+
}
41+
42+
/**
43+
* Synchronises old deprecated and new configuration values to have the same value.
44+
* An exception will be thrown if new and deprecated options are both set to non default values.
45+
*
46+
* @param array $config
47+
* @param ContainerBuilder $container
48+
*
49+
* @throws InvalidConfigurationException
50+
*/
51+
private function checkConfigurationOnForInvalidSettings(array $config, ContainerBuilder $container)
52+
{
53+
foreach ($this->getDeprecatedOptionsWithDefaults() as $option => $default) {
54+
55+
// old option is used
56+
if ($config[$option] !== $default && $config['options'][$option] === $default) {
57+
$container->setParameter('sentry.options.' . $option, $config[$option]);
58+
}
59+
60+
// new option is used
61+
if ($config[$option] === $default && $config['options'][$option] !== $default) {
62+
$container->setParameter('sentry.' . $option, $config[$option]);
63+
}
64+
65+
// both are used
66+
if ($config[$option] !== $default && $config['options'][$option] !== $default) {
67+
$message = 'The configuration option sentry.' . $option . ' is deprecated. Use sentry.options.' . $option . ' instead!';
68+
throw new InvalidConfigurationException($message);
69+
}
70+
}
71+
}
72+
73+
/**
74+
* @return array
75+
*/
76+
private function getDeprecatedOptionsWithDefaults()
77+
{
78+
return array(
79+
'environment' => '%kernel.environment%',
80+
'app_path' => '%kernel.root_dir%/..',
81+
'release' => null,
82+
'prefixes' => array('%kernel.root_dir%/..'),
83+
'excluded_app_paths' => array(
84+
'%kernel.root_dir%/../vendor',
85+
'%kernel.root_dir%/../app/cache',
86+
'%kernel.root_dir%/../var/cache',
87+
),
88+
);
3489
}
3590
}

0 commit comments

Comments
 (0)