Skip to content

Commit c68f0dd

Browse files
Disable SDK from autoloading during composer execution.
Fixes #1673.
1 parent ddb222d commit c68f0dd

File tree

3 files changed

+34
-1
lines changed

3 files changed

+34
-1
lines changed

composer.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,5 +207,10 @@
207207
"OpenTelemetry\\Tests\\Integration\\SDK\\Common\\Configuration\\TestEnvSourceProvider"
208208
]
209209
}
210+
},
211+
"scripts": {
212+
"test-psr3": [
213+
"OpenTelemetry\\Tests\\Integration\\Composer\\Psr3CompatabilityTest::run"
214+
]
210215
}
211216
}

src/SDK/_autoload.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,17 @@
22

33
declare(strict_types=1);
44

5-
\OpenTelemetry\SDK\SdkAutoloader::autoload();
5+
/**
6+
* If OTEL_PHP_AUTOLOAD_ENABLED=true, there may be compatability issues
7+
* if the version of PSR-3 installed in ./vendor conflicts with that of the
8+
* packaged composer PSR-3 library.
9+
*
10+
* If COMPOSER_DEV_MODE is present, then we can assume that a composer script
11+
* is running, and we can prevent the PSR-3 compatability issues by disabling
12+
* the SDK from activating.
13+
*
14+
* @see https://github.com/open-telemetry/opentelemetry-php/issues/1673
15+
*/
16+
if (getenv('COMPOSER_DEV_MODE') === false) {
17+
\OpenTelemetry\SDK\SdkAutoloader::autoload();
18+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace OpenTelemetry\Tests\Integration\Composer;
6+
7+
use Composer\Script\Event;
8+
9+
final class Psr3CompatabilityTest
10+
{
11+
public static function run(Event $event): void
12+
{
13+
require_once $event->getComposer()->getConfig()->get('vendor-dir').'/autoload.php';
14+
}
15+
}

0 commit comments

Comments
 (0)