Skip to content

Commit 2ebfbee

Browse files
committed
feature #537 Deprecate sentry and raven handler types (GromNaN)
This PR was squashed before being merged into the 3.x branch. Discussion ---------- Deprecate `sentry` and `raven` handler types | Q | A | ------------- | --- | Branch? | 3.x | Bug fix? | no | New feature? | no | Deprecations? | yes | Issues | Fix #489 (comment) | License | MIT The upgrade path is to use a "service" handler with `sentry/sentry-symfony` as documented: https://docs.sentry.io/platforms/php/guides/symfony/logs/ Commits ------- 1902f5e Deprecate `sentry` and `raven` handler types
2 parents fed9906 + 1902f5e commit 2ebfbee

File tree

5 files changed

+33
-5
lines changed

5 files changed

+33
-5
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
* Drop support for PHP < 8.1
1212
* Drop support for Symfony < 6.4
1313
* Add TelegramBotHandler `topic` support
14+
* Deprecate `sentry` and `raven` handler, use a `service` handler with [`sentry/sentry-symfony`](https://docs.sentry.io/platforms/php/guides/symfony/logs/) instead
1415

1516
## 3.10.0 (2023-11-06)
1617

@@ -78,7 +79,7 @@
7879

7980
## 3.3.1 (2018-11-04)
8081

81-
* Fixed compatiblity with Symfony 4.2
82+
* Fixed compatibility with Symfony 4.2
8283

8384
## 3.3.0 (2018-06-04)
8485

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,14 @@
2121
"monolog/monolog": "^1.25.1 || ^2.0 || ^3.0",
2222
"symfony/config": "^6.4 || ^7.0",
2323
"symfony/dependency-injection": "^6.4 || ^7.0",
24+
"symfony/deprecation-contracts": "^2.5 || ^3.0",
2425
"symfony/http-kernel": "^6.4 || ^7.0",
2526
"symfony/monolog-bridge": "^6.4 || ^7.0",
2627
"symfony/polyfill-php84": "^1.30"
2728
},
2829
"require-dev": {
2930
"symfony/console": "^6.4 || ^7.0",
30-
"symfony/phpunit-bridge": "^7.1",
31+
"symfony/phpunit-bridge": "^7.3.3",
3132
"symfony/yaml": "^6.4 || ^7.0"
3233
},
3334
"autoload": {

src/DependencyInjection/Compiler/DebugHandlerPass.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class DebugHandlerPass implements CompilerPassInterface
3131

3232
public function __construct(LoggerChannelPass $channelPass)
3333
{
34-
@trigger_error('The '.__CLASS__.' class is deprecated since version 2.12 and will be removed in 4.0. Use AddDebugLogProcessorPass in FrameworkBundle instead.', \E_USER_DEPRECATED);
34+
trigger_deprecation('symfony/monolog-bundle', '2.12', 'The %s class is deprecated and will be removed in 4.0. Use AddDebugLogProcessorPass in FrameworkBundle instead.', __CLASS__);
3535

3636
$this->channelPass = $channelPass;
3737
}

src/DependencyInjection/MonologExtension.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ private function buildHandler(ContainerBuilder $container, $name, array $handler
272272
break;
273273

274274
case 'elasticsearch':
275-
@trigger_error('The "elasticsearch" handler type is deprecated in MonologBundle since version 3.8.0, use the "elastica" type instead, or switch to the official Elastic client using the "elastic_search" type.', \E_USER_DEPRECATED);
275+
trigger_deprecation('symfony/monolog-bundle', '3.8', 'The "elasticsearch" handler type is deprecated in MonologBundle since version 3.8.0, use the "elastica" type instead, or switch to the official Elastic client using the "elastic_search" type.');
276276
// no break
277277

278278
case 'elastica':
@@ -413,7 +413,7 @@ private function buildHandler(ContainerBuilder $container, $name, array $handler
413413
$activation = new Reference($handler['activation_strategy']);
414414
} elseif (!empty($handler['excluded_404s'])) {
415415
if (class_exists(HttpCodeActivationStrategy::class)) {
416-
@trigger_error('The "excluded_404s" option is deprecated in MonologBundle since version 3.4.0, you should rely on the "excluded_http_codes" option instead.', \E_USER_DEPRECATED);
416+
trigger_deprecation('symfony/monolog-bundle', '3.4', 'The "excluded_404s" option is deprecated, you should rely on the "excluded_http_codes" option instead.');
417417
}
418418
$activationDef = new Definition('Symfony\Bridge\Monolog\Handler\FingersCrossed\NotFoundActivationStrategy', [
419419
new Reference('request_stack'),
@@ -720,6 +720,7 @@ private function buildHandler(ContainerBuilder $container, $name, array $handler
720720
break;
721721

722722
case 'sentry':
723+
trigger_deprecation('symfony/monolog-bundle', '3.11', 'The "sentry" handler type is deprecated, use the "sentry/sentry-symfony" and a "service" handler instead.');
723724
if (null !== $handler['hub_id']) {
724725
$hubId = $handler['hub_id'];
725726
} else {
@@ -771,6 +772,7 @@ private function buildHandler(ContainerBuilder $container, $name, array $handler
771772
break;
772773

773774
case 'raven':
775+
trigger_deprecation('symfony/monolog-bundle', '3.11', 'The "raven" handler type is deprecated, use the "sentry/sentry-symfony" and a "service" handler instead.');
774776
if (null !== $handler['client_id']) {
775777
$clientId = $handler['client_id'];
776778
} else {

tests/DependencyInjection/MonologExtensionTest.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use Monolog\Handler\RollbarHandler;
1818
use Monolog\Logger;
1919
use Monolog\Processor\UidProcessor;
20+
use Symfony\Bridge\PhpUnit\ExpectUserDeprecationMessageTrait;
2021
use Symfony\Bundle\MonologBundle\DependencyInjection\Compiler\LoggerChannelPass;
2122
use Symfony\Bundle\MonologBundle\DependencyInjection\MonologExtension;
2223
use Symfony\Bundle\MonologBundle\Tests\DependencyInjection\Fixtures\AsMonologProcessor\FooProcessor;
@@ -32,6 +33,8 @@
3233

3334
class MonologExtensionTest extends DependencyInjectionTestCase
3435
{
36+
use ExpectUserDeprecationMessageTrait;
37+
3538
public function testLoadWithDefault()
3639
{
3740
$container = $this->getContainer([['handlers' => ['main' => ['type' => 'stream']]]]);
@@ -303,6 +306,7 @@ public function testRavenHandlerWhenConfigurationIsWrong()
303306
}
304307
}
305308

309+
/** @group legacy */
306310
public function testRavenHandlerWhenADSNIsSpecified()
307311
{
308312
if (Logger::API !== 1) {
@@ -311,6 +315,8 @@ public function testRavenHandlerWhenADSNIsSpecified()
311315
return;
312316
}
313317

318+
$this->expectDeprecation('Since symfony/monolog-bundle 3.11: The "raven" handler type is deprecated, use the "sentry/sentry-symfony" and a "service" handler instead.');
319+
314320
$dsn = 'http://43f6017361224d098402974103bfc53d:[email protected]:9000/1';
315321

316322
$container = $this->getContainer([['handlers' => ['raven' => [
@@ -329,6 +335,7 @@ public function testRavenHandlerWhenADSNIsSpecified()
329335
$this->assertDICDefinitionClass($handler, 'Monolog\Handler\RavenHandler');
330336
}
331337

338+
/** @group legacy */
332339
public function testRavenHandlerWhenADSNAndAClientAreSpecified()
333340
{
334341
if (Logger::API !== 1) {
@@ -337,6 +344,8 @@ public function testRavenHandlerWhenADSNAndAClientAreSpecified()
337344
return;
338345
}
339346

347+
$this->expectDeprecation('Since symfony/monolog-bundle 3.11: The "raven" handler type is deprecated, use the "sentry/sentry-symfony" and a "service" handler instead.');
348+
340349
$container = $this->getContainer([['handlers' => ['raven' => [
341350
'type' => 'raven', 'dsn' => 'foobar', 'client_id' => 'raven.client',
342351
]]]], ['raven.client' => new Definition('Raven_Client')]);
@@ -349,6 +358,7 @@ public function testRavenHandlerWhenADSNAndAClientAreSpecified()
349358
$this->assertDICConstructorArguments($handler, [new Reference('raven.client'), 'DEBUG', true]);
350359
}
351360

361+
/** @group legacy */
352362
public function testRavenHandlerWhenAClientIsSpecified()
353363
{
354364
if (Logger::API !== 1) {
@@ -357,6 +367,8 @@ public function testRavenHandlerWhenAClientIsSpecified()
357367
return;
358368
}
359369

370+
$this->expectDeprecation('Since symfony/monolog-bundle 3.11: The "raven" handler type is deprecated, use the "sentry/sentry-symfony" and a "service" handler instead.');
371+
360372
$container = $this->getContainer([['handlers' => ['raven' => [
361373
'type' => 'raven', 'client_id' => 'raven.client',
362374
]]]], ['raven.client' => new Definition('Raven_Client')]);
@@ -377,8 +389,11 @@ public function testSentryHandlerWhenConfigurationIsWrong()
377389
$this->getContainer([['handlers' => ['sentry' => ['type' => 'sentry']]]]);
378390
}
379391

392+
/** @group legacy */
380393
public function testSentryHandlerWhenADSNIsSpecified()
381394
{
395+
$this->expectDeprecation('Since symfony/monolog-bundle 3.11: The "sentry" handler type is deprecated, use the "sentry/sentry-symfony" and a "service" handler instead.');
396+
382397
$dsn = 'http://43f6017361224d098402974103bfc53d:[email protected]:9000/1';
383398

384399
$container = $this->getContainer([['handlers' => ['sentry' => [
@@ -401,8 +416,11 @@ public function testSentryHandlerWhenADSNIsSpecified()
401416
$this->assertDICConstructorArguments($hub, [new Reference('monolog.sentry.client.'.sha1($dsn))]);
402417
}
403418

419+
/** @group legacy */
404420
public function testSentryHandlerWhenADSNAndAClientAreSpecified()
405421
{
422+
$this->expectDeprecation('Since symfony/monolog-bundle 3.11: The "sentry" handler type is deprecated, use the "sentry/sentry-symfony" and a "service" handler instead.');
423+
406424
$container = $this->getContainer(
407425
[
408426
[
@@ -433,8 +451,11 @@ public function testSentryHandlerWhenADSNAndAClientAreSpecified()
433451
$this->assertDICConstructorArguments($hub, [new Reference('sentry.client')]);
434452
}
435453

454+
/** @group legacy */
436455
public function testSentryHandlerWhenAClientIsSpecified()
437456
{
457+
$this->expectDeprecation('Since symfony/monolog-bundle 3.11: The "sentry" handler type is deprecated, use the "sentry/sentry-symfony" and a "service" handler instead.');
458+
438459
$container = $this->getContainer(
439460
[
440461
[
@@ -464,8 +485,11 @@ public function testSentryHandlerWhenAClientIsSpecified()
464485
$this->assertDICConstructorArguments($hub, [new Reference('sentry.client')]);
465486
}
466487

488+
/** @group legacy */
467489
public function testSentryHandlerWhenAHubIsSpecified()
468490
{
491+
$this->expectDeprecation('Since symfony/monolog-bundle 3.11: The "sentry" handler type is deprecated, use the "sentry/sentry-symfony" and a "service" handler instead.');
492+
469493
$container = $this->getContainer(
470494
[
471495
[

0 commit comments

Comments
 (0)