Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[opentelemetry-php-contrib] Incorrect trace boundaries for Symfony HttpKernel auto instrumentation #1443

Open
petrisorciprian-vitals opened this issue Nov 28, 2024 · 0 comments · May be fixed by open-telemetry/opentelemetry-php-contrib#317
Labels
bug Something isn't working

Comments

@petrisorciprian-vitals
Copy link

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.

@petrisorciprian-vitals petrisorciprian-vitals added the bug Something isn't working label Nov 28, 2024
@petrisorciprian-vitals petrisorciprian-vitals changed the title [opentelemetry-php-contrib] [opentelemetry-php-contrib] Incorrect trace boundaries for Symfony HttpKernel auto instrumentation Nov 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
1 participant