Type
magento2-module
Bugsnag Notifier for Magento 2
magento2-module
MIT
None
None
None
None
None
This module integrates the Bugsnag notifier into Magento's exception handling. Any exception that is left unhandled and eventually caught within the Magento\Framework\App\Bootstrap::run
method will then be notified to Bugsnag.
This works by using two plugins (interceptors) that are placed before the launch
and catchException
methods on any class that implement the Magento\Framework\AppInterface
interface. Within the beforeLaunch
plugin Bugsnag is initialised and a session is started which means within the Bugsnag Dashboard you'll be able to see a calculated stability score.
composer require ashsmith/magento-bugsnag-notifier-module ^1.0.0
bin/magento setup:upgrade
To configure the Bugsnag Notifier you have two options:
1) Use the environment variable: BUGSNAG_API_KEY
, BUGSNAG_ENDPOINT
, BUGSNAG_RELEASE_STAGE
2) Add the following configuration to: app/etc/env.php
return [
...
'bugsnag' => [
'api_key' => 'YOUR API KEY',
'endpoint' => 'custom endpoint if required',
'release_stage' => 'production'
]
]
The endpoint
/BUGSNAG_ENDPOINT
is optional, and only required if you need to notify a different endpoint, such as a self-hosted edition of Bugsnag.
The release_stage
/BUGSNAG_RELEASE_STAGE
will default to production
so is also optional.
If you wish to send additional data to Bugsnag that may help debug your Magento application, there are two events dispatched by this module which can be used to add additionaal metadata.
bugsnag_init
bugsnag_init
is dispatched when the module first initialises Bugsnag and a session is started. You'll be able to retrive the Bugsnag client by doing: $observer->getData('client')
which will give you an instance of \Bugsnag\Client
. From there adding metadata can be done like so:
/** @var \Bugsnag\Client $client */
$client = $observer->getData('client');
$client->setMetaData([
'app' => [
'new_property' => 'new_value'
]
]);
Alternatively you can register a callback which will be executed when an exception occurs to add additional information to the report:
/** @var \Bugsnag\Client $client */
$client = $observer->getData('client');
$client->registerCallback(function (\Bugsnag\Report $report) {
$report->setMetaData([
'app' => [
'new_property' => 'new_value'
]
])
});
bugsnag_add_customer_data
This event allows you add additional customer data to the exception report, you can fetch the current customer data object by calling: $observer->getData('data')
.
This is an instance of \Magento\Framework\DataObject
, so you can use the setData
and getData
properties to modify the object.
By default the module will only send the customers: ID, customer group, and a boolean whether or not they are logged in.