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 a3cf950
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/Instrumentation/Laravel/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"php": "^8.1",
"ext-json": "*",
"laravel/framework": "^10.0 || ^11.0",
"open-telemetry/api": "^1.1",
"open-telemetry/api": "^1.1.1",
"open-telemetry/sem-conv": "^1.24"
},
"require-dev": {
Expand Down
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 @@ -61,7 +64,7 @@ protected function hookHandle(HookManagerInterface $hookManager, TracerInterface
$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 a3cf950

Please sign in to comment.