Skip to content

Commit a3cf950

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

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

src/Instrumentation/Laravel/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"php": "^8.1",
1313
"ext-json": "*",
1414
"laravel/framework": "^10.0 || ^11.0",
15-
"open-telemetry/api": "^1.1",
15+
"open-telemetry/api": "^1.1.1",
1616
"open-telemetry/sem-conv": "^1.24"
1717
},
1818
"require-dev": {

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

Lines changed: 9 additions & 6 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
@@ -61,7 +64,7 @@ protected function hookHandle(HookManagerInterface $hookManager, TracerInterface
6164
$parent = Context::getCurrent();
6265
if ($request) {
6366
/** @phan-suppress-next-line PhanAccessMethodInternal */
64-
$parent = Globals::propagator()->extract($request, HeadersPropagator::instance());
67+
$parent = $propagator->extract($request, HeadersPropagator::instance());
6568
$span = $builder
6669
->setParent($parent)
6770
->setAttribute(TraceAttributes::URL_FULL, $request->fullUrl())

0 commit comments

Comments
 (0)