Skip to content

Commit

Permalink
Adapted code to assume .php.template files converted to .php (#138)
Browse files Browse the repository at this point in the history
* Adapted code to assume .php.template files converted to .php

* Removed redundant local variable
  • Loading branch information
SergeyKleyman authored Nov 28, 2024
1 parent 113e075 commit c3d82ac
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 63 deletions.
2 changes: 1 addition & 1 deletion phpstan.dist.neon
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ parameters:

level: max

reportUnmatchedIgnoredErrors: false
reportUnmatchedIgnoredErrors: true
5 changes: 2 additions & 3 deletions prod/php/ElasticOTel/BootstrapStageLogger.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ public static function nullableToLog(null|int|string $str): string

public static function configure(int $maxEnabledLevel, string $phpSrcCodeRootDir, string $rootNamespace): void
{
/** @noinspection PhpIncludeInspection */
require __DIR__ . DIRECTORY_SEPARATOR . 'Log' . DIRECTORY_SEPARATOR . 'LogFeature.php';

self::$maxEnabledLevel = $maxEnabledLevel;
Expand Down Expand Up @@ -239,12 +238,12 @@ private static function logWithLevel(int $statementLevel, string $message, strin
/**
* elastic_otel_* functions are provided by the extension
*
* @noinspection PhpFullyQualifiedNameUsageInspection, PhpUndefinedClassInspection, PhpUndefinedFunctionInspection
* @noinspection PhpFullyQualifiedNameUsageInspection, PhpUndefinedFunctionInspection
*/
\elastic_otel_log_feature( // @phpstan-ignore function.notFound
0 /* $isForced */,
$statementLevel,
Log\LogFeature::BOOTSTRAP, // @phpstan-ignore class.notFound
Log\LogFeature::BOOTSTRAP,
self::LOG_CATEGORY,
self::processSourceCodeFilePathForLog($file),
$line,
Expand Down
49 changes: 0 additions & 49 deletions prod/php/ElasticOTel/ElasticOTelPhpPartVersion.php

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

namespace Elastic\OTel\HttpTransport;

use Elastic\OTel\ElasticOTelPhpPartVersion;
use Elastic\OTel\PhpPartVersion;
use OpenTelemetry\SDK\Common\Export\TransportFactoryInterface;

class ElasticHttpTransportFactory implements TransportFactoryInterface
Expand All @@ -41,7 +41,7 @@ public function create(
?string $key = null
): ElasticHttpTransport {
spl_autoload_call("Elastic\OTel\PhpPartVersion");
$headers['User-Agent'] = "elastic-otlp-http-php/" . ElasticOTelPhpPartVersion::get();
$headers['User-Agent'] = "elastic-otlp-http-php/" . PhpPartVersion::VALUE;
return new ElasticHttpTransport($endpoint, $contentType, $headers, $compression, $timeout, $retryDelay, $maxRetries, $cacert, $cert, $key);
}
}
9 changes: 5 additions & 4 deletions prod/php/ElasticOTel/Log/ElasticLogWriter.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,20 @@
class ElasticLogWriter implements LogWriterInterface
{
/**
* @param array<mixed> $context
* @param array<array-key, mixed> $context
*/
public function write(mixed $level, string $message, array $context): void
{
$edotLevel = is_string($level) ? Level::getFromPsrLevel($level) : Level::OFF;
/**
* elastic_otel_* functions are provided by the extension
*
* @noinspection PhpFullyQualifiedNameUsageInspection, PhpUndefinedClassInspection, PhpUndefinedFunctionInspection
* @noinspection PhpFullyQualifiedNameUsageInspection, PhpUndefinedFunctionInspection
*/
\elastic_otel_log_feature( // @phpstan-ignore function.notFound
0 /* isForced */,
Level::getFromPsrLevel(strval($level)) /* level */, // @phpstan-ignore argument.type
LogFeature::OTEL /* feature */, // @phpstan-ignore class.notFound
$edotLevel,
LogFeature::OTEL /* feature */,
'' /* category */,
'' /* file */,
0 /* line */,
Expand Down
6 changes: 3 additions & 3 deletions prod/php/ElasticOTel/PhpPartFacade.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,18 +112,18 @@ public static function bootstrap(string $elasticOTelNativePartVersion, int $maxE

private static function buildElasticOTelVersion(string $nativePartVersion): string
{
if ($nativePartVersion === ($phpPartVersion = ElasticOTelPhpPartVersion::get())) {
if ($nativePartVersion === PhpPartVersion::VALUE) {
return $nativePartVersion;
}

BootstrapStageLogger::logWarning(
'Native part and PHP part versions do not match' . "; nativePartVersion: $nativePartVersion" . "; phpPartVersion: $phpPartVersion",
'Native part and PHP part versions do not match. native part version: ' . $nativePartVersion . '; PHP part version: ' . PhpPartVersion::VALUE,
__FILE__,
__LINE__,
__CLASS__,
__FUNCTION__
);
return "$nativePartVersion/$phpPartVersion";
return $nativePartVersion . '/' . PhpPartVersion::VALUE;
}

private static function isInDevMode(): bool
Expand Down
14 changes: 13 additions & 1 deletion prod/php/ElasticOTel/PhpPartVersion.php.template
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,16 @@ declare(strict_types=1);

namespace Elastic\OTel;

const ELASTIC_OTEL_PHP_VERSION = '@_PROJECT_PROPERTIES_VERSION@';
use Elastic\OTel\Util\StaticClassTrait;

/**
* Code in this file is part of implementation internals, and thus it is not covered by the backward compatibility.
*
* @internal
*/
final class PhpPartVersion
{
use StaticClassTrait;

public const VALUE = '@_PROJECT_PROPERTIES_VERSION@';
}

0 comments on commit c3d82ac

Please sign in to comment.