diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml
index 764e8b336..8d84acaef 100644
--- a/.github/workflows/php.yml
+++ b/.github/workflows/php.yml
@@ -13,7 +13,7 @@ jobs:
strategy:
fail-fast: false
matrix:
- php-version: ['7.4', '8.0', '8.1', '8.2', '8.3']
+ php-version: ['8.0', '8.1', '8.2', '8.3']
experimental: [false]
composer_args: [""]
include:
@@ -138,4 +138,5 @@ jobs:
needs: php
with:
matrix_extension: '["ast, json, grpc"]'
+ matrix_php_version: '["8.0", "8.1", "8.2", "8.3"]'
install_directory: '~/.test/.packages'
diff --git a/.github/workflows/publish-otel-php-base-docker-image.yml b/.github/workflows/publish-otel-php-base-docker-image.yml
index 154c38f47..622fa0882 100644
--- a/.github/workflows/publish-otel-php-base-docker-image.yml
+++ b/.github/workflows/publish-otel-php-base-docker-image.yml
@@ -8,7 +8,7 @@ jobs:
name: OpenTelemetry PHP base docker image creation
strategy:
matrix:
- php-version: ['7.4', '8.0', '8.1', '8.2', '8.3']
+ php-version: ['8.0', '8.1', '8.2', '8.3']
runs-on: ubuntu-latest
permissions:
packages: write
diff --git a/.phan/config.php b/.phan/config.php
index f0e92471d..24b9eeaa5 100644
--- a/.phan/config.php
+++ b/.phan/config.php
@@ -44,7 +44,7 @@
//
// Note that the **only** effect of choosing `'5.6'` is to infer that functions removed in php 7.0 exist.
// (See `backward_compatibility_checks` for additional options)
- 'target_php_version' => '7.4',
+ 'target_php_version' => '8.0',
// If enabled, missing properties will be created when
// they are first seen. If false, we'll report an
diff --git a/.php-cs-fixer.php b/.php-cs-fixer.php
index b6811e3eb..7d3434de0 100644
--- a/.php-cs-fixer.php
+++ b/.php-cs-fixer.php
@@ -25,10 +25,10 @@
'blank_line_before_statement' => true,
'cast_spaces' => true,
'declare_strict_types' => true,
- 'function_typehint_space' => true,
+ 'type_declaration_spaces' => true,
'include' => true,
'lowercase_cast' => true,
- 'new_with_braces' => true,
+ 'new_with_parentheses' => true,
'no_extra_blank_lines' => true,
'no_leading_import_slash' => true,
'no_trailing_whitespace' => true,
@@ -41,9 +41,9 @@
'phpdoc_scalar' => true,
'phpdoc_types' => true,
'short_scalar_cast' => true,
- 'single_blank_line_before_namespace' => true,
+ 'blank_lines_before_namespace' => true,
'single_quote' => true,
- 'trailing_comma_in_multiline' => true,
+ 'trailing_comma_in_multiline' => ['elements' => ['arrays', 'parameters', 'match']],
])
->setRiskyAllowed(true)
->setFinder($finder);
diff --git a/DEVELOPMENT.md b/DEVELOPMENT.md
index 5f5a1ab5e..851a5817d 100644
--- a/DEVELOPMENT.md
+++ b/DEVELOPMENT.md
@@ -71,8 +71,8 @@ This does the following things:
### Other PHP versions
We aim to support officially supported PHP versions, according to https://www.php.net/supported-versions.php. The
-developer image `ghcr.io/open-telemetry/opentelemetry-php/opentelemetry-php-base` is tagged as `7.4`, `8.0`, `8.1` and `8.2`
-respectively, with `7.4` being the default. You can execute the test suite against other PHP versions by running the
+developer image `ghcr.io/open-telemetry/opentelemetry-php/opentelemetry-php-base` is tagged as `8.0`, `8.1`, `8.2` and `8.3`
+respectively, with `8.0` being the default. You can execute the test suite against other PHP versions by running the
following command:
```bash
diff --git a/Makefile b/Makefile
index de3cfa1e7..5b71997bc 100644
--- a/Makefile
+++ b/Makefile
@@ -1,6 +1,6 @@
include .env
-PHP_VERSION ?= 7.4
+PHP_VERSION ?= 8.0
DOCKER_COMPOSE ?= docker-compose
DC_RUN_PHP = $(DOCKER_COMPOSE) run --rm php
diff --git a/composer.json b/composer.json
index b86c11037..7d8b14697 100644
--- a/composer.json
+++ b/composer.json
@@ -7,7 +7,7 @@
"readme": "./README.md",
"license": "Apache-2.0",
"require": {
- "php": "^7.4 || ^8.0",
+ "php": "^8.0",
"ext-json": "*",
"google/protobuf": "^3.22",
"php-http/discovery": "^1.14",
@@ -17,7 +17,6 @@
"psr/http-message": "^1.0.1|^2.0",
"psr/log": "^1.1|^2.0|^3.0",
"symfony/polyfill-mbstring": "^1.23",
- "symfony/polyfill-php80": "^1.26",
"symfony/polyfill-php81": "^1.26",
"symfony/polyfill-php82": "^1.26"
},
@@ -77,9 +76,9 @@
"ext-grpc": "*",
"grpc/grpc": "^1.30",
"assertwell/phpunit-global-state": "^0.2.2",
- "composer/xdebug-handler": "^2.0",
+ "composer/xdebug-handler": "^3.0",
"dg/bypass-finals": "^1.4",
- "friendsofphp/php-cs-fixer": "^3.4",
+ "friendsofphp/php-cs-fixer": "^3.51",
"guzzlehttp/guzzle": "^7.4",
"guzzlehttp/psr7": "^2.1",
"mikey179/vfsstream": "^1.6.11",
diff --git a/docker-compose.collector.yaml b/docker-compose.collector.yaml
index 83d223ce8..2a5cbf698 100644
--- a/docker-compose.collector.yaml
+++ b/docker-compose.collector.yaml
@@ -1,7 +1,7 @@
version: '3.7'
services:
php:
- image: ghcr.io/open-telemetry/opentelemetry-php/opentelemetry-php-base:${PHP_VERSION:-7.4}
+ image: ghcr.io/open-telemetry/opentelemetry-php/opentelemetry-php-base:${PHP_VERSION:-8.0}
volumes:
- ./:/usr/src/myapp
depends_on:
diff --git a/docker-compose.prometheus.yaml b/docker-compose.prometheus.yaml
index 6069aab56..ffb77174c 100644
--- a/docker-compose.prometheus.yaml
+++ b/docker-compose.prometheus.yaml
@@ -23,7 +23,7 @@ services:
context: .
dockerfile: docker/examples/Dockerfile
args:
- - PHP_VERSION=7.4-fpm
+ - PHP_VERSION=8.0-fpm
- EXT_ENABLE=redis
volumes:
- ./examples/prometheus/index.php:/var/www/public/index.php
diff --git a/docker-compose.w3cTraceContext.yaml b/docker-compose.w3cTraceContext.yaml
index 6ec1ca968..6d0e3680f 100644
--- a/docker-compose.w3cTraceContext.yaml
+++ b/docker-compose.w3cTraceContext.yaml
@@ -1,7 +1,7 @@
version: '3.7'
services:
php:
- image: ghcr.io/open-telemetry/opentelemetry-php/opentelemetry-php-base:${PHP_VERSION:-7.4}
+ image: ghcr.io/open-telemetry/opentelemetry-php/opentelemetry-php-base:${PHP_VERSION:-8.0}
volumes:
- ./:/usr/src/myapp
- ./:/usr/src/open-telemetry/
diff --git a/docker-compose.yaml b/docker-compose.yaml
index bd4fbcb94..6e71fff7a 100644
--- a/docker-compose.yaml
+++ b/docker-compose.yaml
@@ -1,7 +1,7 @@
version: '3.7'
services:
php:
- image: ghcr.io/open-telemetry/opentelemetry-php/opentelemetry-php-base:${PHP_VERSION:-7.4}
+ image: ghcr.io/open-telemetry/opentelemetry-php/opentelemetry-php-base:${PHP_VERSION:-8.0}
volumes:
- ./:/usr/src/myapp
user: "${PHP_USER}:root"
diff --git a/docker/Dockerfile b/docker/Dockerfile
index 147a9c968..cd10be6cd 100644
--- a/docker/Dockerfile
+++ b/docker/Dockerfile
@@ -1,4 +1,4 @@
-ARG PHP_VERSION=7.4
+ARG PHP_VERSION=8.0
FROM php:${PHP_VERSION}-cli-alpine as php_build
ADD https://github.com/mlocati/docker-php-extension-installer/releases/latest/download/install-php-extensions /usr/local/bin/
diff --git a/examples/traces/features/batch_exporting_with_self_diagnostics.php b/examples/traces/features/batch_exporting_with_self_diagnostics.php
new file mode 100644
index 000000000..5cfee88d0
--- /dev/null
+++ b/examples/traces/features/batch_exporting_with_self_diagnostics.php
@@ -0,0 +1,26 @@
+getTracer('io.opentelemetry.contrib.php');
+$tracer->spanBuilder('root')->startSpan()->end();
+
+echo PHP_EOL . 'Example complete! ' . PHP_EOL;
diff --git a/proto/otel/composer.json b/proto/otel/composer.json
index dc8d24585..1ee4865e8 100644
--- a/proto/otel/composer.json
+++ b/proto/otel/composer.json
@@ -17,7 +17,7 @@
}
],
"require": {
- "php": "^7.4 || ^8.0",
+ "php": "^8.0",
"google/protobuf": "^3.3.0"
},
"autoload": {
diff --git a/psalm.xml.dist b/psalm.xml.dist
index cfc12dd06..bbcd259c9 100644
--- a/psalm.xml.dist
+++ b/psalm.xml.dist
@@ -18,4 +18,11 @@
+
+
+
+
+
+
+
diff --git a/rector.php b/rector.php
index 347905025..69f46d8e8 100644
--- a/rector.php
+++ b/rector.php
@@ -5,18 +5,18 @@
use Rector\CodeQuality\Rector\Array_\CallableThisArrayToAnonymousFunctionRector;
use Rector\CodeQuality\Rector\Identical\FlipTypeControlToUseExclusiveTypeRector;
use Rector\Config\RectorConfig;
-use Rector\Core\ValueObject\PhpVersion;
+use Rector\ValueObject\PhpVersion;
use Rector\Set\ValueObject\SetList;
return static function (RectorConfig $rectorConfig): void {
- $rectorConfig->phpVersion(PhpVersion::PHP_74);
+ $rectorConfig->phpVersion(PhpVersion::PHP_80);
$rectorConfig->paths([
__DIR__ . '/src',
]);
$rectorConfig->sets([
- SetList::PHP_74,
+ SetList::PHP_80,
SetList::CODE_QUALITY,
]);
$rectorConfig->skip([
diff --git a/src/API/Baggage/Baggage.php b/src/API/Baggage/Baggage.php
index 06c701605..e91e14bca 100644
--- a/src/API/Baggage/Baggage.php
+++ b/src/API/Baggage/Baggage.php
@@ -41,13 +41,9 @@ public static function getEmpty(): BaggageInterface
return self::$emptyBaggage;
}
- /** @var array */
- private array $entries;
-
/** @param array $entries */
- public function __construct(array $entries = [])
+ public function __construct(private array $entries = [])
{
- $this->entries = $entries;
}
/** @inheritDoc */
diff --git a/src/API/Baggage/BaggageBuilder.php b/src/API/Baggage/BaggageBuilder.php
index d4500eac5..80778661c 100644
--- a/src/API/Baggage/BaggageBuilder.php
+++ b/src/API/Baggage/BaggageBuilder.php
@@ -6,13 +6,9 @@
final class BaggageBuilder implements BaggageBuilderInterface
{
- /** @var array */
- private array $entries;
-
/** @param array $entries */
- public function __construct(array $entries = [])
+ public function __construct(private array $entries = [])
{
- $this->entries = $entries;
}
/** @inheritDoc */
diff --git a/src/API/Baggage/BaggageBuilderInterface.php b/src/API/Baggage/BaggageBuilderInterface.php
index 301cfbc3c..a65fcc0f7 100644
--- a/src/API/Baggage/BaggageBuilderInterface.php
+++ b/src/API/Baggage/BaggageBuilderInterface.php
@@ -10,9 +10,8 @@ interface BaggageBuilderInterface
{
/**
* @see https://github.com/open-telemetry/opentelemetry-specification/blob/v1.6.1/specification/baggage/api.md#set-value
- * @param mixed $value
*/
- public function set(string $key, $value, API\MetadataInterface $metadata = null): API\BaggageBuilderInterface;
+ public function set(string $key, mixed $value, API\MetadataInterface $metadata = null): API\BaggageBuilderInterface;
/**
* @see https://github.com/open-telemetry/opentelemetry-specification/blob/v1.6.1/specification/baggage/api.md#remove-value
diff --git a/src/API/Baggage/Entry.php b/src/API/Baggage/Entry.php
index eb3d0de5b..659f166cc 100644
--- a/src/API/Baggage/Entry.php
+++ b/src/API/Baggage/Entry.php
@@ -6,27 +6,13 @@
final class Entry
{
- /** @var mixed */
- private $value;
-
- private MetadataInterface $metadata;
-
- /**
- * @param mixed $value
- * @param MetadataInterface $metadata
- */
public function __construct(
- $value,
- MetadataInterface $metadata
+ private mixed $value,
+ private MetadataInterface $metadata,
) {
- $this->value = $value;
- $this->metadata = $metadata;
}
- /**
- * @return mixed
- */
- public function getValue()
+ public function getValue(): mixed
{
return $this->value;
}
diff --git a/src/API/Baggage/Metadata.php b/src/API/Baggage/Metadata.php
index 043c96a8a..bf2a4fbf4 100644
--- a/src/API/Baggage/Metadata.php
+++ b/src/API/Baggage/Metadata.php
@@ -13,11 +13,8 @@ public static function getEmpty(): Metadata
return self::$instance ??= new self('');
}
- private string $metadata;
-
- public function __construct(string $metadata)
+ public function __construct(private string $metadata)
{
- $this->metadata = $metadata;
}
public function getValue(): string
diff --git a/src/API/Baggage/Propagation/Parser.php b/src/API/Baggage/Propagation/Parser.php
index 3518b858d..2473c8235 100644
--- a/src/API/Baggage/Propagation/Parser.php
+++ b/src/API/Baggage/Propagation/Parser.php
@@ -17,12 +17,10 @@ final class Parser
private const EXCLUDED_VALUE_CHARS = [' ', '"', ',', ';', '\\'];
private const EQUALS = '=';
- /** @readonly */
- private string $baggageHeader;
-
- public function __construct(string $baggageHeader)
- {
- $this->baggageHeader = $baggageHeader;
+ public function __construct(
+ /** @readonly */
+ private string $baggageHeader,
+ ) {
}
public function parseInto(BaggageBuilderInterface $baggageBuilder): void
diff --git a/src/API/Behavior/Internal/LogWriter/Psr3LogWriter.php b/src/API/Behavior/Internal/LogWriter/Psr3LogWriter.php
index 5b2d19c15..c83b2631e 100644
--- a/src/API/Behavior/Internal/LogWriter/Psr3LogWriter.php
+++ b/src/API/Behavior/Internal/LogWriter/Psr3LogWriter.php
@@ -8,11 +8,8 @@
class Psr3LogWriter implements LogWriterInterface
{
- private LoggerInterface $logger;
-
- public function __construct(LoggerInterface $logger)
+ public function __construct(private LoggerInterface $logger)
{
- $this->logger = $logger;
}
public function write($level, string $message, array $context): void
diff --git a/src/API/Behavior/Internal/LogWriterFactory.php b/src/API/Behavior/Internal/LogWriterFactory.php
index 07c48cea5..5bf5a3af2 100644
--- a/src/API/Behavior/Internal/LogWriterFactory.php
+++ b/src/API/Behavior/Internal/LogWriterFactory.php
@@ -33,6 +33,7 @@ public function create(): LogWriterInterface
return new Psr3LogWriter($logger);
}
error_log('OpenTelemetry: cannot use OTEL_PHP_LOG_DESTINATION=psr3 without providing a PSR-3 logger');
+
//default to error log
return new ErrorLogWriter();
case 'error_log':
diff --git a/src/API/Globals.php b/src/API/Globals.php
index abf164a53..7256c1ac7 100644
--- a/src/API/Globals.php
+++ b/src/API/Globals.php
@@ -27,21 +27,12 @@ final class Globals
private static array $initializers = [];
private static ?self $globals = null;
- private TracerProviderInterface $tracerProvider;
- private MeterProviderInterface $meterProvider;
- private TextMapPropagatorInterface $propagator;
- private LoggerProviderInterface $loggerProvider;
-
public function __construct(
- TracerProviderInterface $tracerProvider,
- MeterProviderInterface $meterProvider,
- LoggerProviderInterface $loggerProvider,
- TextMapPropagatorInterface $propagator
+ private TracerProviderInterface $tracerProvider,
+ private MeterProviderInterface $meterProvider,
+ private LoggerProviderInterface $loggerProvider,
+ private TextMapPropagatorInterface $propagator,
) {
- $this->tracerProvider = $tracerProvider;
- $this->meterProvider = $meterProvider;
- $this->loggerProvider = $loggerProvider;
- $this->propagator = $propagator;
}
public static function tracerProvider(): TracerProviderInterface
diff --git a/src/API/Instrumentation/CachedInstrumentation.php b/src/API/Instrumentation/CachedInstrumentation.php
index 5ffb3950d..18609b66b 100644
--- a/src/API/Instrumentation/CachedInstrumentation.php
+++ b/src/API/Instrumentation/CachedInstrumentation.php
@@ -4,9 +4,6 @@
namespace OpenTelemetry\API\Instrumentation;
-use ArrayAccess;
-use function assert;
-use function class_exists;
use OpenTelemetry\API\Globals;
use OpenTelemetry\API\Logs\LoggerInterface;
use OpenTelemetry\API\Logs\LoggerProviderInterface;
@@ -14,7 +11,7 @@
use OpenTelemetry\API\Metrics\MeterProviderInterface;
use OpenTelemetry\API\Trace\TracerInterface;
use OpenTelemetry\API\Trace\TracerProviderInterface;
-use const PHP_VERSION_ID;
+use WeakMap;
/**
* Provides access to cached {@link TracerInterface} and {@link MeterInterface}
@@ -26,51 +23,31 @@
*/
final class CachedInstrumentation
{
- private string $name;
- private ?string $version;
- private ?string $schemaUrl;
- private iterable $attributes;
- /** @var ArrayAccess|null */
- private ?ArrayAccess $tracers;
- /** @var ArrayAccess|null */
- private ?ArrayAccess $meters;
- /** @var ArrayAccess|null */
- private ?ArrayAccess $loggers;
-
- public function __construct(string $name, ?string $version = null, ?string $schemaUrl = null, iterable $attributes = [])
- {
- $this->name = $name;
- $this->version = $version;
- $this->schemaUrl = $schemaUrl;
- $this->attributes = $attributes;
- $this->tracers = self::createWeakMap();
- $this->meters = self::createWeakMap();
- $this->loggers = self::createWeakMap();
- }
-
- private static function createWeakMap(): ?ArrayAccess
- {
- if (PHP_VERSION_ID < 80000) {
- return null;
- }
-
- /** @phan-suppress-next-line PhanUndeclaredClassReference */
- assert(class_exists(\WeakMap::class, false));
- /** @phan-suppress-next-line PhanUndeclaredClassMethod */
- $map = new \WeakMap();
- assert($map instanceof ArrayAccess);
-
- return $map;
+ /** @var WeakMap */
+ private WeakMap $tracers;
+ /** @var WeakMap */
+ private WeakMap $meters;
+ /** @var WeakMap */
+ private WeakMap $loggers;
+
+ /**
+ * @psalm-suppress PropertyTypeCoercion
+ */
+ public function __construct(
+ private string $name,
+ private ?string $version = null,
+ private ?string $schemaUrl = null,
+ private iterable $attributes = [],
+ ) {
+ $this->tracers = new \WeakMap();
+ $this->meters = new \WeakMap();
+ $this->loggers = new \WeakMap();
}
public function tracer(): TracerInterface
{
$tracerProvider = Globals::tracerProvider();
- if ($this->tracers === null) {
- return $tracerProvider->getTracer($this->name, $this->version, $this->schemaUrl, $this->attributes);
- }
-
return $this->tracers[$tracerProvider] ??= $tracerProvider->getTracer($this->name, $this->version, $this->schemaUrl, $this->attributes);
}
@@ -78,20 +55,12 @@ public function meter(): MeterInterface
{
$meterProvider = Globals::meterProvider();
- if ($this->meters === null) {
- return $meterProvider->getMeter($this->name, $this->version, $this->schemaUrl, $this->attributes);
- }
-
return $this->meters[$meterProvider] ??= $meterProvider->getMeter($this->name, $this->version, $this->schemaUrl, $this->attributes);
}
public function logger(): LoggerInterface
{
$loggerProvider = Globals::loggerProvider();
- if ($this->loggers === null) {
- return $loggerProvider->getLogger($this->name, $this->version, $this->schemaUrl, $this->attributes);
- }
-
return $this->loggers[$loggerProvider] ??= $loggerProvider->getLogger($this->name, $this->version, $this->schemaUrl, $this->attributes);
}
}
diff --git a/src/API/Instrumentation/InstrumentationTrait.php b/src/API/Instrumentation/InstrumentationTrait.php
index 1e695adb5..b46372d1a 100644
--- a/src/API/Instrumentation/InstrumentationTrait.php
+++ b/src/API/Instrumentation/InstrumentationTrait.php
@@ -111,6 +111,7 @@ abstract public function init(): bool;
public function activate(): bool
{
$this->validateImplementation();
+
// activate instrumentation with the API. not implemented yet.
return true;
}
diff --git a/src/API/Logs/EventLogger.php b/src/API/Logs/EventLogger.php
index 68deb865c..89e942ce7 100644
--- a/src/API/Logs/EventLogger.php
+++ b/src/API/Logs/EventLogger.php
@@ -6,13 +6,10 @@
class EventLogger implements EventLoggerInterface
{
- private LoggerInterface $logger;
- private string $domain;
-
- public function __construct(LoggerInterface $logger, string $domain)
- {
- $this->logger = $logger;
- $this->domain = $domain;
+ public function __construct(
+ private LoggerInterface $logger,
+ private string $domain,
+ ) {
}
public function logEvent(string $eventName, LogRecord $logRecord): void
diff --git a/src/API/Logs/LogRecord.php b/src/API/Logs/LogRecord.php
index 6833c71f9..755344e74 100644
--- a/src/API/Logs/LogRecord.php
+++ b/src/API/Logs/LogRecord.php
@@ -15,15 +15,10 @@ class LogRecord
protected ?ContextInterface $context = null;
protected int $severityNumber = 0;
protected ?string $severityText = null;
- protected $body = null;
protected array $attributes = [];
- /**
- * @param mixed $body
- */
- public function __construct($body = null)
+ public function __construct(protected mixed $body = null)
{
- $this->body = $body;
}
/**
@@ -45,7 +40,6 @@ public function setContext(?ContextInterface $context = null): self
}
/**
- * @param int $severityNumber Severity number
* @see https://opentelemetry.io/docs/reference/specification/logs/data-model/#field-severitynumber
*/
public function setSeverityNumber(int $severityNumber): self
@@ -79,7 +73,7 @@ public function setAttributes(iterable $attributes): self
return $this;
}
- public function setAttribute(string $name, $value): self
+ public function setAttribute(string $name, mixed $value): self
{
$this->attributes[$name] = $value;
@@ -89,7 +83,7 @@ public function setAttribute(string $name, $value): self
/**
* @param mixed $body The log record body
*/
- public function setBody($body = null): self
+ public function setBody(mixed $body = null): self
{
$this->body = $body;
diff --git a/src/API/Logs/LoggerProviderInterface.php b/src/API/Logs/LoggerProviderInterface.php
index e60353de2..340f49d47 100644
--- a/src/API/Logs/LoggerProviderInterface.php
+++ b/src/API/Logs/LoggerProviderInterface.php
@@ -13,6 +13,6 @@ public function getLogger(
string $name,
?string $version = null,
?string $schemaUrl = null,
- iterable $attributes = [] //instrumentation scope attributes
+ iterable $attributes = [], //instrumentation scope attributes
): LoggerInterface;
}
diff --git a/src/API/Logs/Map/Psr3.php b/src/API/Logs/Map/Psr3.php
index 8fd85fad0..63a00e7b9 100644
--- a/src/API/Logs/Map/Psr3.php
+++ b/src/API/Logs/Map/Psr3.php
@@ -16,25 +16,16 @@ class Psr3
*/
public static function severityNumber(string $level): int
{
- switch (strtolower($level)) {
- case LogLevel::DEBUG:
- return 5;
- case LogLevel::INFO:
- return 9;
- case LogLevel::NOTICE:
- return 10;
- case LogLevel::WARNING:
- return 13;
- case LogLevel::ERROR:
- return 17;
- case LogLevel::CRITICAL:
- return 18;
- case LogLevel::ALERT:
- return 19;
- case LogLevel::EMERGENCY:
- return 21;
- default:
- return 0;
- }
+ return match (strtolower($level)) {
+ LogLevel::DEBUG => 5,
+ LogLevel::INFO => 9,
+ LogLevel::NOTICE => 10,
+ LogLevel::WARNING => 13,
+ LogLevel::ERROR => 17,
+ LogLevel::CRITICAL => 18,
+ LogLevel::ALERT => 19,
+ LogLevel::EMERGENCY => 21,
+ default => 0,
+ };
}
}
diff --git a/src/API/Metrics/CounterInterface.php b/src/API/Metrics/CounterInterface.php
index 56f488caf..c5cec7f69 100644
--- a/src/API/Metrics/CounterInterface.php
+++ b/src/API/Metrics/CounterInterface.php
@@ -13,9 +13,8 @@ interface CounterInterface extends SynchronousInstrument
* @param float|int $amount non-negative amount to increment by
* @param iterable $attributes
* attributes of the data point
- * @param ContextInterface|false|null $context execution context
*
* @see https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/metrics/api.md#add
*/
- public function add($amount, iterable $attributes = [], $context = null): void;
+ public function add(float|int $amount, iterable $attributes = [], ContextInterface|false|null $context = null): void;
}
diff --git a/src/API/Metrics/HistogramInterface.php b/src/API/Metrics/HistogramInterface.php
index 34e4e8d2d..71a9091cf 100644
--- a/src/API/Metrics/HistogramInterface.php
+++ b/src/API/Metrics/HistogramInterface.php
@@ -17,5 +17,5 @@ interface HistogramInterface extends SynchronousInstrument
*
* @see https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/metrics/api.md#record
*/
- public function record($amount, iterable $attributes = [], $context = null): void;
+ public function record(float|int $amount, iterable $attributes = [], ContextInterface|false|null $context = null): void;
}
diff --git a/src/API/Metrics/MeterInterface.php b/src/API/Metrics/MeterInterface.php
index 55779fe41..192a0cd08 100644
--- a/src/API/Metrics/MeterInterface.php
+++ b/src/API/Metrics/MeterInterface.php
@@ -38,15 +38,15 @@ interface MeterInterface
public function batchObserve(
callable $callback,
AsynchronousInstrument $instrument,
- AsynchronousInstrument ...$instruments
+ AsynchronousInstrument ...$instruments,
): ObservableCallbackInterface;
/**
* Creates a `Counter`.
*
* @param string $name name of the instrument
- * @param string|null $unit unit of measure
- * @param string|null $description description of the instrument
+ * @param ?string $unit unit of measure
+ * @param ?string $description description of the instrument
* @param array $advisory an optional set of recommendations
* @return CounterInterface created instrument
*
@@ -56,15 +56,15 @@ public function createCounter(
string $name,
?string $unit = null,
?string $description = null,
- array $advisory = []
+ array $advisory = [],
): CounterInterface;
/**
* Creates an `ObservableCounter`.
*
* @param string $name name of the instrument
- * @param string|null $unit unit of measure
- * @param string|null $description description of the instrument
+ * @param ?string $unit unit of measure
+ * @param ?string $description description of the instrument
* @param array|callable $advisory an optional set of recommendations, or
* deprecated: the first callback to report measurements
* @param callable ...$callbacks responsible for reporting measurements
@@ -76,8 +76,8 @@ public function createObservableCounter(
string $name,
?string $unit = null,
?string $description = null,
- $advisory = [],
- callable ...$callbacks
+ array|callable $advisory = [],
+ callable ...$callbacks,
): ObservableCounterInterface;
/**
@@ -96,7 +96,7 @@ public function createHistogram(
string $name,
?string $unit = null,
?string $description = null,
- array $advisory = []
+ array $advisory = [],
): HistogramInterface;
/**
@@ -116,8 +116,8 @@ public function createObservableGauge(
string $name,
?string $unit = null,
?string $description = null,
- $advisory = [],
- callable ...$callbacks
+ array|callable $advisory = [],
+ callable ...$callbacks,
): ObservableGaugeInterface;
/**
@@ -135,7 +135,7 @@ public function createUpDownCounter(
string $name,
?string $unit = null,
?string $description = null,
- array $advisory = []
+ array $advisory = [],
): UpDownCounterInterface;
/**
@@ -155,7 +155,7 @@ public function createObservableUpDownCounter(
string $name,
?string $unit = null,
?string $description = null,
- $advisory = [],
- callable ...$callbacks
+ array|callable $advisory = [],
+ callable ...$callbacks,
): ObservableUpDownCounterInterface;
}
diff --git a/src/API/Metrics/MeterProviderInterface.php b/src/API/Metrics/MeterProviderInterface.php
index f8fa07a2e..fe9393910 100644
--- a/src/API/Metrics/MeterProviderInterface.php
+++ b/src/API/Metrics/MeterProviderInterface.php
@@ -23,6 +23,6 @@ public function getMeter(
string $name,
?string $version = null,
?string $schemaUrl = null,
- iterable $attributes = []
+ iterable $attributes = [],
): MeterInterface;
}
diff --git a/src/API/Metrics/Noop/NoopMeterProvider.php b/src/API/Metrics/Noop/NoopMeterProvider.php
index b4b5810eb..6ee6d6774 100644
--- a/src/API/Metrics/Noop/NoopMeterProvider.php
+++ b/src/API/Metrics/Noop/NoopMeterProvider.php
@@ -13,7 +13,7 @@ public function getMeter(
string $name,
?string $version = null,
?string $schemaUrl = null,
- iterable $attributes = []
+ iterable $attributes = [],
): MeterInterface {
return new NoopMeter();
}
diff --git a/src/API/Metrics/ObserverInterface.php b/src/API/Metrics/ObserverInterface.php
index 36e0ea791..f9975c1bc 100644
--- a/src/API/Metrics/ObserverInterface.php
+++ b/src/API/Metrics/ObserverInterface.php
@@ -14,5 +14,5 @@ interface ObserverInterface
* @param iterable $attributes
* attributes of the data point
*/
- public function observe($amount, iterable $attributes = []): void;
+ public function observe(float|int $amount, iterable $attributes = []): void;
}
diff --git a/src/API/Trace/NonRecordingSpan.php b/src/API/Trace/NonRecordingSpan.php
index 67d74d39b..b94d46305 100644
--- a/src/API/Trace/NonRecordingSpan.php
+++ b/src/API/Trace/NonRecordingSpan.php
@@ -13,12 +13,8 @@
*/
final class NonRecordingSpan extends Span
{
- private SpanContextInterface $context;
-
- public function __construct(
- SpanContextInterface $context
- ) {
- $this->context = $context;
+ public function __construct(private SpanContextInterface $context)
+ {
}
/** @inheritDoc */
diff --git a/src/API/Trace/NoopSpanBuilder.php b/src/API/Trace/NoopSpanBuilder.php
index 6f971e525..024118d35 100644
--- a/src/API/Trace/NoopSpanBuilder.php
+++ b/src/API/Trace/NoopSpanBuilder.php
@@ -10,17 +10,13 @@
final class NoopSpanBuilder implements SpanBuilderInterface
{
- private ContextStorageInterface $contextStorage;
+ private ContextInterface|false|null $parentContext = null;
- /** @var ContextInterface|false|null */
- private $parentContext = null;
-
- public function __construct(ContextStorageInterface $contextStorage)
+ public function __construct(private ContextStorageInterface $contextStorage)
{
- $this->contextStorage = $contextStorage;
}
- public function setParent($context): SpanBuilderInterface
+ public function setParent(ContextInterface|false|null $context): SpanBuilderInterface
{
$this->parentContext = $context;
@@ -32,7 +28,7 @@ public function addLink(SpanContextInterface $context, iterable $attributes = []
return $this;
}
- public function setAttribute(string $key, $value): SpanBuilderInterface
+ public function setAttribute(string $key, mixed $value): SpanBuilderInterface
{
return $this;
}
diff --git a/src/API/Trace/NoopTracerProvider.php b/src/API/Trace/NoopTracerProvider.php
index e186a6fd9..1ffb4be74 100644
--- a/src/API/Trace/NoopTracerProvider.php
+++ b/src/API/Trace/NoopTracerProvider.php
@@ -10,7 +10,7 @@ public function getTracer(
string $name,
?string $version = null,
?string $schemaUrl = null,
- iterable $attributes = []
+ iterable $attributes = [],
): TracerInterface {
return NoopTracer::getInstance();
}
diff --git a/src/API/Trace/Propagation/TraceContextValidator.php b/src/API/Trace/Propagation/TraceContextValidator.php
index 5fb3f12c7..167cc0daa 100644
--- a/src/API/Trace/Propagation/TraceContextValidator.php
+++ b/src/API/Trace/Propagation/TraceContextValidator.php
@@ -11,10 +11,6 @@ class TraceContextValidator
public const TRACE_FLAG_LENGTH = 2;
public const TRACE_VERSION_REGEX = '/^(?!ff)[\da-f]{2}$/';
- /**
- * @param string $traceVersion
- * @return bool Returns a value that indicates whether a trace version is valid.
- */
public static function isValidTraceVersion(string $traceVersion): bool
{
return 1 === preg_match(self::TRACE_VERSION_REGEX, $traceVersion);
diff --git a/src/API/Trace/SpanBuilderInterface.php b/src/API/Trace/SpanBuilderInterface.php
index 52070933a..b8a9bce72 100644
--- a/src/API/Trace/SpanBuilderInterface.php
+++ b/src/API/Trace/SpanBuilderInterface.php
@@ -20,10 +20,10 @@ interface SpanBuilderInterface
*
* @see https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/api.md#span-creation
*/
- public function setParent($context): SpanBuilderInterface;
+ public function setParent(ContextInterface|false|null $context): SpanBuilderInterface;
public function addLink(SpanContextInterface $context, iterable $attributes = []): SpanBuilderInterface;
- public function setAttribute(string $key, $value): SpanBuilderInterface;
+ public function setAttribute(string $key, mixed $value): SpanBuilderInterface;
public function setAttributes(iterable $attributes): SpanBuilderInterface;
/**
diff --git a/src/API/Trace/SpanContext.php b/src/API/Trace/SpanContext.php
index 7da7c0701..7724def86 100644
--- a/src/API/Trace/SpanContext.php
+++ b/src/API/Trace/SpanContext.php
@@ -15,35 +15,24 @@ final class SpanContext implements SpanContextInterface
* @see https://www.w3.org/TR/trace-context/#sampled-flag
*/
private bool $isSampled;
-
- private string $traceId;
- private string $spanId;
- private ?TraceStateInterface $traceState;
private bool $isValid = true;
- private bool $isRemote;
- private int $traceFlags;
private function __construct(
- string $traceId,
- string $spanId,
- int $traceFlags,
- bool $isRemote,
- TraceStateInterface $traceState = null
+ private string $traceId,
+ private string $spanId,
+ private int $traceFlags,
+ private bool $isRemote,
+ private ?TraceStateInterface $traceState = null,
) {
// TraceId must be exactly 16 bytes (32 chars) and at least one non-zero byte
// SpanId must be exactly 8 bytes (16 chars) and at least one non-zero byte
if (!SpanContextValidator::isValidTraceId($traceId) || !SpanContextValidator::isValidSpanId($spanId)) {
- $traceId = SpanContextValidator::INVALID_TRACE;
- $spanId = SpanContextValidator::INVALID_SPAN;
+ $this->traceId = SpanContextValidator::INVALID_TRACE;
+ $this->spanId = SpanContextValidator::INVALID_SPAN;
$this->isValid=false;
}
- $this->traceId = $traceId;
- $this->spanId = $spanId;
- $this->traceState = $traceState;
- $this->isRemote = $isRemote;
$this->isSampled = ($traceFlags & TraceFlags::SAMPLED) === TraceFlags::SAMPLED;
- $this->traceFlags = $traceFlags;
}
public function getTraceId(): string
diff --git a/src/API/Trace/SpanInterface.php b/src/API/Trace/SpanInterface.php
index 274a257ea..72c042603 100644
--- a/src/API/Trace/SpanInterface.php
+++ b/src/API/Trace/SpanInterface.php
@@ -55,7 +55,7 @@ public function isRecording(): bool;
* @param non-empty-string $key
* @param bool|int|float|string|array|null $value Note: arrays MUST be homogeneous, i.e. it MUST NOT contain values of different types.
*/
- public function setAttribute(string $key, $value): SpanInterface;
+ public function setAttribute(string $key, bool|int|float|string|array|null $value): SpanInterface;
/**
* @see https://github.com/open-telemetry/opentelemetry-specification/blob/v1.6.1/specification/trace/api.md#set-attributes
diff --git a/src/API/Trace/TraceStateInterface.php b/src/API/Trace/TraceStateInterface.php
index 79d4e0299..394ea1b95 100644
--- a/src/API/Trace/TraceStateInterface.php
+++ b/src/API/Trace/TraceStateInterface.php
@@ -24,8 +24,6 @@ interface TraceStateInterface
* Return a new TraceState object that inherits from this TraceState
* and contains the given key value pair.
*
- * @param string $key
- * @param string $value
* @return TraceStateInterface
*/
public function with(string $key, string $value): TraceStateInterface;
@@ -34,7 +32,6 @@ public function with(string $key, string $value): TraceStateInterface;
* Return a new TraceState object that inherits from this TraceState
* without the given key value pair.
*
- * @param string $key
* @return TraceStateInterface
*/
public function without(string $key): TraceStateInterface;
@@ -42,7 +39,6 @@ public function without(string $key): TraceStateInterface;
/**
* Return the value of a given key from this TraceState if it exists
*
- * @param string $key
* @return string|null
*/
public function get(string $key): ?string;
diff --git a/src/API/Trace/TracerProviderInterface.php b/src/API/Trace/TracerProviderInterface.php
index 9f5d20759..31a51c0a0 100644
--- a/src/API/Trace/TracerProviderInterface.php
+++ b/src/API/Trace/TracerProviderInterface.php
@@ -14,6 +14,6 @@ public function getTracer(
string $name,
?string $version = null,
?string $schemaUrl = null,
- iterable $attributes = []
+ iterable $attributes = [],
): TracerInterface;
}
diff --git a/src/API/composer.json b/src/API/composer.json
index c756df119..78c9c5ee0 100644
--- a/src/API/composer.json
+++ b/src/API/composer.json
@@ -17,10 +17,9 @@
}
],
"require": {
- "php": "^7.4 || ^8.0",
+ "php": "^8.0",
"open-telemetry/context": "^1.0",
"psr/log": "^1.1|^2.0|^3.0",
- "symfony/polyfill-php80": "^1.26",
"symfony/polyfill-php81": "^1.26",
"symfony/polyfill-php82": "^1.26"
},
diff --git a/src/Context/Context.php b/src/Context/Context.php
index 1a0b26226..278c27d3e 100644
--- a/src/Context/Context.php
+++ b/src/Context/Context.php
@@ -39,6 +39,7 @@ public static function createKey(string $key): ContextKeyInterface
/**
* @param ContextStorageInterface&ExecutionContextAwareInterface $storage
+ * @todo update type-hint (php >= 8.1)
*/
public static function setStorage(ContextStorageInterface $storage): void
{
@@ -47,6 +48,7 @@ public static function setStorage(ContextStorageInterface $storage): void
/**
* @return ContextStorageInterface&ExecutionContextAwareInterface
+ * @todo update return type-hint (php >= 8.1)
*/
public static function storage(): ContextStorageInterface
{
@@ -55,11 +57,9 @@ public static function storage(): ContextStorageInterface
}
/**
- * @param ContextInterface|false|null $context
- *
* @internal OpenTelemetry
*/
- public static function resolve($context, ?ContextStorageInterface $contextStorage = null): ContextInterface
+ public static function resolve(ContextInterface|false|null $context, ?ContextStorageInterface $contextStorage = null): ContextInterface
{
return $context
?? ($contextStorage ?? self::storage())->current()
diff --git a/src/Context/ContextKey.php b/src/Context/ContextKey.php
index f7450249e..16ecb49ee 100644
--- a/src/Context/ContextKey.php
+++ b/src/Context/ContextKey.php
@@ -9,11 +9,8 @@
*/
final class ContextKey implements ContextKeyInterface
{
- private ?string $name;
-
- public function __construct(?string $name=null)
+ public function __construct(private ?string $name = null)
{
- $this->name = $name;
}
public function name(): ?string
diff --git a/src/Context/ContextStorageHead.php b/src/Context/ContextStorageHead.php
index 3cc4d7181..a942496dd 100644
--- a/src/Context/ContextStorageHead.php
+++ b/src/Context/ContextStorageHead.php
@@ -9,11 +9,9 @@
*/
final class ContextStorageHead
{
- public ContextStorage $storage;
public ?ContextStorageNode $node = null;
- public function __construct(ContextStorage $storage)
+ public function __construct(public ContextStorage $storage)
{
- $this->storage = $storage;
}
}
diff --git a/src/Context/ContextStorageNode.php b/src/Context/ContextStorageNode.php
index 12d521660..241fe951e 100644
--- a/src/Context/ContextStorageNode.php
+++ b/src/Context/ContextStorageNode.php
@@ -11,19 +11,13 @@
*/
final class ContextStorageNode implements ScopeInterface, ContextStorageScopeInterface
{
- public ContextInterface $context;
- public ContextStorageHead $head;
- private ?ContextStorageNode $previous;
private array $localStorage = [];
public function __construct(
- ContextInterface $context,
- ContextStorageHead $head,
- ?ContextStorageNode $previous = null
+ public ContextInterface $context,
+ public ContextStorageHead $head,
+ private ?ContextStorageNode $previous = null,
) {
- $this->context = $context;
- $this->head = $head;
- $this->previous = $previous;
}
public function offsetExists($offset): bool
@@ -76,8 +70,8 @@ public function detach(): int
assert($this->head->node !== null);
for ($n = $this->head->node, $depth = 1;
- $n->previous !== $this;
- $n = $n->previous, $depth++) {
+ $n->previous !== $this;
+ $n = $n->previous, $depth++) {
assert($n->previous !== null);
}
$n->previous = $this->previous;
diff --git a/src/Context/DebugScope.php b/src/Context/DebugScope.php
index 887762025..437234e40 100644
--- a/src/Context/DebugScope.php
+++ b/src/Context/DebugScope.php
@@ -24,15 +24,12 @@ final class DebugScope implements ScopeInterface
{
private static bool $shutdownHandlerInitialized = false;
private static bool $finalShutdownPhase = false;
-
- private ContextStorageScopeInterface $scope;
private ?int $fiberId;
private array $createdAt;
private ?array $detachedAt = null;
- public function __construct(ContextStorageScopeInterface $scope)
+ public function __construct(private ContextStorageScopeInterface $scope)
{
- $this->scope = $scope;
$this->fiberId = self::currentFiberId();
$this->createdAt = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
diff --git a/src/Context/FiberBoundContextStorage.php b/src/Context/FiberBoundContextStorage.php
index 667f73b3d..180846f91 100644
--- a/src/Context/FiberBoundContextStorage.php
+++ b/src/Context/FiberBoundContextStorage.php
@@ -20,15 +20,11 @@
*/
final class FiberBoundContextStorage implements ContextStorageInterface, ExecutionContextAwareInterface
{
- /** @var ContextStorageInterface&ExecutionContextAwareInterface */
- private ContextStorageInterface $storage;
-
/**
* @param ContextStorageInterface&ExecutionContextAwareInterface $storage
*/
- public function __construct(ContextStorageInterface $storage)
+ public function __construct(private ContextStorageInterface $storage)
{
- $this->storage = $storage;
}
public function fork($id): void
diff --git a/src/Context/FiberBoundContextStorageScope.php b/src/Context/FiberBoundContextStorageScope.php
index 647552244..f4708f216 100644
--- a/src/Context/FiberBoundContextStorageScope.php
+++ b/src/Context/FiberBoundContextStorageScope.php
@@ -18,11 +18,8 @@
*/
final class FiberBoundContextStorageScope implements ScopeInterface, ContextStorageScopeInterface
{
- private ContextStorageScopeInterface $scope;
-
- public function __construct(ContextStorageScopeInterface $scope)
+ public function __construct(private ContextStorageScopeInterface $scope)
{
- $this->scope = $scope;
}
public function offsetExists($offset): bool
diff --git a/src/Context/Propagation/ArrayAccessGetterSetter.php b/src/Context/Propagation/ArrayAccessGetterSetter.php
index 51263044d..5345de261 100644
--- a/src/Context/Propagation/ArrayAccessGetterSetter.php
+++ b/src/Context/Propagation/ArrayAccessGetterSetter.php
@@ -6,11 +6,8 @@
use function array_key_first;
use ArrayAccess;
-use function get_class;
-use function gettype;
use InvalidArgumentException;
use function is_array;
-use function is_object;
use function is_string;
use function sprintf;
use function strcasecmp;
@@ -53,7 +50,7 @@ public function keys($carrier): array
throw new InvalidArgumentException(
sprintf(
'Unsupported carrier type: %s.',
- is_object($carrier) ? get_class($carrier) : gettype($carrier),
+ get_debug_type($carrier),
)
);
}
@@ -75,7 +72,7 @@ public function get($carrier, string $key): ?string
throw new InvalidArgumentException(
sprintf(
'Unsupported carrier type: %s. Unable to get value associated with key:%s',
- is_object($carrier) ? get_class($carrier) : gettype($carrier),
+ get_debug_type($carrier),
$key
)
);
@@ -100,7 +97,7 @@ public function set(&$carrier, string $key, string $value): void
throw new InvalidArgumentException(
sprintf(
'Unsupported carrier type: %s. Unable to set value associated with key:%s',
- is_object($carrier) ? get_class($carrier) : gettype($carrier),
+ get_debug_type($carrier),
$key
)
);
diff --git a/src/Context/Propagation/MultiTextMapPropagator.php b/src/Context/Propagation/MultiTextMapPropagator.php
index 075fe98fe..9a81324fc 100644
--- a/src/Context/Propagation/MultiTextMapPropagator.php
+++ b/src/Context/Propagation/MultiTextMapPropagator.php
@@ -15,14 +15,6 @@ final class MultiTextMapPropagator implements TextMapPropagatorInterface
{
/**
* @readonly
- *
- * @var list
- */
- private array $propagators = [];
-
- /**
- * @readonly
- *
* @var list
*/
private array $fields;
@@ -32,10 +24,11 @@ final class MultiTextMapPropagator implements TextMapPropagatorInterface
*
* @param list $propagators
*/
- public function __construct(array $propagators)
- {
- $this->propagators = $propagators;
- $this->fields = $this->extractFields($propagators);
+ public function __construct(
+ /** @readonly */
+ private array $propagators,
+ ) {
+ $this->fields = $this->extractFields($this->propagators);
}
public function fields(): array
diff --git a/src/Context/Propagation/SanitizeCombinedHeadersPropagationGetter.php b/src/Context/Propagation/SanitizeCombinedHeadersPropagationGetter.php
index 40652982e..cab2b7b19 100644
--- a/src/Context/Propagation/SanitizeCombinedHeadersPropagationGetter.php
+++ b/src/Context/Propagation/SanitizeCombinedHeadersPropagationGetter.php
@@ -18,11 +18,8 @@ final class SanitizeCombinedHeadersPropagationGetter implements PropagationGette
private const SERVER_CONCAT_HEADERS_REGEX = '/;(?=[^,=;]*=|$)/';
private const TRAILING_LEADING_SEPARATOR_REGEX = '/^' . self::LIST_MEMBERS_SEPARATOR . '+|' . self::LIST_MEMBERS_SEPARATOR . '+$/';
- private PropagationGetterInterface $getter;
-
- public function __construct(PropagationGetterInterface $getter)
+ public function __construct(private PropagationGetterInterface $getter)
{
- $this->getter = $getter;
}
public function keys($carrier): array
diff --git a/src/Context/Propagation/TextMapPropagatorInterface.php b/src/Context/Propagation/TextMapPropagatorInterface.php
index fdf2d5141..b2e6582fa 100644
--- a/src/Context/Propagation/TextMapPropagatorInterface.php
+++ b/src/Context/Propagation/TextMapPropagatorInterface.php
@@ -25,10 +25,8 @@ public function fields() : array;
* via an {@see PropagationSetterInterface}.
*
* @see https://github.com/open-telemetry/opentelemetry-specification/blob/v1.6.1/specification/context/api-propagators.md#textmap-inject
- *
- * @param mixed $carrier
*/
- public function inject(&$carrier, PropagationSetterInterface $setter = null, ContextInterface $context = null): void;
+ public function inject(mixed &$carrier, PropagationSetterInterface $setter = null, ContextInterface $context = null): void;
/**
* Extracts specific values from the provided carrier into the provided {@see ContextInterface}
diff --git a/src/Context/composer.json b/src/Context/composer.json
index 348b57f73..ee191de9b 100644
--- a/src/Context/composer.json
+++ b/src/Context/composer.json
@@ -17,8 +17,7 @@
}
],
"require": {
- "php": "^7.4 || ^8.0",
- "symfony/polyfill-php80": "^1.26",
+ "php": "^8.0",
"symfony/polyfill-php81": "^1.26",
"symfony/polyfill-php82": "^1.26"
},
diff --git a/src/Contrib/Grpc/GrpcTransport.php b/src/Contrib/Grpc/GrpcTransport.php
index 664516844..338b89b3b 100644
--- a/src/Contrib/Grpc/GrpcTransport.php
+++ b/src/Contrib/Grpc/GrpcTransport.php
@@ -18,6 +18,7 @@
use const Grpc\OP_SEND_MESSAGE;
use const Grpc\STATUS_OK;
use Grpc\Timeval;
+use OpenTelemetry\Contrib\Otlp\ContentTypes;
use OpenTelemetry\SDK\Common\Export\TransportInterface;
use OpenTelemetry\SDK\Common\Future\CancellationInterface;
use OpenTelemetry\SDK\Common\Future\CompletedFuture;
@@ -36,23 +37,21 @@ final class GrpcTransport implements TransportInterface
{
private array $metadata;
private Channel $channel;
- private string $method;
private bool $closed = false;
public function __construct(
string $endpoint,
array $opts,
- string $method,
- array $headers = []
+ private string $method,
+ array $headers = [],
) {
$this->channel = new Channel($endpoint, $opts);
- $this->method = $method;
$this->metadata = $this->formatMetadata(array_change_key_case($headers));
}
public function contentType(): string
{
- return 'application/x-protobuf';
+ return ContentTypes::PROTOBUF;
}
public function send(string $payload, ?CancellationInterface $cancellation = null): FutureInterface
diff --git a/src/Contrib/Grpc/GrpcTransportFactory.php b/src/Contrib/Grpc/GrpcTransportFactory.php
index d290fd542..d2c9ecf4b 100644
--- a/src/Contrib/Grpc/GrpcTransportFactory.php
+++ b/src/Contrib/Grpc/GrpcTransportFactory.php
@@ -12,6 +12,7 @@
use InvalidArgumentException;
use function json_encode;
use OpenTelemetry\API\Behavior\LogsMessagesTrait;
+use OpenTelemetry\Contrib\Otlp\ContentTypes;
use OpenTelemetry\SDK\Common\Export\TransportFactoryInterface;
use OpenTelemetry\SDK\Common\Export\TransportInterface;
use function parse_url;
@@ -31,7 +32,7 @@ final class GrpcTransportFactory implements TransportFactoryInterface
*/
public function create(
string $endpoint,
- string $contentType = 'application/x-protobuf',
+ string $contentType = ContentTypes::PROTOBUF,
array $headers = [],
$compression = null,
float $timeout = 10.,
@@ -39,15 +40,15 @@ public function create(
int $maxRetries = 3,
?string $cacert = null,
?string $cert = null,
- ?string $key = null
+ ?string $key = null,
): TransportInterface {
$parts = parse_url($endpoint);
if (!isset($parts['scheme'], $parts['host'], $parts['path'])) {
throw new InvalidArgumentException('Endpoint has to contain scheme, host and path');
}
/** @phpstan-ignore-next-line */
- if ($contentType !== 'application/x-protobuf') {
- throw new InvalidArgumentException(sprintf('Unsupported content type "%s", grpc transport supports only application/x-protobuf', $contentType));
+ if ($contentType !== ContentTypes::PROTOBUF) {
+ throw new InvalidArgumentException(sprintf('Unsupported content type "%s", grpc transport supports only %s', $contentType, ContentTypes::PROTOBUF));
}
$scheme = $parts['scheme'];
@@ -86,7 +87,7 @@ private static function createOpts(
$compression,
float $timeout,
int $maxRetries,
- int $retryDelay
+ int $retryDelay,
): array {
$opts = [];
diff --git a/src/Contrib/Grpc/composer.json b/src/Contrib/Grpc/composer.json
index e5311430e..96b829741 100644
--- a/src/Contrib/Grpc/composer.json
+++ b/src/Contrib/Grpc/composer.json
@@ -17,7 +17,7 @@
}
],
"require": {
- "php": "^7.4 || ^8.0",
+ "php": "^8.0",
"ext-grpc": "*",
"grpc/grpc": "*",
"open-telemetry/sdk": "^1.0"
diff --git a/src/Contrib/Otlp/LogsExporter.php b/src/Contrib/Otlp/LogsExporter.php
index fb100391f..254e407dd 100644
--- a/src/Contrib/Otlp/LogsExporter.php
+++ b/src/Contrib/Otlp/LogsExporter.php
@@ -20,20 +20,17 @@
class LogsExporter implements LogRecordExporterInterface
{
use LogsMessagesTrait;
-
- private TransportInterface $transport;
private ProtobufSerializer $serializer;
/**
* @psalm-param TransportInterface $transport
*/
- public function __construct(TransportInterface $transport)
+ public function __construct(private TransportInterface $transport)
{
if (!class_exists('\Google\Protobuf\Api')) {
throw new RuntimeException('No protobuf implementation found (ext-protobuf or google/protobuf)');
}
- $this->transport = $transport;
- $this->serializer = ProtobufSerializer::forTransport($transport);
+ $this->serializer = ProtobufSerializer::forTransport($this->transport);
}
/**
diff --git a/src/Contrib/Otlp/LogsExporterFactory.php b/src/Contrib/Otlp/LogsExporterFactory.php
index 4a6d78263..f588cfa27 100644
--- a/src/Contrib/Otlp/LogsExporterFactory.php
+++ b/src/Contrib/Otlp/LogsExporterFactory.php
@@ -18,11 +18,8 @@ class LogsExporterFactory implements LogRecordExporterFactoryInterface
{
private const DEFAULT_COMPRESSION = 'none';
- private ?TransportFactoryInterface $transportFactory;
-
- public function __construct(?TransportFactoryInterface $transportFactory = null)
+ public function __construct(private ?TransportFactoryInterface $transportFactory = null)
{
- $this->transportFactory = $transportFactory;
}
/**
diff --git a/src/Contrib/Otlp/MetricConverter.php b/src/Contrib/Otlp/MetricConverter.php
index 584c41365..ba3a0b42b 100644
--- a/src/Contrib/Otlp/MetricConverter.php
+++ b/src/Contrib/Otlp/MetricConverter.php
@@ -132,15 +132,11 @@ private function convertMetric(SDK\Metrics\Data\Metric $metric): Metric
private function convertTemporality($temporality): int
{
- switch ($temporality) {
- case SDK\Metrics\Data\Temporality::DELTA:
- return AggregationTemporality::AGGREGATION_TEMPORALITY_DELTA;
- case SDK\Metrics\Data\Temporality::CUMULATIVE:
- return AggregationTemporality::AGGREGATION_TEMPORALITY_CUMULATIVE;
- }
-
- // @codeCoverageIgnoreStart
- return AggregationTemporality::AGGREGATION_TEMPORALITY_UNSPECIFIED;
+ return match ($temporality) {
+ SDK\Metrics\Data\Temporality::DELTA => AggregationTemporality::AGGREGATION_TEMPORALITY_DELTA,
+ SDK\Metrics\Data\Temporality::CUMULATIVE => AggregationTemporality::AGGREGATION_TEMPORALITY_CUMULATIVE,
+ default => AggregationTemporality::AGGREGATION_TEMPORALITY_UNSPECIFIED,
+ };
// @codeCoverageIgnoreEnd
}
diff --git a/src/Contrib/Otlp/MetricExporter.php b/src/Contrib/Otlp/MetricExporter.php
index efd149c7f..8025766bd 100644
--- a/src/Contrib/Otlp/MetricExporter.php
+++ b/src/Contrib/Otlp/MetricExporter.php
@@ -22,27 +22,19 @@
final class MetricExporter implements PushMetricExporterInterface, AggregationTemporalitySelectorInterface
{
use LogsMessagesTrait;
-
- private TransportInterface $transport;
private ProtobufSerializer $serializer;
- /**
- * @var string|Temporality|null
- */
- private $temporality;
/**
- * @param string|Temporality|null $temporality
- *
* @psalm-param TransportInterface $transport
*/
- public function __construct(TransportInterface $transport, $temporality = null)
- {
+ public function __construct(
+ private TransportInterface $transport,
+ private string|Temporality|null $temporality = null,
+ ) {
if (!class_exists('\Google\Protobuf\Api')) {
throw new RuntimeException('No protobuf implementation found (ext-protobuf or google/protobuf)');
}
- $this->transport = $transport;
- $this->serializer = ProtobufSerializer::forTransport($transport);
- $this->temporality = $temporality;
+ $this->serializer = ProtobufSerializer::forTransport($this->transport);
}
public function temporality(MetricMetadataInterface $metric)
diff --git a/src/Contrib/Otlp/MetricExporterFactory.php b/src/Contrib/Otlp/MetricExporterFactory.php
index e1befe65b..8a201fd53 100644
--- a/src/Contrib/Otlp/MetricExporterFactory.php
+++ b/src/Contrib/Otlp/MetricExporterFactory.php
@@ -19,11 +19,8 @@ class MetricExporterFactory implements MetricExporterFactoryInterface
{
private const DEFAULT_COMPRESSION = 'none';
- private ?TransportFactoryInterface $transportFactory;
-
- public function __construct(?TransportFactoryInterface $transportFactory = null)
+ public function __construct(private ?TransportFactoryInterface $transportFactory = null)
{
- $this->transportFactory = $transportFactory;
}
/**
@@ -66,21 +63,18 @@ private function buildTransport(string $protocol): TransportInterface
}
/**
- * @todo return string|Temporality|null (php >= 8.0)
+ * @phpstan-ignore-next-line
*/
- private function getTemporality()
+ private function getTemporality(): string|Temporality|null
{
$value = Configuration::getEnum(Variables::OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE);
- switch (strtolower($value)) {
- case 'cumulative':
- return Temporality::CUMULATIVE;
- case 'delta':
- return Temporality::DELTA;
- case 'lowmemory':
- return null;
- default:
- throw new \UnexpectedValueException('Unknown temporality: ' . $value);
- }
+
+ return match (strtolower($value)) {
+ 'cumulative' => Temporality::CUMULATIVE,
+ 'delta' => Temporality::DELTA,
+ 'lowmemory' => null,
+ default => throw new \UnexpectedValueException('Unknown temporality: ' . $value),
+ };
}
private function getCompression(): string
diff --git a/src/Contrib/Otlp/OtlpHttpTransportFactory.php b/src/Contrib/Otlp/OtlpHttpTransportFactory.php
index 5cf3ff9e4..637e3ae5f 100644
--- a/src/Contrib/Otlp/OtlpHttpTransportFactory.php
+++ b/src/Contrib/Otlp/OtlpHttpTransportFactory.php
@@ -22,7 +22,7 @@ public function create(
int $maxRetries = 3,
?string $cacert = null,
?string $cert = null,
- ?string $key = null
+ ?string $key = null,
): PsrTransport {
if ($compression === self::DEFAULT_COMPRESSION) {
$compression = null;
diff --git a/src/Contrib/Otlp/ProtobufSerializer.php b/src/Contrib/Otlp/ProtobufSerializer.php
index a8b83acb0..f8897d193 100644
--- a/src/Contrib/Otlp/ProtobufSerializer.php
+++ b/src/Contrib/Otlp/ProtobufSerializer.php
@@ -4,11 +4,9 @@
namespace OpenTelemetry\Contrib\Otlp;
-use AssertionError;
use function base64_decode;
use function bin2hex;
use Exception;
-use function get_class;
use Google\Protobuf\Descriptor;
use Google\Protobuf\DescriptorPool;
use Google\Protobuf\FieldDescriptor;
@@ -28,25 +26,17 @@
/**
* @internal
- *
- * @psalm-type SUPPORTED_CONTENT_TYPES = self::PROTOBUF|self::JSON|self::NDJSON
+ * @psalm-type SUPPORTED_CONTENT_TYPES = ContentTypes::PROTOBUF|ContentTypes::JSON|ContentTypes::NDJSON
*/
final class ProtobufSerializer
{
- private const PROTOBUF = 'application/x-protobuf';
- private const JSON = 'application/json';
- private const NDJSON = 'application/x-ndjson';
-
- private string $contentType;
-
- private function __construct(string $contentType)
+ private function __construct(private string $contentType)
{
- $this->contentType = $contentType;
}
public static function getDefault(): ProtobufSerializer
{
- return new self(self::PROTOBUF);
+ return new self(ContentTypes::PROTOBUF);
}
/**
@@ -54,75 +44,51 @@ public static function getDefault(): ProtobufSerializer
*/
public static function forTransport(TransportInterface $transport): ProtobufSerializer
{
- switch ($contentType = $transport->contentType()) {
- case self::PROTOBUF:
- case self::JSON:
- case self::NDJSON:
- return new self($contentType);
- default:
- throw new InvalidArgumentException(sprintf('Not supported content type "%s"', $contentType));
- }
+ return match ($contentType = $transport->contentType()) {
+ ContentTypes::PROTOBUF, ContentTypes::JSON, ContentTypes::NDJSON => new self($contentType),
+ default => throw new InvalidArgumentException(sprintf('Not supported content type "%s"', $contentType)),
+ };
}
public function serializeTraceId(string $traceId): string
{
- switch ($this->contentType) {
- case self::PROTOBUF:
- return $traceId;
- case self::JSON:
- case self::NDJSON:
- return base64_decode(bin2hex($traceId));
- default:
- throw new AssertionError();
- }
+ // @phpstan-ignore-next-line
+ return match ($this->contentType) {
+ ContentTypes::PROTOBUF => $traceId,
+ ContentTypes::JSON, ContentTypes::NDJSON => base64_decode(bin2hex($traceId)),
+ };
}
public function serializeSpanId(string $spanId): string
{
- switch ($this->contentType) {
- case self::PROTOBUF:
- return $spanId;
- case self::JSON:
- case self::NDJSON:
- return base64_decode(bin2hex($spanId));
- default:
- throw new AssertionError();
- }
+ // @phpstan-ignore-next-line
+ return match ($this->contentType) {
+ ContentTypes::PROTOBUF => $spanId,
+ ContentTypes::JSON, ContentTypes::NDJSON => base64_decode(bin2hex($spanId)),
+ };
}
public function serialize(Message $message): string
{
- switch ($this->contentType) {
- case self::PROTOBUF:
- return $message->serializeToString();
- case self::JSON:
- return self::postProcessJsonEnumValues($message, $message->serializeToJsonString());
- case self::NDJSON:
- return self::postProcessJsonEnumValues($message, $message->serializeToJsonString()) . "\n";
- default:
- throw new AssertionError();
- }
+ // @phpstan-ignore-next-line
+ return match ($this->contentType) {
+ ContentTypes::PROTOBUF => $message->serializeToString(),
+ ContentTypes::JSON => self::postProcessJsonEnumValues($message, $message->serializeToJsonString()),
+ ContentTypes::NDJSON => self::postProcessJsonEnumValues($message, $message->serializeToJsonString()) . "\n",
+ };
}
/**
+ * @phan-suppress PhanParamTooManyInternal (@see https://github.com/phan/phan/pull/4840)
* @throws Exception
*/
public function hydrate(Message $message, string $payload): void
{
- switch ($this->contentType) {
- case self::PROTOBUF:
- $message->mergeFromString($payload);
-
- break;
- case self::JSON:
- case self::NDJSON:
- // @phan-suppress-next-line PhanParamTooManyInternal
- $message->mergeFromJsonString($payload, true);
-
- break;
- default:
- throw new AssertionError();
- }
+ // @phpstan-ignore-next-line
+ match ($this->contentType) {
+ ContentTypes::PROTOBUF => $message->mergeFromString($payload),
+ ContentTypes::JSON, ContentTypes::NDJSON => $message->mergeFromJsonString($payload, true),
+ };
}
/**
@@ -137,7 +103,7 @@ public function hydrate(Message $message, string $payload): void
private static function postProcessJsonEnumValues(Message $message, string $payload): string
{
$pool = DescriptorPool::getGeneratedPool();
- $desc = $pool->getDescriptorByClassName(get_class($message));
+ $desc = $pool->getDescriptorByClassName($message::class);
if (!$desc instanceof Descriptor) {
return $payload;
}
diff --git a/src/Contrib/Otlp/SpanConverter.php b/src/Contrib/Otlp/SpanConverter.php
index cab84cbd5..fba1e9727 100644
--- a/src/Contrib/Otlp/SpanConverter.php
+++ b/src/Contrib/Otlp/SpanConverter.php
@@ -121,15 +121,14 @@ private function setAttributes($pElement, AttributesInterface $attributes): void
private function convertSpanKind(int $kind): int
{
- switch ($kind) {
- case API\SpanKind::KIND_INTERNAL: return SpanKind::SPAN_KIND_INTERNAL;
- case API\SpanKind::KIND_CLIENT: return SpanKind::SPAN_KIND_CLIENT;
- case API\SpanKind::KIND_SERVER: return SpanKind::SPAN_KIND_SERVER;
- case API\SpanKind::KIND_PRODUCER: return SpanKind::SPAN_KIND_PRODUCER;
- case API\SpanKind::KIND_CONSUMER: return SpanKind::SPAN_KIND_CONSUMER;
- }
-
- return SpanKind::SPAN_KIND_UNSPECIFIED;
+ return match ($kind) {
+ API\SpanKind::KIND_INTERNAL => SpanKind::SPAN_KIND_INTERNAL,
+ API\SpanKind::KIND_CLIENT => SpanKind::SPAN_KIND_CLIENT,
+ API\SpanKind::KIND_SERVER => SpanKind::SPAN_KIND_SERVER,
+ API\SpanKind::KIND_PRODUCER => SpanKind::SPAN_KIND_PRODUCER,
+ API\SpanKind::KIND_CONSUMER => SpanKind::SPAN_KIND_CONSUMER,
+ default => SpanKind::SPAN_KIND_UNSPECIFIED,
+ };
}
private function convertStatusCode(string $status): int
diff --git a/src/Contrib/Otlp/SpanExporter.php b/src/Contrib/Otlp/SpanExporter.php
index a496206f4..f8e8b28e4 100644
--- a/src/Contrib/Otlp/SpanExporter.php
+++ b/src/Contrib/Otlp/SpanExporter.php
@@ -19,20 +19,17 @@
final class SpanExporter implements SpanExporterInterface
{
use LogsMessagesTrait;
-
- private TransportInterface $transport;
private ProtobufSerializer $serializer;
/**
* @psalm-param TransportInterface $transport
*/
- public function __construct(TransportInterface $transport)
+ public function __construct(private TransportInterface $transport)
{
if (!class_exists('\Google\Protobuf\Api')) {
throw new RuntimeException('No protobuf implementation found (ext-protobuf or google/protobuf)');
}
- $this->transport = $transport;
- $this->serializer = ProtobufSerializer::forTransport($transport);
+ $this->serializer = ProtobufSerializer::forTransport($this->transport);
}
public function export(iterable $batch, ?CancellationInterface $cancellation = null): FutureInterface
diff --git a/src/Contrib/Otlp/SpanExporterFactory.php b/src/Contrib/Otlp/SpanExporterFactory.php
index 667f79a5b..67627a7b9 100644
--- a/src/Contrib/Otlp/SpanExporterFactory.php
+++ b/src/Contrib/Otlp/SpanExporterFactory.php
@@ -19,13 +19,10 @@ class SpanExporterFactory implements SpanExporterFactoryInterface
{
use LogsMessagesTrait;
- private ?TransportFactoryInterface $transportFactory;
-
private const DEFAULT_COMPRESSION = 'none';
- public function __construct(?TransportFactoryInterface $transportFactory = null)
+ public function __construct(private ?TransportFactoryInterface $transportFactory = null)
{
- $this->transportFactory = $transportFactory;
}
/**
diff --git a/src/Contrib/Otlp/composer.json b/src/Contrib/Otlp/composer.json
index e4e2604eb..519a09a63 100644
--- a/src/Contrib/Otlp/composer.json
+++ b/src/Contrib/Otlp/composer.json
@@ -17,7 +17,7 @@
}
],
"require": {
- "php": "^7.4 || ^8.0",
+ "php": "^8.0",
"php-http/discovery": "^1.14",
"open-telemetry/gen-otlp-protobuf": "^1.1",
"open-telemetry/api": "^1.0",
diff --git a/src/Contrib/Zipkin/Exporter.php b/src/Contrib/Zipkin/Exporter.php
index 78608bdc5..ef5298c00 100644
--- a/src/Contrib/Zipkin/Exporter.php
+++ b/src/Contrib/Zipkin/Exporter.php
@@ -23,13 +23,10 @@ class Exporter implements SpanExporterInterface
use LogsMessagesTrait;
use UsesSpanConverterTrait;
- private TransportInterface $transport;
-
public function __construct(
- TransportInterface $transport,
- SpanConverterInterface $spanConverter = null
+ private TransportInterface $transport,
+ SpanConverterInterface $spanConverter = null,
) {
- $this->transport = $transport;
$this->setSpanConverter($spanConverter ?? new SpanConverter());
}
diff --git a/src/Contrib/Zipkin/SpanConverter.php b/src/Contrib/Zipkin/SpanConverter.php
index a8ed3471e..9f00d514a 100644
--- a/src/Contrib/Zipkin/SpanConverter.php
+++ b/src/Contrib/Zipkin/SpanConverter.php
@@ -171,20 +171,14 @@ private function convertSpan(SpanDataInterface $span): array
private static function toSpanKind(SpanDataInterface $span): ?string
{
- switch ($span->getKind()) {
- case SpanKind::KIND_SERVER:
- return ZipkinSpanKind::SERVER;
- case SpanKind::KIND_CLIENT:
- return ZipkinSpanKind::CLIENT;
- case SpanKind::KIND_PRODUCER:
- return ZipkinSpanKind::PRODUCER;
- case SpanKind::KIND_CONSUMER:
- return ZipkinSpanKind::CONSUMER;
- case SpanKind::KIND_INTERNAL:
- return null;
- }
-
- return null;
+ return match ($span->getKind()) {
+ SpanKind::KIND_SERVER => ZipkinSpanKind::SERVER,
+ SpanKind::KIND_CLIENT => ZipkinSpanKind::CLIENT,
+ SpanKind::KIND_PRODUCER => ZipkinSpanKind::PRODUCER,
+ SpanKind::KIND_CONSUMER => ZipkinSpanKind::CONSUMER,
+ SpanKind::KIND_INTERNAL => null,
+ default => null,
+ };
}
private static function toAnnotation(EventInterface $event): array
@@ -231,17 +225,15 @@ private static function toRemoteEndpoint(SpanDataInterface $span): ?array
return null;
}
- switch ($key) {
- case SpanConverter::NET_PEER_IP_KEY:
- return SpanConverter::getRemoteEndpointDataFromIpAddressAndPort(
- $value,
- SpanConverter::getPortNumberFromSpanAttributes($span)
- );
- default:
- return [
- 'serviceName' => $value,
- ];
- }
+ return match ($key) {
+ SpanConverter::NET_PEER_IP_KEY => SpanConverter::getRemoteEndpointDataFromIpAddressAndPort(
+ $value,
+ SpanConverter::getPortNumberFromSpanAttributes($span)
+ ),
+ default => [
+ 'serviceName' => $value,
+ ],
+ };
}
private static function findRemoteEndpointPreferredAttribute(SpanDataInterface $span): ?array
diff --git a/src/Contrib/Zipkin/composer.json b/src/Contrib/Zipkin/composer.json
index 6db63d782..4eb7604b5 100644
--- a/src/Contrib/Zipkin/composer.json
+++ b/src/Contrib/Zipkin/composer.json
@@ -17,7 +17,7 @@
}
],
"require": {
- "php": "^7.4 || ^8.0",
+ "php": "^8.0",
"open-telemetry/api": "^1.0",
"open-telemetry/sdk": "^1.0",
"php-http/async-client-implementation": "^1.0",
diff --git a/src/Contrib/composer.json b/src/Contrib/composer.json
index 28277dc55..603aaeb5f 100644
--- a/src/Contrib/composer.json
+++ b/src/Contrib/composer.json
@@ -11,7 +11,7 @@
}
],
"require": {
- "php": "^7.4 || ^8.0",
+ "php": "^8.0",
"ext-json": "*",
"open-telemetry/api": "^1.0",
"open-telemetry/context": "^1.0",
@@ -23,7 +23,6 @@
"psr/http-factory-implementation": "^1.0",
"psr/log": "^1.1|^2.0|^3.0",
"symfony/polyfill-mbstring": "^1.23",
- "symfony/polyfill-php80": "^1.26",
"symfony/polyfill-php81": "^1.26",
"symfony/polyfill-php82": "^1.26"
},
diff --git a/src/Extension/Propagator/B3/B3Propagator.php b/src/Extension/Propagator/B3/B3Propagator.php
index 841c5c96c..d796049f6 100644
--- a/src/Extension/Propagator/B3/B3Propagator.php
+++ b/src/Extension/Propagator/B3/B3Propagator.php
@@ -18,11 +18,8 @@
*/
final class B3Propagator implements TextMapPropagatorInterface
{
- private TextMapPropagatorInterface $propagator;
-
- private function __construct(TextMapPropagatorInterface $propagator)
+ private function __construct(private TextMapPropagatorInterface $propagator)
{
- $this->propagator = $propagator;
}
public static function getB3SingleHeaderInstance(): self
diff --git a/src/Extension/Propagator/B3/composer.json b/src/Extension/Propagator/B3/composer.json
index f15cd74c3..c7c094c52 100644
--- a/src/Extension/Propagator/B3/composer.json
+++ b/src/Extension/Propagator/B3/composer.json
@@ -17,7 +17,7 @@
}
],
"require": {
- "php": "^7.4 || ^8.0",
+ "php": "^8.0",
"open-telemetry/api": "^1.0",
"open-telemetry/context": "^1.0"
},
diff --git a/src/Extension/Propagator/CloudTrace/CloudTraceFormatter.php b/src/Extension/Propagator/CloudTrace/CloudTraceFormatter.php
index c03a18e89..1309cfddc 100644
--- a/src/Extension/Propagator/CloudTrace/CloudTraceFormatter.php
+++ b/src/Extension/Propagator/CloudTrace/CloudTraceFormatter.php
@@ -20,9 +20,6 @@ final class CloudTraceFormatter
/**
* Generate a SpanContext object from the Trace Context header
- *
- * @param string $header
- * @return SpanContextInterface
*/
public static function deserialize(string $header) : SpanContextInterface
{
@@ -47,9 +44,6 @@ public static function deserialize(string $header) : SpanContextInterface
/**
* Convert a SpanContextInterface to header string
- *
- * @param SpanContextInterface $context
- * @return string
*/
public static function serialize(SpanContextInterface $context) : string
{
diff --git a/src/Extension/Propagator/CloudTrace/CloudTracePropagator.php b/src/Extension/Propagator/CloudTrace/CloudTracePropagator.php
index 8bb062eba..60d59a1c9 100644
--- a/src/Extension/Propagator/CloudTrace/CloudTracePropagator.php
+++ b/src/Extension/Propagator/CloudTrace/CloudTracePropagator.php
@@ -46,11 +46,8 @@ public static function getInstance(): TextMapPropagatorInterface
self::XCLOUD,
];
- private bool $oneWay;
-
- private function __construct(bool $oneWay)
+ private function __construct(private bool $oneWay)
{
- $this->oneWay = $oneWay;
}
/** {@inheritdoc} */
diff --git a/src/Extension/Propagator/CloudTrace/composer.json b/src/Extension/Propagator/CloudTrace/composer.json
index e571d954e..216f730c8 100644
--- a/src/Extension/Propagator/CloudTrace/composer.json
+++ b/src/Extension/Propagator/CloudTrace/composer.json
@@ -17,7 +17,7 @@
}
],
"require": {
- "php": "^7.4 || ^8.0",
+ "php": "^8.0",
"open-telemetry/api": "^1.0",
"open-telemetry/context": "^1.0"
},
diff --git a/src/Extension/Propagator/Jaeger/JaegerBaggagePropagator.php b/src/Extension/Propagator/Jaeger/JaegerBaggagePropagator.php
index 3a2ba76e1..a7a2b6c9b 100644
--- a/src/Extension/Propagator/Jaeger/JaegerBaggagePropagator.php
+++ b/src/Extension/Propagator/Jaeger/JaegerBaggagePropagator.php
@@ -73,7 +73,7 @@ public function extract($carrier, PropagationGetterInterface $getter = null, Con
$baggageBuilder = Baggage::getBuilder();
foreach ($baggageKeys as $key) {
- if (strpos($key, self::UBER_BAGGAGE_HEADER_PREFIX) === 0) {
+ if (str_starts_with($key, self::UBER_BAGGAGE_HEADER_PREFIX)) {
$baggageKey = substr($key, strlen(self::UBER_BAGGAGE_HEADER_PREFIX));
$value = $getter->get($carrier, $key) ?? '';
$baggageBuilder->set($baggageKey, rawurldecode($value));
diff --git a/src/SDK/Common/Adapter/HttpDiscovery/DependencyResolver.php b/src/SDK/Common/Adapter/HttpDiscovery/DependencyResolver.php
index 8ba992f9a..057e4434d 100644
--- a/src/SDK/Common/Adapter/HttpDiscovery/DependencyResolver.php
+++ b/src/SDK/Common/Adapter/HttpDiscovery/DependencyResolver.php
@@ -26,7 +26,7 @@ final class DependencyResolver implements DependencyResolverInterface
public function __construct(
?MessageFactoryResolverInterface $messageFactoryResolver = null,
?PsrClientResolverInterface $psrClientResolver = null,
- ?HttpPlugClientResolverInterface $httpPlugClientResolver = null
+ ?HttpPlugClientResolverInterface $httpPlugClientResolver = null,
) {
$this->messageFactoryResolver = $messageFactoryResolver ?? MessageFactoryResolver::create();
$this->psrClientResolver = $psrClientResolver ?? PsrClientResolver::create();
@@ -36,7 +36,7 @@ public function __construct(
public static function create(
?MessageFactoryResolverInterface $messageFactoryResolver = null,
?PsrClientResolverInterface $psrClientResolver = null,
- ?HttpPlugClientResolverInterface $httpPlugClientResolver = null
+ ?HttpPlugClientResolverInterface $httpPlugClientResolver = null,
): self {
return new self($messageFactoryResolver, $psrClientResolver, $httpPlugClientResolver);
}
diff --git a/src/SDK/Common/Adapter/HttpDiscovery/HttpPlugClientResolver.php b/src/SDK/Common/Adapter/HttpDiscovery/HttpPlugClientResolver.php
index 9751984ee..d297a1b13 100644
--- a/src/SDK/Common/Adapter/HttpDiscovery/HttpPlugClientResolver.php
+++ b/src/SDK/Common/Adapter/HttpDiscovery/HttpPlugClientResolver.php
@@ -10,11 +10,8 @@
final class HttpPlugClientResolver implements ResolverInterface
{
- private ?HttpAsyncClient $httpAsyncClient;
-
- public function __construct(?HttpAsyncClient $httpAsyncClient = null)
+ public function __construct(private ?HttpAsyncClient $httpAsyncClient = null)
{
- $this->httpAsyncClient = $httpAsyncClient;
}
public static function create(?HttpAsyncClient $httpAsyncClient = null): self
diff --git a/src/SDK/Common/Adapter/HttpDiscovery/MessageFactoryResolver.php b/src/SDK/Common/Adapter/HttpDiscovery/MessageFactoryResolver.php
index 6ed0895ff..ae4028b61 100644
--- a/src/SDK/Common/Adapter/HttpDiscovery/MessageFactoryResolver.php
+++ b/src/SDK/Common/Adapter/HttpDiscovery/MessageFactoryResolver.php
@@ -15,27 +15,14 @@
final class MessageFactoryResolver implements FactoryResolverInterface
{
- private ?RequestFactoryInterface $requestFactory;
- private ?ResponseFactoryInterface $responseFactory;
- private ?ServerRequestFactoryInterface $serverRequestFactory;
- private ?StreamFactoryInterface $streamFactory;
- private ?UploadedFileFactoryInterface $uploadedFileFactory;
- private ?UriFactoryInterface $uriFactory;
-
public function __construct(
- ?RequestFactoryInterface $requestFactory = null,
- ?ResponseFactoryInterface $responseFactory = null,
- ?ServerRequestFactoryInterface $serverRequestFactory = null,
- ?StreamFactoryInterface $streamFactory = null,
- ?UploadedFileFactoryInterface $uploadedFileFactory = null,
- ?UriFactoryInterface $uriFactory = null
+ private ?RequestFactoryInterface $requestFactory = null,
+ private ?ResponseFactoryInterface $responseFactory = null,
+ private ?ServerRequestFactoryInterface $serverRequestFactory = null,
+ private ?StreamFactoryInterface $streamFactory = null,
+ private ?UploadedFileFactoryInterface $uploadedFileFactory = null,
+ private ?UriFactoryInterface $uriFactory = null,
) {
- $this->requestFactory = $requestFactory;
- $this->responseFactory = $responseFactory;
- $this->serverRequestFactory = $serverRequestFactory;
- $this->streamFactory = $streamFactory;
- $this->uploadedFileFactory = $uploadedFileFactory;
- $this->uriFactory = $uriFactory;
}
public static function create(
@@ -44,7 +31,7 @@ public static function create(
?ServerRequestFactoryInterface $serverRequestFactory = null,
?StreamFactoryInterface $streamFactory = null,
?UploadedFileFactoryInterface $uploadedFileFactory = null,
- ?UriFactoryInterface $uriFactory = null
+ ?UriFactoryInterface $uriFactory = null,
): self {
return new self(
$requestFactory,
diff --git a/src/SDK/Common/Adapter/HttpDiscovery/PsrClientResolver.php b/src/SDK/Common/Adapter/HttpDiscovery/PsrClientResolver.php
index 46fb36312..1a362c91d 100644
--- a/src/SDK/Common/Adapter/HttpDiscovery/PsrClientResolver.php
+++ b/src/SDK/Common/Adapter/HttpDiscovery/PsrClientResolver.php
@@ -10,11 +10,8 @@
final class PsrClientResolver implements ResolverInterface
{
- private ?ClientInterface $client;
-
- public function __construct(?ClientInterface $client = null)
+ public function __construct(private ?ClientInterface $client = null)
{
- $this->client = $client;
}
public static function create(?ClientInterface $client = null): self
diff --git a/src/SDK/Common/Attribute/Attributes.php b/src/SDK/Common/Attribute/Attributes.php
index bb131ce94..cebf063fd 100644
--- a/src/SDK/Common/Attribute/Attributes.php
+++ b/src/SDK/Common/Attribute/Attributes.php
@@ -10,16 +10,13 @@
final class Attributes implements AttributesInterface, IteratorAggregate
{
- private array $attributes;
- private int $droppedAttributesCount;
-
/**
* @internal
*/
- public function __construct(array $attributes, int $droppedAttributesCount)
- {
- $this->attributes = $attributes;
- $this->droppedAttributesCount = $droppedAttributesCount;
+ public function __construct(
+ private array $attributes,
+ private int $droppedAttributesCount,
+ ) {
}
public static function create(iterable $attributes): AttributesInterface
diff --git a/src/SDK/Common/Attribute/AttributesBuilder.php b/src/SDK/Common/Attribute/AttributesBuilder.php
index ee855b34a..cd3232a46 100644
--- a/src/SDK/Common/Attribute/AttributesBuilder.php
+++ b/src/SDK/Common/Attribute/AttributesBuilder.php
@@ -17,24 +17,15 @@
final class AttributesBuilder implements AttributesBuilderInterface
{
use LogsMessagesTrait;
-
- private array $attributes;
- private ?int $attributeCountLimit;
- private ?int $attributeValueLengthLimit;
- private int $droppedAttributesCount;
private AttributeValidatorInterface $attributeValidator;
public function __construct(
- array $attributes,
- ?int $attributeCountLimit,
- ?int $attributeValueLengthLimit,
- int $droppedAttributesCount,
- ?AttributeValidatorInterface $attributeValidator
+ private array $attributes,
+ private ?int $attributeCountLimit,
+ private ?int $attributeValueLengthLimit,
+ private int $droppedAttributesCount,
+ ?AttributeValidatorInterface $attributeValidator,
) {
- $this->attributes = $attributes;
- $this->attributeCountLimit = $attributeCountLimit;
- $this->attributeValueLengthLimit = $attributeValueLengthLimit;
- $this->droppedAttributesCount = $droppedAttributesCount;
$this->attributeValidator = $attributeValidator ?? new AttributeValidator();
}
diff --git a/src/SDK/Common/Attribute/AttributesFactory.php b/src/SDK/Common/Attribute/AttributesFactory.php
index d53ab25aa..8e072c7ab 100644
--- a/src/SDK/Common/Attribute/AttributesFactory.php
+++ b/src/SDK/Common/Attribute/AttributesFactory.php
@@ -9,13 +9,10 @@
*/
final class AttributesFactory implements AttributesFactoryInterface
{
- private ?int $attributeCountLimit;
- private ?int $attributeValueLengthLimit;
-
- public function __construct(?int $attributeCountLimit = null, ?int $attributeValueLengthLimit = null)
- {
- $this->attributeCountLimit = $attributeCountLimit;
- $this->attributeValueLengthLimit = $attributeValueLengthLimit;
+ public function __construct(
+ private ?int $attributeCountLimit = null,
+ private ?int $attributeValueLengthLimit = null,
+ ) {
}
public function builder(iterable $attributes = [], ?AttributeValidatorInterface $attributeValidator = null): AttributesBuilderInterface
diff --git a/src/SDK/Common/Attribute/FilteredAttributesBuilder.php b/src/SDK/Common/Attribute/FilteredAttributesBuilder.php
index 28bb00905..a0269ea49 100644
--- a/src/SDK/Common/Attribute/FilteredAttributesBuilder.php
+++ b/src/SDK/Common/Attribute/FilteredAttributesBuilder.php
@@ -11,17 +11,15 @@
*/
final class FilteredAttributesBuilder implements AttributesBuilderInterface
{
- private AttributesBuilderInterface $builder;
- private array $rejectedKeys;
private int $rejected = 0;
/**
* @param list $rejectedKeys
*/
- public function __construct(AttributesBuilderInterface $builder, array $rejectedKeys)
- {
- $this->builder = $builder;
- $this->rejectedKeys = $rejectedKeys;
+ public function __construct(
+ private AttributesBuilderInterface $builder,
+ private array $rejectedKeys,
+ ) {
}
public function __clone()
diff --git a/src/SDK/Common/Attribute/FilteredAttributesFactory.php b/src/SDK/Common/Attribute/FilteredAttributesFactory.php
index 1d9c4ae1c..fca0ce492 100644
--- a/src/SDK/Common/Attribute/FilteredAttributesFactory.php
+++ b/src/SDK/Common/Attribute/FilteredAttributesFactory.php
@@ -9,16 +9,13 @@
*/
final class FilteredAttributesFactory implements AttributesFactoryInterface
{
- private AttributesFactoryInterface $factory;
- private array $rejectedKeys;
-
/**
* @param list $rejectedKeys
*/
- public function __construct(AttributesFactoryInterface $factory, array $rejectedKeys)
- {
- $this->factory = $factory;
- $this->rejectedKeys = $rejectedKeys;
+ public function __construct(
+ private AttributesFactoryInterface $factory,
+ private array $rejectedKeys,
+ ) {
}
public function builder(iterable $attributes = [], ?AttributeValidatorInterface $attributeValidator = null): AttributesBuilderInterface
diff --git a/src/SDK/Common/Configuration/Configuration.php b/src/SDK/Common/Configuration/Configuration.php
index 58673fd98..577c85708 100644
--- a/src/SDK/Common/Configuration/Configuration.php
+++ b/src/SDK/Common/Configuration/Configuration.php
@@ -61,7 +61,7 @@ public static function getBoolean(string $key, bool $default = null): bool
try {
return BooleanParser::parse($resolved);
- } catch (InvalidArgumentException $e) {
+ } catch (InvalidArgumentException) {
self::logWarning(sprintf('Invalid boolean value "%s" interpreted as "false" for %s', $resolved, $key));
return false;
diff --git a/src/SDK/Common/Configuration/Parser/MapParser.php b/src/SDK/Common/Configuration/Parser/MapParser.php
index 273d57c87..7e0d44534 100644
--- a/src/SDK/Common/Configuration/Parser/MapParser.php
+++ b/src/SDK/Common/Configuration/Parser/MapParser.php
@@ -34,7 +34,7 @@ public static function parse($value): array
private static function validateKeyValuePair(string $pair)
{
- if (strpos($pair, self::KEY_VALUE_SEPARATOR) === false) {
+ if (!str_contains($pair, self::KEY_VALUE_SEPARATOR)) {
throw new InvalidArgumentException(sprintf(
'Key-Value pair "%s" does not contain separator "%s"',
$pair,
diff --git a/src/SDK/Common/Dev/Compatibility/Util.php b/src/SDK/Common/Dev/Compatibility/Util.php
index 1a3debfdd..fdc2930b7 100644
--- a/src/SDK/Common/Dev/Compatibility/Util.php
+++ b/src/SDK/Common/Dev/Compatibility/Util.php
@@ -57,7 +57,7 @@ public static function triggerClassDeprecationNotice(string $className, string $
public static function triggerMethodDeprecationNotice(
string $methodName,
string $alternativeMethodName = null,
- string $alternativeClassName = null
+ string $alternativeClassName = null,
): void {
if (self::getErrorLevel() === self::E_NONE) {
return;
diff --git a/src/SDK/Common/Exception/StackTraceFormatter.php b/src/SDK/Common/Exception/StackTraceFormatter.php
index 0d0fa7cb6..8fc7a2104 100644
--- a/src/SDK/Common/Exception/StackTraceFormatter.php
+++ b/src/SDK/Common/Exception/StackTraceFormatter.php
@@ -6,7 +6,6 @@
use function basename;
use function count;
-use function get_class;
use function sprintf;
use function str_repeat;
@@ -77,8 +76,8 @@ private static function writeFrames(string &$s, array $frames, ?array $enclosing
$n = count($frames);
if ($enclosing) {
for ($m = count($enclosing);
- $n && $m && $frames[$n - 1] === $enclosing[$m - 1];
- $n--, $m--) {
+ $n && $m && $frames[$n - 1] === $enclosing[$m - 1];
+ $n--, $m--) {
}
}
for ($i = 0; $i < $n; $i++) {
@@ -110,7 +109,7 @@ private static function writeFrames(string &$s, array $frames, ?array $enclosing
private static function writeInlineHeader(string &$s, Throwable $e): void
{
- $s .= self::formatName(get_class($e));
+ $s .= self::formatName($e::class);
if ($e->getMessage() !== '') {
$s .= ': ';
$s .= $e->getMessage();
diff --git a/src/SDK/Common/Export/Http/PsrTransport.php b/src/SDK/Common/Export/Http/PsrTransport.php
index a53e5b80a..99530fcc1 100644
--- a/src/SDK/Common/Export/Http/PsrTransport.php
+++ b/src/SDK/Common/Export/Http/PsrTransport.php
@@ -30,42 +30,22 @@
*/
final class PsrTransport implements TransportInterface
{
- private ClientInterface $client;
- private RequestFactoryInterface $requestFactory;
- private StreamFactoryInterface $streamFactory;
-
- private string $endpoint;
- private string $contentType;
- private array $headers;
- private array $compression;
- private int $retryDelay;
- private int $maxRetries;
-
private bool $closed = false;
/**
* @psalm-param CONTENT_TYPE $contentType
*/
public function __construct(
- ClientInterface $client,
- RequestFactoryInterface $requestFactory,
- StreamFactoryInterface $streamFactory,
- string $endpoint,
- string $contentType,
- array $headers,
- array $compression,
- int $retryDelay,
- int $maxRetries
+ private ClientInterface $client,
+ private RequestFactoryInterface $requestFactory,
+ private StreamFactoryInterface $streamFactory,
+ private string $endpoint,
+ private string $contentType,
+ private array $headers,
+ private array $compression,
+ private int $retryDelay,
+ private int $maxRetries,
) {
- $this->client = $client;
- $this->requestFactory = $requestFactory;
- $this->streamFactory = $streamFactory;
- $this->endpoint = $endpoint;
- $this->contentType = $contentType;
- $this->headers = $headers;
- $this->compression = $compression;
- $this->retryDelay = $retryDelay;
- $this->maxRetries = $maxRetries;
}
public function contentType(): string
diff --git a/src/SDK/Common/Export/Http/PsrTransportFactory.php b/src/SDK/Common/Export/Http/PsrTransportFactory.php
index 5ef78d82c..200f7d1ba 100644
--- a/src/SDK/Common/Export/Http/PsrTransportFactory.php
+++ b/src/SDK/Common/Export/Http/PsrTransportFactory.php
@@ -16,18 +16,11 @@
final class PsrTransportFactory implements TransportFactoryInterface
{
- private ClientInterface $client;
- private RequestFactoryInterface $requestFactory;
- private StreamFactoryInterface $streamFactory;
-
public function __construct(
- ClientInterface $client,
- RequestFactoryInterface $requestFactory,
- StreamFactoryInterface $streamFactory
+ private ClientInterface $client,
+ private RequestFactoryInterface $requestFactory,
+ private StreamFactoryInterface $streamFactory,
) {
- $this->client = $client;
- $this->requestFactory = $requestFactory;
- $this->streamFactory = $streamFactory;
}
/**
@@ -43,7 +36,7 @@ public function create(
int $maxRetries = 3,
?string $cacert = null,
?string $cert = null,
- ?string $key = null
+ ?string $key = null,
): PsrTransport {
if (!filter_var($endpoint, FILTER_VALIDATE_URL)) {
throw new InvalidArgumentException(sprintf('Invalid endpoint url "%s"', $endpoint));
diff --git a/src/SDK/Common/Export/Http/PsrUtils.php b/src/SDK/Common/Export/Http/PsrUtils.php
index eaf2f3b47..7cc020818 100644
--- a/src/SDK/Common/Export/Http/PsrUtils.php
+++ b/src/SDK/Common/Export/Http/PsrUtils.php
@@ -75,7 +75,7 @@ public static function encode(string $value, array $encodings, ?array &$appliedE
try {
$value = $encoder($value);
- } catch (Throwable $e) {
+ } catch (Throwable) {
unset($encodings[$i]);
}
}
@@ -115,7 +115,7 @@ public static function compression($compression): array
if (!$compression) {
return [];
}
- if (strpos($compression, ',') === false) {
+ if (!str_contains($compression, ',')) {
return [$compression];
}
diff --git a/src/SDK/Common/Export/Stream/StreamTransport.php b/src/SDK/Common/Export/Stream/StreamTransport.php
index 4b99cf756..e22295cb6 100644
--- a/src/SDK/Common/Export/Stream/StreamTransport.php
+++ b/src/SDK/Common/Export/Stream/StreamTransport.php
@@ -28,20 +28,14 @@
final class StreamTransport implements TransportInterface
{
/**
- * @var resource|null
- */
- private $stream;
- private string $contentType;
-
- /**
- * @param resource $stream
+ * @param resource|null $stream
*
* @psalm-param CONTENT_TYPE $contentType
*/
- public function __construct($stream, string $contentType)
- {
- $this->stream = $stream;
- $this->contentType = $contentType;
+ public function __construct(
+ private $stream,
+ private string $contentType,
+ ) {
}
public function contentType(): string
diff --git a/src/SDK/Common/Export/Stream/StreamTransportFactory.php b/src/SDK/Common/Export/Stream/StreamTransportFactory.php
index 59e411318..c6544bbe5 100644
--- a/src/SDK/Common/Export/Stream/StreamTransportFactory.php
+++ b/src/SDK/Common/Export/Stream/StreamTransportFactory.php
@@ -29,6 +29,7 @@ final class StreamTransportFactory implements TransportFactoryInterface
* @psalm-template CONTENT_TYPE of string
* @psalm-param CONTENT_TYPE $contentType
* @psalm-return TransportInterface
+ * @throws ErrorException
*/
public function create(
$endpoint,
@@ -40,7 +41,7 @@ public function create(
int $maxRetries = 3,
?string $cacert = null,
?string $cert = null,
- ?string $key = null
+ ?string $key = null,
): TransportInterface {
assert(!empty($endpoint));
$stream = is_resource($endpoint)
@@ -69,7 +70,7 @@ private static function createStream(
float $timeout = 10.,
?string $cacert = null,
?string $cert = null,
- ?string $key = null
+ ?string $key = null,
) {
$context = stream_context_create([
'http' => [
diff --git a/src/SDK/Common/Export/TransportFactoryInterface.php b/src/SDK/Common/Export/TransportFactoryInterface.php
index 48e538443..a2dd3a1e1 100644
--- a/src/SDK/Common/Export/TransportFactoryInterface.php
+++ b/src/SDK/Common/Export/TransportFactoryInterface.php
@@ -27,6 +27,6 @@ public function create(
int $maxRetries = 3,
?string $cacert = null,
?string $cert = null,
- ?string $key = null
+ ?string $key = null,
): TransportInterface;
}
diff --git a/src/SDK/Common/Future/CompletedFuture.php b/src/SDK/Common/Future/CompletedFuture.php
index 7f0cd6536..b6e01c41f 100644
--- a/src/SDK/Common/Future/CompletedFuture.php
+++ b/src/SDK/Common/Future/CompletedFuture.php
@@ -13,15 +13,11 @@
*/
final class CompletedFuture implements FutureInterface
{
- /** @var T */
- private $value;
-
/**
* @param T $value
*/
- public function __construct($value)
+ public function __construct(private $value)
{
- $this->value = $value;
}
public function await()
diff --git a/src/SDK/Common/Future/ErrorFuture.php b/src/SDK/Common/Future/ErrorFuture.php
index 32cf3d995..253ca803e 100644
--- a/src/SDK/Common/Future/ErrorFuture.php
+++ b/src/SDK/Common/Future/ErrorFuture.php
@@ -9,11 +9,8 @@
final class ErrorFuture implements FutureInterface
{
- private Throwable $throwable;
-
- public function __construct(Throwable $throwable)
+ public function __construct(private Throwable $throwable)
{
- $this->throwable = $throwable;
}
public function await()
diff --git a/src/SDK/Common/Http/Psr/Message/MessageFactory.php b/src/SDK/Common/Http/Psr/Message/MessageFactory.php
index 8e99d64c0..63aac0850 100644
--- a/src/SDK/Common/Http/Psr/Message/MessageFactory.php
+++ b/src/SDK/Common/Http/Psr/Message/MessageFactory.php
@@ -13,24 +13,17 @@
final class MessageFactory implements MessageFactoryInterface
{
- private RequestFactoryInterface $requestFactory;
- private ResponseFactoryInterface $responseFactory;
- private ServerRequestFactoryInterface $serverRequestFactory;
-
public function __construct(
- RequestFactoryInterface $requestFactory,
- ResponseFactoryInterface $responseFactory,
- ServerRequestFactoryInterface $serverRequestFactory
+ private RequestFactoryInterface $requestFactory,
+ private ResponseFactoryInterface $responseFactory,
+ private ServerRequestFactoryInterface $serverRequestFactory,
) {
- $this->requestFactory = $requestFactory;
- $this->responseFactory = $responseFactory;
- $this->serverRequestFactory = $serverRequestFactory;
}
public static function create(
RequestFactoryInterface $requestFactory,
ResponseFactoryInterface $responseFactory,
- ServerRequestFactoryInterface $serverRequestFactory
+ ServerRequestFactoryInterface $serverRequestFactory,
): self {
return new self($requestFactory, $responseFactory, $serverRequestFactory);
}
diff --git a/src/SDK/Common/Instrumentation/InstrumentationScope.php b/src/SDK/Common/Instrumentation/InstrumentationScope.php
index ec9b52fb0..f6a009624 100644
--- a/src/SDK/Common/Instrumentation/InstrumentationScope.php
+++ b/src/SDK/Common/Instrumentation/InstrumentationScope.php
@@ -11,17 +11,12 @@
*/
final class InstrumentationScope implements InstrumentationScopeInterface
{
- private string $name;
- private ?string $version;
- private ?string $schemaUrl;
- private AttributesInterface $attributes;
-
- public function __construct(string $name, ?string $version, ?string $schemaUrl, AttributesInterface $attributes)
- {
- $this->name = $name;
- $this->version = $version;
- $this->schemaUrl = $schemaUrl;
- $this->attributes = $attributes;
+ public function __construct(
+ private string $name,
+ private ?string $version,
+ private ?string $schemaUrl,
+ private AttributesInterface $attributes,
+ ) {
}
public function getName(): string
diff --git a/src/SDK/Common/Instrumentation/InstrumentationScopeFactory.php b/src/SDK/Common/Instrumentation/InstrumentationScopeFactory.php
index f1ae7c072..f3f73341d 100644
--- a/src/SDK/Common/Instrumentation/InstrumentationScopeFactory.php
+++ b/src/SDK/Common/Instrumentation/InstrumentationScopeFactory.php
@@ -8,18 +8,15 @@
final class InstrumentationScopeFactory implements InstrumentationScopeFactoryInterface
{
- private AttributesFactoryInterface $attributesFactory;
-
- public function __construct(AttributesFactoryInterface $attributesFactory)
+ public function __construct(private AttributesFactoryInterface $attributesFactory)
{
- $this->attributesFactory = $attributesFactory;
}
public function create(
string $name,
?string $version = null,
?string $schemaUrl = null,
- iterable $attributes = []
+ iterable $attributes = [],
): InstrumentationScopeInterface {
return new InstrumentationScope(
$name,
diff --git a/src/SDK/Common/Instrumentation/InstrumentationScopeFactoryInterface.php b/src/SDK/Common/Instrumentation/InstrumentationScopeFactoryInterface.php
index 78292de58..ddc45eb04 100644
--- a/src/SDK/Common/Instrumentation/InstrumentationScopeFactoryInterface.php
+++ b/src/SDK/Common/Instrumentation/InstrumentationScopeFactoryInterface.php
@@ -10,6 +10,6 @@ public function create(
string $name,
?string $version = null,
?string $schemaUrl = null,
- iterable $attributes = []
+ iterable $attributes = [],
): InstrumentationScopeInterface;
}
diff --git a/src/SDK/Common/Time/StopWatch.php b/src/SDK/Common/Time/StopWatch.php
index b2abdabae..10b967e9e 100644
--- a/src/SDK/Common/Time/StopWatch.php
+++ b/src/SDK/Common/Time/StopWatch.php
@@ -7,17 +7,14 @@
final class StopWatch implements StopWatchInterface
{
private const INITIAL_ELAPSED_TIME = 0;
-
- private ClockInterface $clock;
private bool $running = false;
- private ?int $initialStartTime;
private ?int $startTime = null;
private ?int $stopTime = null;
- public function __construct(ClockInterface $clock, ?int $initialStartTime = null)
- {
- $this->clock = $clock;
- $this->initialStartTime = $initialStartTime;
+ public function __construct(
+ private ClockInterface $clock,
+ private ?int $initialStartTime = null,
+ ) {
}
public function isRunning(): bool
diff --git a/src/SDK/Common/Time/StopWatchFactory.php b/src/SDK/Common/Time/StopWatchFactory.php
index f60c377fc..080cdce57 100644
--- a/src/SDK/Common/Time/StopWatchFactory.php
+++ b/src/SDK/Common/Time/StopWatchFactory.php
@@ -9,12 +9,12 @@ final class StopWatchFactory implements StopWatchFactoryInterface
private static ?StopWatchInterface $default = null;
private ClockInterface $clock;
- private ?int $initialStartTime;
- public function __construct(?ClockInterface $clock = null, ?int $initialStartTime = null)
- {
+ public function __construct(
+ ?ClockInterface $clock = null,
+ private ?int $initialStartTime = null,
+ ) {
$this->clock = $clock ?? ClockFactory::getDefault();
- $this->initialStartTime = $initialStartTime;
}
public static function create(?ClockInterface $clock = null, ?int $initialStartTime = null): self
diff --git a/src/SDK/Common/Util/ShutdownHandler.php b/src/SDK/Common/Util/ShutdownHandler.php
index 2de6d47df..d748c3e81 100644
--- a/src/SDK/Common/Util/ShutdownHandler.php
+++ b/src/SDK/Common/Util/ShutdownHandler.php
@@ -5,16 +5,16 @@
namespace OpenTelemetry\SDK\Common\Util;
use function array_key_last;
-use ArrayAccess;
use Closure;
use function register_shutdown_function;
+use WeakMap;
final class ShutdownHandler
{
/** @var array|null */
private static ?array $handlers = null;
- /** @var ArrayAccess