7
7
use Illuminate \Contracts \Http \Kernel as KernelContract ;
8
8
use Illuminate \Http \Request ;
9
9
use Illuminate \Routing \Route ;
10
- use OpenTelemetry \API \Globals ;
11
10
use OpenTelemetry \API \Instrumentation \AutoInstrumentation \Context as InstrumentationContext ;
12
11
use OpenTelemetry \API \Instrumentation \AutoInstrumentation \HookManagerInterface ;
13
12
use OpenTelemetry \API \Trace \Span ;
16
15
use OpenTelemetry \API \Trace \StatusCode ;
17
16
use OpenTelemetry \API \Trace \TracerInterface ;
18
17
use OpenTelemetry \Context \Context ;
18
+ use OpenTelemetry \Context \Propagation \TextMapPropagatorInterface ;
19
19
use OpenTelemetry \Contrib \Instrumentation \Laravel \Hooks \Hook ;
20
20
use OpenTelemetry \Contrib \Instrumentation \Laravel \Hooks \PostHookTrait ;
21
21
use OpenTelemetry \Contrib \Instrumentation \Laravel \LaravelInstrumentation ;
@@ -40,15 +40,18 @@ public function instrument(
40
40
schemaUrl: Version::VERSION_1_24_0 ->url (),
41
41
);
42
42
43
- $ this ->hookHandle ($ hookManager , $ tracer );
43
+ $ this ->hookHandle ($ hookManager , $ tracer, $ context -> propagator );
44
44
}
45
45
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 {
48
51
$ hookManager ->hook (
49
52
KernelContract::class,
50
53
'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 ) {
52
55
$ request = ($ params [0 ] instanceof Request) ? $ params [0 ] : null ;
53
56
/** @psalm-suppress ArgumentTypeCoercion */
54
57
$ builder = $ tracer
@@ -61,7 +64,7 @@ protected function hookHandle(HookManagerInterface $hookManager, TracerInterface
61
64
$ parent = Context::getCurrent ();
62
65
if ($ request ) {
63
66
/** @phan-suppress-next-line PhanAccessMethodInternal */
64
- $ parent = Globals:: propagator () ->extract ($ request , HeadersPropagator::instance ());
67
+ $ parent = $ propagator ->extract ($ request , HeadersPropagator::instance ());
65
68
$ span = $ builder
66
69
->setParent ($ parent )
67
70
->setAttribute (TraceAttributes::URL_FULL , $ request ->fullUrl ())
0 commit comments