Home

Awesome

Magento 2 Sentry Logger

Latest Version on Packagist Total Downloads Magento Support PHPStan passing

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. feel free to fork this project or make a pull request.

Ideas, bugs or suggestions?

Please create a issue or a pull request.

Contributing

Contributing? Awesome! Thank you for your help improving the module!

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


<a href="https://justbetter.nl" title="JustBetter"><img src="https://raw.githubusercontent.com/justbetter/art/master/justbetter-logo.png" width="200px" alt="JustBetter logo"></a>