• Stars
    star
    159
  • Rank 235,916 (Top 5 %)
  • Language
    PHP
  • License
    MIT License
  • Created over 6 years ago
  • Updated 4 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Magento 2 module to log to 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

  • 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

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' => []
]

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 system
  • log_level: With this configuration you can specify from which logging level on Sentry should get the messages
  • errorexception_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 also ignoreErrors in Sentry documentation)

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();
}

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

More Repositories

1

laravel-pagination-with-havings

Makes it possible to use pagination with havings in queries with Laravel.
PHP
66
star
2

laravel-magento-client

A client to easily communicate with Magento from your Laravel application
PHP
40
star
3

magento2-image-optimizer

This Magento 2 module is a wrapper based on the package https://github.com/spatie/image-optimizer
PHP
40
star
4

laravel-dynamics-client

A package to easily use Microsoft Dynamics web services via OData with Laravel
PHP
26
star
5

magento2-akeneo-bundle

Magento2 bundle for extending the Akeneo connector with awesome features.
PHP
26
star
6

magento2-disable-spam-in-log

Magento 2 disables log lines with certain log level
PHP
18
star
7

magento2-algolia-wordpress-integration

Magento 2 module which integrates Wordpress pages and posts in the Algolia Magento 2 module
PHP
17
star
8

laravel-magento-prices

Package to send prices to Magento from a Laravel application using a configurable source.
PHP
17
star
9

magento1-css-merge-data-uri-fix

A Magento 1 module to fix the CSS merging data uri bug which is present in all Magento 1 versions
PHP
16
star
10

laravel-magento-prices-nova

Laravel Nova integration for justbetter/laravel-magento-prices
PHP
15
star
11

laravel-akeneo-client

A Laravel package for the Akeneo API
PHP
15
star
12

laravel-magento-products

This package tracks if products exist in Magento by storing the status locally in the DB.
PHP
15
star
13

laravel-magento-products-nova

This package is the Laravel Nova integration for justbetter/laravel-magento-prices
PHP
14
star
14

magento1-cache-buster

A very light weight cache buster module for Magento 1
PHP
14
star
15

laravel-magento-customer-prices-nova

Laravel Nova integration for justbetter/laravel-magento-customer-prices
PHP
14
star
16

laravel-magento-customer-prices

Package to send customer specific prices to Magento from a Laravel application using a configurable source.
PHP
14
star
17

statamic-image-optimize

Image optimization after upload
PHP
13
star
18

laravel-magento-webhooks

A Laravel package to listen to webhooks dispatched from mageplaza/webhooks.
PHP
13
star
19

laravel-nova-links

Easily add a links section to your Laravel Nova application
PHP
12
star
20

magento2-customer-pricing

Magento 2 module that enables customer specific pricing
PHP
8
star
21

magento2-dotenv

Adds support for dot env configuration files to Magento 2.
PHP
5
star
22

art

JustBetter logo and other artwork.
5
star
23

laravel-magento-stock

Package to send stock to Magento from a Laravel application using a configurable source.
PHP
5
star
24

laravel-blade-tailwind-merge

Tailwind classes merging with Laravel Blade components
PHP
5
star
25

magento2-product-grid-export

Add the export grid button to your product grid!
PHP
4
star
26

laravel-error-logger

PHP
4
star
27

nova-error-logger

PHP
3
star
28

statamic-eloquent-driver-globalset-migration-generator

PHP
3
star
29

laravel-akeneo

Akeneo api wrapper for Laravel
PHP
3
star
30

magento2-optimizeflattable

PHP
2
star
31

akeneo-readonly

A readonly frontend for Akeneo written with the TALL stack
PHP
2
star
32

generate-changelogs-action

Generate changelogs based on a repositories Github releases
PHP
2
star
33

statamic-partytown

Speed up your Statamic frontend with marketing scripts using Partytown
PHP
1
star
34

magento2-paynl-graphql

This module aims to add basic GraphQL support for the paynl module for Magento 2
PHP
1
star
35

statamic-feedback-company

PHP
1
star
36

statamic-toolkit

Opinionated toolkit for statamic
PHP
1
star
37

laravel-magento-stock-nova

Laravel Nova integration for justbetter/laravel-magento-stock
PHP
1
star
38

statamic-postcodeservice

PHP
1
star