Skip to content

Commit 5d3210d

Browse files
Laravel: use TextMapPropagatorInterface from InstrumentationContext instead of Globals.
1 parent 44440df commit 5d3210d

File tree

1 file changed

+9
-7
lines changed
  • src/Instrumentation/Laravel/src/Hooks/Illuminate/Contracts/Http

1 file changed

+9
-7
lines changed

src/Instrumentation/Laravel/src/Hooks/Illuminate/Contracts/Http/Kernel.php

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
use Illuminate\Contracts\Http\Kernel as KernelContract;
88
use Illuminate\Http\Request;
99
use Illuminate\Routing\Route;
10-
use OpenTelemetry\API\Globals;
1110
use OpenTelemetry\API\Instrumentation\AutoInstrumentation\Context as InstrumentationContext;
1211
use OpenTelemetry\API\Instrumentation\AutoInstrumentation\HookManagerInterface;
1312
use OpenTelemetry\API\Trace\Span;
@@ -16,6 +15,7 @@
1615
use OpenTelemetry\API\Trace\StatusCode;
1716
use OpenTelemetry\API\Trace\TracerInterface;
1817
use OpenTelemetry\Context\Context;
18+
use OpenTelemetry\Context\Propagation\TextMapPropagatorInterface;
1919
use OpenTelemetry\Contrib\Instrumentation\Laravel\Hooks\Hook;
2020
use OpenTelemetry\Contrib\Instrumentation\Laravel\Hooks\PostHookTrait;
2121
use OpenTelemetry\Contrib\Instrumentation\Laravel\LaravelInstrumentation;
@@ -40,15 +40,18 @@ public function instrument(
4040
schemaUrl: Version::VERSION_1_24_0->url(),
4141
);
4242

43-
$this->hookHandle($hookManager, $tracer);
43+
$this->hookHandle($hookManager, $tracer, $context->propagator);
4444
}
4545

46-
protected function hookHandle(HookManagerInterface $hookManager, TracerInterface $tracer): void
47-
{
46+
protected function hookHandle(
47+
HookManagerInterface $hookManager,
48+
TracerInterface $tracer,
49+
TextMapPropagatorInterface $propagator,
50+
): void {
4851
$hookManager->hook(
4952
KernelContract::class,
5053
'handle',
51-
preHook: function (KernelContract $kernel, array $params, string $class, string $function, ?string $filename, ?int $lineno) use ($tracer) {
54+
preHook: function (KernelContract $kernel, array $params, string $class, string $function, ?string $filename, ?int $lineno) use ($tracer, $propagator) {
5255
$request = ($params[0] instanceof Request) ? $params[0] : null;
5356
/** @psalm-suppress ArgumentTypeCoercion */
5457
$builder = $tracer
@@ -60,8 +63,7 @@ protected function hookHandle(HookManagerInterface $hookManager, TracerInterface
6063
->setAttribute(TraceAttributes::CODE_LINENO, $lineno);
6164
$parent = Context::getCurrent();
6265
if ($request) {
63-
/** @phan-suppress-next-line PhanAccessMethodInternal */
64-
$parent = Globals::propagator()->extract($request, HeadersPropagator::instance());
66+
$parent = $propagator->extract($request, HeadersPropagator::instance());
6567
$span = $builder
6668
->setParent($parent)
6769
->setAttribute(TraceAttributes::URL_FULL, $request->fullUrl())

0 commit comments

Comments
 (0)