Skip to content

Commit

Permalink
Added default configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
aschempp committed Apr 29, 2024
1 parent 833085c commit f5974c3
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 1 deletion.
2 changes: 2 additions & 0 deletions config/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ services:
public: false
tags:
- { name: twig.runtime }

Oneup\ContaoSentryBundle\Integration\IgnorePreviousExceptionsIntegration: ~
39 changes: 39 additions & 0 deletions config/skeleton.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
parameters:
'%env(SENTRY_DSN)%': ''
'%env(SENTRY_ENV)%': '%kernel.environment%'

sentry:
dsn: '%env(SENTRY_DSN)%'
register_error_listener: false
register_error_handler: false
options:
environment: "%env(SENTRY_ENV)%"
before_send: Oneup\ContaoSentryBundle\Integration\IgnorePreviousExceptionsIntegration
ignore_exceptions:
- Contao\CoreBundle\Exception\AccessDeniedException
- Contao\CoreBundle\Exception\AjaxRedirectResponseException
- Contao\CoreBundle\Exception\InsufficientAuthenticationException
- Contao\CoreBundle\Exception\InvalidRequestTokenException
- Contao\CoreBundle\Exception\NoActivePageFoundException
- Contao\CoreBundle\Exception\NoContentResponseException
- Contao\CoreBundle\Exception\PageNotFoundException
- Contao\CoreBundle\Exception\RedirectResponseException
- Contao\CoreBundle\Exception\ResponseException
- Contao\CoreBundle\Exception\ServiceUnavailableException
- Contao\UnusedArgumentsException
- Symfony\Component\Console\Exception\CommandNotFoundException
- Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException
- Symfony\Component\HttpKernel\Exception\NotFoundHttpException
- Symfony\Component\HttpKernel\Exception\UnauthorizedHttpException
- Symfony\Component\Security\Core\Exception\AccessDeniedException

monolog:
handlers:
sentry:
type: sentry
level: !php/const Monolog\Logger::ERROR
hub_id: Sentry\State\HubInterface

services:
Monolog\Processor\PsrLogMessageProcessor:
tags: { name: monolog.processor, handler: sentry }
9 changes: 8 additions & 1 deletion src/ContaoManager/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@
use Contao\ManagerPlugin\Bundle\BundlePluginInterface;
use Contao\ManagerPlugin\Bundle\Config\BundleConfig;
use Contao\ManagerPlugin\Bundle\Parser\ParserInterface;
use Contao\ManagerPlugin\Config\ConfigPluginInterface;
use Oneup\ContaoSentryBundle\OneupContaoSentryBundle;
use Sentry\SentryBundle\SentryBundle;
use Symfony\Component\Config\Loader\LoaderInterface;

class Plugin implements BundlePluginInterface
class Plugin implements BundlePluginInterface, ConfigPluginInterface
{
public function getBundles(ParserInterface $parser): array
{
Expand All @@ -23,4 +25,9 @@ public function getBundles(ParserInterface $parser): array
]),
];
}

public function registerContainerConfiguration(LoaderInterface $loader, array $managerConfig): void
{
$loader->load(__DIR__.'/../../config/skeleton.yaml');
}
}
31 changes: 31 additions & 0 deletions src/Integration/IgnorePreviousExceptionsIntegration.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

declare(strict_types=1);

namespace Oneup\ContaoSentryBundle\Integration;

use Sentry\Event;
use Sentry\EventHint;
use Sentry\SentrySdk;

class IgnorePreviousExceptionsIntegration
{
public function __invoke(Event $event, ?EventHint $hint): ?Event
{
if (!($exception = $hint?->exception) instanceof \Throwable) {
return $event;
}

$sentry = SentrySdk::getCurrentHub();

foreach ($sentry->getClient()?->getOptions()->getIgnoreExceptions() ?? [] as $class) {
while ($exception && $exception = $exception->getPrevious()) {
if (\is_a($exception, $class)) {
return null;
}
}
}

return $event;
}
}

0 comments on commit f5974c3

Please sign in to comment.