-
Notifications
You must be signed in to change notification settings - Fork 212
Description
Describe your environment
PHP 8.2.24 (cli) (built: Sep 27 2024 04:16:10) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.2.24, Copyright (c) Zend Technologies
with Zend OPcache v8.2.24, Copyright (c), by Zend Technologies
with Xdebug v3.3.1, Copyright (c) 2002-2023, by Derick Rethans
Relevant packages:
- open-telemetry/opentelemetry-auto-symfony
- open-telemetry/opentelemetry-auto-psr14
Steps to reproduce
Install both packages in a Symfony project, enable otel SDK autoloader and fire a request to the application.
What is the expected behavior?
A single trace for the request.
What is the actual behavior?
Two traces, one for the request itself, and one for the Symfony\Component\HttpKernel\Event\TerminateEvent emitted by Symfony at the end of Symfony\Component\Runtime\Runner\Symfony\HttpKernelRunner.
Additional context
The problem seems to be the hooks set up in open-telemetry/opentelemetry-auto-symfony:
It hooks into the HttpKernel::handle method. The post hook detaches the scope via scope->detach().
The TerminateEvent is emitted by Symfony however after the post hook runs for HttpKernel::handle, at which point it no longer has a context with a traceId available, so a new one seems to be generated.
Potential solution
Since the HttpKernel extends TerminableInterface which exposes a terminate function, I propose removing the post hook from HttpKernel::handle and registering it on HttpKernel::terminate instead, so that this event is captured properly by opentelemetry-auto-psr14 and part of the same request trace instead of an individual one.