From 5d3210db9b77141da45de69a4f057b02b0c80ecf Mon Sep 17 00:00:00 2001 From: Chris Lightfoot-Wild Date: Sat, 26 Oct 2024 23:24:13 +0100 Subject: [PATCH] Laravel: use TextMapPropagatorInterface from InstrumentationContext instead of Globals. --- .../Hooks/Illuminate/Contracts/Http/Kernel.php | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/Instrumentation/Laravel/src/Hooks/Illuminate/Contracts/Http/Kernel.php b/src/Instrumentation/Laravel/src/Hooks/Illuminate/Contracts/Http/Kernel.php index 1a00ce38..0eab43e9 100644 --- a/src/Instrumentation/Laravel/src/Hooks/Illuminate/Contracts/Http/Kernel.php +++ b/src/Instrumentation/Laravel/src/Hooks/Illuminate/Contracts/Http/Kernel.php @@ -7,7 +7,6 @@ use Illuminate\Contracts\Http\Kernel as KernelContract; use Illuminate\Http\Request; use Illuminate\Routing\Route; -use OpenTelemetry\API\Globals; use OpenTelemetry\API\Instrumentation\AutoInstrumentation\Context as InstrumentationContext; use OpenTelemetry\API\Instrumentation\AutoInstrumentation\HookManagerInterface; use OpenTelemetry\API\Trace\Span; @@ -16,6 +15,7 @@ use OpenTelemetry\API\Trace\StatusCode; use OpenTelemetry\API\Trace\TracerInterface; use OpenTelemetry\Context\Context; +use OpenTelemetry\Context\Propagation\TextMapPropagatorInterface; use OpenTelemetry\Contrib\Instrumentation\Laravel\Hooks\Hook; use OpenTelemetry\Contrib\Instrumentation\Laravel\Hooks\PostHookTrait; use OpenTelemetry\Contrib\Instrumentation\Laravel\LaravelInstrumentation; @@ -40,15 +40,18 @@ public function instrument( schemaUrl: Version::VERSION_1_24_0->url(), ); - $this->hookHandle($hookManager, $tracer); + $this->hookHandle($hookManager, $tracer, $context->propagator); } - protected function hookHandle(HookManagerInterface $hookManager, TracerInterface $tracer): void - { + protected function hookHandle( + HookManagerInterface $hookManager, + TracerInterface $tracer, + TextMapPropagatorInterface $propagator, + ): void { $hookManager->hook( KernelContract::class, 'handle', - preHook: function (KernelContract $kernel, array $params, string $class, string $function, ?string $filename, ?int $lineno) use ($tracer) { + preHook: function (KernelContract $kernel, array $params, string $class, string $function, ?string $filename, ?int $lineno) use ($tracer, $propagator) { $request = ($params[0] instanceof Request) ? $params[0] : null; /** @psalm-suppress ArgumentTypeCoercion */ $builder = $tracer @@ -60,8 +63,7 @@ protected function hookHandle(HookManagerInterface $hookManager, TracerInterface ->setAttribute(TraceAttributes::CODE_LINENO, $lineno); $parent = Context::getCurrent(); if ($request) { - /** @phan-suppress-next-line PhanAccessMethodInternal */ - $parent = Globals::propagator()->extract($request, HeadersPropagator::instance()); + $parent = $propagator->extract($request, HeadersPropagator::instance()); $span = $builder ->setParent($parent) ->setAttribute(TraceAttributes::URL_FULL, $request->fullUrl())