Skip to content

Commit

Permalink
Merge pull request #20 from jop-software/extension-configuration
Browse files Browse the repository at this point in the history
[FEATURE] Extension Configuration
  • Loading branch information
cngJo authored Nov 24, 2021
2 parents eaba4d8 + 6b9bf10 commit 8c6484b
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 16 deletions.
34 changes: 30 additions & 4 deletions Classes/Service/ConfigurationService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
4 changes: 4 additions & 0 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
14 changes: 2 additions & 12 deletions Tests/Unit/ConfigurationServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
8 changes: 8 additions & 0 deletions ext_conf_template.txt
Original file line number Diff line number Diff line change
@@ -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 =

0 comments on commit 8c6484b

Please sign in to comment.