Skip to content

Commit

Permalink
updated getRecorderSpans helper
Browse files Browse the repository at this point in the history
  • Loading branch information
cappuc committed Feb 13, 2024
1 parent 1ab99d3 commit 116bdf9
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 15 deletions.
8 changes: 2 additions & 6 deletions tests/Instrumentation/HttpClientInstrumentationTest.php
Expand Up @@ -41,9 +41,7 @@

Http::withTrace()->get(Server::$url);

$spans = getRecordedSpans();

$httpSpan = Arr::last($spans);
$httpSpan = getRecordedSpans()->last();

expect($httpSpan)
->getKind()->toBe(SpanKind::KIND_CLIENT)
Expand All @@ -69,9 +67,7 @@

Http::withTrace()->get(Server::$url);

$spans = getRecordedSpans();

$httpSpan = Arr::last($spans);
$httpSpan = getRecordedSpans()->last();

expect($httpSpan)
->getKind()->toBe(SpanKind::KIND_CLIENT)
Expand Down
7 changes: 3 additions & 4 deletions tests/Instrumentation/QueryInstrumentationTest.php
@@ -1,7 +1,6 @@
<?php

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Arr;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;
use OpenTelemetry\API\Trace\SpanKind;
Expand All @@ -21,7 +20,7 @@

flushSpans();

$span = Arr::last(getRecordedSpans());
$span = getRecordedSpans()->last();
assert($span instanceof ImmutableSpan);

expect($span)
Expand All @@ -48,7 +47,7 @@

flushSpans();

$span = Arr::last(getRecordedSpans());
$span = getRecordedSpans()->last();
assert($span instanceof ImmutableSpan);

expect($span)
Expand All @@ -75,7 +74,7 @@

flushSpans();

$span = Arr::last(getRecordedSpans());
$span = getRecordedSpans()->last();
assert($span instanceof ImmutableSpan);

expect($span)
Expand Down
3 changes: 1 addition & 2 deletions tests/Instrumentation/RedisInstrumentationTest.php
@@ -1,6 +1,5 @@
<?php

use Illuminate\Support\Arr;
use OpenTelemetry\API\Trace\SpanKind;
use OpenTelemetry\SDK\Common\Time\ClockFactory;
use OpenTelemetry\SDK\Trace\ImmutableSpan;
Expand All @@ -10,7 +9,7 @@

flushSpans();

$span = Arr::last(getRecordedSpans());
$span = getRecordedSpans()->last();
assert($span instanceof ImmutableSpan);

expect($span)
Expand Down
7 changes: 4 additions & 3 deletions tests/Pest.php
@@ -1,5 +1,6 @@
<?php

use Illuminate\Support\Collection;
use OpenTelemetry\API\Globals;
use OpenTelemetry\SDK\Trace\TracerProviderInterface;

Expand All @@ -16,16 +17,16 @@ function flushSpans()
}

/**
* @return \OpenTelemetry\SDK\Trace\ImmutableSpan[]
* @return Collection<array-key,\OpenTelemetry\SDK\Trace\ImmutableSpan>
*/
function getRecordedSpans(): array
function getRecordedSpans(): Collection
{
flushSpans();

$exporter = app(\OpenTelemetry\SDK\Trace\SpanExporterInterface::class);
assert($exporter instanceof \OpenTelemetry\SDK\Trace\SpanExporter\InMemoryExporter);

return $exporter->getSpans();
return collect($exporter->getSpans());
}

function withRootSpan(Closure $callback): mixed
Expand Down

0 comments on commit 116bdf9

Please sign in to comment.