opentelemetry-php icon indicating copy to clipboard operation
opentelemetry-php copied to clipboard

Disable SDK from autoloading during composer execution.

Open ChrisLightfootWild opened this issue 4 months ago • 2 comments

Proposal to prevent the SDK from auto-loading during composer script execution.

During a composer script, the packaged dependencies in the composer.phar are currently locked to PSR-3 v2 and thus any local application dependencies which expect v3 can trigger a fatal error.

By preventing the SdkAutoloader from being auto-loaded, we can hopefully avoid the fatal error from triggering.

Fixes #1673.


To test, we can perform the following actions:

make update PHP_VERSION=8.3

make bash PHP_VERSION=8.3

OTEL_PHP_AUTOLOAD_ENABLED=true composer run-script test-psr3

Before:

> OpenTelemetry\Tests\Integration\Composer\Psr3CompatabilityTest::run

Fatal error: Declaration of Psr\Log\AbstractLogger::emergency(Stringable|string $message, array $context = []): void must be compatible with Psr\Log\LoggerInterface::emergency($message, array $context = []) in /usr/src/myapp/vendor/psr/log/src/LoggerTrait.php on line 18
echo $?
255

After:

> OpenTelemetry\Tests\Integration\Composer\Psr3CompatabilityTest::run
echo $?
0

ChrisLightfootWild avatar Oct 10 '25 15:10 ChrisLightfootWild

Codecov Report

:x: Patch coverage is 0% with 9 lines in your changes missing coverage. Please review. :white_check_mark: Project coverage is 68.25%. Comparing base (ddb222d) to head (e3005fb). :warning: Report is 12 commits behind head on main.

Files with missing lines Patch % Lines
src/SDK/Common/Util/ComposerHandler.php 0.00% 7 Missing :warning:
src/SDK/_autoload.php 0.00% 2 Missing :warning:
Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff              @@
##               main    #1727      +/-   ##
============================================
- Coverage     68.37%   68.25%   -0.12%     
- Complexity     2971     2974       +3     
============================================
  Files           448      449       +1     
  Lines          9020     8720     -300     
============================================
- Hits           6167     5952     -215     
+ Misses         2853     2768      -85     
Flag Coverage Δ
8.1 68.03% <0.00%> (-0.03%) :arrow_down:
8.2 68.22% <0.00%> (-0.03%) :arrow_down:
8.3 68.22% <0.00%> (+<0.01%) :arrow_up:
8.4 68.23% <0.00%> (-0.02%) :arrow_down:
8.5 68.21% <0.00%> (+0.01%) :arrow_up:

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
src/SDK/_autoload.php 0.00% <0.00%> (ø)
src/SDK/Common/Util/ComposerHandler.php 0.00% <0.00%> (ø)

... and 216 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update ddb222d...e3005fb. Read the comment docs.

:rocket: New features to boost your workflow:
  • :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

codecov[bot] avatar Oct 10 '25 15:10 codecov[bot]

@Nevay / @brettmc - can y'all take a look at this when you get a moment?

bobstrecansky avatar Nov 05 '25 13:11 bobstrecansky