Skip to content

Commit

Permalink
Add option to exclude default-integrations (#146)
Browse files Browse the repository at this point in the history
  • Loading branch information
rommelfreddy authored Aug 9, 2024
1 parent 1a87259 commit 2e0b8ad
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 deletions.
6 changes: 6 additions & 0 deletions Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class Data extends AbstractHelper
'tracing_enabled',
'tracing_sample_rate',
'ignore_js_errors',
'disable_default_integrations',
];

/**
Expand Down Expand Up @@ -93,6 +94,11 @@ public function getTracingSampleRate(): float
return (float) $this->config['tracing_sample_rate'] ?? 0.2;
}

public function getDisabledDefaultIntegrations(): array
{
return $this->config['disable_default_integrations'] ?? [];
}

/**
* @return array|null
*/
Expand Down
9 changes: 9 additions & 0 deletions Plugin/GlobalExceptionCatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@
use JustBetter\Sentry\Model\ReleaseIdentifier;
use JustBetter\Sentry\Model\SentryInteraction;
use Magento\Framework\AppInterface;
use Magento\Framework\DataObject;
use Magento\Framework\DataObjectFactory;
use Magento\Framework\Event\ManagerInterface as EventManagerInterface;
use Sentry\Integration\IntegrationInterface;

class GlobalExceptionCatcher
{
Expand Down Expand Up @@ -37,6 +39,7 @@ public function aroundLaunch(AppInterface $subject, callable $proceed)
return $proceed();
}

/** @var DataObject $config */
$config = $this->dataObjectFactory->create();

$config->setDsn($this->sentryHelper->getDSN());
Expand All @@ -59,6 +62,12 @@ public function aroundLaunch(AppInterface $subject, callable $proceed)
return $data->getEvent();
});

$disabledDefaultIntegrations = $this->sentryHelper->getDisabledDefaultIntegrations();
$config->setData('integrations', static fn (array $integrations) => array_filter(
$integrations,
static fn (IntegrationInterface $integration) => !in_array(get_class($integration), $disabledDefaultIntegrations)
));

$this->eventManager->dispatch('sentry_before_init', [
'config' => $config,
]);
Expand Down
14 changes: 9 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,12 @@ This module uses the [Magento Deployment Configuration](https://devdocs.magento.
'ignore_exceptions' => [],
'mage_mode_development' => false,
'js_sdk_version' => \JustBetter\Sentry\Block\SentryScript::CURRENT_VERSION,
'tracing_enabled' => true,
'tracing_enabled' => true,
'tracing_sample_rate' => 0.5,
'ignore_js_errors' => []
'ignore_js_errors' => [],
'disable_default_integrations' => [
\Sentry\Integration\ModulesIntegration::class,
]
]
```

Expand All @@ -39,13 +42,14 @@ Next to that there are some configuration options under Stores > Configuration >
* `errorexception_reporting`: If the Exception being thrown is an instance of [ErrorException](https://www.php.net/manual/en/class.errorexception.php) send the error to sentry if it matches the error reporting. This uses the same syntax as [Error Reporting](https://www.php.net/manual/en/function.error-reporting.php) 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.
* `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](https://docs.sentry.io/clients/javascript/config/))
* `disable_default_integrations` provide a list of FQCN of default integrations, which you do not want to use. [List of default integrations](https://github.com/getsentry/sentry-php/tree/master/src/Integration). 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
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`: boolean
Expand All @@ -61,7 +65,7 @@ using the "Variables" in Adobe Commerce using the following variables:
* `CONFIG__SENTRY__ENVIRONMENT__TRACING_SAMPLE_RATE`: float
* `CONFIG__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
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
Expand Down

0 comments on commit 2e0b8ad

Please sign in to comment.