Skip to content

Commit 23be9d0

Browse files
committed
Merge branch 'master' into track-subrequests-with-scopes to resolve conflicts
2 parents a57fb74 + 965ca7b commit 23be9d0

File tree

8 files changed

+238
-102
lines changed

8 files changed

+238
-102
lines changed

Makefile

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,18 @@ update-submodules:
99
git submodule update
1010

1111
cs:
12-
vendor/bin/php-cs-fixer fix --config-file=.php_cs --verbose --diff
12+
vendor/bin/php-cs-fixer fix --verbose
1313

1414
cs-dry-run:
15-
vendor/bin/php-cs-fixer fix --config-file=.php_cs --verbose --diff --dry-run
15+
vendor/bin/php-cs-fixer fix --verbose --dry-run
16+
17+
phpstan:
18+
vendor/bin/phpstan analyze
1619

1720
test:
1821
vendor/bin/phpunit
1922

23+
pre-commit-check: cs phpstan test
24+
2025
setup-git:
2126
git config branch.autosetuprebase always

phpstan.neon

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ parameters:
55
- test/
66
ignoreErrors:
77
- "/Call to function method_exists.. with 'Symfony.+' and 'getProjectDir' will always evaluate to false./"
8-
excludes_analyse:
9-
- '%currentWorkingDirectory%/src/DependencyInjection/Configuration.php'
8+
- "/Call to function method_exists.. with 'Symfony.+' and 'getRootNode' will always evaluate to false./"
109

1110
includes:
1211
- vendor/jangregor/phpstan-prophecy/src/extension.neon

src/DependencyInjection/Configuration.php

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

33
namespace Sentry\SentryBundle\DependencyInjection;
44

