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

Exceptions in Consumers are not sent to Sentry #100

Open
VladyslavSikailo opened this issue Sep 8, 2022 · 0 comments
Open

Exceptions in Consumers are not sent to Sentry #100

VladyslavSikailo opened this issue Sep 8, 2022 · 0 comments
Labels
enhancement New feature or request

Comments

@VladyslavSikailo
Copy link

VladyslavSikailo commented Sep 8, 2022

Sentry module bug

In case exceptions are thrown from the Magento Consumer - they are not logged to Sentry.
It might be a big problem for projects that use Queues.

Bug: What is the current behavior?
Exceptions from Consumers just logged to log files, but not sent to Sentry.

Bug: What is the expected behavior?
Exceptions from Consumers should be sent to Sentry.

Bug: What is the proposed solution?

Why exceptions from Consumer are not sent so Sentry? Because Sentry initialization happens using around plugin for Application class - \JustBetter\Sentry\Plugin\GlobalExceptionCatcher::aroundLaunch, but this application class doesn't exist when the application is launched from the CLI.

So we need to initialize Sentry plugin also for the CLI. How to do it?

  • The first thing that I would recommend to do is to replace static method calling (like \Sentry\captureException) in \JustBetter\Sentry\Model\SentryLog::send. As they are static - it's impossible to create a Magento Plugin for those methods calling. Static methods should be replaced by the wrapper, for example by this - \JustBetter\Sentry\Model\SentryInteraction. So let's assume we call \JustBetter\Sentry\Model\SentryInteraction::captureException and \JustBetter\Sentry\Model\SentryInteraction::captureMessage instead of \Sentry\captureException and \Sentry\captureMessage.
  • When SentryInteraction::captureException or SentryInteraction::captureMessage is called - we need to check is Sentry is initialized. Just introduce $isInitialized variable, that will be set to true when SentryInteraction::initialize is called.
  • In case Sentry is not initialized - just initialize it in the same way as it's done in src/justbetter/magento2-sentry/Plugin/GlobalExceptionCatcher.php:75
  • then get rid of initialization in the \JustBetter\Sentry\Plugin\GlobalExceptionCatcher::aroundLaunch, so this method will become more transparent and clean.

Note: Maybe we don't need to have all exceptions from CLI logged to Sentry. But we 100% need to have all exceptions from Magento Consumer to be logged.

What is the version of Magento and of Sentry extension you are using? Always use the latest version of the extension one before opening a bug issue.

  • Magento 2.4.4
  • justbetter/magento2-sentry:3.2.0
@indykoning indykoning added the enhancement New feature or request label Mar 27, 2024
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

No branches or pull requests

2 participants