-
Notifications
You must be signed in to change notification settings - Fork 171
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-instrumentation] unable to hook functions that have already executed #1278
[opentelemetry-php-instrumentation] unable to hook functions that have already executed #1278
Comments
I'm pretty sure that's just how zend observer works. In all of the auto-instrumentation packages we provide, hooks are registered as part of composer autoloading (via autoload->files in composer.json), and then assume that calling I think documentation is the answer here (and if the suggestion above is helpful, maybe that can be better documented, too). |
Thanks for the reply @brettmc ,
Yes, exactly this - although I had other problems with the auto instrumentation, in that when running on the CLI locally without the opentelemetry extension installed, it was throwing fatal errors; our Laravel package is to allow an app to run on Google's serverless environment and seemlessly enable all the extra observability, by detecting when running in that environment at runtime & only enabling the features there. I've rolled all the instrumentation into our Laravel package itself & changed the order everything is loaded, which seems to be working great. If the documentation could be updated to help make this more clear, that would be ideal please. |
@iamacarpet - what sort of documentation would have helped you in this particular situation now that you understand it better? |
Thanks @bobstrecansky , In the extension repository, it already includes the following under “Usage”:
I feel a similar warning, to say something like: Warning: Be aware when registering a hook that functions can only be registered to be traced if they haven’t already been called in the current runtime context. I’m not sure of the exact wording, but something to that effect would have been helpful. |
Describe your environment
PHP 8.3.0
OpenTelemetry extension 1.0.0
Docker imaged based on gcr.io/gae-runtimes/buildpacks/php83/run:latest
Steps to reproduce
What is the expected behavior?
I expect that the hooks should run the second time those functions are called (after the hooks are registered).
What is the actual behavior?
The hooks never run, or more specifically, the closure specified as
pre
never runs.If however, you comment out the execution before you register the hooks, i.e.:
then the hooks run as expected.
So to clarify, if you try to register a hook for a function that has already been executed during the current request - it doesn't appear that those hooks will ever run.
Additional context
I stumbled upon this while trying to get instrumentation working for Guzzle - no matter what I tried, I couldn't hook the correct function (
GuzzleHttp\Client::transfer
), nor many of the surrounding functions or even classes, likeHandlerStack
: it was driving me crazy, initially thinking it was optimiser inlining, something to do with the JIT, or that you couldn't traceprivate
orprotected
functions - although all of those assumptions turned out to be false.After much testing, I discovered the problem as described above.
I was hitting this due to Guzzle being used VERY early in the request, due to metadata & authentication tokens being loaded from the metadata server (on GCP) before the instrumentation hooks were being registered.
Now this may not be something you can fix, as it may well be something inherent to the underlying zend_observer implementation, however, it may be useful to document it alongside the warning about function inlining, in case someone else runs across the same problem.
The text was updated successfully, but these errors were encountered: