Skip to content
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
41 changes: 41 additions & 0 deletions Classes/ClientOptions/BaseClientOptionsProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

declare(strict_types=1);

namespace Netlogix\Sentry\ClientOptions;

use Neos\Flow\Annotations as Flow;
use Netlogix\Sentry\Integration\NetlogixIntegration;

/**
* Sets up the basic options for the Sentry client.
* To add additional options, you can extend this class and register it as
* implementation for the {@see ClientOptionsProviderInterface}.
*/
class BaseClientOptionsProvider implements ClientOptionsProviderInterface
{
/**
* @Flow\InjectConfiguration(package="Netlogix.Sentry", path="dsn")
* @var string|null
*/
protected $dsn;

/**
* @Flow\InjectConfiguration(package="Netlogix.Sentry", path="inAppExclude")
* @var string[]|null
*/
protected $inAppExclude;

public function getClientOptions(): array
{
$dsn = $this->dsn;
$inAppExclude = $this->inAppExclude;

return [
'dsn' => $dsn,
'integrations' => [
new NetlogixIntegration($inAppExclude ?? []),
],
];
}
}
18 changes: 18 additions & 0 deletions Classes/ClientOptions/ClientOptionsProviderInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

declare(strict_types=1);

namespace Netlogix\Sentry\ClientOptions;

/**
* Interface to provide options to the Sentry client.
* You may want to extend the {@see BaseClientOptionsProvider} instead.
*/
interface ClientOptionsProviderInterface
{
/**
* Provide the options used to initialize the Sentry client.
* @return array<string, mixed>
*/
public function getClientOptions(): array;
}
32 changes: 9 additions & 23 deletions Classes/Package.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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());
}
);
});
}

}
25 changes: 25 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.