Skip to content

Commit f6d310d

Browse files
committed
Added default configuration
1 parent 833085c commit f6d310d

File tree

4 files changed

+76
-1
lines changed

4 files changed

+76
-1
lines changed

config/services.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,5 @@ services:
77
public: false
88
tags:
99
- { name: twig.runtime }
10+
11+
Oneup\ContaoSentryBundle\Integration\IgnorePreviousExceptionsIntegration: ~

config/skeleton.yaml

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
sentry:
2+
dsn: '%env(default::SENTRY_DSN)%'
3+
register_error_listener: false
4+
register_error_handler: false
5+
options:
6+
environment: "%env(default::SENTRY_ENV)%"
7+
before_send: Oneup\ContaoSentryBundle\Integration\IgnorePreviousExceptionsIntegration
8+
ignore_exceptions:
9+
- Contao\CoreBundle\Exception\AccessDeniedException
10+
- Contao\CoreBundle\Exception\AjaxRedirectResponseException
11+
- Contao\CoreBundle\Exception\InsufficientAuthenticationException
12+
- Contao\CoreBundle\Exception\InvalidRequestTokenException
13+
- Contao\CoreBundle\Exception\NoActivePageFoundException
14+
- Contao\CoreBundle\Exception\NoContentResponseException
15+
- Contao\CoreBundle\Exception\PageNotFoundException
16+
- Contao\CoreBundle\Exception\RedirectResponseException
17+
- Contao\CoreBundle\Exception\ResponseException
18+
- Contao\CoreBundle\Exception\ServiceUnavailableException
19+
- Contao\UnusedArgumentsException
20+
- Symfony\Component\Console\Exception\CommandNotFoundException
21+
- Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException
22+
- Symfony\Component\HttpKernel\Exception\NotFoundHttpException
23+
- Symfony\Component\HttpKernel\Exception\UnauthorizedHttpException
24+
- Symfony\Component\Security\Core\Exception\AccessDeniedException
25+
26+
monolog:
27+
handlers:
28+
sentry:
29+
type: sentry
30+
level: !php/const Monolog\Logger::ERROR
31+
hub_id: Sentry\State\HubInterface
32+
33+
services:
34+
Monolog\Processor\PsrLogMessageProcessor:
35+
tags: { name: monolog.processor, handler: sentry }

src/ContaoManager/Plugin.php

+8-1
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@
88
use Contao\ManagerPlugin\Bundle\BundlePluginInterface;
99
use Contao\ManagerPlugin\Bundle\Config\BundleConfig;
1010
use Contao\ManagerPlugin\Bundle\Parser\ParserInterface;
11+
use Contao\ManagerPlugin\Config\ConfigPluginInterface;
1112
use Oneup\ContaoSentryBundle\OneupContaoSentryBundle;
1213
use Sentry\SentryBundle\SentryBundle;
14+
use Symfony\Component\Config\Loader\LoaderInterface;
1315

14-
class Plugin implements BundlePluginInterface
16+
class Plugin implements BundlePluginInterface, ConfigPluginInterface
1517
{
1618
public function getBundles(ParserInterface $parser): array
1719
{
@@ -23,4 +25,9 @@ public function getBundles(ParserInterface $parser): array
2325
]),
2426
];
2527
}
28+
29+
public function registerContainerConfiguration(LoaderInterface $loader, array $managerConfig): void
30+
{
31+
$loader->load(__DIR__.'/../../config/skeleton.yaml');
32+
}
2633
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Oneup\ContaoSentryBundle\Integration;
6+
7+
use Sentry\Event;
8+
use Sentry\EventHint;
9+
use Sentry\SentrySdk;
10+
11+
class IgnorePreviousExceptionsIntegration
12+
{
13+
public function __invoke(Event $event, ?EventHint $hint): ?Event
14+
{
15+
if (!($exception = $hint?->exception) instanceof \Throwable) {
16+
return $event;
17+
}
18+
19+
$sentry = SentrySdk::getCurrentHub();
20+
21+
foreach ($sentry->getClient()?->getOptions()->getIgnoreExceptions() ?? [] as $class) {
22+
while ($exception && $exception = $exception->getPrevious()) {
23+
if (\is_a($exception, $class)) {
24+
return null;
25+
}
26+
}
27+
}
28+
29+
return $event;
30+
}
31+
}

0 commit comments

Comments
 (0)