5+
use Jean85\PrettyVersions;
56
use Sentry\Options;
67
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
78
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
@@ -24,113 +25,108 @@ public function getConfigTreeBuilder()
2425
{
2526
$treeBuilder = new TreeBuilder('sentry');
2627
/** @var ArrayNodeDefinition $rootNode */
27-
$rootNode = \method_exists(TreeBuilder::class, 'getRootNode') ? $treeBuilder->getRootNode() : $treeBuilder->root('sentry');
28+
$rootNode = \method_exists(TreeBuilder::class, 'getRootNode')
29+
? $treeBuilder->getRootNode()
30+
: $treeBuilder->root('sentry');
2831

2932
// Basic Sentry configuration
3033
$rootNode->children()
3134
->scalarNode('dsn')
32-
->beforeNormalization()
33-
->ifString()
34-
->then($this->getTrimClosure())
35-
->end()
36-
->defaultNull()
37-
->end();
35+
->defaultNull()
36+
->beforeNormalization()
37+
->ifString()
38+
->then($this->getTrimClosure());
3839

3940
// Options array (to be passed to Sentry\Options constructor) -- please keep alphabetical order!
4041
$optionsNode = $rootNode->children()
4142
->arrayNode('options')
4243
->addDefaultsIfNotSet();
4344

4445
$defaultValues = new Options();
45-
46-
$optionsNode
47-
->children()
48-
->booleanNode('attach_stacktrace')->end()
49-
->variableNode('before_breadcrumb')
50-
->validate()
51-
->ifTrue($this->isNotAValidCallback())
52-
->thenInvalid('Expecting callable or service reference, got %s')
53-
->end()
54-
->end()
55-
->variableNode('before_send')
56-
->validate()
57-
->ifTrue($this->isNotAValidCallback())
58-
->thenInvalid('Expecting callable or service reference, got %s')
59-
->end()
60-
->end()
61-
->booleanNode('default_integrations')->end()
62-
->integerNode('context_lines')
63-
->min(0)
64-
->max(99)
65-
->end()
66-
->booleanNode('enable_compression')->end()
67-
->scalarNode('environment')
68-
->defaultValue('%kernel.environment%')
69-
->cannotBeEmpty()
70-
->end()
71-
->scalarNode('error_types')
72-
->end()
73-
->arrayNode('in_app_exclude')
74-
->defaultValue([
75-
'%kernel.cache_dir%',
76-
$this->getProjectRoot() . '/vendor',
77-
])
78-
->prototype('scalar')->end()
79-
->end()
80-
->arrayNode('excluded_exceptions')
81-
->defaultValue($defaultValues->getExcludedExceptions())
82-
->prototype('scalar')->end()
83-
->end()
84-
->scalarNode('http_proxy')
85-
->end()
86-
// TODO -- integrations
87-
->scalarNode('logger')
88-
->end()
89-
->integerNode('max_breadcrumbs')
90-
->min(1)
91-
->end()
92-
->arrayNode('prefixes')
93-
->defaultValue($defaultValues->getPrefixes())
94-
->prototype('scalar')->end()
95-
->end()
96-
->scalarNode('project_root')
97-
->defaultValue($this->getProjectRoot())
98-
->end()
99-
->scalarNode('release')
100-
->end()
101-
->floatNode('sample_rate')
102-
->min(0.0)
103-
->max(1.0)
104-
->end()
105-
->integerNode('send_attempts')
106-
->min(1)
107-
->end()
108-
->booleanNode('send_default_pii')->end()
109-
->scalarNode('server_name')
110-
->end()
111-
->arrayNode('tags')
112-
->normalizeKeys(false)
113-
->prototype('scalar')
114-
->end()
115-
;
46+
$optionsChildNodes = $optionsNode->children();
47+
48+
$optionsChildNodes->booleanNode('attach_stacktrace');
49+
$optionsChildNodes->variableNode('before_breadcrumb')
50+
->validate()
51+
->ifTrue($this->isNotAValidCallback())
52+
->thenInvalid('Expecting callable or service reference, got %s');
53+
$optionsChildNodes->variableNode('before_send')
54+
->validate()
55+
->ifTrue($this->isNotAValidCallback())
56+
->thenInvalid('Expecting callable or service reference, got %s');
57+
if (PrettyVersions::getVersion('sentry/sentry')->getPrettyVersion() !== '2.0.0') {
58+
$optionsChildNodes->booleanNode('capture_silenced_errors');
59+
}
60+
$optionsChildNodes->integerNode('context_lines')
61+
->min(0)
62+
->max(99);
63+
$optionsChildNodes->booleanNode('default_integrations');
64+
$optionsChildNodes->booleanNode('enable_compression');
65+
$optionsChildNodes->scalarNode('environment')
66+
->defaultValue('%kernel.environment%')
67+
->cannotBeEmpty();
68+
$optionsChildNodes->scalarNode('error_types');
69+
$optionsChildNodes->arrayNode('in_app_exclude')
70+
->defaultValue([
71+
'%kernel.cache_dir%',
72+
$this->getProjectRoot() . '/vendor',
73+
])
74+
->prototype('scalar');
75+
$optionsChildNodes->arrayNode('excluded_exceptions')
76+
->defaultValue($defaultValues->getExcludedExceptions())
77+
->prototype('scalar');
78+
$optionsChildNodes->scalarNode('http_proxy');
79+
$optionsChildNodes->arrayNode('integrations')
80+
->prototype('scalar')
81+
->validate()
82+
->ifTrue(function ($value): bool {
83+
if (! is_string($value)) {
84+
return true;
85+
}
86+
87+
return '@' !== substr($value, 0, 1);
88+
})
89+
->thenInvalid('Expecting service reference, got %s');
90+
$optionsChildNodes->scalarNode('logger');
91+
$optionsChildNodes->integerNode('max_breadcrumbs')
92+
->min(1);
93+
$optionsChildNodes->integerNode('max_value_length')
94+
->min(1);
95+
$optionsChildNodes->arrayNode('prefixes')
96+
->defaultValue($defaultValues->getPrefixes())
97+
->prototype('scalar');
98+
$optionsChildNodes->scalarNode('project_root')
99+
->defaultValue($this->getProjectRoot());
100+
$optionsChildNodes->scalarNode('release');
101+
$optionsChildNodes->floatNode('sample_rate')
102+
->min(0.0)
103+
->max(1.0);
104+
$optionsChildNodes->integerNode('send_attempts')
105+
->min(1);
106+
$optionsChildNodes->booleanNode('send_default_pii');
107+
$optionsChildNodes->scalarNode('server_name');
108+
$optionsChildNodes->arrayNode('tags')
109+
->normalizeKeys(false)
110+
->prototype('scalar');
116111

117112
// Bundle-specific configuration
118-
$rootNode->children()
113+
$listenerPriorities = $rootNode->children()
119114
->arrayNode('listener_priorities')
120-
->addDefaultsIfNotSet()
121-
->children()
122-
->scalarNode('request')->defaultValue(1)->end()
123-
->scalarNode('sub_request')->defaultValue(1)->end()
124-
->scalarNode('console')->defaultValue(1)->end()
125-
->end()
126-
->end();
115+
->addDefaultsIfNotSet()
116+
->children();
117+
$listenerPriorities->scalarNode('request')
118+
->defaultValue(1);
119+
$listenerPriorities->scalarNode('sub_request')
120+
->defaultValue(1);
121+
$listenerPriorities->scalarNode('console')
122+
->defaultValue(1);
127123

128124
return $treeBuilder;
129125
}
130126

