Skip to content

Commit 6734e81

Browse files
author
oxcom
committed
fix: configuration *_sample_rates
1 parent e6fa668 commit 6734e81

File tree

4 files changed

+35
-31
lines changed

4 files changed

+35
-31
lines changed

DependencyInjection/Configuration.php

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -97,24 +97,17 @@ public function getConfigTreeBuilder()
9797
->end()
9898
->arrayNode('error_sample_rates')
9999
->treatNullLike([])
100-
->prototype('scalar')->end()
100+
->useAttributeAsKey('type')
101+
->arrayPrototype()
102+
->children()
103+
->integerNode('type')->end()
104+
->floatNode('rate')->end()
105+
->end()
106+
->end()
101107
->defaultValue([])
102108
->end()
103109
->arrayNode('exception_sample_rates')
104110
->treatNullLike([])
105-
->beforeNormalization()
106-
->always(function($values) {
107-
$result = [];
108-
109-
foreach ($values as $value) {
110-
foreach ($value as $class => $rate) {
111-
$result[] = ['class' => $class, 'rate' => $rate];
112-
}
113-
}
114-
115-
return $result;
116-
})
117-
->end()
118111
->useAttributeAsKey('class')
119112
->arrayPrototype()
120113
->children()

Provider/RollbarHandler.php

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -117,19 +117,20 @@ protected function initialize()
117117
}
118118

119119
// map rates fields
120-
$map = [
121-
'exception_sample_rates',
122-
'error_sample_rates',
123-
];
124-
125-
foreach ($map as $key) {
126-
$rConfig[$key] = \array_map(function($data) {
127-
return empty($data['rate']) ? null : $data['rate'];
128-
}, $rConfig[$key]);
129-
130-
// drop empty values
131-
$rConfig[$key] = \array_filter($rConfig[$key]);
120+
$key = 'exception_sample_rates';
121+
$rConfig[$key] = \array_map(function ($data) {
122+
return empty($data['rate']) ? null : $data['rate'];
123+
}, $rConfig[$key]);
124+
$rConfig[$key] = \array_filter($rConfig[$key]);
125+
126+
$key = 'error_sample_rates';
127+
foreach ($rConfig[$key] as $const => $data) {
128+
$newKey = constant($const);
129+
unset($rConfig[$key][$const]);
130+
131+
$rConfig[$key][$newKey] = empty($data['rate']) ? null : $data['rate'];
132132
}
133+
$rConfig[$key] = \array_filter($rConfig[$key]);
133134

134135
$this->exclude = empty($config['exclude']) ? [] : $config['exclude'];
135136

Tests/Fixtures/app/config/config_test.yml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,14 @@ symfony_rollbar:
1515
person_fn: \SymfonyRollbarBundle\Tests\Fixtures\PersonProvider
1616
checkIgnore: \SymfonyRollbarBundle\Tests\Fixtures\CheckIgnoreProvider
1717
exception_sample_rates:
18-
- \Symfony\Component\Security\Core\Exception\AccessDeniedException: 0.1
19-
- \Symfony\Component\HttpKernel\Exception\NotFoundHttpException: 0.5
20-
- \Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException: 0.5
21-
- \Symfony\Component\Security\Core\Exception\AuthenticationCredentialsNotFoundException: 1
18+
- {class: \Symfony\Component\Security\Core\Exception\AccessDeniedException, rate: 0.1}
19+
- {class: \Symfony\Component\HttpKernel\Exception\NotFoundHttpException, rate: 0.5}
20+
- {class: \Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException, rate: 0.5}
21+
- {class: \Symfony\Component\Security\Core\Exception\AuthenticationCredentialsNotFoundException, rate: 1}
22+
error_sample_rates:
23+
- {type: E_NOTICE, rate: 0.1}
24+
- {type: E_USER_ERROR, rate: 0.5}
25+
- {type: E_USER_NOTICE, rate: 0.1}
2226

2327
rollbar_js:
2428
accessToken: 'SOME_ROLLBAR_ACCESS_TOKEN_654321'

Tests/SymfonyRollbarBundle/DependencyInjection/ConfigurationTest.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@ public function testParameters()
2626
$exclude[] = '\ParseError';
2727
$exclude[] = '\Symfony\Component\HttpKernel\Exception\HttpExceptionInterface';
2828

29+
$errorRates = [
30+
'E_NOTICE' => ['rate' => 0.1],
31+
'E_USER_ERROR' => ['rate' => 0.5],
32+
'E_USER_NOTICE' => ['rate' => 0.1],
33+
];
34+
2935
$exceptionRates = [
3036
'\Symfony\Component\Security\Core\Exception\AccessDeniedException' => [
3137
'rate' => 0.1,
@@ -54,7 +60,7 @@ public function testParameters()
5460
'code_version' => '',
5561
'enable_utf8_sanitization' => true,
5662
'environment' => static::$kernel->getEnvironment(),
57-
'error_sample_rates' => [],
63+
'error_sample_rates' => $errorRates,
5864
'handler' => Configuration::HANDLER_BLOCKING,
5965
'include_error_code_context' => false,
6066
'include_exception_code_context' => false,

0 commit comments

Comments
 (0)