Repository navigation
Disable SDK from autoloading during composer execution. - #1727
Conversation
483a850 to
c68f0dd
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1727 +/- ##
============================================
- Coverage 68.37% 68.29% -0.08%
- Complexity 2971 2978 +7
============================================
Files 448 450 +2
Lines 9020 8731 -289
============================================
- Hits 6167 5963 -204
+ Misses 2853 2768 -85
Flags with carried forward coverage won't be shown. Click here to find out more.
... and 222 files with indirect coverage changes Continue to review full report in Codecov by Sentry.
🚀 New features to boost your workflow:
|
c68f0dd to
58b8ecc
Compare
58b8ecc to
9ec2a8c
Compare
| * | ||
| * @see https://github.com/open-telemetry/opentelemetry-php/issues/1673 | ||
| */ | ||
| if (getenv('COMPOSER_DEV_MODE') === false) { |
There was a problem hiding this comment.
| if (getenv('COMPOSER_DEV_MODE') === false) { | |
| if (getenv('COMPOSER_BINARY') === false) { |
COMPOSER_DEV_MODE is only set by the run-script command, running scripts directly still fails:
OTEL_PHP_AUTOLOAD_ENABLED=true composer test-psr3Edit: checking solely for COMPOSER_BINARY will be too strict as this environment variable is also propagated to @php scripts.
There was a problem hiding this comment.
@Nevay Ah, that is unfortunate - thanks for highlighting. Realistically, there may be no safe way to do this then? 🤔
There was a problem hiding this comment.
Why not start with COMPOSER_DEV_MODE, since that covers some failure cases? It could be broken out into its own class+function such as ComposerHandler::isRunning() to allow for future expansion of methods to identify whether composer is running?
There was a problem hiding this comment.
I've made the suggested change to move to a ComposerHandler::isRunning() check.
I have also added an additional rudimentary check to try to infer whether or not the composer executable has been called directly.
This does fix the problem with running this way:
OTEL_PHP_AUTOLOAD_ENABLED=true composer test-psr3
Are there any foreseen problems in doing these additional checks?
There was a problem hiding this comment.
I also noted a discussion started here which links to this issue.
|
|
||
| if ( | ||
| ($entrypoint = $_SERVER['argv'][0] ?? '') === getenv('COMPOSER_BINARY') | ||
| || in_array(basename($entrypoint), ['composer', 'composer.phar'], true) |
There was a problem hiding this comment.
Checking class_exists(\Composer\Console\Application::class, false) is likely the most reliable way to detect whether we are running as composer command.
There was a problem hiding this comment.
Thank you, I hadn't seen this comment until today (it is timestamped as 2 weeks ago though?! 🤔)
Would you prefer switching to the class_exists check?
There was a problem hiding this comment.
It sounds like a good check to me, yes please @ChrisLightfootWild
There was a problem hiding this comment.
@brettmc apologies for the huge delay here - just revisited this PR and made the suggested change.
…g under Composer.
Proposal to prevent the SDK from auto-loading during composer script execution.
During a composer script, the packaged dependencies in the
composer.pharare currently locked to PSR-3 v2 and thus any local application dependencies which expect v3 can trigger a fatal error.By preventing the
SdkAutoloaderfrom being auto-loaded, we can hopefully avoid the fatal error from triggering.Fixes #1673.
To test, we can perform the following actions:
Before:
After: