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

[FEATURE] Extension Configuration #20

Merged
merged 3 commits into from
Nov 24, 2021
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
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 =