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
16 changes: 9 additions & 7 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -331,13 +331,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 @@ -22,6 +22,7 @@
use Sentry\Severity;
use Sentry\Stacktrace;
use Sentry\State\Scope;
use Sentry\Tests\Fixtures\code\CustomException;
use Sentry\Transport\Result;
use Sentry\Transport\ResultStatus;
use Sentry\Transport\TransportInterface;
Expand Down Expand Up @@ -594,6 +595,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
{
}