diff --git a/.gitsplit.yml b/.gitsplit.yml index 9f7eb8289..95c7a4a25 100644 --- a/.gitsplit.yml +++ b/.gitsplit.yml @@ -10,6 +10,8 @@ splits: target: "https://${GH_TOKEN}@github.com/opentelemetry-php/gen-otlp-protobuf.git" - prefix: "src/Context" target: "https://${GH_TOKEN}@github.com/opentelemetry-php/context.git" + - prefix: "src/Config/Configuration" + target: "https://${GH_TOKEN}@github.com/opentelemetry-php/config.git" - prefix: "src/SemConv" target: "https://${GH_TOKEN}@github.com/opentelemetry-php/sem-conv.git" - prefix: "src/API" diff --git a/composer.json b/composer.json index 4bb3abee2..780ae0245 100644 --- a/composer.json +++ b/composer.json @@ -37,6 +37,7 @@ ], "replace": { "open-telemetry/api": "1.0.x-dev", + "open-telemetry/config": "1.0.x-dev", "open-telemetry/context": "1.0.x-dev", "open-telemetry/exporter-otlp": "1.0.x-dev", "open-telemetry/exporter-zipkin": "1.0.x-dev", diff --git a/deptrac.yaml b/deptrac.yaml index 8507328db..fcbbc3133 100644 --- a/deptrac.yaml +++ b/deptrac.yaml @@ -25,6 +25,14 @@ deptrac: collectors: - type: directory value: src/SDK/.* + - name: Config + collectors: + - type: directory + value: src/Config/Configuration/.* + - name: ConfigSDK + collectors: + - type: directory + value: src/Config/SDK/.* - name: Context collectors: - type: directory @@ -77,12 +85,22 @@ deptrac: collectors: - type: className regex: ^Composer\\* + - name: SymfonyConfig + collectors: + - type: className + regex: ^Symfony\\Component\\* + - name: SPI + collectors: + - type: className + regex: ^Nevay\\SPI\\* ruleset: Context: - FFI + - Config SemConv: ~ API: + - Config - Context - PsrLog SDK: @@ -91,6 +109,15 @@ deptrac: - PsrHttp - HttpPlug - Composer + Config: + - PsrLog + ConfigSDK: + - Contrib + - Extension + - PsrLog + - SymfonyConfig + - +SDK + - SPI Contrib: - +SDK - +OtelProto @@ -101,3 +128,4 @@ deptrac: OtelProto: - GoogleProtobuf - Grpc + SdkConfig: diff --git a/phpstan.neon.dist b/phpstan.neon.dist index 74b2971a2..6507b01ed 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -13,11 +13,6 @@ parameters: - tests/TraceContext/W3CTestService - tests/Unit/Config/SDK/Configuration/ExampleSdk ignoreErrors: - - - message: "#Call to an undefined method .*#" - paths: - - tests/Unit/SDK/Common/Configuration/Resolver/PhpIniResolverTest.php - - tests/Unit/SDK/Common/Configuration/Resolver/CompositeResolverTest.php - message: "#Call to an undefined method .*:allows.*#" paths: diff --git a/src/API/Behavior/Internal/LogWriterFactory.php b/src/API/Behavior/Internal/LogWriterFactory.php index 5bf5a3af2..c0435be2f 100644 --- a/src/API/Behavior/Internal/LogWriterFactory.php +++ b/src/API/Behavior/Internal/LogWriterFactory.php @@ -9,26 +9,26 @@ use OpenTelemetry\API\Behavior\Internal\LogWriter\NoopLogWriter; use OpenTelemetry\API\Behavior\Internal\LogWriter\Psr3LogWriter; use OpenTelemetry\API\Behavior\Internal\LogWriter\StreamLogWriter; -use OpenTelemetry\API\Instrumentation\ConfigurationResolver; use OpenTelemetry\API\LoggerHolder; +use OpenTelemetry\Config\Configuration\Configuration; +use OpenTelemetry\Config\Configuration\KnownValues; +use OpenTelemetry\Config\Configuration\Variables; class LogWriterFactory { - private const OTEL_PHP_LOG_DESTINATION = 'OTEL_PHP_LOG_DESTINATION'; - public function create(): LogWriterInterface { - $dest = (new ConfigurationResolver())->getString(self::OTEL_PHP_LOG_DESTINATION); + $dest = (new Configuration())->getEnum(Variables::OTEL_PHP_LOG_DESTINATION); $logger = LoggerHolder::get(); switch ($dest) { - case 'none': + case KnownValues::VALUE_NONE: return new NoopLogWriter(); - case 'stderr': + case KnownValues::VALUE_STDERR: return new StreamLogWriter('php://stderr'); - case 'stdout': + case KnownValues::VALUE_STDOUT: return new StreamLogWriter('php://stdout'); - case 'psr3': + case KnownValues::VALUE_PSR3: if ($logger) { return new Psr3LogWriter($logger); } @@ -36,7 +36,7 @@ public function create(): LogWriterInterface //default to error log return new ErrorLogWriter(); - case 'error_log': + case KnownValues::VALUE_ERROR_LOG: return new ErrorLogWriter(); default: if ($logger) { diff --git a/src/API/Behavior/Internal/Logging.php b/src/API/Behavior/Internal/Logging.php index e5bec7ab5..47e13bdc9 100644 --- a/src/API/Behavior/Internal/Logging.php +++ b/src/API/Behavior/Internal/Logging.php @@ -5,6 +5,8 @@ namespace OpenTelemetry\API\Behavior\Internal; use OpenTelemetry\API\Behavior\Internal\LogWriter\LogWriterInterface; +use OpenTelemetry\Config\Configuration\Configuration; +use OpenTelemetry\Config\Configuration\Variables; use Psr\Log\LogLevel; /** @@ -69,15 +71,7 @@ public static function logLevel(): int private static function getLogLevel(): int { - $level = array_key_exists(self::OTEL_LOG_LEVEL, $_SERVER) - ? $_SERVER[self::OTEL_LOG_LEVEL] - : getenv(self::OTEL_LOG_LEVEL); - if (!$level) { - $level = ini_get(self::OTEL_LOG_LEVEL); - } - if (!$level) { - $level = self::DEFAULT_LEVEL; - } + $level = Configuration::getEnum(Variables::OTEL_LOG_LEVEL, self::DEFAULT_LEVEL); return self::level($level); } diff --git a/src/API/Instrumentation/ConfigurationResolver.php b/src/API/Instrumentation/ConfigurationResolver.php deleted file mode 100644 index bb5619c30..000000000 --- a/src/API/Instrumentation/ConfigurationResolver.php +++ /dev/null @@ -1,77 +0,0 @@ -getVariable($name) !== null; - } - - public function getString(string $name): ?string - { - return $this->getVariable($name); - } - - public function getBoolean(string $name): ?bool - { - $value = $this->getVariable($name); - if ($value === null) { - return null; - } - - return ($value === 'true'); - } - - public function getInt(string $name): ?int - { - $value = $this->getVariable($name); - if ($value === null) { - return null; - } - if (filter_var($value, FILTER_VALIDATE_INT) === false) { - //log warning - return null; - } - - return (int) $value; - } - - public function getList(string $name): array - { - $value = $this->getVariable($name); - if ($value === null) { - return []; - } - - return explode(',', $value); - } - - private function getVariable(string $name): ?string - { - $value = $_SERVER[$name] ?? null; - if ($value !== false && !self::isEmpty($value)) { - assert(is_string($value)); - - return $value; - } - $value = getenv($name); - if ($value !== false && !self::isEmpty($value)) { - return $value; - } - $value = ini_get($name); - if ($value !== false && !self::isEmpty($value)) { - return $value; - } - - return null; - } - - private static function isEmpty($value): bool - { - return $value === false || $value === null || $value === ''; - } -} diff --git a/src/API/Instrumentation/ConfigurationResolverInterface.php b/src/API/Instrumentation/ConfigurationResolverInterface.php deleted file mode 100644 index 79bd94047..000000000 --- a/src/API/Instrumentation/ConfigurationResolverInterface.php +++ /dev/null @@ -1,14 +0,0 @@ -hasVariable($name); @@ -32,10 +28,7 @@ public static function has(string $name): bool public static function getInt(string $key, ?int $default = null): int { return (int) self::validateVariableValue( - CompositeResolver::instance()->resolve( - self::validateVariableType($key, VariableTypes::INTEGER), - $default - ), + CompositeResolver::instance()->resolve($key, $default), FILTER_VALIDATE_INT ); } @@ -43,10 +36,7 @@ public static function getInt(string $key, ?int $default = null): int public static function getString(string $key, ?string $default = null): string { return (string) self::validateVariableValue( - CompositeResolver::instance()->resolve( - self::validateVariableType($key, VariableTypes::STRING), - $default - ) + CompositeResolver::instance()->resolve($key, $default), ); } @@ -54,21 +44,15 @@ public static function getBoolean(string $key, ?bool $default = null): bool { $resolved = self::validateVariableValue( CompositeResolver::instance()->resolve( - self::validateVariableType($key, VariableTypes::BOOL), + $key, null === $default ? $default : ($default ? 'true' : 'false') ) ); - try { - return BooleanParser::parse($resolved); - } catch (InvalidArgumentException) { - self::logWarning(sprintf('Invalid boolean value "%s" interpreted as "false" for %s', $resolved, $key)); - - return false; - } + return BooleanParser::parse($resolved); } - public static function getMixed(string $key, $default = null) + public static function getMixed(string $key, $default = null): mixed { return self::validateVariableValue( CompositeResolver::instance()->resolve( @@ -81,40 +65,28 @@ public static function getMixed(string $key, $default = null) public static function getMap(string $key, ?array $default = null): array { return MapParser::parse( - CompositeResolver::instance()->resolve( - self::validateVariableType($key, VariableTypes::MAP), - $default - ) + CompositeResolver::instance()->resolve($key, $default), ); } public static function getList(string $key, ?array $default = null): array { return ListParser::parse( - CompositeResolver::instance()->resolve( - self::validateVariableType($key, VariableTypes::LIST), - $default - ) + CompositeResolver::instance()->resolve($key, $default), ); } public static function getEnum(string $key, ?string $default = null): string { return (string) self::validateVariableValue( - CompositeResolver::instance()->resolve( - self::validateVariableType($key, VariableTypes::ENUM), - $default - ) + CompositeResolver::instance()->resolve($key, $default), ); } public static function getFloat(string $key, ?float $default = null): float { return (float) self::validateVariableValue( - CompositeResolver::instance()->resolve( - self::validateVariableType($key, VariableTypes::FLOAT), - $default - ), + CompositeResolver::instance()->resolve($key, $default), FILTER_VALIDATE_FLOAT ); } @@ -123,10 +95,7 @@ public static function getRatio(string $key, ?float $default = null): float { return RatioParser::parse( self::validateVariableValue( - CompositeResolver::instance()->resolve( - self::validateVariableType($key, VariableTypes::RATIO), - $default - ) + CompositeResolver::instance()->resolve($key, $default), ) ); } @@ -141,31 +110,13 @@ public static function getDefault(string $variableName) return ClassConstantAccessor::getValue(Defaults::class, $variableName); } - public static function getType(string $variableName): ?string - { - return ClassConstantAccessor::getValue(ValueTypes::class, $variableName); - } - public static function isEmpty($value): bool { // don't use 'empty()', since '0' is not considered to be empty return $value === null || $value === ''; } - private static function validateVariableType(string $variableName, string $type): string - { - $variableType = self::getType($variableName); - - if ($variableType !== null && $variableType !== $type && $variableType !== VariableTypes::MIXED) { - throw new UnexpectedValueException( - sprintf('Variable "%s" is not supposed to be of type "%s" but type "%s"', $variableName, $type, $variableType) - ); - } - - return $variableName; - } - - private static function validateVariableValue($value, ?int $filterType = null) + private static function validateVariableValue(mixed $value, ?int $filterType = null): mixed { if ($filterType !== null && filter_var($value, $filterType) === false) { throw new UnexpectedValueException(sprintf('Value has invalid type "%s"', gettype($value))); diff --git a/src/SDK/Common/Configuration/Defaults.php b/src/Config/Configuration/Defaults.php similarity index 97% rename from src/SDK/Common/Configuration/Defaults.php rename to src/Config/Configuration/Defaults.php index fcfea6e4e..7aa95bb7e 100644 --- a/src/SDK/Common/Configuration/Defaults.php +++ b/src/Config/Configuration/Defaults.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace OpenTelemetry\SDK\Common\Configuration; +namespace OpenTelemetry\Config\Configuration; /** * Default values for environment variables defined by the OpenTelemetry specification and language specific variables for the PHP SDK. @@ -119,4 +119,6 @@ interface Defaults public const OTEL_PHP_DISABLED_INSTRUMENTATIONS = []; public const OTEL_PHP_LOGS_PROCESSOR = 'batch'; public const OTEL_PHP_LOG_DESTINATION = 'default'; + public const OTEL_PHP_DEBUG_SCOPES_DISABLED = 'false'; + public const OTEL_PHP_FIBERS_ENABLED = 'false'; } diff --git a/src/SDK/Common/Configuration/KnownValues.php b/src/Config/Configuration/KnownValues.php similarity index 99% rename from src/SDK/Common/Configuration/KnownValues.php rename to src/Config/Configuration/KnownValues.php index a7636214c..0387e3e6e 100644 --- a/src/SDK/Common/Configuration/KnownValues.php +++ b/src/Config/Configuration/KnownValues.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace OpenTelemetry\SDK\Common\Configuration; +namespace OpenTelemetry\Config\Configuration; use Psr\Log\LogLevel; diff --git a/src/SDK/Common/Configuration/Parser/BooleanParser.php b/src/Config/Configuration/Parser/BooleanParser.php similarity index 78% rename from src/SDK/Common/Configuration/Parser/BooleanParser.php rename to src/Config/Configuration/Parser/BooleanParser.php index 4141c61ef..50e054fe8 100644 --- a/src/SDK/Common/Configuration/Parser/BooleanParser.php +++ b/src/Config/Configuration/Parser/BooleanParser.php @@ -2,19 +2,19 @@ declare(strict_types=1); -namespace OpenTelemetry\SDK\Common\Configuration\Parser; +namespace OpenTelemetry\Config\Configuration\Parser; use InvalidArgumentException; +/** + * @internal + */ class BooleanParser { private const TRUE_VALUE = 'true'; private const FALSE_VALUE = 'false'; - /** - * @param string|bool $value - */ - public static function parse($value): bool + public static function parse(string|bool $value): bool { if (is_bool($value)) { return $value; diff --git a/src/SDK/Common/Configuration/Parser/ListParser.php b/src/Config/Configuration/Parser/ListParser.php similarity index 71% rename from src/SDK/Common/Configuration/Parser/ListParser.php rename to src/Config/Configuration/Parser/ListParser.php index f27b16597..3edf0cbe2 100644 --- a/src/SDK/Common/Configuration/Parser/ListParser.php +++ b/src/Config/Configuration/Parser/ListParser.php @@ -2,16 +2,16 @@ declare(strict_types=1); -namespace OpenTelemetry\SDK\Common\Configuration\Parser; +namespace OpenTelemetry\Config\Configuration\Parser; +/** + * @internal + */ class ListParser { private const DEFAULT_SEPARATOR = ','; - /** - * @param string|array $value - */ - public static function parse($value): array + public static function parse(string|array $value): array { if (is_array($value)) { return $value; diff --git a/src/SDK/Common/Configuration/Parser/MapParser.php b/src/Config/Configuration/Parser/MapParser.php similarity index 72% rename from src/SDK/Common/Configuration/Parser/MapParser.php rename to src/Config/Configuration/Parser/MapParser.php index b6404bb70..3a352c197 100644 --- a/src/SDK/Common/Configuration/Parser/MapParser.php +++ b/src/Config/Configuration/Parser/MapParser.php @@ -2,27 +2,30 @@ declare(strict_types=1); -namespace OpenTelemetry\SDK\Common\Configuration\Parser; +namespace OpenTelemetry\Config\Configuration\Parser; use InvalidArgumentException; +/** + * @internal + */ class MapParser { private const VARIABLE_SEPARATOR = ','; private const KEY_VALUE_SEPARATOR = '='; - public static function parse($value): array + public static function parse(string|array|null $value): array { if (is_array($value)) { return $value; } $result = []; - if (null === $value || trim((string) $value) === '') { + if (null === $value || trim($value) === '') { return $result; } - foreach (explode(self::VARIABLE_SEPARATOR, (string) $value) as $pair) { + foreach (explode(self::VARIABLE_SEPARATOR, $value) as $pair) { self::validateKeyValuePair($pair); /** @psalm-suppress PossiblyUndefinedArrayOffset */ @@ -33,7 +36,7 @@ public static function parse($value): array return $result; } - private static function validateKeyValuePair(string $pair) + private static function validateKeyValuePair(string $pair): void { if (!str_contains($pair, self::KEY_VALUE_SEPARATOR)) { throw new InvalidArgumentException(sprintf( diff --git a/src/SDK/Common/Configuration/Parser/RatioParser.php b/src/Config/Configuration/Parser/RatioParser.php similarity index 85% rename from src/SDK/Common/Configuration/Parser/RatioParser.php rename to src/Config/Configuration/Parser/RatioParser.php index f0fe32100..ff9335e6c 100644 --- a/src/SDK/Common/Configuration/Parser/RatioParser.php +++ b/src/Config/Configuration/Parser/RatioParser.php @@ -2,17 +2,20 @@ declare(strict_types=1); -namespace OpenTelemetry\SDK\Common\Configuration\Parser; +namespace OpenTelemetry\Config\Configuration\Parser; use InvalidArgumentException; use RangeException; +/** + * @internal + */ class RatioParser { private const MAX_VALUE = 1; private const MIN_VALUE = 0; - public static function parse($value): float + public static function parse(string|int|float $value): float { if (filter_var($value, FILTER_VALIDATE_FLOAT) === false) { throw new InvalidArgumentException( diff --git a/src/SDK/Common/Configuration/Resolver/CompositeResolver.php b/src/Config/Configuration/Resolver/CompositeResolver.php similarity index 85% rename from src/SDK/Common/Configuration/Resolver/CompositeResolver.php rename to src/Config/Configuration/Resolver/CompositeResolver.php index 1054b6239..4e13b5678 100644 --- a/src/SDK/Common/Configuration/Resolver/CompositeResolver.php +++ b/src/Config/Configuration/Resolver/CompositeResolver.php @@ -2,16 +2,16 @@ declare(strict_types=1); -namespace OpenTelemetry\SDK\Common\Configuration\Resolver; +namespace OpenTelemetry\Config\Configuration\Resolver; -use OpenTelemetry\SDK\Common\Configuration\Configuration; +use OpenTelemetry\Config\Configuration\Configuration; /** * @internal */ class CompositeResolver { - /** @var list */ + /** @var ResolverInterface[] */ private array $resolvers = []; public static function instance(): self @@ -42,7 +42,7 @@ public function getResolvers(): array return $this->resolvers; } - public function resolve(string $variableName, $default = '') + public function resolve(string $variableName, mixed $default = ''): mixed { foreach ($this->resolvers as $resolver) { if ($resolver->hasVariable($variableName)) { diff --git a/src/SDK/Common/Configuration/Resolver/EnvironmentResolver.php b/src/Config/Configuration/Resolver/EnvironmentResolver.php similarity index 69% rename from src/SDK/Common/Configuration/Resolver/EnvironmentResolver.php rename to src/Config/Configuration/Resolver/EnvironmentResolver.php index 453f98e39..c7d223a0e 100644 --- a/src/SDK/Common/Configuration/Resolver/EnvironmentResolver.php +++ b/src/Config/Configuration/Resolver/EnvironmentResolver.php @@ -2,9 +2,9 @@ declare(strict_types=1); -namespace OpenTelemetry\SDK\Common\Configuration\Resolver; +namespace OpenTelemetry\Config\Configuration\Resolver; -use OpenTelemetry\SDK\Common\Configuration\Configuration; +use OpenTelemetry\Config\Configuration\Configuration; /** * @internal @@ -24,11 +24,7 @@ public function hasVariable(string $variableName): bool return !Configuration::isEmpty($env); } - /** - * @psalm-suppress InvalidReturnStatement - * @psalm-suppress InvalidReturnType - */ - public function retrieveValue(string $variableName) + public function retrieveValue(string $variableName): mixed { $value = getenv($variableName); if ($value === false) { diff --git a/src/SDK/Common/Configuration/Resolver/PhpIniResolver.php b/src/Config/Configuration/Resolver/PhpIniResolver.php similarity index 74% rename from src/SDK/Common/Configuration/Resolver/PhpIniResolver.php rename to src/Config/Configuration/Resolver/PhpIniResolver.php index 29445dd88..066e01a72 100644 --- a/src/SDK/Common/Configuration/Resolver/PhpIniResolver.php +++ b/src/Config/Configuration/Resolver/PhpIniResolver.php @@ -2,9 +2,10 @@ declare(strict_types=1); -namespace OpenTelemetry\SDK\Common\Configuration\Resolver; +namespace OpenTelemetry\Config\Configuration\Resolver; -use OpenTelemetry\SDK\Common\Configuration\Configuration; +use OpenTelemetry\Config\Configuration\Accessor\PhpIniAccessor; +use OpenTelemetry\Config\Configuration\Configuration; /** * @internal @@ -16,7 +17,7 @@ public function __construct(private readonly PhpIniAccessor $accessor = new PhpI { } - public function retrieveValue(string $variableName) + public function retrieveValue(string $variableName): string|bool { $value = $this->accessor->get($variableName) ?: ''; if (is_array($value)) { diff --git a/src/Config/Configuration/Resolver/ResolverInterface.php b/src/Config/Configuration/Resolver/ResolverInterface.php new file mode 100644 index 000000000..a9ec8a9aa --- /dev/null +++ b/src/Config/Configuration/Resolver/ResolverInterface.php @@ -0,0 +1,12 @@ += 8.1`, an NTS build, `ext-ffi`, and setting the environment variable `OTEL_PHP_FIBERS_ENABLED` to `true`. Additionally `vendor/autoload.php` has to be preloaded for non-CLI SAPIs if [`ffi.enable`](https://www.php.net/manual/en/ffi.configuration.php#ini.ffi.enable) is set to `preload`. ### Event loops diff --git a/src/Context/ZendObserverFiber.php b/src/Context/ZendObserverFiber.php index b700307e3..2db82d50a 100644 --- a/src/Context/ZendObserverFiber.php +++ b/src/Context/ZendObserverFiber.php @@ -11,9 +11,8 @@ use function extension_loaded; use FFI; -use const FILTER_VALIDATE_BOOLEAN; -use function filter_var; -use function is_string; +use OpenTelemetry\Config\Configuration\Configuration; +use OpenTelemetry\Config\Configuration\Variables; use const PHP_VERSION_ID; use const PHP_ZTS; use function sprintf; @@ -26,11 +25,7 @@ final class ZendObserverFiber { public static function isEnabled(): bool { - $enabled = $_SERVER['OTEL_PHP_FIBERS_ENABLED'] ?? false; - - return is_string($enabled) - ? filter_var($enabled, FILTER_VALIDATE_BOOLEAN) - : (bool) $enabled; + return Configuration::getBoolean(Variables::OTEL_PHP_FIBERS_ENABLED); } public static function init(): bool diff --git a/src/Context/composer.json b/src/Context/composer.json index 2717e8e3b..c4b6e13c8 100644 --- a/src/Context/composer.json +++ b/src/Context/composer.json @@ -18,6 +18,8 @@ ], "require": { "php": "^8.1", + "open-telemetry/config": "*", + "symfony/polyfill-php81": "^1.26", "symfony/polyfill-php82": "^1.26" }, "autoload": { diff --git a/src/Contrib/Otlp/LogsExporterFactory.php b/src/Contrib/Otlp/LogsExporterFactory.php index a92cffa3b..62def8ea9 100644 --- a/src/Contrib/Otlp/LogsExporterFactory.php +++ b/src/Contrib/Otlp/LogsExporterFactory.php @@ -5,9 +5,9 @@ namespace OpenTelemetry\Contrib\Otlp; use OpenTelemetry\API\Signals; -use OpenTelemetry\SDK\Common\Configuration\Configuration; -use OpenTelemetry\SDK\Common\Configuration\Defaults; -use OpenTelemetry\SDK\Common\Configuration\Variables; +use OpenTelemetry\Config\Configuration\Configuration; +use OpenTelemetry\Config\Configuration\Defaults; +use OpenTelemetry\Config\Configuration\Variables; use OpenTelemetry\SDK\Common\Export\TransportFactoryInterface; use OpenTelemetry\SDK\Common\Export\TransportInterface; use OpenTelemetry\SDK\Logs\LogRecordExporterFactoryInterface; diff --git a/src/Contrib/Otlp/MetricExporterFactory.php b/src/Contrib/Otlp/MetricExporterFactory.php index 1ba7488f3..3ed4b343a 100644 --- a/src/Contrib/Otlp/MetricExporterFactory.php +++ b/src/Contrib/Otlp/MetricExporterFactory.php @@ -5,9 +5,9 @@ namespace OpenTelemetry\Contrib\Otlp; use OpenTelemetry\API\Signals; -use OpenTelemetry\SDK\Common\Configuration\Configuration; -use OpenTelemetry\SDK\Common\Configuration\Defaults; -use OpenTelemetry\SDK\Common\Configuration\Variables; +use OpenTelemetry\Config\Configuration\Configuration; +use OpenTelemetry\Config\Configuration\Defaults; +use OpenTelemetry\Config\Configuration\Variables; use OpenTelemetry\SDK\Common\Export\TransportFactoryInterface; use OpenTelemetry\SDK\Common\Export\TransportInterface; use OpenTelemetry\SDK\Metrics\Data\Temporality; diff --git a/src/Contrib/Otlp/OtlpUtil.php b/src/Contrib/Otlp/OtlpUtil.php index 3de3085d6..774dd8497 100644 --- a/src/Contrib/Otlp/OtlpUtil.php +++ b/src/Contrib/Otlp/OtlpUtil.php @@ -6,8 +6,8 @@ use function explode; use OpenTelemetry\API\Signals; -use OpenTelemetry\SDK\Common\Configuration\Configuration; -use OpenTelemetry\SDK\Common\Configuration\Variables; +use OpenTelemetry\Config\Configuration\Configuration; +use OpenTelemetry\Config\Configuration\Variables; use OpenTelemetry\SDK\Resource\Detectors\Sdk; use OpenTelemetry\SemConv\ResourceAttributes; use UnexpectedValueException; diff --git a/src/Contrib/Otlp/Protocols.php b/src/Contrib/Otlp/Protocols.php index 736436a8f..d4c90d12c 100644 --- a/src/Contrib/Otlp/Protocols.php +++ b/src/Contrib/Otlp/Protocols.php @@ -4,7 +4,7 @@ namespace OpenTelemetry\Contrib\Otlp; -use OpenTelemetry\SDK\Common\Configuration\KnownValues; +use OpenTelemetry\Config\Configuration\KnownValues; use UnexpectedValueException; class Protocols diff --git a/src/Contrib/Otlp/SpanExporterFactory.php b/src/Contrib/Otlp/SpanExporterFactory.php index 1ef7d49aa..508f87b33 100644 --- a/src/Contrib/Otlp/SpanExporterFactory.php +++ b/src/Contrib/Otlp/SpanExporterFactory.php @@ -6,9 +6,9 @@ use OpenTelemetry\API\Behavior\LogsMessagesTrait; use OpenTelemetry\API\Signals; -use OpenTelemetry\SDK\Common\Configuration\Configuration; -use OpenTelemetry\SDK\Common\Configuration\Defaults; -use OpenTelemetry\SDK\Common\Configuration\Variables; +use OpenTelemetry\Config\Configuration\Configuration; +use OpenTelemetry\Config\Configuration\Defaults; +use OpenTelemetry\Config\Configuration\Variables; use OpenTelemetry\SDK\Common\Export\TransportFactoryInterface; use OpenTelemetry\SDK\Common\Export\TransportInterface; use OpenTelemetry\SDK\Registry; diff --git a/src/Contrib/Zipkin/SpanExporterFactory.php b/src/Contrib/Zipkin/SpanExporterFactory.php index 0714d48da..ec8a6f2db 100644 --- a/src/Contrib/Zipkin/SpanExporterFactory.php +++ b/src/Contrib/Zipkin/SpanExporterFactory.php @@ -4,8 +4,8 @@ namespace OpenTelemetry\Contrib\Zipkin; -use OpenTelemetry\SDK\Common\Configuration\Configuration; -use OpenTelemetry\SDK\Common\Configuration\Variables; +use OpenTelemetry\Config\Configuration\Configuration; +use OpenTelemetry\Config\Configuration\Variables; use OpenTelemetry\SDK\Common\Export\Http\PsrTransportFactory; use OpenTelemetry\SDK\Trace\SpanExporter\SpanExporterFactoryInterface; use OpenTelemetry\SDK\Trace\SpanExporterInterface; diff --git a/src/SDK/Common/Configuration/Resolver/ResolverInterface.php b/src/SDK/Common/Configuration/Resolver/ResolverInterface.php deleted file mode 100644 index 4e88f3ff6..000000000 --- a/src/SDK/Common/Configuration/Resolver/ResolverInterface.php +++ /dev/null @@ -1,15 +0,0 @@ - --ENV-- -OTEL_PHP_FIBERS_ENABLED=1 +OTEL_PHP_FIBERS_ENABLED=true --FILE-- --ENV-- -OTEL_PHP_FIBERS_ENABLED=1 +OTEL_PHP_FIBERS_ENABLED=true --FILE-- --ENV-- -OTEL_PHP_FIBERS_ENABLED=0 +OTEL_PHP_FIBERS_ENABLED=false --FILE-- --ENV-- -OTEL_PHP_FIBERS_ENABLED=0 +OTEL_PHP_FIBERS_ENABLED=false --FILE-- resolver = new ConfigurationResolver(); - } - - public function tearDown(): void - { - $this->restoreEnvironmentVariables(); - } - - /** - * @dataProvider hasProvider - */ - public function test_has(?string $value, bool $expected): void - { - $this->assertFalse($this->resolver->has('OTEL_FOO')); - $this->setEnvironmentVariable('OTEL_FOO', $value); - $this->assertSame($expected, $this->resolver->has('OTEL_FOO')); - } - - public static function hasProvider(): array - { - return [ - ['bar', true], - ['', false], - [null, false], - ]; - } - - public function test_get_string(): void - { - $this->assertFalse($this->resolver->has('OTEL_FOO')); - $this->setEnvironmentVariable('OTEL_FOO', 'bar'); - $this->assertSame('bar', $this->resolver->getString('OTEL_FOO')); - } - - /** - * @dataProvider booleanProvider - */ - public function test_get_boolean(?string $value, ?bool $expected): void - { - $this->assertFalse($this->resolver->has('OTEL_FOO')); - $this->setEnvironmentVariable('OTEL_FOO', $value); - $this->assertSame($expected, $this->resolver->getBoolean('OTEL_FOO')); - } - - public static function booleanProvider(): array - { - return [ - ['true', true], - ['false', false], - ['random', false], - ['', null], - [null, null], - ]; - } - - /** - * @dataProvider intProvider - */ - public function test_get_int(?string $value, ?int $expected): void - { - $this->assertFalse($this->resolver->has('OTEL_FOO')); - $this->setEnvironmentVariable('OTEL_FOO', $value); - $this->assertSame($expected, $this->resolver->getInt('OTEL_FOO')); - } - - public static function intProvider(): array - { - return [ - ['0', 0], - ['1', 1], - ['-1', -1], - ['', null], - [null, null], - ['3.14159', null], - ]; - } - - /** - * @dataProvider listProvider - */ - public function test_get_list(?string $value, array $expected): void - { - $this->assertFalse($this->resolver->has('OTEL_FOO')); - $this->setEnvironmentVariable('OTEL_FOO', $value); - $this->assertSame($expected, $this->resolver->getList('OTEL_FOO')); - } - - public static function listProvider(): array - { - return [ - ['foo,bar,baz', ['foo','bar','baz']], - ['foo', ['foo']], - ['', []], - [null, []], - ]; - } - - public function test_has_when_missing(): void - { - $this->assertFalse($this->resolver->has('OTEL_MISSING')); - } -} diff --git a/tests/Unit/Config/Configuration/Accessor/PhpIniAccessorTest.php b/tests/Unit/Config/Configuration/Accessor/PhpIniAccessorTest.php new file mode 100644 index 000000000..be31e6885 --- /dev/null +++ b/tests/Unit/Config/Configuration/Accessor/PhpIniAccessorTest.php @@ -0,0 +1,23 @@ +get('assert.active'); + + /** @psalm-suppress RedundantCondition */ + $this->assertNotNull($value); + } +} diff --git a/tests/Unit/SDK/Common/Configuration/ConfigurationTest.php b/tests/Unit/Config/Configuration/ConfigurationTest.php similarity index 69% rename from tests/Unit/SDK/Common/Configuration/ConfigurationTest.php rename to tests/Unit/Config/Configuration/ConfigurationTest.php index 994186782..ffde6385c 100644 --- a/tests/Unit/SDK/Common/Configuration/ConfigurationTest.php +++ b/tests/Unit/Config/Configuration/ConfigurationTest.php @@ -2,80 +2,79 @@ declare(strict_types=1); -namespace OpenTelemetry\Tests\Unit\SDK\Common\Configuration; +namespace OpenTelemetry\Tests\Unit\Config\Configuration; use AssertWell\PHPUnitGlobalState\EnvironmentVariables; use Exception; use Generator; -use OpenTelemetry\SDK\Common\Configuration\Configuration; -use OpenTelemetry\SDK\Common\Configuration\Defaults; -use OpenTelemetry\SDK\Common\Configuration\KnownValues; -use OpenTelemetry\SDK\Common\Configuration\Variables; -use OpenTelemetry\SDK\Common\Configuration\VariableTypes; +use OpenTelemetry\Config\Configuration\Configuration; +use OpenTelemetry\Config\Configuration\Defaults; +use OpenTelemetry\Config\Configuration\KnownValues; +use OpenTelemetry\Config\Configuration\Variables; use PHPUnit\Framework\TestCase; use UnexpectedValueException; /** - * @covers \OpenTelemetry\SDK\Common\Configuration\Configuration + * @covers \OpenTelemetry\Config\Configuration\Configuration */ class ConfigurationTest extends TestCase { use EnvironmentVariables; private const ALLOW_EMPTY = [ - VariableTypes::LIST, - VariableTypes::MAP, - VariableTypes::MIXED, + 'list', + 'map', + 'mixed', ]; private const METHOD_NAMES = [ - VariableTypes::STRING => ['getString'], - VariableTypes::BOOL => ['getBoolean'], - VariableTypes::INTEGER => ['getInt'], - VariableTypes::FLOAT => ['getFloat'], - VariableTypes::RATIO => ['getRatio'], - VariableTypes::ENUM => ['getEnum'], - VariableTypes::LIST => ['getList'], - VariableTypes::MAP => ['getMap'], - VariableTypes::MIXED => ['getMixed'], + 'string' => ['getString'], + 'bool' => ['getBoolean'], + 'integer' => ['getInt'], + 'float' => ['getFloat'], + 'ratio' => ['getRatio'], + 'enum' => ['getEnum'], + 'list' => ['getList'], + 'map' => ['getMap'], + 'mixed' => ['getMixed'], ]; private const TYPES = [ - VariableTypes::STRING => [Variables::OTEL_SERVICE_NAME], - VariableTypes::BOOL => [Variables::OTEL_EXPORTER_OTLP_INSECURE], - VariableTypes::INTEGER => [Variables::OTEL_BSP_MAX_QUEUE_SIZE], - VariableTypes::ENUM => [Variables::OTEL_LOG_LEVEL], - VariableTypes::LIST => [Variables::OTEL_PROPAGATORS], - VariableTypes::MAP => [Variables::OTEL_RESOURCE_ATTRIBUTES], - VariableTypes::MIXED => [Variables::OTEL_TRACES_SAMPLER_ARG], + 'string' => [Variables::OTEL_SERVICE_NAME], + 'bool' => [Variables::OTEL_EXPORTER_OTLP_INSECURE], + 'integer' => [Variables::OTEL_BSP_MAX_QUEUE_SIZE], + 'enum' => [Variables::OTEL_LOG_LEVEL], + 'list' => [Variables::OTEL_PROPAGATORS], + 'map' => [Variables::OTEL_RESOURCE_ATTRIBUTES], + 'mixed' => [Variables::OTEL_TRACES_SAMPLER_ARG], ]; private const USER_VALUES = [ - VariableTypes::STRING => ['foo', 'foo'], - VariableTypes::BOOL => ['true', true], - VariableTypes::INTEGER => ['42', 42], - VariableTypes::ENUM => ['val1', 'val1'], - VariableTypes::LIST => [['val1', 'val2'], ['val1','val2']], - VariableTypes::MAP => [['var1' => 'val1', 'var2' => 'val2'], ['var1'=>'val1','var2'=>'val2']], - VariableTypes::MIXED => ['foo', 'foo'], + 'string' => ['foo', 'foo'], + 'bool' => ['true', true], + 'integer' => ['42', 42], + 'enum' => ['val1', 'val1'], + 'list' => [['val1', 'val2'], ['val1','val2']], + 'map' => [['var1' => 'val1', 'var2' => 'val2'], ['var1'=>'val1','var2'=>'val2']], + 'mixed' => ['foo', 'foo'], ]; private const USER_ENV_VALUES = [ - VariableTypes::STRING => ['foo', 'foo'], - VariableTypes::BOOL => ['true', true], - VariableTypes::INTEGER => ['42', 42], - VariableTypes::ENUM => ['val1', 'val1'], - VariableTypes::LIST => ['val1,val2', ['val1','val2']], - VariableTypes::MAP => ['var1=val1,var2=val2', ['var1'=>'val1','var2'=>'val2']], - VariableTypes::MIXED => ['foo', 'foo'], + 'string' => ['foo', 'foo'], + 'bool' => ['true', true], + 'integer' => ['42', 42], + 'enum' => ['val1', 'val1'], + 'list' => ['val1,val2', ['val1','val2']], + 'map' => ['var1=val1,var2=val2', ['var1'=>'val1','var2'=>'val2']], + 'mixed' => ['foo', 'foo'], ]; private const LIBRARY_DEFAULTS = [ - VariableTypes::STRING => [Variables::OTEL_EXPORTER_OTLP_ENDPOINT, 'http://localhost:4318'], - VariableTypes::BOOL => [Variables::OTEL_EXPORTER_OTLP_INSECURE, false], - VariableTypes::INTEGER => [Variables::OTEL_BSP_MAX_QUEUE_SIZE, 2048], - VariableTypes::ENUM => [Variables::OTEL_LOG_LEVEL, 'info'], - VariableTypes::LIST => [Variables::OTEL_PROPAGATORS, ['tracecontext', 'baggage']], + 'string' => [Variables::OTEL_EXPORTER_OTLP_ENDPOINT, 'http://localhost:4318'], + 'bool' => [Variables::OTEL_EXPORTER_OTLP_INSECURE, false], + 'integer' => [Variables::OTEL_BSP_MAX_QUEUE_SIZE, 2048], + 'enum' => [Variables::OTEL_LOG_LEVEL, 'info'], + 'list' => [Variables::OTEL_PROPAGATORS, ['tracecontext', 'baggage']], ]; private const DEFAULT_VALUES = [ @@ -85,10 +84,10 @@ class ConfigurationTest extends TestCase ]; private const NO_DEFAULTS = [ - VariableTypes::STRING => [Variables::OTEL_SERVICE_NAME], - VariableTypes::ENUM => [Variables::OTEL_EXPORTER_OTLP_COMPRESSION], - VariableTypes::MAP => [Variables::OTEL_EXPORTER_OTLP_HEADERS], - VariableTypes::MIXED => [Variables::OTEL_TRACES_SAMPLER_ARG], + 'string' => [Variables::OTEL_SERVICE_NAME], + 'enum' => [Variables::OTEL_EXPORTER_OTLP_COMPRESSION], + 'map' => [Variables::OTEL_EXPORTER_OTLP_HEADERS], + 'mixed' => [Variables::OTEL_TRACES_SAMPLER_ARG], ]; private const KNOWN_VALUES = [ @@ -262,16 +261,6 @@ public function test_no_value_throws_exception(string $methodName): void call_user_func([Configuration::class, $methodName], 'FOO_BAR_' . $methodName); } - /** - * @dataProvider invalidTypeProvider - */ - public function test_invalid_type_throws_exception(string $methodName, string $variable): void - { - $this->expectException(UnexpectedValueException::class); - - call_user_func([Configuration::class, $methodName], $variable); - } - /** * @dataProvider noDefaultProvider */ @@ -334,24 +323,6 @@ public static function nonEmptyMethodNameProvider(): Generator } } - public static function invalidTypeProvider(): Generator - { - foreach (self::METHOD_NAMES as $varType => $names) { - if ($varType === VariableTypes::MIXED) { - continue; - } - $methodName = $names[0]; - foreach (self::TYPES as $methodType => $types) { - if ($varType === $methodType || $methodType === VariableTypes::MIXED) { - continue; - } - $variableName = $types[0]; - - yield sprintf('%s - %s', $varType, $methodType) => [$methodName, $variableName]; - } - } - } - public static function noDefaultProvider(): Generator { foreach (self::NO_DEFAULTS as $varType => $values) { @@ -400,30 +371,6 @@ public function test_retrieve_value_library_default(): void ); } - /** - * @dataProvider typeProvider - */ - public function test_get_type(string $varName, string $type): void - { - $this->assertSame( - $type, - Configuration::getType($varName) - ); - } - - public static function typeProvider(): array - { - return [ - 'bool' => ['OTEL_EXPORTER_OTLP_INSECURE', VariableTypes::BOOL], - 'string' => ['OTEL_SERVICE_NAME', VariableTypes::STRING], - 'integer' => ['OTEL_BSP_MAX_QUEUE_SIZE', VariableTypes::INTEGER], - 'enum' => ['OTEL_LOG_LEVEL', VariableTypes::ENUM], - 'list' => ['OTEL_PROPAGATORS', VariableTypes::LIST], - 'map' => ['OTEL_RESOURCE_ATTRIBUTES', VariableTypes::MAP], - 'mixed' => ['OTEL_TRACES_SAMPLER_ARG', VariableTypes::MIXED], - ]; - } - /** * @dataProvider defaultValueProvider */ diff --git a/tests/Unit/SDK/Common/Configuration/Parser/BooleanParserTest.php b/tests/Unit/Config/Configuration/Parser/BooleanParserTest.php similarity index 81% rename from tests/Unit/SDK/Common/Configuration/Parser/BooleanParserTest.php rename to tests/Unit/Config/Configuration/Parser/BooleanParserTest.php index 97fde7e44..8fa7883e8 100644 --- a/tests/Unit/SDK/Common/Configuration/Parser/BooleanParserTest.php +++ b/tests/Unit/Config/Configuration/Parser/BooleanParserTest.php @@ -2,14 +2,14 @@ declare(strict_types=1); -namespace OpenTelemetry\Tests\Unit\SDK\Common\Configuration\Parser; +namespace OpenTelemetry\Tests\Unit\Config\Configuration\Parser; use InvalidArgumentException; -use OpenTelemetry\SDK\Common\Configuration\Parser\BooleanParser; +use OpenTelemetry\Config\Configuration\Parser\BooleanParser; use PHPUnit\Framework\TestCase; /** - * @covers \OpenTelemetry\SDK\Common\Configuration\Parser\BooleanParser + * @covers \OpenTelemetry\Config\Configuration\Parser\BooleanParser */ class BooleanParserTest extends TestCase { @@ -100,4 +100,20 @@ public static function nonBooleanValueProvider(): array { return self::NON_BOOLEAN_VALUES; } + + /** + * @dataProvider boolProvider + */ + public function test_boolean(bool $bool): void + { + $this->assertSame($bool, BooleanParser::parse($bool)); + } + + public static function boolProvider(): array + { + return [ + [true], + [false], + ]; + } } diff --git a/tests/Unit/SDK/Common/Configuration/Parser/ListParserTest.php b/tests/Unit/Config/Configuration/Parser/ListParserTest.php similarity index 67% rename from tests/Unit/SDK/Common/Configuration/Parser/ListParserTest.php rename to tests/Unit/Config/Configuration/Parser/ListParserTest.php index 17eb7a834..2a6a66149 100644 --- a/tests/Unit/SDK/Common/Configuration/Parser/ListParserTest.php +++ b/tests/Unit/Config/Configuration/Parser/ListParserTest.php @@ -2,12 +2,13 @@ declare(strict_types=1); -namespace OpenTelemetry\Tests\Unit\SDK\Common\Configuration\Parser; +namespace OpenTelemetry\Tests\Unit\Config\Configuration\Parser; +use OpenTelemetry\Config\Configuration\Parser\ListParser; use PHPUnit\Framework\TestCase; /** - * @covers \OpenTelemetry\SDK\Common\Configuration\Parser\ListParser + * @covers \OpenTelemetry\Config\Configuration\Parser\ListParser */ class ListParserTest extends TestCase { @@ -32,15 +33,19 @@ class ListParserTest extends TestCase 'foo, bar , faz, baz', ['foo', 'bar', 'faz', 'baz'], ], + 'array' => [ + ['foo', 'bar'], + ['foo', 'bar'], + ], ]; /** * @dataProvider listValueProvider */ - public function test_comma_separated_list_returns_array(string $value, array $expected): void + public function test_comma_separated_list_returns_array(mixed $value, array $expected): void { $this->assertSame( - \OpenTelemetry\SDK\Common\Configuration\Parser\ListParser::parse($value), + ListParser::parse($value), $expected ); } diff --git a/tests/Unit/SDK/Common/Configuration/Parser/MapParserTest.php b/tests/Unit/Config/Configuration/Parser/MapParserTest.php similarity index 76% rename from tests/Unit/SDK/Common/Configuration/Parser/MapParserTest.php rename to tests/Unit/Config/Configuration/Parser/MapParserTest.php index 85f8f941f..4164f6dc0 100644 --- a/tests/Unit/SDK/Common/Configuration/Parser/MapParserTest.php +++ b/tests/Unit/Config/Configuration/Parser/MapParserTest.php @@ -2,13 +2,14 @@ declare(strict_types=1); -namespace OpenTelemetry\Tests\Unit\SDK\Common\Configuration\Parser; +namespace OpenTelemetry\Tests\Unit\Config\Configuration\Parser; use InvalidArgumentException; +use OpenTelemetry\Config\Configuration\Parser\MapParser; use PHPUnit\Framework\TestCase; /** - * @covers \OpenTelemetry\SDK\Common\Configuration\Parser\MapParser + * @covers \OpenTelemetry\Config\Configuration\Parser\MapParser */ class MapParserTest extends TestCase { @@ -33,6 +34,10 @@ class MapParserTest extends TestCase 'Authorization=Basic 1234abc=,bar=baz', ['Authorization' => 'Basic 1234abc=', 'bar' => 'baz'], ], + 'array' => [ + ['foo' => 'foo', 'bar' => 'bar'], + ['foo' => 'foo', 'bar' => 'bar'], + ], ]; private const INVALID_VALUES = [ @@ -43,10 +48,10 @@ class MapParserTest extends TestCase /** * @dataProvider mapValueProvider */ - public function test_map_values_return_array(string $value, array $expected): void + public function test_map_values_return_array(string|array $value, array $expected): void { $this->assertSame( - \OpenTelemetry\SDK\Common\Configuration\Parser\MapParser::parse($value), + MapParser::parse($value), $expected ); } @@ -58,7 +63,7 @@ public function test_invalid_values_throw_exception(string $value): void { $this->expectException(InvalidArgumentException::class); - \OpenTelemetry\SDK\Common\Configuration\Parser\MapParser::parse($value); + MapParser::parse($value); } public static function mapValueProvider(): array diff --git a/tests/Unit/SDK/Common/Configuration/Parser/RatioParserTest.php b/tests/Unit/Config/Configuration/Parser/RatioParserTest.php similarity index 88% rename from tests/Unit/SDK/Common/Configuration/Parser/RatioParserTest.php rename to tests/Unit/Config/Configuration/Parser/RatioParserTest.php index 36300225b..4345d8dba 100644 --- a/tests/Unit/SDK/Common/Configuration/Parser/RatioParserTest.php +++ b/tests/Unit/Config/Configuration/Parser/RatioParserTest.php @@ -2,15 +2,15 @@ declare(strict_types=1); -namespace OpenTelemetry\Tests\Unit\SDK\Common\Configuration\Parser; +namespace OpenTelemetry\Tests\Unit\Config\Configuration\Parser; use InvalidArgumentException; -use OpenTelemetry\SDK\Common\Configuration\Parser\RatioParser; +use OpenTelemetry\Config\Configuration\Parser\RatioParser; use PHPUnit\Framework\TestCase; use RangeException; /** - * @covers \OpenTelemetry\SDK\Common\Configuration\Parser\RatioParser + * @covers \OpenTelemetry\Config\Configuration\Parser\RatioParser */ class RatioParserTest extends TestCase { diff --git a/tests/Unit/SDK/Common/Configuration/Resolver/CompositeResolverTest.php b/tests/Unit/Config/Configuration/Resolver/CompositeResolverTest.php similarity index 83% rename from tests/Unit/SDK/Common/Configuration/Resolver/CompositeResolverTest.php rename to tests/Unit/Config/Configuration/Resolver/CompositeResolverTest.php index 74d8d5c0f..2018074c2 100644 --- a/tests/Unit/SDK/Common/Configuration/Resolver/CompositeResolverTest.php +++ b/tests/Unit/Config/Configuration/Resolver/CompositeResolverTest.php @@ -2,22 +2,23 @@ declare(strict_types=1); -namespace OpenTelemetry\Tests\Unit\SDK\Common\Configuration\Resolver; +namespace OpenTelemetry\Tests\Unit\Config\Configuration\Resolver; -use OpenTelemetry\SDK\Common\Configuration\Defaults; -use OpenTelemetry\SDK\Common\Configuration\Resolver\CompositeResolver; -use OpenTelemetry\SDK\Common\Configuration\Resolver\ResolverInterface; -use OpenTelemetry\SDK\Common\Configuration\Variables; +use OpenTelemetry\Config\Configuration\Defaults; +use OpenTelemetry\Config\Configuration\Resolver\CompositeResolver; +use OpenTelemetry\Config\Configuration\Resolver\ResolverInterface; +use OpenTelemetry\Config\Configuration\Variables; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; /** - * @covers \OpenTelemetry\SDK\Common\Configuration\Resolver\CompositeResolver + * @covers \OpenTelemetry\Config\Configuration\Resolver\CompositeResolver * @psalm-suppress UndefinedInterfaceMethod */ class CompositeResolverTest extends TestCase { - private ResolverInterface $one; - private ResolverInterface $two; + private ResolverInterface&MockObject $one; + private ResolverInterface&MockObject $two; private CompositeResolver $resolver; public function setUp(): void diff --git a/tests/Unit/SDK/Common/Configuration/Resolver/EnvironmentResolverTest.php b/tests/Unit/Config/Configuration/Resolver/EnvironmentResolverTest.php similarity index 92% rename from tests/Unit/SDK/Common/Configuration/Resolver/EnvironmentResolverTest.php rename to tests/Unit/Config/Configuration/Resolver/EnvironmentResolverTest.php index 280c21476..8807b74d4 100644 --- a/tests/Unit/SDK/Common/Configuration/Resolver/EnvironmentResolverTest.php +++ b/tests/Unit/Config/Configuration/Resolver/EnvironmentResolverTest.php @@ -2,14 +2,14 @@ declare(strict_types=1); -namespace OpenTelemetry\Tests\Unit\SDK\Common\Configuration\Resolver; +namespace OpenTelemetry\Tests\Unit\Config\Configuration\Resolver; use AssertWell\PHPUnitGlobalState\EnvironmentVariables; -use OpenTelemetry\SDK\Common\Configuration\Resolver\EnvironmentResolver; +use OpenTelemetry\Config\Configuration\Resolver\EnvironmentResolver; use PHPUnit\Framework\TestCase; /** - * @covers \OpenTelemetry\SDK\Common\Configuration\Resolver\EnvironmentResolver + * @covers \OpenTelemetry\Config\Configuration\Resolver\EnvironmentResolver */ class EnvironmentResolverTest extends TestCase { diff --git a/tests/Unit/SDK/Common/Configuration/Resolver/PhpIniResolverTest.php b/tests/Unit/Config/Configuration/Resolver/PhpIniResolverTest.php similarity index 77% rename from tests/Unit/SDK/Common/Configuration/Resolver/PhpIniResolverTest.php rename to tests/Unit/Config/Configuration/Resolver/PhpIniResolverTest.php index 33b7489fc..c276e5691 100644 --- a/tests/Unit/SDK/Common/Configuration/Resolver/PhpIniResolverTest.php +++ b/tests/Unit/Config/Configuration/Resolver/PhpIniResolverTest.php @@ -2,19 +2,20 @@ declare(strict_types=1); -namespace OpenTelemetry\Tests\Unit\SDK\Common\Configuration\Resolver; +namespace OpenTelemetry\Tests\Unit\Config\Configuration\Resolver; -use OpenTelemetry\SDK\Common\Configuration\Resolver\PhpIniAccessor; -use OpenTelemetry\SDK\Common\Configuration\Resolver\PhpIniResolver; +use OpenTelemetry\Config\Configuration\Accessor\PhpIniAccessor; +use OpenTelemetry\Config\Configuration\Resolver\PhpIniResolver; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; /** - * @covers \OpenTelemetry\SDK\Common\Configuration\Resolver\PhpIniResolver + * @covers \OpenTelemetry\Config\Configuration\Resolver\PhpIniResolver * @psalm-suppress UndefinedMethod */ class PhpIniResolverTest extends TestCase { - private PhpIniAccessor $accessor; + private PhpIniAccessor&MockObject $accessor; private PhpIniResolver $resolver; public function setUp(): void @@ -50,7 +51,7 @@ public static function hasVariableProvider(): array 'string' => ['foo', true], 'array' => [['foo'], true], 'empty string' => ['', false], - 'null' => [null, false], + 'false' => [false, false], 'empty array' => [[], false], ]; } diff --git a/tests/Unit/Context/ContextTest.php b/tests/Unit/Context/ContextTest.php index b023300a4..44b730c33 100644 --- a/tests/Unit/Context/ContextTest.php +++ b/tests/Unit/Context/ContextTest.php @@ -4,6 +4,8 @@ namespace OpenTelemetry\Tests\Unit\Context; +use AssertWell\PHPUnitGlobalState\EnvironmentVariables; +use OpenTelemetry\Config\Configuration\Variables; use OpenTelemetry\Context\Context; use OpenTelemetry\Context\ContextKeys; use OpenTelemetry\Context\DebugScope; @@ -16,6 +18,14 @@ */ class ContextTest extends TestCase { + use EnvironmentVariables; + + public function tearDown(): void + { + $this->restoreEnvironmentVariables(); + unset($_SERVER[Variables::OTEL_PHP_DEBUG_SCOPES_DISABLED]); + } + public function test_activate(): void { $context = Context::getRoot(); @@ -179,87 +189,31 @@ public function test_attach_and_detach_set_current_ctx(): void } } - public function test_debug_scopes_disabled_env_var(): void + public function test_debug_scopes_disabled(): void { - \putenv('OTEL_PHP_DEBUG_SCOPES_DISABLED=1'); + $this->setEnvironmentVariable(Variables::OTEL_PHP_DEBUG_SCOPES_DISABLED, 'true'); $context = Context::getRoot(); - $scope = $context->activate(); try { $this->assertNotInstanceOf(DebugScope::class, $scope); } finally { $scope->detach(); - \putenv('OTEL_PHP_DEBUG_SCOPES_DISABLED'); } } - public function test_debug_scopes_disabled_server_var(): void + public function test_debug_scopes_disabled_false(): void { - $_SERVER['OTEL_PHP_DEBUG_SCOPES_DISABLED'] = '1'; + $this->setEnvironmentVariable(Variables::OTEL_PHP_DEBUG_SCOPES_DISABLED, 'false'); $context = Context::getRoot(); - - $scope = $context->activate(); - - try { - $this->assertNotInstanceOf(DebugScope::class, $scope); - } finally { - $scope->detach(); - unset($_SERVER['OTEL_PHP_DEBUG_SCOPES_DISABLED']); - } - } - - public function test_debug_scopes_disabled_order_server(): void - { - $_SERVER['OTEL_PHP_DEBUG_SCOPES_DISABLED'] = '1'; - \putenv('OTEL_PHP_DEBUG_SCOPES_DISABLED=0'); - - $context = Context::getRoot(); - - $scope = $context->activate(); - - try { - $this->assertNotInstanceOf(DebugScope::class, $scope); - } finally { - $scope->detach(); - unset($_SERVER['OTEL_PHP_DEBUG_SCOPES_DISABLED']); - \putenv('OTEL_PHP_DEBUG_SCOPES_DISABLED'); - } - } - - public function test_debug_scopes_disabled_falsey_server(): void - { - $_SERVER['OTEL_PHP_DEBUG_SCOPES_DISABLED'] = '0'; - \putenv('OTEL_PHP_DEBUG_SCOPES_DISABLED=1'); - - $context = Context::getRoot(); - - $scope = $context->activate(); - - try { - $this->assertInstanceOf(DebugScope::class, $scope); - } finally { - $scope->detach(); - unset($_SERVER['OTEL_PHP_DEBUG_SCOPES_DISABLED']); - \putenv('OTEL_PHP_DEBUG_SCOPES_DISABLED'); - } - } - - public function test_debug_scopes_disabled_falsey_env(): void - { - \putenv('OTEL_PHP_DEBUG_SCOPES_DISABLED=0'); - - $context = Context::getRoot(); - $scope = $context->activate(); try { $this->assertInstanceOf(DebugScope::class, $scope); } finally { $scope->detach(); - \putenv('OTEL_PHP_DEBUG_SCOPES_DISABLED'); } } } diff --git a/tests/Unit/Contrib/Otlp/LogsExporterFactoryTest.php b/tests/Unit/Contrib/Otlp/LogsExporterFactoryTest.php index eab64311a..2c5375963 100644 --- a/tests/Unit/Contrib/Otlp/LogsExporterFactoryTest.php +++ b/tests/Unit/Contrib/Otlp/LogsExporterFactoryTest.php @@ -5,9 +5,9 @@ namespace OpenTelemetry\Tests\Unit\Contrib\Otlp; use AssertWell\PHPUnitGlobalState\EnvironmentVariables; +use OpenTelemetry\Config\Configuration\KnownValues; +use OpenTelemetry\Config\Configuration\Variables; use OpenTelemetry\Contrib\Otlp\LogsExporterFactory; -use OpenTelemetry\SDK\Common\Configuration\KnownValues; -use OpenTelemetry\SDK\Common\Configuration\Variables; use OpenTelemetry\SDK\Common\Export\TransportFactoryInterface; use OpenTelemetry\SDK\Common\Export\TransportInterface; use PHPUnit\Framework\MockObject\MockObject; diff --git a/tests/Unit/Contrib/Otlp/MetricExporterFactoryTest.php b/tests/Unit/Contrib/Otlp/MetricExporterFactoryTest.php index fc9f406ba..1e5329f56 100644 --- a/tests/Unit/Contrib/Otlp/MetricExporterFactoryTest.php +++ b/tests/Unit/Contrib/Otlp/MetricExporterFactoryTest.php @@ -5,9 +5,9 @@ namespace OpenTelemetry\Tests\Unit\Contrib\Otlp; use AssertWell\PHPUnitGlobalState\EnvironmentVariables; +use OpenTelemetry\Config\Configuration\KnownValues; +use OpenTelemetry\Config\Configuration\Variables; use OpenTelemetry\Contrib\Otlp\MetricExporterFactory; -use OpenTelemetry\SDK\Common\Configuration\KnownValues; -use OpenTelemetry\SDK\Common\Configuration\Variables; use OpenTelemetry\SDK\Common\Export\TransportFactoryInterface; use OpenTelemetry\SDK\Common\Export\TransportInterface; use OpenTelemetry\SDK\Metrics\AggregationTemporalitySelectorInterface; diff --git a/tests/Unit/Contrib/Otlp/OtlpUtilTest.php b/tests/Unit/Contrib/Otlp/OtlpUtilTest.php index 8b22c6383..c02b98323 100644 --- a/tests/Unit/Contrib/Otlp/OtlpUtilTest.php +++ b/tests/Unit/Contrib/Otlp/OtlpUtilTest.php @@ -6,8 +6,8 @@ use AssertWell\PHPUnitGlobalState\EnvironmentVariables; use OpenTelemetry\API\Signals; +use OpenTelemetry\Config\Configuration\Variables; use OpenTelemetry\Contrib\Otlp\OtlpUtil; -use OpenTelemetry\SDK\Common\Configuration\Variables; use PHPUnit\Framework\TestCase; /** diff --git a/tests/Unit/Contrib/Otlp/SpanExporterFactoryTest.php b/tests/Unit/Contrib/Otlp/SpanExporterFactoryTest.php index af39021fb..620ffde15 100644 --- a/tests/Unit/Contrib/Otlp/SpanExporterFactoryTest.php +++ b/tests/Unit/Contrib/Otlp/SpanExporterFactoryTest.php @@ -5,9 +5,9 @@ namespace OpenTelemetry\Tests\Unit\Contrib\Otlp; use AssertWell\PHPUnitGlobalState\EnvironmentVariables; +use OpenTelemetry\Config\Configuration\KnownValues; +use OpenTelemetry\Config\Configuration\Variables; use OpenTelemetry\Contrib\Otlp\SpanExporterFactory; -use OpenTelemetry\SDK\Common\Configuration\KnownValues; -use OpenTelemetry\SDK\Common\Configuration\Variables; use OpenTelemetry\SDK\Common\Export\TransportFactoryInterface; use OpenTelemetry\SDK\Common\Export\TransportInterface; use PHPUnit\Framework\TestCase; diff --git a/tests/Unit/SDK/Common/Util/ClassConstantAccessorTest.php b/tests/Unit/SDK/Common/Util/ClassConstantAccessorTest.php index 801d25253..9b90a3732 100644 --- a/tests/Unit/SDK/Common/Util/ClassConstantAccessorTest.php +++ b/tests/Unit/SDK/Common/Util/ClassConstantAccessorTest.php @@ -5,11 +5,11 @@ namespace OpenTelemetry\Tests\Unit\SDK\Common\Util; use LogicException; -use OpenTelemetry\SDK\Common\Util\ClassConstantAccessor; +use OpenTelemetry\Config\Configuration\Accessor\ClassConstantAccessor; use PHPUnit\Framework\TestCase; /** - * @covers \OpenTelemetry\SDK\Common\Util\ClassConstantAccessor + * @covers \OpenTelemetry\Config\Configuration\Accessor\ClassConstantAccessor */ class ClassConstantAccessorTest extends TestCase { diff --git a/tests/Unit/SDK/Logs/LogRecordProcessorFactoryTest.php b/tests/Unit/SDK/Logs/LogRecordProcessorFactoryTest.php index 3154066fd..22d14f673 100644 --- a/tests/Unit/SDK/Logs/LogRecordProcessorFactoryTest.php +++ b/tests/Unit/SDK/Logs/LogRecordProcessorFactoryTest.php @@ -5,7 +5,7 @@ namespace OpenTelemetry\Tests\Unit\SDK\Logs; use AssertWell\PHPUnitGlobalState\EnvironmentVariables; -use OpenTelemetry\SDK\Common\Configuration\Variables; +use OpenTelemetry\Config\Configuration\Variables; use OpenTelemetry\SDK\Logs\LogRecordExporterInterface; use OpenTelemetry\SDK\Logs\LogRecordProcessorFactory; use OpenTelemetry\SDK\Logs\Processor\BatchLogRecordProcessor; diff --git a/tests/Unit/SDK/Metrics/MeterProviderFactoryTest.php b/tests/Unit/SDK/Metrics/MeterProviderFactoryTest.php index c6370bb15..fd5ec0936 100644 --- a/tests/Unit/SDK/Metrics/MeterProviderFactoryTest.php +++ b/tests/Unit/SDK/Metrics/MeterProviderFactoryTest.php @@ -7,8 +7,8 @@ use AssertWell\PHPUnitGlobalState\EnvironmentVariables; use OpenTelemetry\API\LoggerHolder; use OpenTelemetry\API\Metrics\MeterInterface; -use OpenTelemetry\SDK\Common\Configuration\KnownValues; -use OpenTelemetry\SDK\Common\Configuration\Variables; +use OpenTelemetry\Config\Configuration\KnownValues; +use OpenTelemetry\Config\Configuration\Variables; use OpenTelemetry\SDK\Metrics\MeterProviderFactory; use PHPUnit\Framework\TestCase; use Psr\Log\NullLogger; diff --git a/tests/Unit/SDK/Propagation/PropagatorFactoryTest.php b/tests/Unit/SDK/Propagation/PropagatorFactoryTest.php index 67fdb4f91..b9522d0b6 100644 --- a/tests/Unit/SDK/Propagation/PropagatorFactoryTest.php +++ b/tests/Unit/SDK/Propagation/PropagatorFactoryTest.php @@ -8,14 +8,14 @@ use OpenTelemetry\API\Baggage\Propagation\BaggagePropagator; use OpenTelemetry\API\LoggerHolder; use OpenTelemetry\API\Trace\Propagation\TraceContextPropagator; +use OpenTelemetry\Config\Configuration\KnownValues; +use OpenTelemetry\Config\Configuration\Variables; use OpenTelemetry\Context\Propagation\MultiTextMapPropagator; use OpenTelemetry\Context\Propagation\NoopTextMapPropagator; use OpenTelemetry\Extension\Propagator\B3\B3Propagator; use OpenTelemetry\Extension\Propagator\CloudTrace\CloudTracePropagator; use OpenTelemetry\Extension\Propagator\Jaeger\JaegerBaggagePropagator; use OpenTelemetry\Extension\Propagator\Jaeger\JaegerPropagator; -use OpenTelemetry\SDK\Common\Configuration\KnownValues; -use OpenTelemetry\SDK\Common\Configuration\Variables; use OpenTelemetry\SDK\Propagation\PropagatorFactory; use PHPUnit\Framework\TestCase; use Psr\Log\NullLogger; diff --git a/tests/Unit/SDK/SdkAutoloaderTest.php b/tests/Unit/SDK/SdkAutoloaderTest.php index e053cc0f5..6fd6aedea 100644 --- a/tests/Unit/SDK/SdkAutoloaderTest.php +++ b/tests/Unit/SDK/SdkAutoloaderTest.php @@ -10,8 +10,8 @@ use OpenTelemetry\API\Logs\NoopLoggerProvider; use OpenTelemetry\API\Metrics\Noop\NoopMeterProvider; use OpenTelemetry\API\Trace\NoopTracerProvider; +use OpenTelemetry\Config\Configuration\Variables; use OpenTelemetry\Context\Propagation\NoopTextMapPropagator; -use OpenTelemetry\SDK\Common\Configuration\Variables; use OpenTelemetry\SDK\SdkAutoloader; use PHPUnit\Framework\TestCase; use Psr\Log\NullLogger; diff --git a/tests/Unit/SDK/SdkTest.php b/tests/Unit/SDK/SdkTest.php index 4eff6943f..bc21518f1 100644 --- a/tests/Unit/SDK/SdkTest.php +++ b/tests/Unit/SDK/SdkTest.php @@ -5,8 +5,8 @@ namespace OpenTelemetry\Tests\Unit\SDK; use AssertWell\PHPUnitGlobalState\EnvironmentVariables; +use OpenTelemetry\Config\Configuration\Variables; use OpenTelemetry\Context\Propagation\TextMapPropagatorInterface; -use OpenTelemetry\SDK\Common\Configuration\Variables; use OpenTelemetry\SDK\Logs\LoggerProviderInterface; use OpenTelemetry\SDK\Metrics\MeterProviderInterface; use OpenTelemetry\SDK\Sdk;