-
Notifications
You must be signed in to change notification settings - Fork 147
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
Compatibility with PHP 7.4+ preloading #1298
Conversation
9958713
to
14962c0
Compare
When the release is made, make sure there's a note about there now multiple generated files -- I think I've seen some customers copying the generated file. The note should also recommend against copying these files and rely on official builds and install processes, I think. |
…ersions of php unit
Recently static analysis started to fail because composer would install binaries, specifically phpstan binary, to ~/.config/composer/vendor/bin instead of ~/.composer/vendor/bin In addition to fix this path, we also now use the most modern cimg/php images as recommended by circleci: https://circleci.com/developer/images/image/cimg/php
14962c0
to
9158697
Compare
…er, as PHP-8 executes a request shutdown
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for explaining the complexities in detail. And the preloading + Composer tests in CI are fantastic. 💯 I left one optional suggestion but otherwise this LGTM! 👍
bridge/autoload.php
Outdated
// The autoloading mechanism is explained in `docs/autoloading.md`. If this file is changed, make sure that | ||
// documentation is up to date. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Totally optional: What do you think about moving the docs out of docs/autoloading.md
and into the relevant parts of this script as big comment blocks? I think having the docs and the code in the same file would really make it easier to understand and make it easier to keep the docs/comments up to date moving forward.
@SammyK thanks for the review, and I really like the idea of inlining the explanation. Here is the fix (plus a fix to a wrong skip comment in tests) 1c6525f...f1414a4 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me, good job with the testsuite, it should cover all scenarios :-)
Thanks both for the review |
Description
This PR fixes compatibility with PHP 7.4+ preload mechanism when
DDTrace
classes are used and required in theopcache.preload
script.While having a fully working tracing might require additional steps, for example lazy dependencies declaration when using Symfony's DI container, the primary objective of this PR is to not cause application crashes in any possible autoloading scenario. An example of application crash that this PR intend to avoid is described in #1042 (thanks @olsavmic for the excellent investigation and reproduction case).
An extract of a page added in
docs/autoloading.md
is reported here to explain the rationale behind specific decisions in the changes implemented.Autoloading mechanism
The autoloading mechanism of the tracing library is pretty complex and has to support different use cases:
DDTrace\*
classes in theopcache.preload
script;Most of the complexity comes from the following facts:
DDTrace
classes are defined internally by the extension, some are defined in userland but not autoloaded by composer and meant for internal use, while some others represent the public api and are both required by the internal loaded and by composer;opcache.preload
script;How it works
At request's
RINIT
time, the filebridge/autoload.php
is loaded which is in charge of loading all the required classes.The autoloading procedure works as described below:
DDTrace\ComposerBootstrap
is declared. Do not trigger the autoloading mechanism if the class is not defined, so 'terminal' autoloaders - that trigger errors if a class was not found - are supported.DDTrace\ComposerBootstrap
is declared insrc/api/bootstrap.composer.php
and it is loaded when the Composer'svendor/autoload.php
file is required by the user;files
section of the composer file, not as apsr4
autoloader, so it is loaded always, even when not explicitly required by the user;RINIT
means that all the following conditions are met:opcache.preload
script was executed;opcache.preload
script used composer;datadog/dd-trace
;opcache.preload
script are not visible while the autoload script is loaded duringRINIT
.src/api
classes that follows thepsr4
specificationpsr4
class loader is used in place of loading the_generated_api.php
file described below because some classes fromsrc/api
might have already be loaded during the execution of theopcache.preload
._generated_api.php
is loaded which contains all the classes that would be provided by the composer package;psr4
autoloader for performance reasons. As a matter of facts, composer never kicks in in this condition, since all the classes are already defined._generated_internal.php
is loaded, which declares all the classes and functions meant only for internal use, and not meant to be used by users for manual instrumentation.Readiness checklist
Reviewer checklist