diff --git a/prod/native/extension/phpt/tests/includes/bootstrap_mock.inc b/prod/native/extension/phpt/tests/includes/bootstrap_mock.inc index 0667840..1445baf 100644 --- a/prod/native/extension/phpt/tests/includes/bootstrap_mock.inc +++ b/prod/native/extension/phpt/tests/includes/bootstrap_mock.inc @@ -6,7 +6,7 @@ namespace Elastic\OTel; final class PhpPartFacade { - public static function bootstrap(int $maxEnabledLogLevel, float $requestInitStartTime): bool { + public static function bootstrap(string $elasticOTelNativePartVersion, int $maxEnabledLogLevel, float $requestInitStartTime): bool { return true; } diff --git a/prod/php/ElasticOTel/PhpPartFacade.php b/prod/php/ElasticOTel/PhpPartFacade.php index 6518a3a..0e3b670 100644 --- a/prod/php/ElasticOTel/PhpPartFacade.php +++ b/prod/php/ElasticOTel/PhpPartFacade.php @@ -50,25 +50,25 @@ final class PhpPartFacade /** * Called by the extension * - * @param string $elasticOTelVersion + * @param string $elasticOTelNativePartVersion * @param int $maxEnabledLogLevel * @param float $requestInitStartTime * * @return bool */ - public static function bootstrap(string $elasticOTelVersion, int $maxEnabledLogLevel, float $requestInitStartTime): bool + public static function bootstrap(string $elasticOTelNativePartVersion, int $maxEnabledLogLevel, float $requestInitStartTime): bool { - self::$elasticOTelVersion = $elasticOTelVersion; - require __DIR__ . DIRECTORY_SEPARATOR . 'BootstrapStageLogger.php'; BootstrapStageLogger::configure($maxEnabledLogLevel, __DIR__, __NAMESPACE__); BootstrapStageLogger::logDebug( 'Starting bootstrap sequence...' - . "; elasticOTelVersion: $elasticOTelVersion" . "; maxEnabledLogLevel: $maxEnabledLogLevel" . "; requestInitStartTime: $requestInitStartTime", + . "; elasticOTelNativePartVersion: $elasticOTelNativePartVersion" . "; maxEnabledLogLevel: $maxEnabledLogLevel" . "; requestInitStartTime: $requestInitStartTime", __FILE__, __LINE__, __CLASS__, __FUNCTION__ ); + self::setElasticOTelVersion($elasticOTelNativePartVersion); + if (self::$singletonInstance !== null) { BootstrapStageLogger::logCritical( 'bootstrap() is called even though singleton instance is already created' @@ -96,6 +96,32 @@ public static function bootstrap(string $elasticOTelVersion, int $maxEnabledLogL return true; } + private static function setElasticOTelVersion(string $nativePartVersion): void + { + /** @noinspection PhpIncludeInspection */ + require __DIR__ . DIRECTORY_SEPARATOR . 'PhpPartVersion.php'; + + /** + * Constant Elastic\OTel\ELASTIC_OTEL_PHP_VERSION is defined in the generated file prod/php/ElasticOTel/PhpPartVersion.php + * + * @noinspection PhpUnnecessaryFullyQualifiedNameInspection, PhpUndefinedConstantInspection + * @phpstan-ignore-next-line + * + * @var string $phpPartVersion + */ + $phpPartVersion = \Elastic\OTel\ELASTIC_OTEL_PHP_VERSION; + + if ($nativePartVersion === $phpPartVersion) { + self::$elasticOTelVersion = $nativePartVersion; + } else { + BootstrapStageLogger::logDebug( + 'Native part and PHP part versions do not match' . "; nativePartVersion: $nativePartVersion" . "; phpPartVersion: $phpPartVersion", + __FILE__, __LINE__, __CLASS__, __FUNCTION__ + ); + self::$elasticOTelVersion = "$nativePartVersion/$phpPartVersion"; + } + } + private static function isInDevMode(): bool { $modeIsDevEnvVarVal = getenv('ELASTIC_OTEL_PHP_DEV_INTERNAL_MODE_IS_DEV');