Skip to content

Commit af3d1b7

Browse files
authored
Support sentry/sentry 2.3 and fix deprecations (#298)
* Fix a test * Require sentry/sdk:^2.1 to obtain sentry/sentry:^2.3 * Use a callable to filter the integrations * Remove deprecation * Add in_app_include option support * Remap excluded_exceptions option to add the new IgnoreErrorIntegration and avoid deprecation * Map the in_app_include option correctly * Remove multiple conditional code that was necessary to avoid deprecations * Remove multiple conditional code from tests too * Make tests run faster by using process isolation only on End2End * Add changelog entries * Fix test failure message * Revert remapping of project_root to avoid confusion * Add changelog entry for new sentry/sentry support * Fix test * Fix another test * Update changelog to slate 3.4.0 release
1 parent 3a9c266 commit af3d1b7

22 files changed

+183
-206
lines changed

Diff for: CHANGELOG.md

+8-2
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,18 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
66

77
## Unreleased
88
- ...
9+
10+
## 3.4.0 (2020-01-17)
11+
- Add support for `sentry/sentry` 2.3 (#298)
12+
- Drop support for `sentry/sentry` < 2.3 (#298)
13+
- Add support to `in_app_include` client option (#298)
14+
- Remap `excluded_exception` option to use the new `IgnoreErrorIntegration` (#298)
915

1016
## 3.3.2 (2020-01-16)
11-
- Fix issue with exception listener under Symfony 4.3 (#301)
17+
- Fix issue with exception listener under Symfony 4.3 (#301)
1218

1319
## 3.3.1 (2020-01-14)
14-
- Fixed Release
20+
- Fixed Release
1521

1622
## 3.3.0 (2020-01-14)
1723
- Add support for Symfony 5.0 (#266, thanks to @Big-Shark)

Diff for: composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"php": "^7.1",
2323
"jean85/pretty-package-versions": "^1.0",
2424
"ocramius/package-versions": "^1.3.0",
25-
"sentry/sdk": "^2.0",
25+
"sentry/sdk": "^2.1",
2626
"symfony/config": "^3.4||^4.0||^5.0",
2727
"symfony/console": "^3.4||^4.0||^5.0",
2828
"symfony/dependency-injection": "^3.4||^4.0||^5.0",

Diff for: phpstan.neon

-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ parameters:
66
ignoreErrors:
77
- "/Call to function method_exists.. with 'Symfony.+' and 'getRootNode' will always evaluate to false./"
88
- "/Call to function method_exists.. with 'Symfony.+' and 'getThrowable' will always evaluate to false./"
9-
- "/Call to function method_exists.. with 'Sentry..Options' and 'getClassSerializers' will always evaluate to false./"
10-
- "/Call to function method_exists.. with 'Sentry..Options' and 'getMaxRequestBodySi...' will always evaluate to false./"
119
- '/Class PHPUnit_Framework_TestCase not found/'
1210
- '/Symfony\\Component\\HttpKernel\\Event\\(GetResponse|FilterController)Event not found.$/'
1311
-

Diff for: phpunit.xml

-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
backupGlobals="false"
77
bootstrap="vendor/autoload.php"
88
cacheResult="false"
9-
processIsolation="true"
109
>
1110
<php>
1211
<env name="SYMFONY_DEPRECATIONS_HELPER" value="weak" />

Diff for: src/Command/SentryTestCommand.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace Sentry\SentryBundle\Command;
44

5-
use Sentry\SentryBundle\SentryBundle;
5+
use Sentry\SentrySdk;
66
use Symfony\Component\Console\Command\Command;
77
use Symfony\Component\Console\Input\InputInterface;
88
use Symfony\Component\Console\Output\OutputInterface;
@@ -16,7 +16,7 @@ public function __construct()
1616

1717
protected function execute(InputInterface $input, OutputInterface $output): int
1818
{
19-
$currentHub = SentryBundle::getCurrentHub();
19+
$currentHub = SentrySdk::getCurrentHub();
2020
$client = $currentHub->getClient();
2121

2222
if (! $client) {

Diff for: src/DependencyInjection/ClientBuilderConfigurator.php

-21
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@
33
namespace Sentry\SentryBundle\DependencyInjection;
44

55
use Sentry\ClientBuilderInterface;
6-
use Sentry\Integration\ErrorListenerIntegration;
7-
use Sentry\Integration\ExceptionListenerIntegration;
8-
use Sentry\Integration\IntegrationInterface;
96
use Sentry\SentryBundle\SentryBundle;
107

118
class ClientBuilderConfigurator
@@ -14,23 +11,5 @@ public static function configure(ClientBuilderInterface $clientBuilder): void
1411
{
1512
$clientBuilder->setSdkIdentifier(SentryBundle::SDK_IDENTIFIER);
1613
$clientBuilder->setSdkVersion(SentryBundle::getSdkVersion());
17-
18-
$options = $clientBuilder->getOptions();
19-
if (! $options->hasDefaultIntegrations()) {
20-
return;
21-
}
22-
23-
$integrations = $options->getIntegrations();
24-
$options->setIntegrations(array_filter($integrations, static function (IntegrationInterface $integration): bool {
25-
if ($integration instanceof ErrorListenerIntegration) {
26-
return false;
27-
}
28-
29-
if ($integration instanceof ExceptionListenerIntegration) {
30-
return false;
31-
}
32-
33-
return true;
34-
}));
3514
}
3615
}

Diff for: src/DependencyInjection/Configuration.php

+18-31
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace Sentry\SentryBundle\DependencyInjection;
44

5-
use Jean85\PrettyVersions;
65
use PackageVersions\Versions;
76
use Sentry\Options;
87
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
@@ -58,14 +57,10 @@ public function getConfigTreeBuilder(): TreeBuilder
5857
->validate()
5958
->ifTrue($this->isNotAValidCallback())
6059
->thenInvalid('Expecting callable or service reference, got %s');
61-
if (PrettyVersions::getVersion('sentry/sentry')->getPrettyVersion() !== '2.0.0') {
62-
$optionsChildNodes->booleanNode('capture_silenced_errors');
63-
}
64-
if ($this->classSerializersAreSupported()) {
65-
$optionsChildNodes->arrayNode('class_serializers')
66-
->defaultValue([])
67-
->prototype('scalar');
68-
}
60+
$optionsChildNodes->booleanNode('capture_silenced_errors');
61+
$optionsChildNodes->arrayNode('class_serializers')
62+
->defaultValue([])
63+
->prototype('scalar');
6964
$optionsChildNodes->integerNode('context_lines')
7065
->min(0)
7166
->max(99);
@@ -75,14 +70,19 @@ public function getConfigTreeBuilder(): TreeBuilder
7570
->defaultValue('%kernel.environment%')
7671
->cannotBeEmpty();
7772
$optionsChildNodes->scalarNode('error_types');
73+
$optionsChildNodes->arrayNode('in_app_include')
74+
->defaultValue([
75+
'%kernel.project_dir%/src',
76+
])
77+
->prototype('scalar');
7878
$optionsChildNodes->arrayNode('in_app_exclude')
7979
->defaultValue([
8080
'%kernel.cache_dir%',
8181
'%kernel.project_dir%/vendor',
8282
])
8383
->prototype('scalar');
8484
$optionsChildNodes->arrayNode('excluded_exceptions')
85-
->defaultValue($defaultValues->getExcludedExceptions())
85+
->defaultValue([])
8686
->prototype('scalar');
8787
$optionsChildNodes->scalarNode('http_proxy');
8888
$optionsChildNodes->arrayNode('integrations')
@@ -97,24 +97,21 @@ public function getConfigTreeBuilder(): TreeBuilder
9797
})
9898
->thenInvalid('Expecting service reference, got "%s"');
9999
$optionsChildNodes->scalarNode('logger');
100-
if ($this->maxRequestBodySizeIsSupported()) {
101-
$optionsChildNodes->enumNode('max_request_body_size')
102-
->values([
103-
'none',
104-
'small',
105-
'medium',
106-
'always',
107-
]);
108-
}
100+
$optionsChildNodes->enumNode('max_request_body_size')
101+
->values([
102+
'none',
103+
'small',
104+
'medium',
105+
'always',
106+
]);
109107
$optionsChildNodes->integerNode('max_breadcrumbs')
110108
->min(1);
111109
$optionsChildNodes->integerNode('max_value_length')
112110
->min(1);
113111
$optionsChildNodes->arrayNode('prefixes')
114112
->defaultValue($defaultValues->getPrefixes())
115113
->prototype('scalar');
116-
$optionsChildNodes->scalarNode('project_root')
117-
->defaultValue('%kernel.project_dir%');
114+
$optionsChildNodes->scalarNode('project_root');
118115
$optionsChildNodes->scalarNode('release')
119116
->defaultValue(Versions::getVersion(Versions::ROOT_PACKAGE_NAME))
120117
->info('Release version to be reported to sentry, see https://docs.sentry.io/workflow/releases/?platform=php')
@@ -193,14 +190,4 @@ private function isNotAValidCallback(): \Closure
193190
return true;
194191
};
195192
}
196-
197-
private function classSerializersAreSupported(): bool
198-
{
199-
return method_exists(Options::class, 'getClassSerializers');
200-
}
201-
202-
private function maxRequestBodySizeIsSupported(): bool
203-
{
204-
return method_exists(Options::class, 'getMaxRequestBodySize');
205-
}
206193
}

Diff for: src/DependencyInjection/IntegrationFilterFactory.php

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
namespace Sentry\SentryBundle\DependencyInjection;
4+
5+
use Sentry\Integration\ErrorListenerIntegration;
6+
use Sentry\Integration\ExceptionListenerIntegration;
7+
use Sentry\Integration\IntegrationInterface;
8+
9+
class IntegrationFilterFactory
10+
{
11+
public static function create(array $integrationsFromConfiguration): callable
12+
{
13+
return function (array $integrations) use ($integrationsFromConfiguration) {
14+
$allIntegrations = array_merge($integrations, $integrationsFromConfiguration);
15+
16+
return array_filter(
17+
$allIntegrations,
18+
static function (IntegrationInterface $integration): bool {
19+
if ($integration instanceof ErrorListenerIntegration) {
20+
return false;
21+
}
22+
23+
if ($integration instanceof ExceptionListenerIntegration) {
24+
return false;
25+
}
26+
27+
return true;
28+
}
29+
);
30+
};
31+
}
32+
}

Diff for: src/DependencyInjection/SentryExtension.php

+19-3
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@
44

55
use Monolog\Logger as MonologLogger;
66
use Sentry\ClientBuilderInterface;
7+
use Sentry\Integration\IgnoreErrorsIntegration;
78
use Sentry\Monolog\Handler;
89
use Sentry\Options;
910
use Sentry\SentryBundle\ErrorTypesParser;
1011
use Sentry\SentryBundle\EventListener\ErrorListener;
1112
use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException;
1213
use Symfony\Component\Config\FileLocator;
1314
use Symfony\Component\DependencyInjection\ContainerBuilder;
15+
use Symfony\Component\DependencyInjection\Definition;
1416
use Symfony\Component\DependencyInjection\Exception\LogicException;
1517
use Symfony\Component\DependencyInjection\Loader;
1618
use Symfony\Component\DependencyInjection\Reference;
@@ -63,7 +65,6 @@ private function passConfigurationToOptions(ContainerBuilder $container, array $
6365
'default_integrations',
6466
'enable_compression',
6567
'environment',
66-
'excluded_exceptions',
6768
'http_proxy',
6869
'logger',
6970
'max_request_body_size',
@@ -90,6 +91,10 @@ private function passConfigurationToOptions(ContainerBuilder $container, array $
9091
$options->addMethodCall('setInAppExcludedPaths', [$processedOptions['in_app_exclude']]);
9192
}
9293

94+
if (\array_key_exists('in_app_include', $processedOptions)) {
95+
$options->addMethodCall('setInAppIncludedPaths', [$processedOptions['in_app_include']]);
96+
}
97+
9398
if (\array_key_exists('error_types', $processedOptions)) {
9499
$parsedValue = (new ErrorTypesParser($processedOptions['error_types']))->parse();
95100
$options->addMethodCall('setErrorTypes', [$parsedValue]);
@@ -114,14 +119,25 @@ private function passConfigurationToOptions(ContainerBuilder $container, array $
114119
$options->addMethodCall('setClassSerializers', [$classSerializers]);
115120
}
116121

122+
$integrations = [];
117123
if (\array_key_exists('integrations', $processedOptions)) {
118-
$integrations = [];
119124
foreach ($processedOptions['integrations'] as $integrationName) {
120125
$integrations[] = new Reference(substr($integrationName, 1));
121126
}
127+
}
122128

123-
$options->addMethodCall('setIntegrations', [$integrations]);
129+
if (\array_key_exists('excluded_exceptions', $processedOptions) && $processedOptions['excluded_exceptions']) {
130+
$ignoreOptions = [
131+
'ignore_exceptions' => $processedOptions['excluded_exceptions'],
132+
];
133+
134+
$integrations[] = new Definition(IgnoreErrorsIntegration::class, [$ignoreOptions]);
124135
}
136+
137+
$integrationsCallable = new Definition('callable', [$integrations]);
138+
$integrationsCallable->setFactory([IntegrationFilterFactory::class, 'create']);
139+
140+
$options->addMethodCall('setIntegrations', [$integrationsCallable]);
125141
}
126142

127143
private function valueToCallable($value)

Diff for: src/EventListener/ConsoleListener.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace Sentry\SentryBundle\EventListener;
44

5-
use Sentry\SentryBundle\SentryBundle;
5+
use Sentry\SentrySdk;
66
use Sentry\State\HubInterface;
77
use Sentry\State\Scope;
88
use Symfony\Component\Console\Event\ConsoleCommandEvent;
@@ -38,7 +38,7 @@ public function onConsoleCommand(ConsoleCommandEvent $event): void
3838
$commandName = $command->getName();
3939
}
4040

41-
SentryBundle::getCurrentHub()
41+
SentrySdk::getCurrentHub()
4242
->configureScope(static function (Scope $scope) use ($commandName): void {
4343
$scope->setTag('command', $commandName ?? 'N/A');
4444
});

Diff for: src/EventListener/RequestListener.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace Sentry\SentryBundle\EventListener;
44

5-
use Sentry\SentryBundle\SentryBundle;
5+
use Sentry\SentrySdk;
66
use Sentry\State\HubInterface;
77
use Sentry\State\Scope;
88
use Symfony\Component\HttpKernel\Event\ControllerEvent;
@@ -56,7 +56,7 @@ public function onKernelRequest(RequestEvent $event): void
5656
return;
5757
}
5858

59-
$currentClient = SentryBundle::getCurrentHub()->getClient();
59+
$currentClient = SentrySdk::getCurrentHub()->getClient();
6060
if (null === $currentClient || ! $currentClient->getOptions()->shouldSendDefaultPii()) {
6161
return;
6262
}
@@ -79,9 +79,9 @@ public function onKernelRequest(RequestEvent $event): void
7979

8080
$userData['ip_address'] = $event->getRequest()->getClientIp();
8181

82-
SentryBundle::getCurrentHub()
82+
SentrySdk::getCurrentHub()
8383
->configureScope(function (Scope $scope) use ($userData): void {
84-
$scope->setUser($userData);
84+
$scope->setUser($userData, true);
8585
});
8686
}
8787

@@ -97,7 +97,7 @@ public function onKernelController(ControllerEvent $event): void
9797

9898
$matchedRoute = (string) $event->getRequest()->attributes->get('_route');
9999

100-
SentryBundle::getCurrentHub()
100+
SentrySdk::getCurrentHub()
101101
->configureScope(function (Scope $scope) use ($matchedRoute): void {
102102
$scope->setTag('route', $matchedRoute);
103103
});

Diff for: src/EventListener/SubRequestListener.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace Sentry\SentryBundle\EventListener;
44

5-
use Sentry\SentryBundle\SentryBundle;
5+
use Sentry\SentrySdk;
66
use Symfony\Component\HttpKernel\Event\FinishRequestEvent;
77
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
88
use Symfony\Component\HttpKernel\Event\RequestEvent;
@@ -24,7 +24,7 @@ public function onKernelRequest(RequestEvent $event): void
2424
return;
2525
}
2626

27-
SentryBundle::getCurrentHub()->pushScope();
27+
SentrySdk::getCurrentHub()->pushScope();
2828
}
2929

3030
/**
@@ -38,6 +38,6 @@ public function onKernelFinishRequest(FinishRequestEvent $event): void
3838
return;
3939
}
4040

41-
SentryBundle::getCurrentHub()->popScope();
41+
SentrySdk::getCurrentHub()->popScope();
4242
}
4343
}

0 commit comments

Comments
 (0)