Skip to content

Commit

Permalink
Use both native part and PHP part versions (if differ)
Browse files Browse the repository at this point in the history
  • Loading branch information
SergeyKleyman committed Sep 13, 2024
1 parent 34e95ee commit c83384a
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
36 changes: 31 additions & 5 deletions prod/php/ElasticOTel/PhpPartFacade.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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');
Expand Down

0 comments on commit c83384a

Please sign in to comment.