From 837197df68e0d720cd9d82d60b6ba5b77530177d Mon Sep 17 00:00:00 2001 From: Fabio Capucci Date: Fri, 9 Feb 2024 15:26:25 +0100 Subject: [PATCH] improved types --- phpstan.neon | 2 +- src/Support/SpanBuilder.php | 2 +- src/Tracer.php | 3 ++- tests/Instrumentation/QueueInstrumentationTest.php | 3 ++- tests/Pest.php | 2 +- tests/TracerTest.php | 5 +++-- 6 files changed, 10 insertions(+), 7 deletions(-) diff --git a/phpstan.neon b/phpstan.neon index 19e5c54..28ffc4f 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,5 +1,5 @@ parameters: - level: 7 + level: 8 paths: - src - config diff --git a/src/Support/SpanBuilder.php b/src/Support/SpanBuilder.php index 8444dd3..7efb02f 100644 --- a/src/Support/SpanBuilder.php +++ b/src/Support/SpanBuilder.php @@ -70,7 +70,7 @@ public function startSpan(): SpanInterface * @template U * * @param Closure(SpanInterface $span): U $callback - * @return U + * @return (U is PendingDispatch ? null : U) * * @throws Throwable */ diff --git a/src/Tracer.php b/src/Tracer.php index 320584b..9f036b1 100644 --- a/src/Tracer.php +++ b/src/Tracer.php @@ -3,6 +3,7 @@ namespace Keepsuit\LaravelOpenTelemetry; use Closure; +use Illuminate\Foundation\Bus\PendingDispatch; use Illuminate\Support\Facades\Log; use Keepsuit\LaravelOpenTelemetry\Support\SpanBuilder; use OpenTelemetry\API\Trace\SpanInterface; @@ -42,7 +43,7 @@ public function start(string $name): SpanInterface * * @param non-empty-string $name * @param Closure(SpanInterface $span): U $callback - * @return U + * @return (U is PendingDispatch ? null : U) * * @throws \Throwable */ diff --git a/tests/Instrumentation/QueueInstrumentationTest.php b/tests/Instrumentation/QueueInstrumentationTest.php index a3be68d..a4c9fc7 100644 --- a/tests/Instrumentation/QueueInstrumentationTest.php +++ b/tests/Instrumentation/QueueInstrumentationTest.php @@ -3,6 +3,7 @@ use Illuminate\Support\Facades\Artisan; use Keepsuit\LaravelOpenTelemetry\Facades\Tracer; use Keepsuit\LaravelOpenTelemetry\Tests\Support\TestJob; +use OpenTelemetry\API\Trace\SpanInterface; use OpenTelemetry\API\Trace\SpanKind; use OpenTelemetry\SDK\Trace\Span; use Spatie\Valuestore\Valuestore; @@ -21,7 +22,7 @@ Tracer::newSpan('dispatcher') ->setSpanKind(SpanKind::KIND_PRODUCER) - ->measure(function (Span $span) use (&$traceId, &$spanId) { + ->measure(function (SpanInterface $span) use (&$traceId, &$spanId) { $spanId = $span->getContext()->getSpanId(); $traceId = $span->getContext()->getTraceId(); diff --git a/tests/Pest.php b/tests/Pest.php index 588c4c9..1722681 100644 --- a/tests/Pest.php +++ b/tests/Pest.php @@ -30,7 +30,7 @@ function getRecordedSpans(): array function withRootSpan(Closure $callback): mixed { - $rootSpan = \Keepsuit\LaravelOpenTelemetry\Facades\Tracer::build('root')->startSpan(); + $rootSpan = \Keepsuit\LaravelOpenTelemetry\Facades\Tracer::newSpan('root')->startSpan(); $rootScope = $rootSpan->activate(); $result = $callback(); diff --git a/tests/TracerTest.php b/tests/TracerTest.php index f06ed04..e24b55f 100644 --- a/tests/TracerTest.php +++ b/tests/TracerTest.php @@ -1,6 +1,7 @@