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

Include default configuration for Contao managed edition #12

Merged
merged 5 commits into from
May 23, 2024

Conversation

aschempp
Copy link
Contributor

@aschempp aschempp commented Apr 29, 2024

This PR adds some default configurations if the bundle is included in a Contao Managed Edition. Because most times, the configuration will be identical and repetitive.

I also added an event listener to filter previous exceptions. In my case, I had Twig components throwing an AccessDeniedException (which correctly triggers the firewall), which are logged as RuntimeError even though the previous exception was one to be filtered.

The namespace also changed from Oneup\Contao\SentryBundle to Oneup\ContaoSentryBundle which I think would be more correct in terms of Composer packages.

@fritzmg @richardhj any opinions on this?

TODO:

  • Update README

@bytehead bytehead added the enhancement New feature or request label Apr 29, 2024
@bytehead bytehead added this to the 4.x milestone Apr 29, 2024
@bytehead
Copy link
Member

/cc @Shadow-Devil

config/skeleton.yaml Outdated Show resolved Hide resolved
@fritzmg
Copy link
Contributor

fritzmg commented Apr 29, 2024

I also have

Symfony\Component\Security\Core\Exception\AuthenticationException

in my ignore_exceptions list.

Copy link
Contributor

@fritzmg fritzmg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I usually only set sentry.dsn and sentry.options.ignore_exceptions in my projects. Why do you also set sentry.register_error_listener, sentry.register_error_handler and monolog.handlers.sentry? i.e. what's the purpose/advantage.

@Shadow-Devil
Copy link
Contributor

Would this be a major version release since all PHP, Contao and Sentry minimum versions were increased?

@bytehead
Copy link
Member

Would this be a major version release since all PHP, Contao and Sentry minimum versions were increased?

Yes.

Co-authored-by: Fritz Michael Gschwantner <[email protected]>
@aschempp
Copy link
Contributor Author

I usually only set sentry.dsn and sentry.options.ignore_exceptions in my projects. Why do you also set sentry.register_error_listener, sentry.register_error_handler and monolog.handlers.sentry? i.e. what's the purpose/advantage.

I was wondering that as well, but that's what the official docs say: https://docs.sentry.io/platforms/php/guides/symfony/#monolog-integration

If you have monolog …

I know that we do often get error messages twice in our projects (with the same setup you have). I can only assume that's because Monolog integration is logged to sentry as well as the error handler 🤔

@fritzmg
Copy link
Contributor

fritzmg commented Apr 29, 2024

Hm, I never get error messages twice - I only get multiple sentry entries when there are previous exceptions, which your PR fixes. imho the default config without configuring monolog is enough.

@aschempp
Copy link
Contributor Author

aschempp commented Apr 30, 2024

🤔 symfony/symfony#36472 (comment)

I think the reason is that you can only have one error handler in PHP, and if you already have Symfony/Monolog handling the errors, you don't want Sentry to override or interefer with that.

symfony/symfony#36472 (comment)

Found in getsentry/sentry-symfony#337

@fritzmg
Copy link
Contributor

fritzmg commented Apr 30, 2024

Ah, I see 👍

@aschempp
Copy link
Contributor Author

Another big advantage I just noticed: this now also logs all other monolog errors to Sentry! In my case the CSP violation logged by Contao was added to Sentry 😎

@fritzmg
Copy link
Contributor

fritzmg commented Apr 30, 2024

Which is something that should be ignored though imho 😁 CSP reports can be quite spammy (as anyone can send anything to the controller).

@aschempp
Copy link
Contributor Author

aschempp commented May 3, 2024

Which is something that should be ignored though imho 😁 CSP reports can be quite spammy (as anyone can send anything to the controller).

well yeah… but Sentry also has specific CSP monitoring, which would make more sense than this. But not really related to this PR 😆

@aschempp
Copy link
Contributor Author

aschempp commented May 3, 2024

@bytehead are you ok with the namespace change or was that "group" intentional? In our bundle, we would actually use Oneup\SentryBundle because the contao part is fictional to me, to show the package is built for Contao. But there's never gonna be a Terminal42\DcawizardBundle that is not for Contao, so no point in adding Contao to the namespace.

@fritzmg
Copy link
Contributor

fritzmg commented May 3, 2024

Personally I would definitely call it Oneup\ContaoSentryBundle as there already exists a Sentry\SentryBundle - which the Oneup\ContaoSentryBundle loads for the Contao Managed Edition. Calling it Oneup\SentryBundle would make it look like a fork of Sentry\SentryBundle imho - which it is not.

@bytehead
Copy link
Member

bytehead commented May 3, 2024

I would optin for Oneup\ContaoSentryBundle 👍

@aschempp aschempp marked this pull request as ready for review May 15, 2024 08:43
@aschempp
Copy link
Contributor Author

I have now used this on several systems in production, and it seems to work fine 🙃

@bytehead
Copy link
Member

Back from holidays, I'll have a look this week!

Copy link
Member

@bytehead bytehead left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me apart from the service naming (best practices).

config/services.yaml Outdated Show resolved Hide resolved
config/services.yaml Outdated Show resolved Hide resolved
config/services.yaml Outdated Show resolved Hide resolved
config/skeleton.yaml Outdated Show resolved Hide resolved
Copy link
Member

@bytehead bytehead left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❤️

@bytehead bytehead merged commit 63cc7af into 1up-lab:main May 23, 2024
@bytehead
Copy link
Member

Thank you @aschempp & @fritzmg!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants