Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use the hub injected in the constructor of the listeners rather than retrieving it from the SDK singleton #387

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
- Added `options.traces_sampler` and `options.traces_sample_rate` configuration options (#385)
- [BC BREAK] Removed the `options.project_root` configuration option. Instead of setting it, use a combination of `options.in_app_include` and `options.in_app_exclude` (#385)
- [BC BREAK] Removed the `options.excluded_exceptions` configuration option. Instead of setting it, configure the `IgnoreErrorsIntegration` integration (#385)
- [BC BREAK] Refactorized the `ConsoleCommandListener`, `ErrorListener`, `RequestListener` and `SubRequestListener` event listeners (#387)
- CLI commands registration policy changed to lazy load

## 3.5.3 (2020-10-13)
Expand Down
15 changes: 15 additions & 0 deletions UPGRADE-4.0.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
# Upgrade 3.x to 4.0

- Added the `$hub` argument to the constructor of the `SubRequestListener` class.
- Renamed the `ConsoleListener` class to `ConsoleCommandListener`.
- Renamed the `ConsoleListener::onConsoleCommand` method to `ConsoleCommandListener::handleConsoleCommandEvent`.
- Renamed the `ErrorListener::onException` method to `ErrorListener::handleExceptionEvent`.
- Removed the `ErrorListener::onKernelException` method.
- Removed the `ErrorListener::onConsoleError` method.
- Renamed the `RequestListener::onKernelRequest` method to `RequestListener::handleKernelRequestEvent`.
- Renamed the `RequestListener::onKernelController` method to `RequestListener::handleKernelControllerEvent`.
- Renamed the `SubRequestListener::onKernelRequest` method to `SubRequestListener::handleKernelRequestEvent`.
- Renamed the `SubRequestListener::onKernelFinishRequest` method to `SubRequestListener::handleKernelFinishRequestEvent`.
- Removed the `sentry.listener_priorities.console` configuration option.
- Removed the `Sentry\FlushableClientInterface` service alias.
- Removed the `sentry.options.excluded_exceptions` configuration option.

Before:
Expand All @@ -25,3 +37,6 @@
ignore_exceptions:
- RuntimeException
```

- Changed the default value of the `sentry.listener_priorities.console_error` configuration option to `-64`.
- Changed the default value of the `sentry.listener_priorities.console` configuration option to `128`.
3 changes: 0 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,17 @@
"friendsofphp/php-cs-fixer": "^2.16",
"jangregor/phpstan-prophecy": "^0.8",
"monolog/monolog": "^1.3||^2.0",
"php-http/mock-client": "^1.4",
"phpspec/prophecy": "!=1.11.0",
"phpspec/prophecy-phpunit": "^1.1||^2.0",
"phpstan/extension-installer": "^1.0",
"phpstan/phpstan": "^0.12",
"phpstan/phpstan-phpunit": "^0.12",
"phpunit/phpunit": "^8.5||^9.0",
"symfony/browser-kit": "^3.4||^4.0||^5.0",
"symfony/expression-language": "^3.4||^4.0||^5.0",
"symfony/framework-bundle": "^3.4.23||^4.0||^5.0",
"symfony/messenger": "^4.3||^5.0",
"symfony/monolog-bundle": "^3.4",
"symfony/phpunit-bridge": "^5.0",
"symfony/process": "^3.4||^4.0||^5.0",
"symfony/yaml": "^3.4||^4.0||^5.0"
},
"suggest": {
Expand Down
96 changes: 46 additions & 50 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,19 @@ parameters:
path: src/DependencyInjection/SentryExtension.php

-
message: "#^Parameter \\$event of method Sentry\\\\SentryBundle\\\\EventListener\\\\ErrorListener\\:\\:onKernelException\\(\\) has invalid typehint type Symfony\\\\Component\\\\HttpKernel\\\\Event\\\\GetResponseForExceptionEvent\\.$#"
message: "#^If condition is always true\\.$#"
ste93cry marked this conversation as resolved.
Show resolved Hide resolved
count: 1
path: src/EventListener/ErrorListener.php

-
message: "#^Call to method getException\\(\\) on an unknown class Symfony\\\\Component\\\\HttpKernel\\\\Event\\\\GetResponseForExceptionEvent\\.$#"
message: "#^Class Symfony\\\\Component\\\\HttpKernel\\\\Event\\\\GetResponseForExceptionEvent not found\\.$#"
count: 1
path: src/EventListener/ErrorListener.php

-
message: "#^Comparison operation \"\\>\\=\" between 5 and 5 is always true\\.$#"
message: "#^Else branch is unreachable because previous condition is always true\\.$#"
count: 1
path: src/EventListener/RequestListener.php
path: src/EventListener/ErrorListener.php

-
message: "#^Class Sentry\\\\SentryBundle\\\\EventListener\\\\RequestListenerRequestEvent not found\\.$#"
Expand All @@ -56,12 +56,17 @@ parameters:
path: src/EventListener/RequestListener.php

-
message: "#^Else branch is unreachable because previous condition is always true\\.$#"
message: "#^Class Symfony\\\\Component\\\\HttpKernel\\\\Event\\\\GetResponseEvent not found\\.$#"
count: 1
path: src/EventListener/RequestListener.php

-
message: "#^Class Symfony\\\\Component\\\\HttpKernel\\\\Event\\\\FilterControllerEvent not found\\.$#"
count: 1
path: src/EventListener/RequestListener.php

-
message: "#^Parameter \\$event of method Sentry\\\\SentryBundle\\\\EventListener\\\\RequestListener\\:\\:onKernelRequest\\(\\) has invalid typehint type Sentry\\\\SentryBundle\\\\EventListener\\\\RequestListenerRequestEvent\\.$#"
message: "#^Parameter \\$event of method Sentry\\\\SentryBundle\\\\EventListener\\\\RequestListener\\:\\:handleKernelRequestEvent\\(\\) has invalid typehint type Sentry\\\\SentryBundle\\\\EventListener\\\\RequestListenerRequestEvent\\.$#"
count: 2
path: src/EventListener/RequestListener.php

Expand All @@ -76,8 +81,8 @@ parameters:
path: src/EventListener/RequestListener.php

-
message: "#^Parameter \\$event of method Sentry\\\\SentryBundle\\\\EventListener\\\\RequestListener\\:\\:onKernelController\\(\\) has invalid typehint type Sentry\\\\SentryBundle\\\\EventListener\\\\RequestListenerControllerEvent\\.$#"
count: 1
message: "#^Parameter \\$event of method Sentry\\\\SentryBundle\\\\EventListener\\\\RequestListener\\:\\:handleKernelControllerEvent\\(\\) has invalid typehint type Sentry\\\\SentryBundle\\\\EventListener\\\\RequestListenerControllerEvent\\.$#"
count: 2
path: src/EventListener/RequestListener.php

-
Expand All @@ -87,26 +92,21 @@ parameters:

-
message: "#^Call to method getRequest\\(\\) on an unknown class Sentry\\\\SentryBundle\\\\EventListener\\\\RequestListenerControllerEvent\\.$#"
count: 2
path: src/EventListener/RequestListener.php

-
message: "#^Comparison operation \"\\>\\=\" between 5 and 5 is always true\\.$#"
count: 1
path: src/EventListener/SubRequestListener.php
path: src/EventListener/RequestListener.php

-
message: "#^Class Sentry\\\\SentryBundle\\\\EventListener\\\\SubRequestListenerRequestEvent not found\\.$#"
count: 2
path: src/EventListener/SubRequestListener.php

-
message: "#^Else branch is unreachable because previous condition is always true\\.$#"
message: "#^Class Symfony\\\\Component\\\\HttpKernel\\\\Event\\\\GetResponseEvent not found\\.$#"
count: 1
path: src/EventListener/SubRequestListener.php

-
message: "#^Parameter \\$event of method Sentry\\\\SentryBundle\\\\EventListener\\\\SubRequestListener\\:\\:onKernelRequest\\(\\) has invalid typehint type Sentry\\\\SentryBundle\\\\EventListener\\\\SubRequestListenerRequestEvent\\.$#"
message: "#^Parameter \\$event of method Sentry\\\\SentryBundle\\\\EventListener\\\\SubRequestListener\\:\\:handleKernelRequestEvent\\(\\) has invalid typehint type Sentry\\\\SentryBundle\\\\EventListener\\\\SubRequestListenerRequestEvent\\.$#"
count: 2
path: src/EventListener/SubRequestListener.php

Expand All @@ -115,11 +115,6 @@ parameters:
count: 1
path: src/EventListener/SubRequestListener.php

-
message: "#^Method Sentry\\\\SentryBundle\\\\Test\\\\BaseTestCase\\:\\:createRequestEvent\\(\\) has no return typehint specified\\.$#"
count: 1
path: test/BaseTestCase.php

-
message: "#^Method Sentry\\\\SentryBundle\\\\Test\\\\DependencyInjection\\\\ConfigurationTest\\:\\:testOptionValuesProcessing\\(\\) has parameter \\$value with no typehint specified\\.$#"
count: 1
Expand Down Expand Up @@ -225,17 +220,13 @@ parameters:
count: 1
path: test/DependencyInjection/SentryExtensionTest.php

-
message: "#^Comparison operation \"\\>\\=\" between \\d+ and 40300 is always true\\.$#"
count: 1
path: test/End2End/App/Kernel.php
-
message: "#^Class Symfony\\\\Bundle\\\\FrameworkBundle\\\\Client not found\\.$#"
count: 1
path: test/End2End/End2EndTest.php

-
message: "#^Comparison operation \"\\<\" between \\d+ and 40300 is always false\\.$#"
message: "#^Comparison operation \"\\<\" between 50108 and 40300 is always false\\.$#"
count: 1
path: test/End2End/End2EndTest.php

Expand All @@ -250,22 +241,27 @@ parameters:
path: test/ErrorTypesParserTest.php

-
message: "#^Property Sentry\\\\SentryBundle\\\\Test\\\\EventListener\\\\ConsoleListenerTest\\:\\:\\$currentHub has no typehint specified\\.$#"
message: "#^Parameter \\$event of method Sentry\\\\SentryBundle\\\\Test\\\\EventListener\\\\ErrorListenerTest\\:\\:testHandleExceptionEvent\\(\\) has invalid typehint type Symfony\\\\Component\\\\HttpKernel\\\\Event\\\\GetResponseForExceptionEvent\\.$#"
count: 1
path: test/EventListener/ErrorListenerTest.php

-
message: "#^Call to method getException\\(\\) on an unknown class Symfony\\\\Component\\\\HttpKernel\\\\Event\\\\GetResponseForExceptionEvent\\.$#"
count: 1
path: test/EventListener/ConsoleListenerTest.php
path: test/EventListener/ErrorListenerTest.php

-
message: "#^Property Sentry\\\\SentryBundle\\\\Test\\\\EventListener\\\\ConsoleListenerTest\\:\\:\\$currentScope has no typehint specified\\.$#"
message: "#^Parameter \\#1 \\$event of method Sentry\\\\SentryBundle\\\\EventListener\\\\ErrorListener\\:\\:handleExceptionEvent\\(\\) expects Symfony\\\\Component\\\\HttpKernel\\\\Event\\\\ExceptionEvent, Symfony\\\\Component\\\\HttpKernel\\\\Event\\\\ExceptionEvent\\|Symfony\\\\Component\\\\HttpKernel\\\\Event\\\\GetResponseForExceptionEvent given\\.$#"
count: 1
path: test/EventListener/ConsoleListenerTest.php
path: test/EventListener/ErrorListenerTest.php

-
message: "#^Method Sentry\\\\SentryBundle\\\\Test\\\\EventListener\\\\ConsoleListenerTest\\:\\:getTagsContext\\(\\) return type has no value type specified in iterable type array\\.$#"
message: "#^Instantiated class Symfony\\\\Component\\\\HttpKernel\\\\Event\\\\GetResponseForExceptionEvent not found\\.$#"
count: 1
path: test/EventListener/ConsoleListenerTest.php
path: test/EventListener/ErrorListenerTest.php

-
message: "#^Class Symfony\\\\Component\\\\Messenger\\\\Event\\\\WorkerMessageHandledEvent constructor invoked with 3 parameters, 2 required\\.$#"
message: "#^If condition is always false\\.$#"
count: 1
path: test/EventListener/MessengerListenerTest.php

Expand All @@ -275,52 +271,52 @@ parameters:
path: test/EventListener/MessengerListenerTest.php

-
message: "#^Property Sentry\\\\SentryBundle\\\\Test\\\\EventListener\\\\RequestListenerTest\\:\\:\\$currentScope has no typehint specified\\.$#"
message: "#^Parameter \\$requestEvent of method Sentry\\\\SentryBundle\\\\Test\\\\EventListener\\\\RequestListenerTest\\:\\:testHandleKernelRequestEvent\\(\\) has invalid typehint type Symfony\\\\Component\\\\HttpKernel\\\\Event\\\\GetResponseEvent\\.$#"
count: 1
path: test/EventListener/RequestListenerTest.php

-
message: "#^Property Sentry\\\\SentryBundle\\\\Test\\\\EventListener\\\\RequestListenerTest\\:\\:\\$currentHub has no typehint specified\\.$#"
message: "#^Parameter \\#1 \\$event of method Sentry\\\\SentryBundle\\\\EventListener\\\\RequestListener\\:\\:handleKernelRequestEvent\\(\\) expects Sentry\\\\SentryBundle\\\\EventListener\\\\RequestListenerRequestEvent, Symfony\\\\Component\\\\HttpKernel\\\\Event\\\\GetResponseEvent\\|Symfony\\\\Component\\\\HttpKernel\\\\Event\\\\RequestEvent given\\.$#"
count: 1
path: test/EventListener/RequestListenerTest.php

-
message: "#^Property Sentry\\\\SentryBundle\\\\Test\\\\EventListener\\\\RequestListenerTest\\:\\:\\$options has no typehint specified\\.$#"
count: 1
message: "#^Instantiated class Symfony\\\\Component\\\\HttpKernel\\\\Event\\\\GetResponseEvent not found\\.$#"
count: 6
path: test/EventListener/RequestListenerTest.php

-
message: "#^Method Sentry\\\\SentryBundle\\\\Test\\\\EventListener\\\\RequestListenerTest\\:\\:testOnKernelRequestUserDataIsSetToScope\\(\\) has parameter \\$user with no typehint specified\\.$#"
message: "#^Parameter \\$controllerEvent of method Sentry\\\\SentryBundle\\\\Test\\\\EventListener\\\\RequestListenerTest\\:\\:testHandleKernelControllerEvent\\(\\) has invalid typehint type Symfony\\\\Component\\\\HttpKernel\\\\Event\\\\FilterControllerEvent\\.$#"
count: 1
path: test/EventListener/RequestListenerTest.php

-
message: "#^Method Sentry\\\\SentryBundle\\\\Test\\\\EventListener\\\\RequestListenerTest\\:\\:userDataProvider\\(\\) return type has no value type specified in iterable type Generator\\.$#"
message: "#^Parameter \\#1 \\$event of method Sentry\\\\SentryBundle\\\\EventListener\\\\RequestListener\\:\\:handleKernelControllerEvent\\(\\) expects Sentry\\\\SentryBundle\\\\EventListener\\\\RequestListenerControllerEvent, Symfony\\\\Component\\\\HttpKernel\\\\Event\\\\ControllerEvent\\|Symfony\\\\Component\\\\HttpKernel\\\\Event\\\\FilterControllerEvent given\\.$#"
count: 1
path: test/EventListener/RequestListenerTest.php

-
message: "#^Method Sentry\\\\SentryBundle\\\\Test\\\\EventListener\\\\RequestListenerTest\\:\\:getTagsContext\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
message: "#^Instantiated class Symfony\\\\Component\\\\HttpKernel\\\\Event\\\\FilterControllerEvent not found\\.$#"
count: 3
path: test/EventListener/RequestListenerTest.php

-
message: "#^Method Sentry\\\\SentryBundle\\\\Test\\\\EventListener\\\\RequestListenerTest\\:\\:createControllerEvent\\(\\) has no return typehint specified\\.$#"
message: "#^Parameter \\$event of method Sentry\\\\SentryBundle\\\\Test\\\\EventListener\\\\SubRequestListenerTest\\:\\:testHandleKernelRequestEvent\\(\\) has invalid typehint type Symfony\\\\Component\\\\HttpKernel\\\\Event\\\\GetResponseEvent\\.$#"
count: 1
path: test/EventListener/RequestListenerTest.php
path: test/EventListener/SubRequestListenerTest.php

-
message: "#^Property Sentry\\\\SentryBundle\\\\Test\\\\EventListener\\\\UserWithInterface\\:\\:\\$username has no typehint specified\\.$#"
message: "#^Call to method isMasterRequest\\(\\) on an unknown class Symfony\\\\Component\\\\HttpKernel\\\\Event\\\\GetResponseEvent\\.$#"
count: 1
path: test/EventListener/RequestListenerTest.php
path: test/EventListener/SubRequestListenerTest.php

-
message: "#^Method Sentry\\\\SentryBundle\\\\Test\\\\EventListener\\\\UserWithInterface\\:\\:eraseCredentials\\(\\) has no return typehint specified\\.$#"
message: "#^Parameter \\#1 \\$event of method Sentry\\\\SentryBundle\\\\EventListener\\\\SubRequestListener\\:\\:handleKernelRequestEvent\\(\\) expects Sentry\\\\SentryBundle\\\\EventListener\\\\SubRequestListenerRequestEvent, Symfony\\\\Component\\\\HttpKernel\\\\Event\\\\GetResponseEvent\\|Symfony\\\\Component\\\\HttpKernel\\\\Event\\\\RequestEvent given\\.$#"
count: 1
path: test/EventListener/RequestListenerTest.php
path: test/EventListener/SubRequestListenerTest.php

-
message: "#^Property Sentry\\\\SentryBundle\\\\Test\\\\EventListener\\\\ToStringUser\\:\\:\\$username has no typehint specified\\.$#"
count: 1
path: test/EventListener/RequestListenerTest.php
message: "#^Instantiated class Symfony\\\\Component\\\\HttpKernel\\\\Event\\\\GetResponseEvent not found\\.$#"
count: 2
path: test/EventListener/SubRequestListenerTest.php

11 changes: 7 additions & 4 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
includes:
- phpstan-baseline.neon

parameters:
level: 7
paths:
- src/
- test/
ignoreErrors:
- '/Symfony\\Component\\HttpKernel\\Event\\(GetResponse|FilterController)Event not found.$/'
includes:
- phpstan-baseline.neon
excludes_analyse:
- test/End2End/App
dynamicConstantNames:
- Symfony\Component\HttpKernel\Kernel::VERSION
ste93cry marked this conversation as resolved.
Show resolved Hide resolved
8 changes: 5 additions & 3 deletions src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,14 +137,16 @@ public function getConfigTreeBuilder(): TreeBuilder
->children();
$listenerPriorities->scalarNode('request')
->defaultValue(1);
$listenerPriorities->scalarNode('sub_request')
->defaultValue(1);
$listenerPriorities->scalarNode('console')
->defaultValue(128);
$listenerPriorities->scalarNode('sub_request')
->defaultValue(1);
$listenerPriorities->scalarNode('request_error')
->defaultValue(128);
$listenerPriorities->scalarNode('console_error')
->defaultValue(128);
->defaultValue(-64);
$listenerPriorities->scalarNode('console_terminate')
->defaultValue(-64);
Jean85 marked this conversation as resolved.
Show resolved Hide resolved
$listenerPriorities->scalarNode('worker_error')
->defaultValue(99);

Expand Down
25 changes: 0 additions & 25 deletions src/DependencyInjection/SentryExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\ErrorHandler\Error\FatalError;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
use Symfony\Component\HttpKernel\Event\ExceptionEvent;
use Symfony\Component\HttpKernel\KernelEvents;

/**
* This is the class that loads and manages your bundle configuration
Expand Down Expand Up @@ -157,11 +155,7 @@ private function configureErrorListener(ContainerBuilder $container, array $proc
{
if (! $processedConfiguration['register_error_listener']) {
$container->removeDefinition(ErrorListener::class);

return;
}

$this->tagExceptionListener($container);
}

private function configureMessengerListener(ContainerBuilder $container, array $processedConfiguration): void
Expand All @@ -175,25 +169,6 @@ private function configureMessengerListener(ContainerBuilder $container, array $
$container->getDefinition(MessengerListener::class)->setArgument(1, $processedConfiguration['capture_soft_fails']);
}

/**
* BC layer for Symfony < 4.3
*/
private function tagExceptionListener(ContainerBuilder $container): void
{
$listener = $container->getDefinition(ErrorListener::class);
$method = class_exists(ExceptionEvent::class) && method_exists(ExceptionEvent::class, 'getThrowable')
? 'onException'
: 'onKernelException';

$tagAttributes = [
'event' => KernelEvents::EXCEPTION,
'method' => $method,
'priority' => '%sentry.listener_priorities.request_error%',
];

$listener->addTag('kernel.event_listener', $tagAttributes);
}

private function configureMonologHandler(ContainerBuilder $container, array $monologConfiguration): void
{
$errorHandler = $monologConfiguration['error_handler'];
Expand Down