diff --git a/examples/traces/exporters/in_memory.php b/examples/traces/exporters/in_memory.php index 1e9d1ad48..b421e6cd3 100644 --- a/examples/traces/exporters/in_memory.php +++ b/examples/traces/exporters/in_memory.php @@ -34,6 +34,7 @@ $childSpan2->end(); $childSpan1->end(); $rootSpan->end(); +$rootScope->detach(); /** @var SpanDataInterface $span */ foreach ($storage as $span) { diff --git a/src/API/Signals.php b/src/API/Signals.php index c533470c4..95582aaa2 100644 --- a/src/API/Signals.php +++ b/src/API/Signals.php @@ -4,9 +4,7 @@ namespace OpenTelemetry\API; -use InvalidArgumentException; - -class Signals +interface Signals { /** @var string */ public const TRACE = 'trace'; @@ -20,11 +18,4 @@ class Signals self::METRICS, self::LOGS, ]; - - public static function validate(string $signal): void - { - if (!in_array($signal, self::SIGNALS)) { - throw new InvalidArgumentException('Unknown signal: ' . $signal); - } - } } diff --git a/src/API/Trace/SpanKind.php b/src/API/Trace/SpanKind.php index 83112daeb..f44339e00 100644 --- a/src/API/Trace/SpanKind.php +++ b/src/API/Trace/SpanKind.php @@ -7,26 +7,11 @@ /** * @see https://github.com/open-telemetry/opentelemetry-specification/blob/v1.6.1/specification/trace/api.md#spankind */ -final class SpanKind +interface SpanKind { public const KIND_INTERNAL = 0; public const KIND_CLIENT = 1; public const KIND_SERVER = 2; public const KIND_PRODUCER = 3; public const KIND_CONSUMER = 4; - - public static function getChoices(): array - { - return [ - self::KIND_INTERNAL, - self::KIND_CLIENT, - self::KIND_SERVER, - self::KIND_PRODUCER, - self::KIND_CONSUMER, - ]; - } - - private function __construct() - { - } } diff --git a/src/API/Trace/StatusCode.php b/src/API/Trace/StatusCode.php index f03cdb56c..0d95e96a5 100644 --- a/src/API/Trace/StatusCode.php +++ b/src/API/Trace/StatusCode.php @@ -7,22 +7,9 @@ /** * @see https://github.com/open-telemetry/opentelemetry-specification/blob/v1.6.1/specification/trace/api.md#set-status */ -final class StatusCode +interface StatusCode { public const STATUS_UNSET = 'Unset'; public const STATUS_OK = 'Ok'; public const STATUS_ERROR = 'Error'; - - public function getChoices(): array - { - return [ - self::STATUS_UNSET, - self::STATUS_OK, - self::STATUS_ERROR, - ]; - } - - private function __construct() - { - } } diff --git a/src/Context/Propagation/TextMapPropagator.php b/src/Context/Propagation/TextMapPropagator.php deleted file mode 100644 index debf41a22..000000000 --- a/src/Context/Propagation/TextMapPropagator.php +++ /dev/null @@ -1,28 +0,0 @@ -messageFactoryResolver->resolveUriFactory(); } - public function resolveHttpClient(): ClientInterface - { - return $this->psrClientResolver->resolvePsrClient(); - } - public function resolveHttpPlugAsyncClient(): HttpAsyncClient { return $this->httpPlugClientResolver->resolveHttpPlugAsyncClient(); diff --git a/src/SDK/Common/Export/Http/PsrTransportFactory.php b/src/SDK/Common/Export/Http/PsrTransportFactory.php index 6f69b30d5..5ef78d82c 100644 --- a/src/SDK/Common/Export/Http/PsrTransportFactory.php +++ b/src/SDK/Common/Export/Http/PsrTransportFactory.php @@ -57,7 +57,7 @@ public function create( $endpoint, $contentType, $headers, - (array) $compression, + PsrUtils::compression($compression), $retryDelay, $maxRetries, ); diff --git a/src/SDK/Common/Export/Http/PsrUtils.php b/src/SDK/Common/Export/Http/PsrUtils.php index 96f4fab31..eaf2f3b47 100644 --- a/src/SDK/Common/Export/Http/PsrUtils.php +++ b/src/SDK/Common/Export/Http/PsrUtils.php @@ -104,6 +104,24 @@ public static function decode(string $value, array $encodings): string return $value; } + /** + * Resolve an array or CSV of compression types to a list + */ + public static function compression($compression): array + { + if (is_array($compression)) { + return $compression; + } + if (!$compression) { + return []; + } + if (strpos($compression, ',') === false) { + return [$compression]; + } + + return array_map('trim', explode(',', $compression)); + } + private static function encoder(string $encoding): ?callable { static $encoders; diff --git a/tests/Unit/Context/ScopeTest.php b/tests/Unit/Context/ScopeTest.php index 7f0c2b0ce..08149ada5 100644 --- a/tests/Unit/Context/ScopeTest.php +++ b/tests/Unit/Context/ScopeTest.php @@ -116,7 +116,7 @@ public function test_scope_local_storage_is_preserved_between_attach_and_scope() $scope['key'] = 'value'; $scope = $storage->scope(); $this->assertNotNull($scope); - $this->assertArrayHasKey('key', $scope); /** @phpstan-ignore-line */ + $this->assertArrayHasKey('key', $scope); $this->assertSame('value', $scope['key']); unset($scope['key']); diff --git a/tests/Unit/SDK/Common/Export/Http/PsrUtilsTest.php b/tests/Unit/SDK/Common/Export/Http/PsrUtilsTest.php index 5a5c62c51..3f743ccd2 100644 --- a/tests/Unit/SDK/Common/Export/Http/PsrUtilsTest.php +++ b/tests/Unit/SDK/Common/Export/Http/PsrUtilsTest.php @@ -91,4 +91,23 @@ public function test_decode_stream_unknown_encoding(): void PsrUtils::decode('', ['invalid']); } + + /** + * @dataProvider compressionProvider + */ + public function test_resolve_compression($input, $expected): void + { + $this->assertSame($expected, PsrUtils::compression($input)); + } + + public static function compressionProvider(): array + { + return [ + ['gzip', ['gzip']], + ['', []], + ['gzip,br', ['gzip','br']], + ['gzip , brotli', ['gzip','brotli']], + [['gzip'], ['gzip']], + ]; + } }