Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to exclude default-integrations #146

Merged
merged 1 commit into from
Aug 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading