diff --git a/src/SDK/Common/Configuration/Variables.php b/src/SDK/Common/Configuration/Variables.php index d0bb3c8ab..ad5ebe107 100644 --- a/src/SDK/Common/Configuration/Variables.php +++ b/src/SDK/Common/Configuration/Variables.php @@ -139,4 +139,5 @@ interface Variables public const OTEL_PHP_AUTOLOAD_ENABLED = 'OTEL_PHP_AUTOLOAD_ENABLED'; public const OTEL_PHP_INTERNAL_METRICS_ENABLED = 'OTEL_PHP_INTERNAL_METRICS_ENABLED'; //whether the SDK should emit its own metrics public const OTEL_PHP_DISABLED_INSTRUMENTATIONS = 'OTEL_PHP_DISABLED_INSTRUMENTATIONS'; + public const OTEL_PHP_DEVELOPER_MODE_ENABLED = 'OTEL_PHP_DEVELOPER_MODE_ENABLED'; } diff --git a/src/SDK/Sdk.php b/src/SDK/Sdk.php index 3b63eb93a..5b2212671 100644 --- a/src/SDK/Sdk.php +++ b/src/SDK/Sdk.php @@ -43,6 +43,15 @@ public static function isInstrumentationDisabled(string $name): bool return in_array($name, Configuration::getList(Variables::OTEL_PHP_DISABLED_INSTRUMENTATIONS)); } + /** + * Tests whether developer mode has been enabled by config. + */ + public static function isDeveloperModeEnabled(): bool + { + return Configuration::has(Variables::OTEL_PHP_DEVELOPER_MODE_ENABLED) + && Configuration::getBoolean(Variables::OTEL_PHP_DEVELOPER_MODE_ENABLED); + } + public static function builder(): SdkBuilder { return new SdkBuilder(); diff --git a/tests/Unit/SDK/SdkTest.php b/tests/Unit/SDK/SdkTest.php index a862efe41..de394132d 100644 --- a/tests/Unit/SDK/SdkTest.php +++ b/tests/Unit/SDK/SdkTest.php @@ -68,6 +68,16 @@ public static function instrumentationDisabledProvider(): array ]; } + /** + * @dataProvider disabledProvider + */ + public function test_developer_mode_can_be_toggled(string $value, bool $expected): void + { + $this->setEnvironmentVariable(Variables::OTEL_PHP_DEVELOPER_MODE_ENABLED, $value); + + $this->assertEquals($expected, Sdk::isDeveloperModeEnabled()); + } + public function test_builder(): void { $this->assertInstanceOf(SdkBuilder::class, Sdk::builder());