Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
4 changes: 2 additions & 2 deletions src/DependencyInjection/SentryExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'])) {
Expand Down
2 changes: 1 addition & 1 deletion src/Resources/config/schema/sentry-1.0.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
<xsd:attribute name="before-send-transaction" type="xsd:string" />
<xsd:attribute name="before-send-check-in" type="xsd:string" />
<xsd:attribute name="before-send-metrics" type="xsd:string" />
<xsd:attribute name="before-send-logs" type="xsd:string" />
<xsd:attribute name="before-send-log" type="xsd:string" />
<xsd:attribute name="error-types" type="xsd:string" />
<xsd:attribute name="max-breadcrumbs" type="xsd:integer" />
<xsd:attribute name="before-breadcrumb" type="xsd:string" />
Expand Down
2 changes: 1 addition & 1 deletion tests/DependencyInjection/Fixtures/php/full.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
2 changes: 1 addition & 1 deletion tests/DependencyInjection/Fixtures/xml/full.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion tests/DependencyInjection/Fixtures/yml/full.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion tests/DependencyInjection/SentryExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
21 changes: 21 additions & 0 deletions tests/End2End/App/Callback/BeforeSendLogCallback.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

declare(strict_types=1);

namespace Sentry\SentryBundle\Tests\End2End\App\Callback;

use Sentry\Logs\Log;

class BeforeSendLogCallback
{
public function getCallback(): callable
{
return function (Log $log): ?Log {
if ('before_send_log' === $log->getBody()) {
return null;
}

return $log;
};
}
}
9 changes: 9 additions & 0 deletions tests/End2End/App/Controller/LoggingController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
8 changes: 8 additions & 0 deletions tests/End2End/App/logging.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
sentry:
options:
enable_logs: true
before_send_log: "sentry.callback.before_send_log"

monolog:
handlers:
Expand All @@ -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:
Expand Down
4 changes: 4 additions & 0 deletions tests/End2End/App/routing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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' }
17 changes: 17 additions & 0 deletions tests/End2End/LoggingEnd2EndTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
Loading