Skip to content

Commit

Permalink
Laravel: use TextMapPropagatorInterface from InstrumentationContext i…
Browse files Browse the repository at this point in the history
…nstead of Globals.
  • Loading branch information
ChrisLightfootWild committed Oct 26, 2024
1 parent 44440df commit 5d3210d
Showing 1 changed file with 9 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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
Expand All @@ -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())
Expand Down

0 comments on commit 5d3210d

Please sign in to comment.