diff --git a/composer.json b/composer.json index b0e978c..2cda69c 100644 --- a/composer.json +++ b/composer.json @@ -21,7 +21,7 @@ "spiral/boot": "^3.2", "spiral/console": "^3.2", "spiral/telemetry": "^3.3", - "open-telemetry/opentelemetry": "^0.0.15", + "open-telemetry/sdk": "^0.0.17", "php-http/guzzle6-adapter": "~2" }, "require-dev": { diff --git a/src/Bootloader/OpenTelemetryBootloader.php b/src/Bootloader/OpenTelemetryBootloader.php index 860f80b..813c40a 100644 --- a/src/Bootloader/OpenTelemetryBootloader.php +++ b/src/Bootloader/OpenTelemetryBootloader.php @@ -60,18 +60,12 @@ public function initTextMapPropagator(): TextMapPropagatorInterface public function initSpanProcessor( SpanExporterInterface $exporter, ): SpanProcessorInterface { - return (new SpanProcessorFactory())->fromEnvironment($exporter); + return (new SpanProcessorFactory())->create($exporter); } - public function initSpanExporter( - ParserInterface $parser, - EnvironmentInterface $env - ): SpanExporterInterface { + public function initSpanExporter(): SpanExporterInterface { return new DeferredSpanExporter( - new ExporterFactory( - $env->get('OTEL_SERVICE_NAME', 'Spiral Framework'), - $parser - ) + new ExporterFactory() ); } diff --git a/src/Trace/DeferredSpanExporter.php b/src/Trace/DeferredSpanExporter.php index 4e66bea..e044614 100644 --- a/src/Trace/DeferredSpanExporter.php +++ b/src/Trace/DeferredSpanExporter.php @@ -5,7 +5,7 @@ namespace Spiral\OpenTelemetry\Trace; use OpenTelemetry\SDK\Common\Future\CancellationInterface; -use OpenTelemetry\SDK\Common\Future\CompletedFuture; +use OpenTelemetry\SDK\Common\Future\ErrorFuture; use OpenTelemetry\SDK\Common\Future\FutureInterface; use OpenTelemetry\SDK\Trace\ExporterFactory; use OpenTelemetry\SDK\Trace\SpanExporterInterface; @@ -27,13 +27,13 @@ public static function fromConnectionString(string $endpointUrl, string $name, s /** * @psalm-suppress InvalidReturnType,InvalidReturnStatement */ - public function export(iterable $spans, ?CancellationInterface $cancellation = null): FutureInterface + public function export(iterable $batch, ?CancellationInterface $cancellation = null): FutureInterface { if ($this->getExporter() !== null) { - return $this->getExporter()->export($spans, $cancellation); + return $this->getExporter()->export($batch, $cancellation); } - return new CompletedFuture(SpanExporterInterface::STATUS_FAILED_NOT_RETRYABLE); + return new ErrorFuture(new \BadMethodCallException('Exporter is not initialized.')); } public function shutdown(?CancellationInterface $cancellation = null): bool @@ -49,7 +49,7 @@ public function forceFlush(?CancellationInterface $cancellation = null): bool private function getExporter(): ?SpanExporterInterface { if ($this->exporter === null) { - $this->exporter = $this->exporterFactory->fromEnvironment(); + $this->exporter = $this->exporterFactory->create(); } return $this->exporter; diff --git a/tests/src/Trace/DeferredSpanExporterTest.php b/tests/src/Trace/DeferredSpanExporterTest.php index 8173f02..23dc062 100644 --- a/tests/src/Trace/DeferredSpanExporterTest.php +++ b/tests/src/Trace/DeferredSpanExporterTest.php @@ -18,7 +18,7 @@ public function testExport(): void { $exporter = new DeferredSpanExporter($factory = m::mock(ExporterFactory::class)); - $factory->shouldReceive('fromEnvironment')->withNoArgs()->andReturn( + $factory->shouldReceive('create')->withNoArgs()->andReturn( $span = m::mock(SpanExporterInterface::class) ); @@ -35,7 +35,7 @@ public function testExportWithCancellation(): void $cancellation = m::mock(CancellationInterface::class); - $factory->shouldReceive('fromEnvironment')->withNoArgs()->andReturn( + $factory->shouldReceive('create')->withNoArgs()->andReturn( $span = m::mock(SpanExporterInterface::class) ); @@ -63,7 +63,7 @@ public function testOtherMethods(string $method, $cancellation): void { $exporter = new DeferredSpanExporter($factory = m::mock(ExporterFactory::class)); - $factory->shouldReceive('fromEnvironment')->withNoArgs()->andReturn( + $factory->shouldReceive('create')->withNoArgs()->andReturn( $span = m::mock(SpanExporterInterface::class) );