131-
private function getTrimClosure(): callable
127+
private function getTrimClosure(): \Closure
132128
{
133-
return function ($str) {
129+
return function ($str): ?string {
134130
$value = trim($str);
135131
if ($value === '') {
136132
return null;

src/DependencyInjection/SentryExtension.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ private function passConfigurationToOptions(ContainerBuilder $container, array $
5252
$processedOptions = $processedConfiguration['options'];
5353
$mappableOptions = [
5454
'attach_stacktrace',
55+
'capture_silenced_errors',
5556
'context_lines',
5657
'default_integrations',
5758
'enable_compression',
@@ -60,6 +61,7 @@ private function passConfigurationToOptions(ContainerBuilder $container, array $
6061
'http_proxy',
6162
'logger',
6263
'max_breadcrumbs',
64+
'max_value_length',
6365
'prefixes',
6466
'project_root',
6567
'release',
@@ -93,6 +95,15 @@ private function passConfigurationToOptions(ContainerBuilder $container, array $
9395
if (\array_key_exists('before_breadcrumb', $processedOptions)) {
9496
$this->mapCallableValue($options, 'setBeforeBreadcrumbCallback', $processedOptions['before_breadcrumb']);
9597
}
98+
99+
if (\array_key_exists('integrations', $processedOptions)) {
100+
$integrations = [];
101+
foreach ($processedOptions['integrations'] as $integrationName) {
102+
$integrations[] = new Reference(substr($integrationName, 1));
103+
}
104+
105+
$options->addMethodCall('setIntegrations', [$integrations]);
106+
}
96107
}
97108

98109
/**

src/EventListener/RequestListener.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@ public function onKernelRequest(GetResponseEvent $event): void
5454
return;
5555
}
5656

57+
$currentClient = Hub::getCurrent()->getClient();
58+
if (null === $currentClient || ! $currentClient->getOptions()->shouldSendDefaultPii()) {
59+
return;
60+
}
61+
5762
$token = null;
5863

5964
if ($this->tokenStorage instanceof TokenStorageInterface) {

test/DependencyInjection/ConfigurationTest.php

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

33
namespace Sentry\SentryBundle\Test\DependencyInjection;
44

5+
use Jean85\PrettyVersions;
56
use PHPUnit\Framework\TestCase;
67
use Sentry\Options;
78
use Sentry\SentryBundle\DependencyInjection\Configuration;
@@ -11,15 +12,21 @@
1112

1213
class ConfigurationTest extends TestCase
1314
{
14-
public const SUPPORTED_SENTRY_OPTIONS_COUNT = 21;
15+
public const SUPPORTED_SENTRY_OPTIONS_COUNT = 23;
1516

1617
public function testDataProviderIsMappingTheRightNumberOfOptions(): void
1718
{
1819
$providerData = $this->optionValuesProvider();
1920
$supportedOptions = \array_unique(\array_column($providerData, 0));
2021

22+
$expectedCount = self::SUPPORTED_SENTRY_OPTIONS_COUNT;
23+
24+
if (PrettyVersions::getVersion('sentry/sentry')->getPrettyVersion() !== '2.0.0') {
25+
++$expectedCount;
26+
}
27+
2128
$this->assertCount(
22-
self::SUPPORTED_SENTRY_OPTIONS_COUNT,
29+
$expectedCount,
2330
$supportedOptions,
2431
'Provider for configuration options mismatch: ' . PHP_EOL . print_r($supportedOptions, true)
2532
);
@@ -54,6 +61,7 @@ public function testConfigurationDefaults(): void
5461
'%kernel.cache_dir%',
5562
'%kernel.root_dir%/../vendor',
5663
],
64+
'integrations' => $defaultSdkValues->getIntegrations(),
5765
'excluded_exceptions' => $defaultSdkValues->getExcludedExceptions(),
5866
'prefixes' => $defaultSdkValues->getPrefixes(),
5967
'project_root' => '%kernel.root_dir%/..',
@@ -83,7 +91,7 @@ public function testOptionValuesProcessing(string $option, $value): void
8391

8492
public function optionValuesProvider(): array
8593
{
86-
return [
94+
$options = [
8795
['attach_stacktrace', true],
8896
['before_breadcrumb', 'count'],
8997
['before_send', 'count'],
@@ -96,9 +104,11 @@ public function optionValuesProvider(): array
96104
['error_types', E_ALL],
97105
['http_proxy', '1.2.3.4:5678'],
98106
['in_app_exclude', ['some/path']],
107+
['integrations', []],
99108
['excluded_exceptions', [\Throwable::class]],
100109
['logger', 'some-logger'],
101110
['max_breadcrumbs', 15],
111+
['max_value_length', 1000],
102112
['prefixes', ['some-string']],
103113
['project_root', '/some/dir'],
104114
['release', 'abc0123'],
@@ -110,6 +120,12 @@ public function optionValuesProvider(): array
110120
['server_name', 'server001.example.com'],
111121
['tags', ['tag-name' => 'value']],
112122
];
123+
124+
if (PrettyVersions::getVersion('sentry/sentry')->getPrettyVersion() !== '2.0.0') {
125+
$options[] = ['capture_silenced_errors', true];
126+
}
127+
128+
return $options;
113129
}
114130

115131
/**
@@ -144,12 +160,16 @@ public function invalidValuesProvider(): array
144160
['enable_compression', 'string'],
145161
['environment', ''],
146162
['error_types', []],
163+
['excluded_exceptions', 'some-string'],
147164
['http_proxy', []],
148165
['in_app_exclude', 'some/single/path'],
149-
['excluded_exceptions', 'some-string'],
166+
['integrations', [1]],
167+
['integrations', 'a string'],
150168
['logger', []],
151169
['max_breadcrumbs', -1],
152170
['max_breadcrumbs', 'string'],
171+
['max_value_length', -1],
172+
['max_value_length', []],
153173
['prefixes', 'string'],
154174
['project_root', []],
155175
['release', []],

0 commit comments

Comments
 (0)