From 15ebaeb98ca1e8a51a3f545746f382fa84f0c676 Mon Sep 17 00:00:00 2001 From: Tobias Bachert Date: Sun, 18 Sep 2022 23:27:51 +0200 Subject: [PATCH] Change `SpanExporter::export()` return value to boolean (#827) --- src/Contrib/Jaeger/AgentExporter.php | 7 ++-- src/Contrib/Jaeger/HttpCollectorExporter.php | 7 ++-- src/Contrib/Newrelic/Exporter.php | 6 ++-- src/Contrib/OtlpGrpc/Exporter.php | 10 +++--- src/Contrib/OtlpHttp/Exporter.php | 10 +++--- src/Contrib/Zipkin/Exporter.php | 6 ++-- src/Contrib/ZipkinToNewrelic/Exporter.php | 6 ++-- .../Behavior/SpanExporterDecoratorTrait.php | 6 ++-- src/SDK/Trace/Behavior/SpanExporterTrait.php | 9 ++--- .../SpanExporter/ConsoleSpanExporter.php | 6 ++-- .../Trace/SpanExporter/InMemoryExporter.php | 4 +-- .../Trace/SpanExporter/LoggerDecorator.php | 34 ++++++++----------- src/SDK/Trace/SpanExporter/LoggerExporter.php | 6 ++-- src/SDK/Trace/SpanExporterInterface.php | 9 +---- .../Unit/Contrib/AbstractHttpExporterTest.php | 34 +++++++++---------- .../Unit/Contrib/Jaeger/AgentExporterTest.php | 3 +- .../JaegerHttpCollectorExporterTest.php | 3 +- .../Contrib/OtlpGrpc/OTLPGrpcExporterTest.php | 14 ++++---- .../Contrib/OtlpHttp/OTLPHttpExporterTest.php | 25 +++++++------- .../SpanExporter/AbstractExporterTest.php | 2 +- .../SpanExporter/ConsoleSpanExporterTest.php | 7 ++-- .../SpanExporter/LoggerDecoratorTest.php | 29 ++-------------- .../Trace/SpanExporter/LoggerExporterTest.php | 10 ++---- 23 files changed, 100 insertions(+), 153 deletions(-) diff --git a/src/Contrib/Jaeger/AgentExporter.php b/src/Contrib/Jaeger/AgentExporter.php index 3ec80ea75..d3885f782 100644 --- a/src/Contrib/Jaeger/AgentExporter.php +++ b/src/Contrib/Jaeger/AgentExporter.php @@ -39,10 +39,7 @@ public function closeAgentConnection(): void $this->jaegerTransport->close(); } - /** - * @psalm-return SpanExporterInterface::STATUS_* - */ - public function doExport(iterable $spans): int + public function doExport(iterable $spans): bool { // UDP Transport begins here after converting to thrift format span foreach ($spans as $span) { @@ -52,7 +49,7 @@ public function doExport(iterable $spans): int ); } - return SpanExporterInterface::STATUS_SUCCESS; + return true; } /** @inheritDoc */ diff --git a/src/Contrib/Jaeger/HttpCollectorExporter.php b/src/Contrib/Jaeger/HttpCollectorExporter.php index 06da0b697..3ca6c0402 100644 --- a/src/Contrib/Jaeger/HttpCollectorExporter.php +++ b/src/Contrib/Jaeger/HttpCollectorExporter.php @@ -39,14 +39,11 @@ public function __construct( ); } - /** - * @psalm-return SpanExporterInterface::STATUS_* - */ - public function doExport(iterable $spans): int + public function doExport(iterable $spans): bool { $this->sender->send($spans); - return SpanExporterInterface::STATUS_SUCCESS; + return true; } /** @inheritDoc */ diff --git a/src/Contrib/Newrelic/Exporter.php b/src/Contrib/Newrelic/Exporter.php index 05b847e00..92a66da28 100644 --- a/src/Contrib/Newrelic/Exporter.php +++ b/src/Contrib/Newrelic/Exporter.php @@ -97,11 +97,11 @@ public function export(iterable $spans, ?CancellationInterface $cancellation = n { return $this->transport ->send($this->serializeTrace($spans), 'application/json', $cancellation) - ->map(static fn (): int => 0) - ->catch(static function (Throwable $throwable): int { + ->map(static fn (): bool => true) + ->catch(static function (Throwable $throwable): bool { self::logError('Export failure', ['exception' => $throwable]); - return 1; + return false; }); } diff --git a/src/Contrib/OtlpGrpc/Exporter.php b/src/Contrib/OtlpGrpc/Exporter.php index 9bebd202a..218ef0dc8 100644 --- a/src/Contrib/OtlpGrpc/Exporter.php +++ b/src/Contrib/OtlpGrpc/Exporter.php @@ -105,7 +105,7 @@ public function getClientOptions(): array * @inheritDoc * @psalm-suppress UndefinedConstant */ - protected function doExport(iterable $spans): int + protected function doExport(iterable $spans): bool { $request = (new SpanConverter())->convert($spans); @@ -120,7 +120,7 @@ protected function doExport(iterable $spans): int 'error' => $response->getPartialSuccess()->getErrorMessage(), ]); - return self::STATUS_FAILED_NOT_RETRYABLE; + return false; } elseif ($response->getPartialSuccess()->getErrorMessage()) { self::logWarning('Export warning', ['server_message' => $response->getPartialSuccess()->getErrorMessage()]); } @@ -129,7 +129,7 @@ protected function doExport(iterable $spans): int if ($status->code === \Grpc\STATUS_OK) { self::logDebug('Exported span(s)', ['spans' => $request->getResourceSpans()]); - return self::STATUS_SUCCESS; + return true; } $error = [ @@ -150,12 +150,12 @@ protected function doExport(iterable $spans): int ], true)) { self::logWarning('Retryable error exporting grpc span', ['error' => $error]); - return self::STATUS_FAILED_RETRYABLE; + return false; } self::logError('Error exporting grpc span', ['error' => $error]); - return self::STATUS_FAILED_NOT_RETRYABLE; + return false; } public function setHeader($key, $value): void diff --git a/src/Contrib/OtlpHttp/Exporter.php b/src/Contrib/OtlpHttp/Exporter.php index 4e7ef69e4..64733f986 100644 --- a/src/Contrib/OtlpHttp/Exporter.php +++ b/src/Contrib/OtlpHttp/Exporter.php @@ -98,7 +98,7 @@ public function export(iterable $spans, ?CancellationInterface $cancellation = n { return $this->transport ->send((new SpanConverter())->convert($spans)->serializeToString(), 'application/x-protobuf', $cancellation) - ->map(static function (string $payload): int { + ->map(static function (string $payload): bool { $serviceResponse = new ExportTraceServiceResponse(); $serviceResponse->mergeFromString($payload); @@ -109,18 +109,18 @@ public function export(iterable $spans, ?CancellationInterface $cancellation = n 'error_message' => $partialSuccess->getErrorMessage(), ]); - return 1; + return false; } if ($partialSuccess !== null && $partialSuccess->getErrorMessage()) { self::logWarning('Export success with warnings/suggestions', ['error_message' => $partialSuccess->getErrorMessage()]); } - return 0; + return true; }) - ->catch(static function (Throwable $throwable): int { + ->catch(static function (Throwable $throwable): bool { self::logError('Export failure', ['exception' => $throwable]); - return 1; + return false; }); } diff --git a/src/Contrib/Zipkin/Exporter.php b/src/Contrib/Zipkin/Exporter.php index 6820e1c6b..2507dc82e 100644 --- a/src/Contrib/Zipkin/Exporter.php +++ b/src/Contrib/Zipkin/Exporter.php @@ -70,11 +70,11 @@ public function export(iterable $spans, ?CancellationInterface $cancellation = n { return $this->transport ->send($this->serializeTrace($spans), 'application/json', $cancellation) - ->map(static fn (): int => 0) - ->catch(static function (Throwable $throwable): int { + ->map(static fn (): bool => true) + ->catch(static function (Throwable $throwable): bool { self::logError('Export failure', ['exception' => $throwable]); - return 1; + return false; }); } diff --git a/src/Contrib/ZipkinToNewrelic/Exporter.php b/src/Contrib/ZipkinToNewrelic/Exporter.php index 35207d124..af27c481a 100644 --- a/src/Contrib/ZipkinToNewrelic/Exporter.php +++ b/src/Contrib/ZipkinToNewrelic/Exporter.php @@ -84,11 +84,11 @@ public function export(iterable $spans, ?CancellationInterface $cancellation = n { return $this->transport ->send($this->serializeTrace($spans), 'application/json', $cancellation) - ->map(static fn (): int => 0) - ->catch(static function (Throwable $throwable): int { + ->map(static fn (): bool => true) + ->catch(static function (Throwable $throwable): bool { self::logError('Export failure', ['exception' => $throwable]); - return 1; + return false; }); } diff --git a/src/SDK/Trace/Behavior/SpanExporterDecoratorTrait.php b/src/SDK/Trace/Behavior/SpanExporterDecoratorTrait.php index dae7658ac..9dd2fda51 100644 --- a/src/SDK/Trace/Behavior/SpanExporterDecoratorTrait.php +++ b/src/SDK/Trace/Behavior/SpanExporterDecoratorTrait.php @@ -15,20 +15,20 @@ trait SpanExporterDecoratorTrait /** * @param iterable $spans - * @return FutureInterface + * @return FutureInterface */ public function export(iterable $spans, ?CancellationInterface $cancellation = null): FutureInterface { $spans = $this->beforeExport($spans); $response = $this->decorated->export($spans, $cancellation); - $response->map(fn (int $result) => $this->afterExport($spans, $result)); + $response->map(fn (bool $result) => $this->afterExport($spans, $result)); return $response; } abstract protected function beforeExport(iterable $spans): iterable; - abstract protected function afterExport(iterable $spans, int $exporterResponse): void; + abstract protected function afterExport(iterable $spans, bool $exportSuccess): void; public function shutdown(?CancellationInterface $cancellation = null): bool { diff --git a/src/SDK/Trace/Behavior/SpanExporterTrait.php b/src/SDK/Trace/Behavior/SpanExporterTrait.php index af8ddb223..9d7bd10e4 100644 --- a/src/SDK/Trace/Behavior/SpanExporterTrait.php +++ b/src/SDK/Trace/Behavior/SpanExporterTrait.php @@ -8,7 +8,6 @@ use OpenTelemetry\SDK\Common\Future\CompletedFuture; use OpenTelemetry\SDK\Common\Future\FutureInterface; use OpenTelemetry\SDK\Trace\SpanDataInterface; -use OpenTelemetry\SDK\Trace\SpanExporterInterface; trait SpanExporterTrait { @@ -32,12 +31,12 @@ abstract public static function fromConnectionString(string $endpointUrl, string /** * @param iterable $spans - * @return FutureInterface + * @return FutureInterface */ public function export(iterable $spans, ?CancellationInterface $cancellation = null): FutureInterface { if (!$this->running) { - return new CompletedFuture(SpanExporterInterface::STATUS_FAILED_NOT_RETRYABLE); + return new CompletedFuture(false); } return new CompletedFuture($this->doExport($spans)); /** @phpstan-ignore-line */ @@ -45,8 +44,6 @@ public function export(iterable $spans, ?CancellationInterface $cancellation = n /** * @param iterable $spans Batch of spans to export - * - * @psalm-return SpanExporterInterface::STATUS_* */ - abstract protected function doExport(iterable $spans): int; /** @phpstan-ignore-line */ + abstract protected function doExport(iterable $spans): bool; /** @phpstan-ignore-line */ } diff --git a/src/SDK/Trace/SpanExporter/ConsoleSpanExporter.php b/src/SDK/Trace/SpanExporter/ConsoleSpanExporter.php index fb2c1151b..89cdc7aa4 100644 --- a/src/SDK/Trace/SpanExporter/ConsoleSpanExporter.php +++ b/src/SDK/Trace/SpanExporter/ConsoleSpanExporter.php @@ -21,7 +21,7 @@ public function __construct(?SpanConverterInterface $converter = null) } /** @inheritDoc */ - public function doExport(iterable $spans): int + public function doExport(iterable $spans): bool { try { foreach ($spans as $span) { @@ -32,10 +32,10 @@ public function doExport(iterable $spans): int ); } } catch (Throwable $t) { - return SpanExporterInterface::STATUS_FAILED_NOT_RETRYABLE; + return false; } - return SpanExporterInterface::STATUS_SUCCESS; + return true; } public static function fromConnectionString(string $endpointUrl = null, string $name = null, $args = null) diff --git a/src/SDK/Trace/SpanExporter/InMemoryExporter.php b/src/SDK/Trace/SpanExporter/InMemoryExporter.php index c9874a439..87e144b03 100644 --- a/src/SDK/Trace/SpanExporter/InMemoryExporter.php +++ b/src/SDK/Trace/SpanExporter/InMemoryExporter.php @@ -24,13 +24,13 @@ public static function fromConnectionString(string $endpointUrl = null, string $ return new self(); } - protected function doExport(iterable $spans): int + protected function doExport(iterable $spans): bool { foreach ($spans as $span) { $this->storage[] = $span; } - return SpanExporterInterface::STATUS_SUCCESS; + return true; } public function getSpans(): array diff --git a/src/SDK/Trace/SpanExporter/LoggerDecorator.php b/src/SDK/Trace/SpanExporter/LoggerDecorator.php index 37c2d52c2..8442fc5fa 100644 --- a/src/SDK/Trace/SpanExporter/LoggerDecorator.php +++ b/src/SDK/Trace/SpanExporter/LoggerDecorator.php @@ -21,18 +21,6 @@ class LoggerDecorator implements SpanExporterInterface, LoggerAwareInterface use UsesSpanConverterTrait; use LoggerAwareTrait; - private const RESPONSE_MAPPING = [ - SpanExporterInterface::STATUS_SUCCESS => LogLevel::INFO, - SpanExporterInterface::STATUS_FAILED_RETRYABLE => LogLevel::ERROR, - SpanExporterInterface::STATUS_FAILED_NOT_RETRYABLE => LogLevel::ALERT, - ]; - - private const MESSAGE_MAPPING = [ - SpanExporterInterface::STATUS_SUCCESS => 'Status Success', - SpanExporterInterface::STATUS_FAILED_RETRYABLE => 'Status Failed Retryable', - SpanExporterInterface::STATUS_FAILED_NOT_RETRYABLE => 'Status Failed Not Retryable', - ]; - public function __construct( SpanExporterInterface $decorated, ?LoggerInterface $logger = null, @@ -57,14 +45,22 @@ protected function beforeExport(iterable $spans): iterable /** * @param iterable $spans - * @param int $exporterResponse + * @param bool $exportSuccess */ - protected function afterExport(iterable $spans, int $exporterResponse): void + protected function afterExport(iterable $spans, bool $exportSuccess): void { - $this->log( - self::MESSAGE_MAPPING[$exporterResponse], - $this->getSpanConverter()->convert($spans), - self::RESPONSE_MAPPING[$exporterResponse] - ); + if ($exportSuccess) { + $this->log( + 'Status Success', + $this->getSpanConverter()->convert($spans), + LogLevel::INFO, + ); + } else { + $this->log( + 'Status Failed Retryable', + $this->getSpanConverter()->convert($spans), + LogLevel::ERROR, + ); + } } } diff --git a/src/SDK/Trace/SpanExporter/LoggerExporter.php b/src/SDK/Trace/SpanExporter/LoggerExporter.php index 86959183f..ddaaf14b1 100644 --- a/src/SDK/Trace/SpanExporter/LoggerExporter.php +++ b/src/SDK/Trace/SpanExporter/LoggerExporter.php @@ -51,15 +51,15 @@ public function __construct( } /** @inheritDoc */ - public function doExport(iterable $spans): int + public function doExport(iterable $spans): bool { try { $this->doLog($spans); } catch (Throwable $t) { - return SpanExporterInterface::STATUS_FAILED_NOT_RETRYABLE; + return false; } - return SpanExporterInterface::STATUS_SUCCESS; + return true; } /** diff --git a/src/SDK/Trace/SpanExporterInterface.php b/src/SDK/Trace/SpanExporterInterface.php index 05d15a23d..c4d0d6926 100644 --- a/src/SDK/Trace/SpanExporterInterface.php +++ b/src/SDK/Trace/SpanExporterInterface.php @@ -12,13 +12,6 @@ */ interface SpanExporterInterface { - /** - * Possible return values as outlined in the OpenTelemetry spec - */ - public const STATUS_SUCCESS = 0; - public const STATUS_FAILED_NOT_RETRYABLE = 1; - public const STATUS_FAILED_RETRYABLE = 2; - public static function fromConnectionString(string $endpointUrl, string $name, string $args); /** @@ -26,7 +19,7 @@ public static function fromConnectionString(string $endpointUrl, string $name, s * * @see https://github.com/open-telemetry/opentelemetry-specification/blob/v1.7.0/specification/trace/sdk.md#exportbatch * - * @psalm-return FutureInterface + * @psalm-return FutureInterface */ public function export(iterable $spans, ?CancellationInterface $cancellation = null): FutureInterface; diff --git a/tests/Unit/Contrib/AbstractHttpExporterTest.php b/tests/Unit/Contrib/AbstractHttpExporterTest.php index 6fab34891..43952d7dc 100644 --- a/tests/Unit/Contrib/AbstractHttpExporterTest.php +++ b/tests/Unit/Contrib/AbstractHttpExporterTest.php @@ -49,24 +49,24 @@ public function test_exporter_response_status($responseStatus, $expected): void ->willReturn(new Response($responseStatus)); $this->assertEquals( - min(1, $expected), - min(1, $this->createExporter()->export([ + $expected, + $this->createExporter()->export([ $this->createMock(SpanData::class), - ])->await()), + ])->await(), ); } public function exporterResponseStatusDataProvider(): array { return [ - 'ok' => [200, SpanExporterInterface::STATUS_SUCCESS], - 'not found' => [404, SpanExporterInterface::STATUS_FAILED_NOT_RETRYABLE], - 'not authorized' => [401, SpanExporterInterface::STATUS_FAILED_NOT_RETRYABLE], - 'bad request' => [402, SpanExporterInterface::STATUS_FAILED_NOT_RETRYABLE], - 'too many requests' => [429, SpanExporterInterface::STATUS_FAILED_NOT_RETRYABLE], - 'server error' => [500, SpanExporterInterface::STATUS_FAILED_RETRYABLE], - 'timeout' => [503, SpanExporterInterface::STATUS_FAILED_RETRYABLE], - 'bad gateway' => [502, SpanExporterInterface::STATUS_FAILED_RETRYABLE], + 'ok' => [200, true], + 'not found' => [404, false], + 'not authorized' => [401, false], + 'bad request' => [402, false], + 'too many requests' => [429, false], + 'server error' => [500, false], + 'timeout' => [503, false], + 'bad gateway' => [502, false], ]; } @@ -103,10 +103,10 @@ public function test_client_exception_decides_return_code($exception, $expected) ->willThrowException($exception); $this->assertEquals( - min(1, $expected), - min(1, $this->createExporter()->export([ + $expected, + $this->createExporter()->export([ $this->createMock(SpanData::class), - ])->await()), + ])->await(), ); } @@ -115,15 +115,15 @@ public function clientExceptionDataProvider(): array return [ 'client' => [ $this->createMock(ClientExceptionInterface::class), - SpanExporterInterface::STATUS_FAILED_RETRYABLE, + false, ], 'network' => [ $this->createMock(NetworkExceptionInterface::class), - SpanExporterInterface::STATUS_FAILED_RETRYABLE, + false, ], 'request' => [ $this->createMock(RequestExceptionInterface::class), - SpanExporterInterface::STATUS_FAILED_NOT_RETRYABLE, + false, ], ]; } diff --git a/tests/Unit/Contrib/Jaeger/AgentExporterTest.php b/tests/Unit/Contrib/Jaeger/AgentExporterTest.php index e0e8abfbe..1d6f73479 100644 --- a/tests/Unit/Contrib/Jaeger/AgentExporterTest.php +++ b/tests/Unit/Contrib/Jaeger/AgentExporterTest.php @@ -5,7 +5,6 @@ namespace OpenTelemetry\Tests\Unit\Contrib\Jaeger; use OpenTelemetry\Contrib\Jaeger\AgentExporter; -use OpenTelemetry\SDK\Trace\SpanExporterInterface; use OpenTelemetry\Tests\Unit\SDK\Util\SpanData; use PHPUnit\Framework\TestCase; @@ -26,7 +25,7 @@ public function test_happy_path() $status = $exporter->export([new SpanData()])->await(); - $this->assertSame(SpanExporterInterface::STATUS_SUCCESS, $status); + $this->assertTrue($status); $exporter->closeAgentConnection(); } diff --git a/tests/Unit/Contrib/Jaeger/JaegerHttpCollectorExporterTest.php b/tests/Unit/Contrib/Jaeger/JaegerHttpCollectorExporterTest.php index f8ea4e1c7..59a4f3839 100644 --- a/tests/Unit/Contrib/Jaeger/JaegerHttpCollectorExporterTest.php +++ b/tests/Unit/Contrib/Jaeger/JaegerHttpCollectorExporterTest.php @@ -5,7 +5,6 @@ namespace OpenTelemetry\Tests\Unit\Contrib\Jaeger; use OpenTelemetry\Contrib\Jaeger\HttpCollectorExporter; -use OpenTelemetry\SDK\Trace\SpanExporterInterface; use OpenTelemetry\Tests\Unit\Contrib\UsesHttpClientTrait; use OpenTelemetry\Tests\Unit\SDK\Util\SpanData; use PHPUnit\Framework\TestCase; @@ -38,6 +37,6 @@ public function test_happy_path() $status = $exporter->export([new SpanData()])->await(); - $this->assertSame(SpanExporterInterface::STATUS_SUCCESS, $status); + $this->assertTrue($status); } } diff --git a/tests/Unit/Contrib/OtlpGrpc/OTLPGrpcExporterTest.php b/tests/Unit/Contrib/OtlpGrpc/OTLPGrpcExporterTest.php index a1ea5a97f..3fe9764b6 100644 --- a/tests/Unit/Contrib/OtlpGrpc/OTLPGrpcExporterTest.php +++ b/tests/Unit/Contrib/OtlpGrpc/OTLPGrpcExporterTest.php @@ -63,7 +63,7 @@ public function test_exporter_happy_path(): void $exporterStatusCode = $exporter->export([new SpanData()])->await(); - $this->assertSame(SpanExporterInterface::STATUS_SUCCESS, $exporterStatusCode); + $this->assertTrue($exporterStatusCode); } public function test_exporter_unexpected_grpc_response_status(): void @@ -93,12 +93,12 @@ public function test_exporter_unexpected_grpc_response_status(): void $exporterStatusCode = $exporter->export([new SpanData()])->await(); - $this->assertSame(SpanExporterInterface::STATUS_FAILED_NOT_RETRYABLE, $exporterStatusCode); + $this->assertFalse($exporterStatusCode); } public function test_exporter_grpc_responds_as_unavailable(): void { - $this->assertEquals(SpanExporterInterface::STATUS_FAILED_RETRYABLE, (new Exporter())->export([new SpanData()])->await()); + $this->assertFalse((new Exporter())->export([new SpanData()])->await()); } public function test_set_headers_with_environment_variables(): void @@ -167,7 +167,7 @@ public function test_client_options(): void /** * @dataProvider partialSuccessProvider */ - public function test_partial_success(int $rejected, string $error, int $expectedStatusCode): void + public function test_partial_success(int $rejected, string $error, bool $expectedStatusCode): void { $exporter = new Exporter( 'localhost:4317', @@ -199,9 +199,9 @@ public function test_partial_success(int $rejected, string $error, int $expected public function partialSuccessProvider(): array { return [ - 'partial success with dropped' => [1, 'some.error.message', SpanExporterInterface::STATUS_FAILED_NOT_RETRYABLE], - 'partial success with no dropped and warning' => [0, 'some.warning.message', SpanExporterInterface::STATUS_SUCCESS], - 'partial success with full success' => [0, '', SpanExporterInterface::STATUS_SUCCESS], + 'partial success with dropped' => [1, 'some.error.message', false], + 'partial success with no dropped and warning' => [0, 'some.warning.message', true], + 'partial success with full success' => [0, '', true], ]; } diff --git a/tests/Unit/Contrib/OtlpHttp/OTLPHttpExporterTest.php b/tests/Unit/Contrib/OtlpHttp/OTLPHttpExporterTest.php index 9b1c752c0..086dc76d1 100644 --- a/tests/Unit/Contrib/OtlpHttp/OTLPHttpExporterTest.php +++ b/tests/Unit/Contrib/OtlpHttp/OTLPHttpExporterTest.php @@ -60,7 +60,7 @@ public function test_exporter_response_status($responseStatus, $expected): void $exporter = new Exporter(Exporter::createTransport(new PsrTransportFactory($client, new HttpFactory(), new HttpFactory()))); $this->assertEquals( - min($expected, 1), + $expected, $exporter->export([new SpanData()])->await(), ); } @@ -68,14 +68,14 @@ public function test_exporter_response_status($responseStatus, $expected): void public function exporterResponseStatusDataProvider(): array { return [ - 'ok' => [200, SpanExporterInterface::STATUS_SUCCESS], - 'not found' => [404, SpanExporterInterface::STATUS_FAILED_NOT_RETRYABLE], - 'not authorized' => [401, SpanExporterInterface::STATUS_FAILED_NOT_RETRYABLE], - 'bad request' => [402, SpanExporterInterface::STATUS_FAILED_NOT_RETRYABLE], - 'too many requests' => [429, SpanExporterInterface::STATUS_FAILED_NOT_RETRYABLE], - 'server error' => [500, SpanExporterInterface::STATUS_FAILED_RETRYABLE], - 'timeout' => [503, SpanExporterInterface::STATUS_FAILED_RETRYABLE], - 'bad gateway' => [502, SpanExporterInterface::STATUS_FAILED_RETRYABLE], + 'ok' => [200, true], + 'not found' => [404, false], + 'not authorized' => [401, false], + 'bad request' => [402, false], + 'too many requests' => [429, false], + 'server error' => [500, false], + 'timeout' => [503, false], + 'bad gateway' => [502, false], ]; } @@ -101,11 +101,11 @@ public function clientExceptionsShouldDecideReturnCodeDataProvider(): array return [ 'client' => [ $this->createMock(ClientExceptionInterface::class), - SpanExporterInterface::STATUS_FAILED_RETRYABLE, + false, ], 'network' => [ $this->createMock(NetworkExceptionInterface::class), - SpanExporterInterface::STATUS_FAILED_RETRYABLE, + false, ], ]; } @@ -163,8 +163,7 @@ public function test_should_be_ok_to_exporter_empty_spans_collection(): void $client = $this->createMock(ClientInterface::class); $client->method('sendRequest')->willReturn(new Response(200)); - $this->assertEquals( - SpanExporterInterface::STATUS_SUCCESS, + $this->assertTrue( (new Exporter(Exporter::createTransport(new PsrTransportFactory( $client, new HttpFactory(), diff --git a/tests/Unit/SDK/Trace/SpanExporter/AbstractExporterTest.php b/tests/Unit/SDK/Trace/SpanExporter/AbstractExporterTest.php index 6f43f6b0a..2fc20687f 100644 --- a/tests/Unit/SDK/Trace/SpanExporter/AbstractExporterTest.php +++ b/tests/Unit/SDK/Trace/SpanExporter/AbstractExporterTest.php @@ -38,6 +38,6 @@ public function test_fails_if_not_test_running(): void $span = $this->createMock(SpanData::class); $exporter->shutdown(); - $this->assertSame(SpanExporterInterface::STATUS_FAILED_NOT_RETRYABLE, $exporter->export([$span])->await()); + $this->assertFalse($exporter->export([$span])->await()); } } diff --git a/tests/Unit/SDK/Trace/SpanExporter/ConsoleSpanExporterTest.php b/tests/Unit/SDK/Trace/SpanExporter/ConsoleSpanExporterTest.php index 960c4f40f..500720554 100644 --- a/tests/Unit/SDK/Trace/SpanExporter/ConsoleSpanExporterTest.php +++ b/tests/Unit/SDK/Trace/SpanExporter/ConsoleSpanExporterTest.php @@ -7,7 +7,6 @@ use OpenTelemetry\SDK\Trace\SpanConverterInterface; use OpenTelemetry\SDK\Trace\SpanDataInterface; use OpenTelemetry\SDK\Trace\SpanExporter\ConsoleSpanExporter; -use OpenTelemetry\SDK\Trace\SpanExporterInterface; /** * @covers \OpenTelemetry\SDK\Trace\SpanExporter\ConsoleSpanExporter @@ -60,8 +59,7 @@ public function test_export_success(): void ob_start(); - $this->assertSame( - SpanExporterInterface::STATUS_SUCCESS, + $this->assertTrue( (new ConsoleSpanExporter($converter))->export([ $this->createMock(SpanDataInterface::class), ])->await(), @@ -80,8 +78,7 @@ public function test_export_failed(): void ob_start(); - $this->assertSame( - SpanExporterInterface::STATUS_FAILED_NOT_RETRYABLE, + $this->assertFalse( (new ConsoleSpanExporter($converter))->export([ $this->createMock(SpanDataInterface::class), ])->await(), diff --git a/tests/Unit/SDK/Trace/SpanExporter/LoggerDecoratorTest.php b/tests/Unit/SDK/Trace/SpanExporter/LoggerDecoratorTest.php index e5c2499b6..3c015169b 100644 --- a/tests/Unit/SDK/Trace/SpanExporter/LoggerDecoratorTest.php +++ b/tests/Unit/SDK/Trace/SpanExporter/LoggerDecoratorTest.php @@ -67,7 +67,7 @@ public function test_export_success(): void $this->getSpanExporterInterfaceMock() ->expects($this->once()) ->method('export') - ->willReturn(new CompletedFuture(SpanExporterInterface::STATUS_SUCCESS)); + ->willReturn(new CompletedFuture(true)); $this->getLoggerInterfaceMock() ->expects($this->once()) @@ -85,12 +85,12 @@ public function test_export_success(): void * @psalm-suppress PossiblyUndefinedMethod * @psalm-suppress PossiblyInvalidArgument */ - public function test_export_failed_retryable(): void + public function test_export_failed(): void { $this->getSpanExporterInterfaceMock() ->expects($this->once()) ->method('export') - ->willReturn(new CompletedFuture(SpanExporterInterface::STATUS_FAILED_RETRYABLE)); + ->willReturn(new CompletedFuture(false)); $this->getLoggerInterfaceMock() ->expects($this->once()) @@ -104,29 +104,6 @@ public function test_export_failed_retryable(): void ->await(); } - /** - * @psalm-suppress PossiblyUndefinedMethod - * @psalm-suppress PossiblyInvalidArgument - */ - public function test_export_failed_not_retryable(): void - { - $this->getSpanExporterInterfaceMock() - ->expects($this->once()) - ->method('export') - ->willReturn(new CompletedFuture(SpanExporterInterface::STATUS_FAILED_NOT_RETRYABLE)); - - $this->getLoggerInterfaceMock() - ->expects($this->once()) - ->method('log') - ->with(LogLevel::ALERT); - - $this->createLoggerDecorator() - ->export( - $this->createSpanMocks() - ) - ->await(); - } - /** * @return LoggerDecorator * @psalm-suppress PossiblyInvalidArgument diff --git a/tests/Unit/SDK/Trace/SpanExporter/LoggerExporterTest.php b/tests/Unit/SDK/Trace/SpanExporter/LoggerExporterTest.php index 6630c6909..6da3fd300 100644 --- a/tests/Unit/SDK/Trace/SpanExporter/LoggerExporterTest.php +++ b/tests/Unit/SDK/Trace/SpanExporter/LoggerExporterTest.php @@ -6,7 +6,6 @@ use Exception; use OpenTelemetry\SDK\Trace\SpanExporter\LoggerExporter; -use OpenTelemetry\SDK\Trace\SpanExporterInterface; /** * @covers \OpenTelemetry\SDK\Trace\SpanExporter\LoggerExporter @@ -47,8 +46,7 @@ public function test_export_granularity_aggregate(): void ->expects($this->once()) ->method('log'); - $this->assertSame( - SpanExporterInterface::STATUS_SUCCESS, + $this->assertTrue( $this->createLoggerExporter(LoggerExporter::GRANULARITY_AGGREGATE) ->export( $this->createSpanMocks() @@ -69,8 +67,7 @@ public function test_export_granularity_span(): void ->expects($this->exactly(count($spans))) ->method('log'); - $this->assertSame( - SpanExporterInterface::STATUS_SUCCESS, + $this->assertTrue( $this->createLoggerExporter(LoggerExporter::GRANULARITY_SPAN) ->export($spans) ->await(), @@ -87,8 +84,7 @@ public function test_logger_throws_exception(): void ->method('log') ->willThrowException(new Exception()); - $this->assertSame( - SpanExporterInterface::STATUS_FAILED_NOT_RETRYABLE, + $this->assertFalse( $this->createLoggerExporter() ->export( $this->createSpanMocks()