Skip to content

Commit

Permalink
Merge pull request #4 from spiral/hotfix/deprecated-package
Browse files Browse the repository at this point in the history
Replaces deprecated open-telemetry/opentelemetry with open-telemetry/sdk package
  • Loading branch information
butschster authored Apr 4, 2023
2 parents 448399a + ac04a8a commit 2a26b87
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 18 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
12 changes: 3 additions & 9 deletions src/Bootloader/OpenTelemetryBootloader.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
);
}

Expand Down
10 changes: 5 additions & 5 deletions src/Trace/DeferredSpanExporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand All @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions tests/src/Trace/DeferredSpanExporterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
);

Expand All @@ -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)
);

Expand Down Expand Up @@ -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)
);

Expand Down

0 comments on commit 2a26b87

Please sign in to comment.