diff --git a/Classes/ClientOptions/BaseClientOptionsProvider.php b/Classes/ClientOptions/BaseClientOptionsProvider.php new file mode 100644 index 0000000..107ff7d --- /dev/null +++ b/Classes/ClientOptions/BaseClientOptionsProvider.php @@ -0,0 +1,41 @@ +dsn; + $inAppExclude = $this->inAppExclude; + + return [ + 'dsn' => $dsn, + 'integrations' => [ + new NetlogixIntegration($inAppExclude ?? []), + ], + ]; + } +} diff --git a/Classes/ClientOptions/ClientOptionsProviderInterface.php b/Classes/ClientOptions/ClientOptionsProviderInterface.php new file mode 100644 index 0000000..1494ce7 --- /dev/null +++ b/Classes/ClientOptions/ClientOptionsProviderInterface.php @@ -0,0 +1,18 @@ + + */ + public function getClientOptions(): array; +} diff --git a/Classes/Package.php b/Classes/Package.php index 23f21c3..9dd0612 100644 --- a/Classes/Package.php +++ b/Classes/Package.php @@ -3,9 +3,11 @@ namespace Netlogix\Sentry; -use Neos\Flow\Configuration\ConfigurationManager; +use Neos\Flow\Core\Booting\Sequence; +use Neos\Flow\Core\Booting\Step; use Neos\Flow\Core\Bootstrap; -use Netlogix\Sentry\Integration\NetlogixIntegration; +use Netlogix\Sentry\ClientOptions\ClientOptionsProviderInterface; + use function Sentry\init; class Package extends \Neos\Flow\Package\Package @@ -15,28 +17,12 @@ public function boot(Bootstrap $bootstrap) { $dispatcher = $bootstrap->getSignalSlotDispatcher(); - $dispatcher->connect( - ConfigurationManager::class, - 'configurationManagerReady', - static function (ConfigurationManager $configurationManager) { - $dsn = $configurationManager->getConfiguration( - ConfigurationManager::CONFIGURATION_TYPE_SETTINGS, - 'Netlogix.Sentry.dsn' - ); - - $inAppExclude = $configurationManager->getConfiguration( - ConfigurationManager::CONFIGURATION_TYPE_SETTINGS, - 'Netlogix.Sentry.inAppExclude' - ); - - init([ - 'dsn' => $dsn, - 'integrations' => [ - new NetlogixIntegration($inAppExclude ?? []), - ] - ]); + $dispatcher->connect(Sequence::class, 'afterInvokeStep', function ($step) use ($bootstrap) { + if ($step instanceof Step && $step->getIdentifier() === 'neos.flow:objectmanagement:runtime') { + $clientOptionsProvider = $bootstrap->getObjectManager()->get(ClientOptionsProviderInterface::class); + init($clientOptionsProvider->getClientOptions()); } - ); + }); } } diff --git a/README.md b/README.md index f224134..3875b10 100644 --- a/README.md +++ b/README.md @@ -394,3 +394,28 @@ Optionally, you can also set max run time and check margin (see https://docs.sen ``` 0 0 * * * user ./flow sentry:test --cron-monitor-slug=sentry_test_midnight --cron-monitor-schedule="0 0 * * *" --cron-monitor-max-time=5 --cron-monitor-check-margin=2 ``` + +## Providing additional Sentry options + +To specify additional options for the Sentry client, passed to the `init()` function, you can implement the `ClientOptionsProviderInterface`. +You may want to extend the `BaseClientOptionsProvider`, which configures the default options. +```php +class MyClientOptionsProvider extends BaseClientOptionsProvider +{ + public function getClientOptions(): array + { + return [ + ...parent::getClientOptions(), + 'additional_option' => '...', + ]; + } +} +``` + +Then you need to configure your class in the `Objects.yaml`: +```yaml +Netlogix\Sentry\ClientOptions\ClientOptionsProviderInterface: + className: My\Package\MyClientOptionsProvider +``` + +As the client is initialized in the boot sequence, you may need to flush caches.