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

[4.x] Rollback to is_a() to ignore exceptions instead of in_array() #1587

Merged
merged 3 commits into from
Oct 18, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
16 changes: 9 additions & 7 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -327,13 +327,15 @@ private function applyIgnoreOptions(Event $event): ?Event
}

foreach ($exceptions as $exception) {
if (\in_array($exception->getType(), $this->options->getIgnoreExceptions(), true)) {
$this->logger->info(
'The event will be discarded because it matches an entry in "ignore_exceptions".',
['event' => $event]
);

return null;
foreach ($this->options->getIgnoreExceptions() as $ignoredException) {
if (is_a($exception->getType(), $ignoredException, true)) {
$this->logger->info(
'The event will be discarded because it matches an entry in "ignore_exceptions".',
['event' => $event]
);

return null;
}
}
}
}
Expand Down
24 changes: 24 additions & 0 deletions tests/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
use Sentry\Severity;
use Sentry\Stacktrace;
use Sentry\State\Scope;
use Sentry\Tests\Fixtures\code\CustomException;
use Sentry\Transport\TransportFactoryInterface;
use Sentry\Transport\TransportInterface;
use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait;
Expand Down Expand Up @@ -597,6 +598,29 @@ public function testProcessEventDiscardsEventWhenIgnoreExceptionsMatches(): void
$client->captureException($exception);
}

public function testProcessEventDiscardsEventWhenParentHierarchyOfIgnoreExceptionsMatches(): void
{
$exception = new CustomException('Some foo error');

/** @var LoggerInterface&MockObject $logger */
$logger = $this->createMock(LoggerInterface::class);
$logger->expects($this->once())
->method('info')
->with('The event will be discarded because it matches an entry in "ignore_exceptions".', $this->callback(static function (array $context): bool {
return isset($context['event']) && $context['event'] instanceof Event;
}));

$options = [
'ignore_exceptions' => [\RuntimeException::class],
];

$client = ClientBuilder::create($options)
->setLogger($logger)
->getClient();

$client->captureException($exception);
}

public function testProcessEventDiscardsEventWhenIgnoreTransactionsMatches(): void
{
$event = Event::createTransaction();
Expand Down
9 changes: 9 additions & 0 deletions tests/Fixtures/code/CustomException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

declare(strict_types=1);

namespace Sentry\Tests\Fixtures\code;

class CustomException extends \RuntimeException
{
}
Loading