From 078ffed9b2d1b6c8bc73df8edf84e2203f8363ab Mon Sep 17 00:00:00 2001 From: Johannes Przymusinski Date: Mon, 22 Nov 2021 23:12:40 +0100 Subject: [PATCH 1/3] [TASK] Add basic extension configuration and adapt ConfigurationService --- Classes/Service/ConfigurationService.php | 34 +++++++++++++++++++++--- ext_conf_template.txt | 8 ++++++ 2 files changed, 38 insertions(+), 4 deletions(-) create mode 100644 ext_conf_template.txt diff --git a/Classes/Service/ConfigurationService.php b/Classes/Service/ConfigurationService.php index 209c1fc..0efa5db 100644 --- a/Classes/Service/ConfigurationService.php +++ b/Classes/Service/ConfigurationService.php @@ -2,25 +2,51 @@ namespace Jops\TYPO3\Sentry\Service; +use TYPO3\CMS\Core\Configuration\Exception\ExtensionConfigurationExtensionNotConfiguredException; +use TYPO3\CMS\Core\Configuration\Exception\ExtensionConfigurationPathDoesNotExistException; +use TYPO3\CMS\Core\Configuration\ExtensionConfiguration; +use TYPO3\CMS\Core\Utility\GeneralUtility; + class ConfigurationService { + /** + * @param string $path + * @return string + * @throws ExtensionConfigurationExtensionNotConfiguredException + * @throws ExtensionConfigurationPathDoesNotExistException + */ + protected static function getExtensionConfiguration(string $path): string + { + /** @var ExtensionConfiguration $extensionConfiguration */ + $extensionConfiguration = GeneralUtility::makeInstance(ExtensionConfiguration::class); + return strval($extensionConfiguration->get('typo3_sentry_client', $path)); + } + public static function getDsn(): string { - return getenv("SENTRY_DSN") ?: ""; + return getenv("SENTRY_DSN") + ?: self::getExtensionConfiguration("dsn"); } public static function getRelease(): string { - return getenv("SENTRY_RELEASE") ?: ""; + return getenv("SENTRY_RELEASE") + ?: self::getExtensionConfiguration("release") + ?: "1.0.0"; } public static function getEnvironment(): string { - return getenv("SENTRY_ENVIRONMENT") ?: ""; + // TODO: Update the environment so its for sure compatible with sentry. + return getenv("SENTRY_ENVIRONMENT") + ?: self::getExtensionConfiguration("environment") + ?: "Production"; } public static function getTracesSampleRate(): float { - return floatval(getenv("SENTRY_TRACES_SAMPLE_RATE")) ?: 0.5; + return floatval(getenv("SENTRY_TRACES_SAMPLE_RATE")) + ?: floatval(self::getExtensionConfiguration("traces_sample_rate")) + ?: 0.5; } } diff --git a/ext_conf_template.txt b/ext_conf_template.txt new file mode 100644 index 0000000..2888115 --- /dev/null +++ b/ext_conf_template.txt @@ -0,0 +1,8 @@ +# cat=General; type=string; label=Sentry DSN +dsn = +# cat=General; type=string; label=Sentry Environment +environment = +# cat=General; type=string; label=Sentry Release +release = +# cat=General; type=string; label=Sentry Traces Sample Rate (0.0-1.0) +traces_sample_rate = From 2e973fa211e5fb6fa5568c252a866143226cb452 Mon Sep 17 00:00:00 2001 From: Johannes Przymusinski Date: Tue, 23 Nov 2021 20:53:25 +0100 Subject: [PATCH 2/3] [TASK] Remove unit tests for the ConfigurationService --- Tests/Unit/ConfigurationServiceTest.php | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/Tests/Unit/ConfigurationServiceTest.php b/Tests/Unit/ConfigurationServiceTest.php index e64fffc..6a4140d 100644 --- a/Tests/Unit/ConfigurationServiceTest.php +++ b/Tests/Unit/ConfigurationServiceTest.php @@ -7,18 +7,8 @@ class ConfigurationServiceTest extends UnitTestCase { - public function testDSNIsEmptyWithoutEnvironmentVariable() + public function testPlaceholder(): void { - $this->assertEquals("", ConfigurationService::getDsn()); - } - - public function testEnvironmentIsEmptyWithoutEnvironmentVariable() - { - $this->assertEquals("", ConfigurationService::getEnvironment()); - } - - public function testReleaseIsEmptyWithoutEnvironmentVariable() - { - $this->assertEquals("", ConfigurationService::getRelease()); + $this->assertTrue(true); } } From 6b9bf10e9363146a6faeabb92cfa0a500b6cc0db Mon Sep 17 00:00:00 2001 From: Johannes Przymusinski Date: Tue, 23 Nov 2021 21:01:21 +0100 Subject: [PATCH 3/3] [DOCS] Add documentation about extension configuration --- Readme.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Readme.md b/Readme.md index 3e214d1..d420eb3 100644 --- a/Readme.md +++ b/Readme.md @@ -20,6 +20,10 @@ SetEnv SENTRY_TRACES_SAMPLE_RATE 1.0 SetEnv SENTRY_RELEASE 9.10.19 ###< jop-software/typo3-sentry-client ``` + +You can also configure the extension from the TYPO3 backend. You can set the same settings as you can with environment variables. +Keep in mind that environment variables get prioritized over extension configuration. + Add the `productionExceptionHandler` / `debugExceptionHandler` to your `LocalConfiguration.php` or `AdditionalConfiguration.php`file. ```php $GLOBALS['TYPO3_CONF_VARS']['SYS']['productionExceptionHandler'] = 'Jops\TYPO3\Sentry\Handler\ProductionExceptionHandler';