symfony / recipes-contrib

Symfony Contrib Recipes Repositories

Home Page:https://github.com/symfony/recipes-contrib/blob/flex/main/RECIPES.md

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Sentry Bundle] Clarify config when using monolog

syther101 opened this issue · comments

commented

After recently upgrading an old Symfony 3 install to the latest 4.0 version, we ended up spending several days trying to debug why no PHP errors were being sent to our log files or the Sentry application monitoring service.

As it turns out, I had incorrectly assumed that the default flex recipe provided would setup Sentry correctly.

With all our logs being blank, it was impossible to tell where the issue was. Further confused by the fact that some console errors were making their way through.

As per the Sentry docs and this PR, there are actually some extra steps to get Sentry to work correctly with Monolog:
https://docs.sentry.io/platforms/php/guides/symfony/#monolog-integration

getsentry/sentry-symfony#444

If I was to take a guess, I'd imagine most Symfony installs will rely on Monolog at some point in their lifetime. Similar to how other bundles do, would it perhaps make sense to have this commented out in the flex recipe like so:

sentry:
    dsn: '%env(SENTRY_DSN)%'   

# If you are using Monolog, you also need these additional configuration and services to log the errors correctly:
# https://docs.sentry.io/platforms/php/guides/symfony/#monolog-integration
    # register_error_listener: false

# monolog:
#    handlers:
#        sentry:
#            type: service
#            id: Sentry\Monolog\Handler

# services:
#    Sentry\Monolog\Handler:
#        arguments:
#           $hub: '@Sentry\State\HubInterface'
#            $level: !php/const Monolog\Logger::ERROR

Without this config step, all logs were getting consumed by Sentry and the environment became very hard to debug.

Hopefully this request is correct and please do shout if it needs any further clarification :)

commented

Further to this. I actually had an issue where after deploying our application to the staging server, we had an influx of events getting sent to Sentry due to bots that crawl our site. Multiple 404 and 400 errors. Due to the new configuration you now need to exclude these. I'd also be interested in how people feel about this being included via the default flex config also?

It looks like these were previously included:
https://github.com/symfony/recipes-contrib/blob/master/sentry/sentry-symfony/1.0/config/packages/sentry.yaml

and some discussions can be found here:
getsentry/sentry-symfony#216

getsentry/sentry-symfony#273

sentry:
    # ...
    options:
        # ...
        excluded_exceptions:
            - Symfony\Component\HttpKernel\Exception\NotFoundHttpException
            - Symfony\Component\Security\Core\Exception\AccessDeniedException

Please send a PR @syther101, we'd be happy to improve the default Sentry config.