justbetter / magento2-sentry

Magento 2 module to log to Sentry
MIT License
160 stars 70 forks source link
magento2 magento2-extension php sentry

Magento 2 Sentry Logger

This Magento 2 module integrates the Sentry sdk into magento 2. Depending on the log level configured in the backend of magento 2, notifications and errors can be send to sentry.

Installation

Configuration

For configuration with Adobe Cloud, check below.

This module uses the Magento Deployment Configuration for most it's configuration. This means that you need to add this array to your app/etc/env.php:

'sentry' => [
    'dsn' => 'example.com',
    'logrocket_key' => 'example/example',
    'environment' => null,
    'log_level' => \Monolog\Logger::WARNING,
    'errorexception_reporting' => E_ALL,
    'ignore_exceptions' => [],
    'mage_mode_development' => false,
    'js_sdk_version' => \JustBetter\Sentry\Block\SentryScript::CURRENT_VERSION,
    'tracing_enabled' => true,
    'tracing_sample_rate' => 0.5,
    'ignore_js_errors' => [],
    'disable_default_integrations' => [
        \Sentry\Integration\ModulesIntegration::class,
    ]
]

Next to that there are some configuration options under Stores > Configuration > JustBetter > Sentry.

Configuration values

Configuration for Adobe Cloud

Since Adobe Cloud doesn't allow you to add manually add content to the env.php file, the configuration can be done using the "Variables" in Adobe Commerce using the following variables:

The following configuration settings can be overridden in the Magento admin. This is limited to ensure that changes to particular config settings can only be done on server level and can't be broken by changes in the admin.

Optional error page configuration

Sending additional data to Sentry when logging errors

Change / Filter events

This module has an event called sentry_before_send that is dispatched before setting the config before_send. This provides the means to edit / filter events. You could for example add extra criteria to determine if the exception should be captured to Sentry. To prevent the Exception from being captured you can set the event to null or unset it completly.

public function execute(\Magento\Framework\Event\Observer $observer)
{
    $observer->getEvent()->getSentryEvent()->unsEvent();
}

Example: https://github.com/justbetter/magento2-sentry-filter-events

Compatibility

The module is tested on Magento version 2.4.x with sentry sdk version 3.x. Magento 2.1.x is not supported by us anymore, feel free to fork this project or make a pull request.

Ideas, bugs or suggestions?

Please create a issue or a pull request.

About us

We’re a innovative development agency from The Netherlands building awesome websites, webshops and web applications with Laravel and Magento. Check out our website justbetter.nl and our open source projects.

License

MIT


JustBetter logo