Skip to content

Commit

Permalink
Remove HttpKernelInterface and EventSubscriberInterface (#3)
Browse files Browse the repository at this point in the history
Co-authored-by: Nick Schuch <[email protected]>
  • Loading branch information
nickschuch and nickschuch authored Feb 27, 2024
1 parent 88b92df commit 7c598c2
Showing 1 changed file with 0 additions and 104 deletions.
104 changes: 0 additions & 104 deletions src/DrupalInstrumentation.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,109 +109,5 @@ public static function register(): void
$span->end();
}
);

hook(
HttpKernelInterface::class,
'handle',
pre: static function (
HttpKernelInterface $kernel,
array $params,
string $class,
string $function,
?string $filename,
?int $lineno,
) use ($instrumentation): array {
$messageClass = \get_class($kernel);

/** @psalm-suppress ArgumentTypeCoercion */
$builder = $instrumentation
->tracer()
->spanBuilder($messageClass)
->setSpanKind(SpanKind::KIND_INTERNAL)
->setAttribute(TraceAttributes::CODE_FUNCTION, $function)
->setAttribute(TraceAttributes::CODE_NAMESPACE, $class)
->setAttribute(TraceAttributes::CODE_FILEPATH, $filename)
->setAttribute(TraceAttributes::CODE_LINENO, $lineno);

$parent = Context::getCurrent();
$span = $builder
->setParent($parent)
->startSpan();

$context = $span->storeInContext($parent);
Context::storage()->attach($context);

return $params;
},
post: static function (
HttpKernelInterface $kernel,
array $params,
?Response $response,
?\Throwable $exception
): void {
$scope = Context::storage()->scope();
if (null === $scope) {
return;
}

$scope->detach();

$span = Span::fromContext($scope->context());

$span->end();
}
);

hook(
EventSubscriberInterface::class,
'handle',
pre: static function (
HttpKernelInterface $kernel,
array $params,
string $class,
string $function,
?string $filename,
?int $lineno,
) use ($instrumentation): array {
$messageClass = \get_class($kernel);

/** @psalm-suppress ArgumentTypeCoercion */
$builder = $instrumentation
->tracer()
->spanBuilder($messageClass)
->setSpanKind(SpanKind::KIND_INTERNAL)
->setAttribute(TraceAttributes::CODE_FUNCTION, $function)
->setAttribute(TraceAttributes::CODE_NAMESPACE, $class)
->setAttribute(TraceAttributes::CODE_FILEPATH, $filename)
->setAttribute(TraceAttributes::CODE_LINENO, $lineno);

$parent = Context::getCurrent();
$span = $builder
->setParent($parent)
->startSpan();

$context = $span->storeInContext($parent);
Context::storage()->attach($context);

return $params;
},
post: static function (
HttpKernelInterface $kernel,
array $params,
?Response $response,
?\Throwable $exception
): void {
$scope = Context::storage()->scope();
if (null === $scope) {
return;
}

$scope->detach();

$span = Span::fromContext($scope->context());

$span->end();
}
);
}
}

0 comments on commit 7c598c2

Please sign in to comment.