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.
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?
\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
.SentryInteraction::captureException
orSentryInteraction::captureMessage
is called - we need to check is Sentry is initialized. Just introduce$isInitialized
variable, that will be set totrue
whenSentryInteraction::initialize
is called.src/justbetter/magento2-sentry/Plugin/GlobalExceptionCatcher.php:75
\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.
justbetter/magento2-sentry:3.2.0