diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 2c01285c..da675be7 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -86,7 +86,7 @@ parameters: path: src/DependencyInjection/SentryExtension.php - - message: "#^Cannot access offset 'before_send_logs' on mixed\\.$#" + message: "#^Cannot access offset 'before_send_log' on mixed\\.$#" count: 1 path: src/DependencyInjection/SentryExtension.php diff --git a/src/DependencyInjection/Configuration.php b/src/DependencyInjection/Configuration.php index f2618281..7a3c9a39 100644 --- a/src/DependencyInjection/Configuration.php +++ b/src/DependencyInjection/Configuration.php @@ -113,7 +113,7 @@ public function getConfigTreeBuilder(): TreeBuilder ->scalarNode('before_send_transaction')->end() ->scalarNode('before_send_check_in')->end() ->scalarNode('before_send_metrics')->end() - ->scalarNode('before_send_logs')->end() + ->scalarNode('before_send_log')->end() ->variableNode('trace_propagation_targets')->end() ->arrayNode('tags') ->useAttributeAsKey('name') diff --git a/src/DependencyInjection/SentryExtension.php b/src/DependencyInjection/SentryExtension.php index 55a268cc..a127069b 100644 --- a/src/DependencyInjection/SentryExtension.php +++ b/src/DependencyInjection/SentryExtension.php @@ -124,8 +124,8 @@ private function registerConfiguration(ContainerBuilder $container, array $confi $options['before_send_metrics'] = new Reference($options['before_send_metrics']); } - if (isset($options['before_send_logs'])) { - $options['before_send_logs'] = new Reference($options['before_send_logs']); + if (isset($options['before_send_log'])) { + $options['before_send_log'] = new Reference($options['before_send_log']); } if (isset($options['before_breadcrumb'])) { diff --git a/src/Resources/config/schema/sentry-1.0.xsd b/src/Resources/config/schema/sentry-1.0.xsd index 0bd49d7a..d8c81294 100644 --- a/src/Resources/config/schema/sentry-1.0.xsd +++ b/src/Resources/config/schema/sentry-1.0.xsd @@ -55,7 +55,7 @@ - + diff --git a/tests/DependencyInjection/Fixtures/php/full.php b/tests/DependencyInjection/Fixtures/php/full.php index 89862bb9..973b125c 100644 --- a/tests/DependencyInjection/Fixtures/php/full.php +++ b/tests/DependencyInjection/Fixtures/php/full.php @@ -33,7 +33,7 @@ 'before_send_transaction' => 'App\\Sentry\\BeforeSendTransactionCallback', 'before_send_check_in' => 'App\\Sentry\\BeforeSendCheckInCallback', 'before_send_metrics' => 'App\\Sentry\\BeforeSendMetricsCallback', - 'before_send_logs' => 'App\\Sentry\\BeforeSendLogsCallback', + 'before_send_log' => 'App\\Sentry\\BeforeSendLogsCallback', 'trace_propagation_targets' => ['website.invalid'], 'tags' => [ 'context' => 'development', diff --git a/tests/DependencyInjection/Fixtures/xml/full.xml b/tests/DependencyInjection/Fixtures/xml/full.xml index ba325880..ddf466a2 100644 --- a/tests/DependencyInjection/Fixtures/xml/full.xml +++ b/tests/DependencyInjection/Fixtures/xml/full.xml @@ -30,7 +30,7 @@ before-send-transaction="App\Sentry\BeforeSendTransactionCallback" before-send-check-in="App\Sentry\BeforeSendCheckInCallback" before-send-metrics="App\Sentry\BeforeSendMetricsCallback" - before-send-logs="App\Sentry\BeforeSendLogsCallback" + before-send-log="App\Sentry\BeforeSendLogsCallback" error-types="E_ALL" max-breadcrumbs="1" before-breadcrumb="App\Sentry\BeforeBreadcrumbCallback" diff --git a/tests/DependencyInjection/Fixtures/yml/full.yml b/tests/DependencyInjection/Fixtures/yml/full.yml index 6537f4d7..e9097964 100644 --- a/tests/DependencyInjection/Fixtures/yml/full.yml +++ b/tests/DependencyInjection/Fixtures/yml/full.yml @@ -30,7 +30,7 @@ sentry: before_send_transaction: App\Sentry\BeforeSendTransactionCallback before_send_check_in: App\Sentry\BeforeSendCheckInCallback before_send_metrics: App\Sentry\BeforeSendMetricsCallback - before_send_logs: App\Sentry\BeforeSendLogsCallback + before_send_log: App\Sentry\BeforeSendLogsCallback trace_propagation_targets: - 'website.invalid' tags: diff --git a/tests/DependencyInjection/SentryExtensionTest.php b/tests/DependencyInjection/SentryExtensionTest.php index 9717df22..ce7e4234 100644 --- a/tests/DependencyInjection/SentryExtensionTest.php +++ b/tests/DependencyInjection/SentryExtensionTest.php @@ -229,7 +229,7 @@ public function testClientIsCreatedFromOptions(): void 'before_send_transaction' => new Reference('App\\Sentry\\BeforeSendTransactionCallback'), 'before_send_check_in' => new Reference('App\\Sentry\\BeforeSendCheckInCallback'), 'before_send_metrics' => new Reference('App\\Sentry\\BeforeSendMetricsCallback'), - 'before_send_logs' => new Reference('App\\Sentry\\BeforeSendLogsCallback'), + 'before_send_log' => new Reference('App\\Sentry\\BeforeSendLogsCallback'), 'trace_propagation_targets' => ['website.invalid'], 'tags' => [ 'context' => 'development', diff --git a/tests/End2End/App/Callback/BeforeSendLogCallback.php b/tests/End2End/App/Callback/BeforeSendLogCallback.php new file mode 100644 index 00000000..e3fadc91 --- /dev/null +++ b/tests/End2End/App/Callback/BeforeSendLogCallback.php @@ -0,0 +1,21 @@ +getBody()) { + return null; + } + + return $log; + }; + } +} diff --git a/tests/End2End/App/Controller/LoggingController.php b/tests/End2End/App/Controller/LoggingController.php index 13580b2c..c62fae6e 100644 --- a/tests/End2End/App/Controller/LoggingController.php +++ b/tests/End2End/App/Controller/LoggingController.php @@ -43,4 +43,13 @@ public function loggingWithError() $this->logger->error('About to crash'); throw new \RuntimeException('Crash'); } + + public function beforeSendLog() + { + $this->logger->warning('warn 1'); + $this->logger->error('before_send_log'); + $this->logger->warning('warn 2'); + + return new Response(); + } } diff --git a/tests/End2End/App/logging.yml b/tests/End2End/App/logging.yml index 0e4d49b5..bbd0f68c 100644 --- a/tests/End2End/App/logging.yml +++ b/tests/End2End/App/logging.yml @@ -1,6 +1,7 @@ sentry: options: enable_logs: true + before_send_log: "sentry.callback.before_send_log" monolog: handlers: @@ -13,6 +14,13 @@ services: arguments: - !php/const Monolog\Logger::WARNING + Sentry\SentryBundle\Tests\End2End\App\Callback\BeforeSendLogCallback: + autowire: true + + sentry.callback.before_send_log: + class: 'Sentry\SentryBundle\Tests\End2End\App\Callback\BeforeSendLogCallback' + factory: ['@Sentry\SentryBundle\Tests\End2End\App\Callback\BeforeSendLogCallback', 'getCallback'] + Sentry\SentryBundle\Tests\End2End\App\Controller\LoggingController: autowire: true tags: diff --git a/tests/End2End/App/routing.yml b/tests/End2End/App/routing.yml index 2ad7b834..e4494d1e 100644 --- a/tests/End2End/App/routing.yml +++ b/tests/End2End/App/routing.yml @@ -50,6 +50,10 @@ logging_With_Error: path: /logging-with-error defaults: { _controller: 'Sentry\SentryBundle\Tests\End2End\App\Controller\LoggingController::loggingWithError' } +logging_before_send_logs: + path: /before-send-log + defaults: { _controller: 'Sentry\SentryBundle\Tests\End2End\App\Controller\LoggingController::beforeSendLog' } + buffer_flush: path: /buffer-flush defaults: { _controller: 'Sentry\SentryBundle\Tests\End2End\App\Controller\BufferFlushController::testBufferFlush' } diff --git a/tests/End2End/LoggingEnd2EndTest.php b/tests/End2End/LoggingEnd2EndTest.php index 4633b0bb..314eb817 100644 --- a/tests/End2End/LoggingEnd2EndTest.php +++ b/tests/End2End/LoggingEnd2EndTest.php @@ -57,6 +57,23 @@ public function testExceptionWithLogs(): void $this->assertCount(2, $logsEvent->getLogs()); } + public function testBeforeSendLogCallback(): void + { + $client = static::createClient(['debug' => false]); + + $client->request('GET', '/before-send-log'); + $this->assertSame(200, $client->getResponse()->getStatusCode()); + + $this->assertCount(1, StubTransport::$events); + $event = StubTransport::$events[0]; + $logs = $this->filterFrameworkLogs($event->getLogs()); + + // Make sure we just have two warn logs and no error log (since it's filtered by the callback) + $this->assertCount(2, $logs); + $this->assertEquals('warn 1', $logs[0]->getBody()); + $this->assertEquals('warn 2', $logs[1]->getBody()); + } + /** * Removes framework logs so that the tests can focus on our expected logs. *