justbetter / magento2-sentry
Magento 2 Logger for Sentry
Installs: 1 070 128
Dependents: 5
Suggesters: 0
Security: 0
Stars: 161
Watchers: 11
Forks: 70
Open Issues: 15
Type:magento2-module
Requires
- php: >=8.0
- magento/framework: *
- magento/module-config: ^101.2
- monolog/monolog: >=2.7.0
- nyholm/psr7: ^1.2
- sentry/sdk: ^4.0
Requires (Dev)
- bitexpert/phpstan-magento: ^0.11.0
- phpstan/phpstan: ^1.10
- dev-master
- 3.8.0
- 3.7.2
- 3.7.1
- 3.7.0
- 3.6.0
- 3.5.2
- 3.5.1
- 3.5.0
- 3.4.0
- 3.3.1
- 3.3.0
- 3.2.0
- 3.1.0
- 3.0.2
- 3.0.1
- 3.0.0
- 2.6.1
- 2.6.0
- 2.5.4
- 2.5.3
- 2.5.2
- 2.5.1
- 2.5.0
- 2.4.0
- 2.3.2
- 2.3.1
- 2.3.0
- 2.2.3
- 2.2.2
- 2.2.1
- 2.2.0
- 2.1.0
- 2.0.0
- 0.8.0
- 0.7.2
- 0.7.1
- 0.7.0
- 0.6.2
- 0.6.1
- 0.6.0
- 0.5.1
- 0.5.0
- 0.4.2
- 0.4.1
- 0.4.0
- 0.3.0
- 0.2.2
- 0.2.0
- 0.1.0
- 0.0.6
- 0.0.5
- dev-feature/user-context
- dev-analysis-kYQRAA
- dev-feature/code-upgrades
- dev-develop
This package is auto-updated.
Last update: 2024-11-06 13:31:19 UTC
README
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
composer require justbetter/magento2-sentry
bin/magento module:enable JustBetter_Sentry
bin/magento setup:upgrade
bin/magento setup:di:compile
bin/magento setup:static-content:deploy
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
dsn
: Please enter here the DSN you got from Sentry for your project. You can find the DSN in the project settings under "Client Key (DSN)"environment
: Here you can specify the environment under which the deployed version is running. Common used environments are production, staging, and development. With this option you can differentiate between errors which happen on the staging and i.e. on the production systemlog_level
: With this configuration you can specify from which logging level on Sentry should get the messageserrorexception_reporting
: If the Exception being thrown is an instance of ErrorException send the error to sentry if it matches the error reporting. This uses the same syntax as Error Reporting eg.E_ERROR | E_WARNING
to only log Errors and Warnings.ignore_exceptions
: If the class being thrown matches any in this list do not send it to Sentry e.g.[\Magento\Framework\Exception\NoSuchEntityException::class]
mage_mode_development
: If this option is set to true you will receive issues in Sentry even if you're Magento is running in develop mode.js_sdk_version
: if this option is set, it will load the explicit version of the javascript SDK of Sentry.tracing_enabled
if this option is set to true, tracing got enabled (bundle file got loaded automatically). Default:false
tracing_sample_rate
if tracing is enabled, you should also set the sample rate. Default:0.2
ignore_js_errors
array of javascript error messages, which should be not send to Sentry. (see alsoignoreErrors
in Sentry documentation)disable_default_integrations
provide a list of FQCN of default integrations, which you do not want to use. List of default integrations. Default:[]
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:
CONFIG__SENTRY__ENVIRONMENT__ENABLED
: booleanCONFIG__SENTRY__ENVIRONMENT__DSN
: stringCONFIG__SENTRY__ENVIRONMENT__LOGROCKET_KEY
: stringCONFIG__SENTRY__ENVIRONMENT__ENVIRONMENT
: stringCONFIG__SENTRY__ENVIRONMENT__LOG_LEVEL
: integerCONFIG__SENTRY__ENVIRONMENT__ERROREXCEPTION_REPORTING
: integerCONFIG__SENTRY__ENVIRONMENT__IGNORE_EXCEPTIONS
: A JSON encoded array of classesCONFIG__SENTRY__ENVIRONMENT__MAGE_MODE_DEVELOPMENT
: stringCONFIG__SENTRY__ENVIRONMENT__JS_SDK_VERSION
: stringCONFIG__SENTRY__ENVIRONMENT__TRACING_ENABLED
: booleanCONFIG__SENTRY__ENVIRONMENT__TRACING_SAMPLE_RATE
: floatCONFIG__SENTRY__ENVIRONMENT__IGNORE_JS_ERRORS
: A JSON encoded array of error messages
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
- Optional you can configure custom error pages in pub/errors. You can use the sentry feedback form and insert here the sentry log ID. The Sentry Log Id is captured in de customer session and can be retrieved in
processor.php
.
Sending additional data to Sentry when logging errors
- When calling any function from the Psr\Log\LoggerInterface you can pass any data to the parameter $context and it will be send to Sentry as 'Custom context'.
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!
- When making a PR please add a description what you've added, and if relevant why.
- To save time on codestyle feedback, please run
composer install
composer run codestyle
composer run analyse
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.