From cdd7ad020e165fe680703b6d3319b908b682fb7a Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Fri, 20 Oct 2023 17:12:29 +0300 Subject: jaeger-client -> opentelemetry --- .../Adapter/HttpDiscovery/DependencyResolver.php | 83 ++++++++ .../HttpDiscovery/HttpPlugClientResolver.php | 29 +++ .../HttpDiscovery/MessageFactoryResolver.php | 88 +++++++++ .../Adapter/HttpDiscovery/PsrClientResolver.php | 29 +++ .../sdk/Common/Attribute/AttributeValidator.php | 58 ++++++ .../Attribute/AttributeValidatorInterface.php | 11 ++ .../sdk/Common/Attribute/Attributes.php | 67 +++++++ .../sdk/Common/Attribute/AttributesBuilder.php | 120 ++++++++++++ .../Attribute/AttributesBuilderInterface.php | 12 ++ .../sdk/Common/Attribute/AttributesFactory.php | 36 ++++ .../Attribute/AttributesFactoryInterface.php | 10 + .../sdk/Common/Attribute/AttributesInterface.php | 19 ++ .../Common/Attribute/FilteredAttributesBuilder.php | 77 ++++++++ .../Common/Attribute/FilteredAttributesFactory.php | 33 ++++ .../Attribute/LogRecordAttributeValidator.php | 19 ++ .../sdk/Common/Configuration/Configuration.php | 182 ++++++++++++++++++ .../sdk/Common/Configuration/Defaults.php | 122 ++++++++++++ .../sdk/Common/Configuration/KnownValues.php | 208 +++++++++++++++++++++ .../Common/Configuration/Parser/BooleanParser.php | 34 ++++ .../sdk/Common/Configuration/Parser/ListParser.php | 28 +++ .../sdk/Common/Configuration/Parser/MapParser.php | 45 +++++ .../Common/Configuration/Parser/RatioParser.php | 38 ++++ .../Configuration/Resolver/CompositeResolver.php | 68 +++++++ .../Configuration/Resolver/EnvironmentResolver.php | 40 ++++ .../Configuration/Resolver/PhpIniAccessor.php | 18 ++ .../Configuration/Resolver/PhpIniResolver.php | 41 ++++ .../Configuration/Resolver/ResolverInterface.php | 15 ++ .../sdk/Common/Configuration/ValueTypes.php | 133 +++++++++++++ .../sdk/Common/Configuration/VariableTypes.php | 62 ++++++ .../sdk/Common/Configuration/Variables.php | 142 ++++++++++++++ .../sdk/Common/Dev/Compatibility/README.md | 14 ++ .../sdk/Common/Dev/Compatibility/Util.php | 93 +++++++++ .../sdk/Common/Dev/Compatibility/_load.php | 7 + .../sdk/Common/Exception/StackTraceFormatter.php | 155 +++++++++++++++ .../sdk/Common/Export/Http/PsrTransport.php | 168 +++++++++++++++++ .../sdk/Common/Export/Http/PsrTransportFactory.php | 74 ++++++++ .../sdk/Common/Export/Http/PsrUtils.php | 175 +++++++++++++++++ .../sdk/Common/Export/Stream/StreamTransport.php | 97 ++++++++++ .../Export/Stream/StreamTransportFactory.php | 118 ++++++++++++ .../Common/Export/TransportFactoryInterface.php | 32 ++++ .../sdk/Common/Export/TransportInterface.php | 22 +++ .../sdk/Common/Future/CancellationInterface.php | 18 ++ .../sdk/Common/Future/CompletedFuture.php | 48 +++++ .../sdk/Common/Future/ErrorFuture.php | 40 ++++ .../sdk/Common/Future/FutureInterface.php | 34 ++++ .../sdk/Common/Future/NullCancellation.php | 20 ++ .../Common/Http/DependencyResolverInterface.php | 13 ++ .../Http/HttpPlug/Client/ResolverInterface.php | 12 ++ .../Common/Http/Psr/Client/ResolverInterface.php | 12 ++ .../Http/Psr/Message/FactoryResolverInterface.php | 22 +++ .../sdk/Common/Http/Psr/Message/MessageFactory.php | 52 ++++++ .../Http/Psr/Message/MessageFactoryInterface.php | 13 ++ .../Instrumentation/InstrumentationScope.php | 46 +++++ .../InstrumentationScopeFactory.php | 31 +++ .../InstrumentationScopeFactoryInterface.php | 15 ++ .../InstrumentationScopeInterface.php | 18 ++ .../sdk/Common/Time/ClockFactory.php | 30 +++ .../sdk/Common/Time/ClockFactoryInterface.php | 16 ++ .../sdk/Common/Time/ClockInterface.php | 19 ++ .../open-telemetry/sdk/Common/Time/StopWatch.php | 119 ++++++++++++ .../sdk/Common/Time/StopWatchFactory.php | 44 +++++ .../sdk/Common/Time/StopWatchFactoryInterface.php | 18 ++ .../sdk/Common/Time/StopWatchInterface.php | 20 ++ .../open-telemetry/sdk/Common/Time/SystemClock.php | 49 +++++ vendor/open-telemetry/sdk/Common/Time/Util.php | 32 ++++ .../sdk/Common/Util/ClassConstantAccessor.php | 35 ++++ .../sdk/Common/Util/ShutdownHandler.php | 82 ++++++++ vendor/open-telemetry/sdk/Common/Util/WeakMap.php | 175 +++++++++++++++++ .../open-telemetry/sdk/Common/Util/functions.php | 52 ++++++ 69 files changed, 3907 insertions(+) create mode 100644 vendor/open-telemetry/sdk/Common/Adapter/HttpDiscovery/DependencyResolver.php create mode 100644 vendor/open-telemetry/sdk/Common/Adapter/HttpDiscovery/HttpPlugClientResolver.php create mode 100644 vendor/open-telemetry/sdk/Common/Adapter/HttpDiscovery/MessageFactoryResolver.php create mode 100644 vendor/open-telemetry/sdk/Common/Adapter/HttpDiscovery/PsrClientResolver.php create mode 100644 vendor/open-telemetry/sdk/Common/Attribute/AttributeValidator.php create mode 100644 vendor/open-telemetry/sdk/Common/Attribute/AttributeValidatorInterface.php create mode 100644 vendor/open-telemetry/sdk/Common/Attribute/Attributes.php create mode 100644 vendor/open-telemetry/sdk/Common/Attribute/AttributesBuilder.php create mode 100644 vendor/open-telemetry/sdk/Common/Attribute/AttributesBuilderInterface.php create mode 100644 vendor/open-telemetry/sdk/Common/Attribute/AttributesFactory.php create mode 100644 vendor/open-telemetry/sdk/Common/Attribute/AttributesFactoryInterface.php create mode 100644 vendor/open-telemetry/sdk/Common/Attribute/AttributesInterface.php create mode 100644 vendor/open-telemetry/sdk/Common/Attribute/FilteredAttributesBuilder.php create mode 100644 vendor/open-telemetry/sdk/Common/Attribute/FilteredAttributesFactory.php create mode 100644 vendor/open-telemetry/sdk/Common/Attribute/LogRecordAttributeValidator.php create mode 100644 vendor/open-telemetry/sdk/Common/Configuration/Configuration.php create mode 100644 vendor/open-telemetry/sdk/Common/Configuration/Defaults.php create mode 100644 vendor/open-telemetry/sdk/Common/Configuration/KnownValues.php create mode 100644 vendor/open-telemetry/sdk/Common/Configuration/Parser/BooleanParser.php create mode 100644 vendor/open-telemetry/sdk/Common/Configuration/Parser/ListParser.php create mode 100644 vendor/open-telemetry/sdk/Common/Configuration/Parser/MapParser.php create mode 100644 vendor/open-telemetry/sdk/Common/Configuration/Parser/RatioParser.php create mode 100644 vendor/open-telemetry/sdk/Common/Configuration/Resolver/CompositeResolver.php create mode 100644 vendor/open-telemetry/sdk/Common/Configuration/Resolver/EnvironmentResolver.php create mode 100644 vendor/open-telemetry/sdk/Common/Configuration/Resolver/PhpIniAccessor.php create mode 100644 vendor/open-telemetry/sdk/Common/Configuration/Resolver/PhpIniResolver.php create mode 100644 vendor/open-telemetry/sdk/Common/Configuration/Resolver/ResolverInterface.php create mode 100644 vendor/open-telemetry/sdk/Common/Configuration/ValueTypes.php create mode 100644 vendor/open-telemetry/sdk/Common/Configuration/VariableTypes.php create mode 100644 vendor/open-telemetry/sdk/Common/Configuration/Variables.php create mode 100644 vendor/open-telemetry/sdk/Common/Dev/Compatibility/README.md create mode 100644 vendor/open-telemetry/sdk/Common/Dev/Compatibility/Util.php create mode 100644 vendor/open-telemetry/sdk/Common/Dev/Compatibility/_load.php create mode 100644 vendor/open-telemetry/sdk/Common/Exception/StackTraceFormatter.php create mode 100644 vendor/open-telemetry/sdk/Common/Export/Http/PsrTransport.php create mode 100644 vendor/open-telemetry/sdk/Common/Export/Http/PsrTransportFactory.php create mode 100644 vendor/open-telemetry/sdk/Common/Export/Http/PsrUtils.php create mode 100644 vendor/open-telemetry/sdk/Common/Export/Stream/StreamTransport.php create mode 100644 vendor/open-telemetry/sdk/Common/Export/Stream/StreamTransportFactory.php create mode 100644 vendor/open-telemetry/sdk/Common/Export/TransportFactoryInterface.php create mode 100644 vendor/open-telemetry/sdk/Common/Export/TransportInterface.php create mode 100644 vendor/open-telemetry/sdk/Common/Future/CancellationInterface.php create mode 100644 vendor/open-telemetry/sdk/Common/Future/CompletedFuture.php create mode 100644 vendor/open-telemetry/sdk/Common/Future/ErrorFuture.php create mode 100644 vendor/open-telemetry/sdk/Common/Future/FutureInterface.php create mode 100644 vendor/open-telemetry/sdk/Common/Future/NullCancellation.php create mode 100644 vendor/open-telemetry/sdk/Common/Http/DependencyResolverInterface.php create mode 100644 vendor/open-telemetry/sdk/Common/Http/HttpPlug/Client/ResolverInterface.php create mode 100644 vendor/open-telemetry/sdk/Common/Http/Psr/Client/ResolverInterface.php create mode 100644 vendor/open-telemetry/sdk/Common/Http/Psr/Message/FactoryResolverInterface.php create mode 100644 vendor/open-telemetry/sdk/Common/Http/Psr/Message/MessageFactory.php create mode 100644 vendor/open-telemetry/sdk/Common/Http/Psr/Message/MessageFactoryInterface.php create mode 100644 vendor/open-telemetry/sdk/Common/Instrumentation/InstrumentationScope.php create mode 100644 vendor/open-telemetry/sdk/Common/Instrumentation/InstrumentationScopeFactory.php create mode 100644 vendor/open-telemetry/sdk/Common/Instrumentation/InstrumentationScopeFactoryInterface.php create mode 100644 vendor/open-telemetry/sdk/Common/Instrumentation/InstrumentationScopeInterface.php create mode 100644 vendor/open-telemetry/sdk/Common/Time/ClockFactory.php create mode 100644 vendor/open-telemetry/sdk/Common/Time/ClockFactoryInterface.php create mode 100644 vendor/open-telemetry/sdk/Common/Time/ClockInterface.php create mode 100644 vendor/open-telemetry/sdk/Common/Time/StopWatch.php create mode 100644 vendor/open-telemetry/sdk/Common/Time/StopWatchFactory.php create mode 100644 vendor/open-telemetry/sdk/Common/Time/StopWatchFactoryInterface.php create mode 100644 vendor/open-telemetry/sdk/Common/Time/StopWatchInterface.php create mode 100644 vendor/open-telemetry/sdk/Common/Time/SystemClock.php create mode 100644 vendor/open-telemetry/sdk/Common/Time/Util.php create mode 100644 vendor/open-telemetry/sdk/Common/Util/ClassConstantAccessor.php create mode 100644 vendor/open-telemetry/sdk/Common/Util/ShutdownHandler.php create mode 100644 vendor/open-telemetry/sdk/Common/Util/WeakMap.php create mode 100644 vendor/open-telemetry/sdk/Common/Util/functions.php (limited to 'vendor/open-telemetry/sdk/Common') diff --git a/vendor/open-telemetry/sdk/Common/Adapter/HttpDiscovery/DependencyResolver.php b/vendor/open-telemetry/sdk/Common/Adapter/HttpDiscovery/DependencyResolver.php new file mode 100644 index 000000000..8ba992f9a --- /dev/null +++ b/vendor/open-telemetry/sdk/Common/Adapter/HttpDiscovery/DependencyResolver.php @@ -0,0 +1,83 @@ +messageFactoryResolver = $messageFactoryResolver ?? MessageFactoryResolver::create(); + $this->psrClientResolver = $psrClientResolver ?? PsrClientResolver::create(); + $this->httpPlugClientResolver = $httpPlugClientResolver ?? HttpPlugClientResolver::create(); + } + + public static function create( + ?MessageFactoryResolverInterface $messageFactoryResolver = null, + ?PsrClientResolverInterface $psrClientResolver = null, + ?HttpPlugClientResolverInterface $httpPlugClientResolver = null + ): self { + return new self($messageFactoryResolver, $psrClientResolver, $httpPlugClientResolver); + } + + public function resolveRequestFactory(): RequestFactoryInterface + { + return $this->messageFactoryResolver->resolveRequestFactory(); + } + + public function resolveResponseFactory(): ResponseFactoryInterface + { + return $this->messageFactoryResolver->resolveResponseFactory(); + } + + public function resolveServerRequestFactory(): ServerRequestFactoryInterface + { + return $this->messageFactoryResolver->resolveServerRequestFactory(); + } + + public function resolveStreamFactory(): StreamFactoryInterface + { + return $this->messageFactoryResolver->resolveStreamFactory(); + } + + public function resolveUploadedFileFactory(): UploadedFileFactoryInterface + { + return $this->messageFactoryResolver->resolveUploadedFileFactory(); + } + + public function resolveUriFactory(): UriFactoryInterface + { + return $this->messageFactoryResolver->resolveUriFactory(); + } + + public function resolveHttpPlugAsyncClient(): HttpAsyncClient + { + return $this->httpPlugClientResolver->resolveHttpPlugAsyncClient(); + } + + public function resolvePsrClient(): ClientInterface + { + return $this->psrClientResolver->resolvePsrClient(); + } +} diff --git a/vendor/open-telemetry/sdk/Common/Adapter/HttpDiscovery/HttpPlugClientResolver.php b/vendor/open-telemetry/sdk/Common/Adapter/HttpDiscovery/HttpPlugClientResolver.php new file mode 100644 index 000000000..9751984ee --- /dev/null +++ b/vendor/open-telemetry/sdk/Common/Adapter/HttpDiscovery/HttpPlugClientResolver.php @@ -0,0 +1,29 @@ +httpAsyncClient = $httpAsyncClient; + } + + public static function create(?HttpAsyncClient $httpAsyncClient = null): self + { + return new self($httpAsyncClient); + } + + public function resolveHttpPlugAsyncClient(): HttpAsyncClient + { + return $this->httpAsyncClient ??= HttpAsyncClientDiscovery::find(); + } +} diff --git a/vendor/open-telemetry/sdk/Common/Adapter/HttpDiscovery/MessageFactoryResolver.php b/vendor/open-telemetry/sdk/Common/Adapter/HttpDiscovery/MessageFactoryResolver.php new file mode 100644 index 000000000..6ed0895ff --- /dev/null +++ b/vendor/open-telemetry/sdk/Common/Adapter/HttpDiscovery/MessageFactoryResolver.php @@ -0,0 +1,88 @@ +requestFactory = $requestFactory; + $this->responseFactory = $responseFactory; + $this->serverRequestFactory = $serverRequestFactory; + $this->streamFactory = $streamFactory; + $this->uploadedFileFactory = $uploadedFileFactory; + $this->uriFactory = $uriFactory; + } + + public static function create( + ?RequestFactoryInterface $requestFactory = null, + ?ResponseFactoryInterface $responseFactory = null, + ?ServerRequestFactoryInterface $serverRequestFactory = null, + ?StreamFactoryInterface $streamFactory = null, + ?UploadedFileFactoryInterface $uploadedFileFactory = null, + ?UriFactoryInterface $uriFactory = null + ): self { + return new self( + $requestFactory, + $responseFactory, + $serverRequestFactory, + $streamFactory, + $uploadedFileFactory, + $uriFactory + ); + } + + public function resolveRequestFactory(): RequestFactoryInterface + { + return $this->requestFactory ??= Psr17FactoryDiscovery::findRequestFactory(); + } + + public function resolveResponseFactory(): ResponseFactoryInterface + { + return $this->responseFactory ??= Psr17FactoryDiscovery::findResponseFactory(); + } + + public function resolveServerRequestFactory(): ServerRequestFactoryInterface + { + return $this->serverRequestFactory ??= Psr17FactoryDiscovery::findServerRequestFactory(); + } + + public function resolveStreamFactory(): StreamFactoryInterface + { + return $this->streamFactory ??= Psr17FactoryDiscovery::findStreamFactory(); + } + + public function resolveUploadedFileFactory(): UploadedFileFactoryInterface + { + return $this->uploadedFileFactory ??= Psr17FactoryDiscovery::findUploadedFileFactory(); + } + + public function resolveUriFactory(): UriFactoryInterface + { + return $this->uriFactory ??= Psr17FactoryDiscovery::findUriFactory(); + } +} diff --git a/vendor/open-telemetry/sdk/Common/Adapter/HttpDiscovery/PsrClientResolver.php b/vendor/open-telemetry/sdk/Common/Adapter/HttpDiscovery/PsrClientResolver.php new file mode 100644 index 000000000..46fb36312 --- /dev/null +++ b/vendor/open-telemetry/sdk/Common/Adapter/HttpDiscovery/PsrClientResolver.php @@ -0,0 +1,29 @@ +client = $client; + } + + public static function create(?ClientInterface $client = null): self + { + return new self($client); + } + + public function resolvePsrClient(): ClientInterface + { + return $this->client ??= Psr18ClientDiscovery::find(); + } +} diff --git a/vendor/open-telemetry/sdk/Common/Attribute/AttributeValidator.php b/vendor/open-telemetry/sdk/Common/Attribute/AttributeValidator.php new file mode 100644 index 000000000..e9a1f7334 --- /dev/null +++ b/vendor/open-telemetry/sdk/Common/Attribute/AttributeValidator.php @@ -0,0 +1,58 @@ +validateArray($value); + } + + return in_array(gettype($value), self::PRIMITIVES); + } + + private function validateArray(array $value): bool + { + if ($value === []) { + return true; + } + $type = gettype(reset($value)); + if (!in_array($type, self::PRIMITIVES)) { + return false; + } + foreach ($value as $v) { + if (in_array(gettype($v), self::NUMERICS) && in_array($type, self::NUMERICS)) { + continue; + } + if (gettype($v) !== $type) { + return false; + } + } + + return true; + } + + public function getInvalidMessage(): string + { + return 'attribute with non-primitive or non-homogeneous array of primitives dropped'; + } +} diff --git a/vendor/open-telemetry/sdk/Common/Attribute/AttributeValidatorInterface.php b/vendor/open-telemetry/sdk/Common/Attribute/AttributeValidatorInterface.php new file mode 100644 index 000000000..afbfba6e7 --- /dev/null +++ b/vendor/open-telemetry/sdk/Common/Attribute/AttributeValidatorInterface.php @@ -0,0 +1,11 @@ +attributes = $attributes; + $this->droppedAttributesCount = $droppedAttributesCount; + } + + public static function create(iterable $attributes): AttributesInterface + { + return self::factory()->builder($attributes)->build(); + } + + public static function factory(?int $attributeCountLimit = null, ?int $attributeValueLengthLimit = null): AttributesFactoryInterface + { + return new AttributesFactory($attributeCountLimit, $attributeValueLengthLimit); + } + + public function has(string $name): bool + { + return array_key_exists($name, $this->attributes); + } + + public function get(string $name) + { + return $this->attributes[$name] ?? null; + } + + /** @psalm-mutation-free */ + public function count(): int + { + return \count($this->attributes); + } + + public function getIterator(): Traversable + { + foreach ($this->attributes as $key => $value) { + yield (string) $key => $value; + } + } + + public function toArray(): array + { + return $this->attributes; + } + + public function getDroppedAttributesCount(): int + { + return $this->droppedAttributesCount; + } +} diff --git a/vendor/open-telemetry/sdk/Common/Attribute/AttributesBuilder.php b/vendor/open-telemetry/sdk/Common/Attribute/AttributesBuilder.php new file mode 100644 index 000000000..5c1150638 --- /dev/null +++ b/vendor/open-telemetry/sdk/Common/Attribute/AttributesBuilder.php @@ -0,0 +1,120 @@ +attributes = $attributes; + $this->attributeCountLimit = $attributeCountLimit; + $this->attributeValueLengthLimit = $attributeValueLengthLimit; + $this->droppedAttributesCount = $droppedAttributesCount; + $this->attributeValidator = $attributeValidator ?? new AttributeValidator(); + } + + public function build(): AttributesInterface + { + return new Attributes($this->attributes, $this->droppedAttributesCount); + } + + public function offsetExists($offset): bool + { + return array_key_exists($offset, $this->attributes); + } + + /** + * @phan-suppress PhanUndeclaredClassAttribute + */ + #[\ReturnTypeWillChange] + public function offsetGet($offset) + { + return $this->attributes[$offset] ?? null; + } + + /** + * @phan-suppress PhanUndeclaredClassAttribute + */ + #[\ReturnTypeWillChange] + public function offsetSet($offset, $value) + { + if ($offset === null) { + return; + } + if ($value === null) { + unset($this->attributes[$offset]); + + return; + } + if (!$this->attributeValidator->validate($value)) { + self::logWarning($this->attributeValidator->getInvalidMessage() . ': ' . $offset); + $this->droppedAttributesCount++; + + return; + } + if (count($this->attributes) === $this->attributeCountLimit && !array_key_exists($offset, $this->attributes)) { + $this->droppedAttributesCount++; + + return; + } + + $this->attributes[$offset] = $this->normalizeValue($value); + //@todo "There SHOULD be a message printed in the SDK's log to indicate to the user that an attribute was + // discarded due to such a limit. To prevent excessive logging, the message MUST be printed at most + // once per (i.e., not per discarded attribute)." + } + + /** + * @phan-suppress PhanUndeclaredClassAttribute + */ + #[\ReturnTypeWillChange] + public function offsetUnset($offset) + { + unset($this->attributes[$offset]); + } + + private function normalizeValue($value) + { + if (is_string($value) && $this->attributeValueLengthLimit !== null) { + return mb_substr($value, 0, $this->attributeValueLengthLimit); + } + + if (is_array($value)) { + foreach ($value as $k => $v) { + $processed = $this->normalizeValue($v); + if ($processed !== $v) { + $value[$k] = $processed; + } + } + + return $value; + } + + return $value; + } +} diff --git a/vendor/open-telemetry/sdk/Common/Attribute/AttributesBuilderInterface.php b/vendor/open-telemetry/sdk/Common/Attribute/AttributesBuilderInterface.php new file mode 100644 index 000000000..7e3d64062 --- /dev/null +++ b/vendor/open-telemetry/sdk/Common/Attribute/AttributesBuilderInterface.php @@ -0,0 +1,12 @@ +attributeCountLimit = $attributeCountLimit; + $this->attributeValueLengthLimit = $attributeValueLengthLimit; + } + + public function builder(iterable $attributes = [], ?AttributeValidatorInterface $attributeValidator = null): AttributesBuilderInterface + { + $builder = new AttributesBuilder( + [], + $this->attributeCountLimit, + $this->attributeValueLengthLimit, + 0, + $attributeValidator, + ); + foreach ($attributes as $key => $value) { + $builder[$key] = $value; + } + + return $builder; + } +} diff --git a/vendor/open-telemetry/sdk/Common/Attribute/AttributesFactoryInterface.php b/vendor/open-telemetry/sdk/Common/Attribute/AttributesFactoryInterface.php new file mode 100644 index 000000000..1b74461d4 --- /dev/null +++ b/vendor/open-telemetry/sdk/Common/Attribute/AttributesFactoryInterface.php @@ -0,0 +1,10 @@ + $rejectedKeys + */ + public function __construct(AttributesBuilderInterface $builder, array $rejectedKeys) + { + $this->builder = $builder; + $this->rejectedKeys = $rejectedKeys; + } + + public function __clone() + { + $this->builder = clone $this->builder; + } + + public function build(): AttributesInterface + { + $attributes = $this->builder->build(); + $dropped = $attributes->getDroppedAttributesCount() + $this->rejected; + + return new Attributes($attributes->toArray(), $dropped); + } + + public function offsetExists($offset): bool + { + return $this->builder->offsetExists($offset); + } + + /** + * @phan-suppress PhanUndeclaredClassAttribute + */ + #[\ReturnTypeWillChange] + public function offsetGet($offset) + { + return $this->builder->offsetGet($offset); + } + + /** + * @phan-suppress PhanUndeclaredClassAttribute + */ + #[\ReturnTypeWillChange] + public function offsetSet($offset, $value) + { + if ($value !== null && in_array($offset, $this->rejectedKeys, true)) { + $this->rejected++; + + return; + } + + $this->builder->offsetSet($offset, $value); + } + + /** + * @phan-suppress PhanUndeclaredClassAttribute + */ + #[\ReturnTypeWillChange] + public function offsetUnset($offset) + { + $this->builder->offsetUnset($offset); + } +} diff --git a/vendor/open-telemetry/sdk/Common/Attribute/FilteredAttributesFactory.php b/vendor/open-telemetry/sdk/Common/Attribute/FilteredAttributesFactory.php new file mode 100644 index 000000000..1d9c4ae1c --- /dev/null +++ b/vendor/open-telemetry/sdk/Common/Attribute/FilteredAttributesFactory.php @@ -0,0 +1,33 @@ + $rejectedKeys + */ + public function __construct(AttributesFactoryInterface $factory, array $rejectedKeys) + { + $this->factory = $factory; + $this->rejectedKeys = $rejectedKeys; + } + + public function builder(iterable $attributes = [], ?AttributeValidatorInterface $attributeValidator = null): AttributesBuilderInterface + { + $builder = new FilteredAttributesBuilder($this->factory->builder([], $attributeValidator), $this->rejectedKeys); + foreach ($attributes as $attribute => $value) { + $builder[$attribute] = $value; + } + + return $builder; + } +} diff --git a/vendor/open-telemetry/sdk/Common/Attribute/LogRecordAttributeValidator.php b/vendor/open-telemetry/sdk/Common/Attribute/LogRecordAttributeValidator.php new file mode 100644 index 000000000..a09d26372 --- /dev/null +++ b/vendor/open-telemetry/sdk/Common/Attribute/LogRecordAttributeValidator.php @@ -0,0 +1,19 @@ +hasVariable($name); + } + + public static function getInt(string $key, int $default = null): int + { + return (int) self::validateVariableValue( + CompositeResolver::instance()->resolve( + self::validateVariableType($key, VariableTypes::INTEGER), + $default + ), + FILTER_VALIDATE_INT + ); + } + + public static function getString(string $key, string $default = null): string + { + return (string) self::validateVariableValue( + CompositeResolver::instance()->resolve( + self::validateVariableType($key, VariableTypes::STRING), + $default + ) + ); + } + + public static function getBoolean(string $key, bool $default = null): bool + { + $resolved = self::validateVariableValue( + CompositeResolver::instance()->resolve( + self::validateVariableType($key, VariableTypes::BOOL), + null === $default ? $default : ($default ? 'true' : 'false') + ) + ); + + try { + return BooleanParser::parse($resolved); + } catch (InvalidArgumentException $e) { + self::logWarning(sprintf('Invalid boolean value "%s" interpreted as "false" for %s', $resolved, $key)); + + return false; + } + } + + public static function getMixed(string $key, $default = null) + { + return self::validateVariableValue( + CompositeResolver::instance()->resolve( + $key, + $default + ) + ); + } + + public static function getMap(string $key, array $default = null): array + { + return MapParser::parse( + CompositeResolver::instance()->resolve( + self::validateVariableType($key, VariableTypes::MAP), + $default + ) + ); + } + + public static function getList(string $key, array $default = null): array + { + return ListParser::parse( + CompositeResolver::instance()->resolve( + self::validateVariableType($key, VariableTypes::LIST), + $default + ) + ); + } + + public static function getEnum(string $key, string $default = null): string + { + return (string) self::validateVariableValue( + CompositeResolver::instance()->resolve( + self::validateVariableType($key, VariableTypes::ENUM), + $default + ) + ); + } + + public static function getFloat(string $key, float $default = null): float + { + return (float) self::validateVariableValue( + CompositeResolver::instance()->resolve( + self::validateVariableType($key, VariableTypes::FLOAT), + $default + ), + FILTER_VALIDATE_FLOAT + ); + } + + public static function getRatio(string $key, float $default = null): float + { + return RatioParser::parse( + self::validateVariableValue( + CompositeResolver::instance()->resolve( + self::validateVariableType($key, VariableTypes::RATIO), + $default + ) + ) + ); + } + + public static function getKnownValues(string $variableName): ?array + { + return ClassConstantAccessor::getValue(KnownValues::class, $variableName); + } + + public static function getDefault(string $variableName) + { + return ClassConstantAccessor::getValue(Defaults::class, $variableName); + } + + public static function getType(string $variableName): ?string + { + return ClassConstantAccessor::getValue(ValueTypes::class, $variableName); + } + + public static function isEmpty($value): bool + { + // don't use 'empty()', since '0' is not considered to be empty + return $value === null || $value === ''; + } + + private static function validateVariableType(string $variableName, string $type): string + { + $variableType = self::getType($variableName); + + if ($variableType !== null && $variableType !== $type && $variableType !== VariableTypes::MIXED) { + throw new UnexpectedValueException( + sprintf('Variable "%s" is not supposed to be of type "%s" but type "%s"', $variableName, $type, $variableType) + ); + } + + return $variableName; + } + + private static function validateVariableValue($value, ?int $filterType = null) + { + if ($filterType !== null && filter_var($value, $filterType) === false) { + throw new UnexpectedValueException(sprintf('Value has invalid type "%s"', gettype($value))); + } + + if ($value === null || $value === '') { + throw new UnexpectedValueException( + 'Variable must not be null or empty' + ); + } + + return $value; + } +} diff --git a/vendor/open-telemetry/sdk/Common/Configuration/Defaults.php b/vendor/open-telemetry/sdk/Common/Configuration/Defaults.php new file mode 100644 index 000000000..7228270a6 --- /dev/null +++ b/vendor/open-telemetry/sdk/Common/Configuration/Defaults.php @@ -0,0 +1,122 @@ + trim($value), + explode(self::DEFAULT_SEPARATOR, $value) + ); + } +} diff --git a/vendor/open-telemetry/sdk/Common/Configuration/Parser/MapParser.php b/vendor/open-telemetry/sdk/Common/Configuration/Parser/MapParser.php new file mode 100644 index 000000000..273d57c87 --- /dev/null +++ b/vendor/open-telemetry/sdk/Common/Configuration/Parser/MapParser.php @@ -0,0 +1,45 @@ + self::MAX_VALUE || $result < self::MIN_VALUE) { + throw new RangeException( + sprintf( + 'Value must not be lower than %s or higher than %s. Given: %s', + self::MIN_VALUE, + self::MAX_VALUE, + $value + ) + ); + } + + return $result; + } +} diff --git a/vendor/open-telemetry/sdk/Common/Configuration/Resolver/CompositeResolver.php b/vendor/open-telemetry/sdk/Common/Configuration/Resolver/CompositeResolver.php new file mode 100644 index 000000000..b72400b01 --- /dev/null +++ b/vendor/open-telemetry/sdk/Common/Configuration/Resolver/CompositeResolver.php @@ -0,0 +1,68 @@ + + private array $resolvers = []; + + public static function instance(): self + { + static $instance; + $instance ??= new self([ + new PhpIniResolver(), + new EnvironmentResolver(), + ]); + + return $instance; + } + + public function __construct($resolvers) + { + foreach ($resolvers as $resolver) { + $this->addResolver($resolver); + } + } + + public function addResolver(ResolverInterface $resolver): void + { + $this->resolvers[] = $resolver; + } + + public function getResolvers(): array + { + return $this->resolvers; + } + + public function resolve(string $variableName, $default = '') + { + foreach ($this->resolvers as $resolver) { + if ($resolver->hasVariable($variableName)) { + return $resolver->retrieveValue($variableName); + } + } + + return Configuration::isEmpty($default) + ? Configuration::getDefault($variableName) + : $default; + } + + public function hasVariable(string $variableName): bool + { + foreach ($this->resolvers as $resolver) { + if ($resolver->hasVariable($variableName)) { + return true; + } + } + + return false; + } +} diff --git a/vendor/open-telemetry/sdk/Common/Configuration/Resolver/EnvironmentResolver.php b/vendor/open-telemetry/sdk/Common/Configuration/Resolver/EnvironmentResolver.php new file mode 100644 index 000000000..453f98e39 --- /dev/null +++ b/vendor/open-telemetry/sdk/Common/Configuration/Resolver/EnvironmentResolver.php @@ -0,0 +1,40 @@ +accessor = $accessor ?? new PhpIniAccessor(); + } + + public function retrieveValue(string $variableName) + { + $value = $this->accessor->get($variableName) ?: ''; + if (is_array($value)) { + return implode(',', $value); + } + + return $value; + } + + public function hasVariable(string $variableName): bool + { + $value = $this->accessor->get($variableName); + if ($value === []) { + return false; + } + + return $value !== false && !Configuration::isEmpty($value); + } +} diff --git a/vendor/open-telemetry/sdk/Common/Configuration/Resolver/ResolverInterface.php b/vendor/open-telemetry/sdk/Common/Configuration/Resolver/ResolverInterface.php new file mode 100644 index 000000000..4e88f3ff6 --- /dev/null +++ b/vendor/open-telemetry/sdk/Common/Configuration/Resolver/ResolverInterface.php @@ -0,0 +1,15 @@ + + */ +final class StackTraceFormatter +{ + private function __construct() + { + } + + /** + * Formats an exception in a java-like format. + * + * @param Throwable $e exception to format + * @return string formatted exception + * + * @see https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/lang/Throwable.html#printStackTrace() + */ + public static function format(Throwable $e): string + { + $s = ''; + $seen = []; + + /** @var Frames|null $enclosing */ + $enclosing = null; + do { + if ($enclosing) { + self::writeNewline($s); + $s .= 'Caused by: '; + } + if (isset($seen[spl_object_id($e)])) { + $s .= '[CIRCULAR REFERENCE: '; + self::writeInlineHeader($s, $e); + $s .= ']'; + + break; + } + $seen[spl_object_id($e)] = $e; + + $frames = self::frames($e); + self::writeInlineHeader($s, $e); + self::writeFrames($s, $frames, $enclosing); + + $enclosing = $frames; + } while ($e = $e->getPrevious()); + + return $s; + } + + /** + * @phan-suppress-next-line PhanTypeMismatchDeclaredParam + * @param Frames $frames + * @phan-suppress-next-line PhanTypeMismatchDeclaredParam + * @param Frames|null $enclosing + */ + private static function writeFrames(string &$s, array $frames, ?array $enclosing): void + { + $n = count($frames); + if ($enclosing) { + for ($m = count($enclosing); + $n && $m && $frames[$n - 1] === $enclosing[$m - 1]; + $n--, $m--) { + } + } + for ($i = 0; $i < $n; $i++) { + $frame = $frames[$i]; + self::writeNewline($s, 1); + $s .= 'at '; + if ($frame['class'] !== null) { + $s .= self::formatName($frame['class']); + $s .= '.'; + } + $s .= self::formatName($frame['function']); + $s .= '('; + if ($frame['file'] !== null) { + $s .= basename($frame['file']); + if ($frame['line']) { + $s .= ':'; + $s .= $frame['line']; + } + } else { + $s .= 'Unknown Source'; + } + $s .= ')'; + } + if ($n !== count($frames)) { + self::writeNewline($s, 1); + $s .= sprintf('... %d more', count($frames) - $n); + } + } + + private static function writeInlineHeader(string &$s, Throwable $e): void + { + $s .= self::formatName(get_class($e)); + if ($e->getMessage() !== '') { + $s .= ': '; + $s .= $e->getMessage(); + } + } + + private static function writeNewline(string &$s, int $indent = 0): void + { + $s .= "\n"; + $s .= str_repeat("\t", $indent); + } + + /** + * @return Frames + * + * @psalm-suppress PossiblyUndefinedArrayOffset + */ + private static function frames(Throwable $e): array + { + $frames = []; + $trace = $e->getTrace(); + $traceCount = count($trace); + for ($i = 0; $i < $traceCount + 1; $i++) { + $frames[] = [ + 'function' => $trace[$i]['function'] ?? '{main}', + 'class' => $trace[$i]['class'] ?? null, + 'file' => $trace[$i - 1]['file'] ?? null, + 'line' => $trace[$i - 1]['line'] ?? null, + ]; + } + $frames[0]['file'] = $e->getFile(); + $frames[0]['line'] = $e->getLine(); + + /** @var Frames $frames */ + return $frames; + } + + private static function formatName(string $name): string + { + return strtr($name, ['\\' => '.']); + } +} diff --git a/vendor/open-telemetry/sdk/Common/Export/Http/PsrTransport.php b/vendor/open-telemetry/sdk/Common/Export/Http/PsrTransport.php new file mode 100644 index 000000000..a53e5b80a --- /dev/null +++ b/vendor/open-telemetry/sdk/Common/Export/Http/PsrTransport.php @@ -0,0 +1,168 @@ + + */ +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 + ) { + $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 + { + return $this->contentType; + } + + public function send(string $payload, ?CancellationInterface $cancellation = null): FutureInterface + { + if ($this->closed) { + return new ErrorFuture(new BadMethodCallException('Transport closed')); + } + + $body = PsrUtils::encode($payload, $this->compression, $appliedEncodings); + $request = $this->requestFactory + ->createRequest('POST', $this->endpoint) + ->withBody($this->streamFactory->createStream($body)) + ->withHeader('Content-Type', $this->contentType) + ; + if ($appliedEncodings) { + $request = $request->withHeader('Content-Encoding', $appliedEncodings); + } + foreach ($this->headers as $header => $value) { + $request = $request->withAddedHeader($header, $value); + } + + for ($retries = 0;; $retries++) { + $response = null; + $e = null; + + try { + $response = $this->client->sendRequest($request); + if ($response->getStatusCode() >= 200 && $response->getStatusCode() < 300) { + break; + } + + if ($response->getStatusCode() >= 400 && $response->getStatusCode() < 500 && !in_array($response->getStatusCode(), [408, 429], true)) { + throw new RuntimeException($response->getReasonPhrase(), $response->getStatusCode()); + } + } catch (NetworkExceptionInterface $e) { + } catch (Throwable $e) { + return new ErrorFuture($e); + } + + if ($retries >= $this->maxRetries) { + return new ErrorFuture(new RuntimeException('Export retry limit exceeded', 0, $e)); + } + + $delay = PsrUtils::retryDelay($retries, $this->retryDelay, $response); + $sec = (int) $delay; + $nsec = (int) (($delay - $sec) * 1e9); + + /** @psalm-suppress ArgumentTypeCoercion */ + if (time_nanosleep($sec, $nsec) !== true) { + return new ErrorFuture(new RuntimeException('Export cancelled', 0, $e)); + } + } + + assert(isset($response)); + + try { + $body = PsrUtils::decode( + $response->getBody()->__toString(), + self::parseContentEncoding($response), + ); + } catch (Throwable $e) { + return new ErrorFuture($e); + } + + return new CompletedFuture($body); + } + + private static function parseContentEncoding(ResponseInterface $response): array + { + $encodings = []; + foreach (explode(',', $response->getHeaderLine('Content-Encoding')) as $encoding) { + if (($encoding = trim($encoding, " \t")) !== '') { + $encodings[] = strtolower($encoding); + } + } + + return $encodings; + } + + public function shutdown(?CancellationInterface $cancellation = null): bool + { + if ($this->closed) { + return false; + } + + $this->closed = true; + + return true; + } + + public function forceFlush(?CancellationInterface $cancellation = null): bool + { + return !$this->closed; + } +} diff --git a/vendor/open-telemetry/sdk/Common/Export/Http/PsrTransportFactory.php b/vendor/open-telemetry/sdk/Common/Export/Http/PsrTransportFactory.php new file mode 100644 index 000000000..5ef78d82c --- /dev/null +++ b/vendor/open-telemetry/sdk/Common/Export/Http/PsrTransportFactory.php @@ -0,0 +1,74 @@ +client = $client; + $this->requestFactory = $requestFactory; + $this->streamFactory = $streamFactory; + } + + /** + * @phan-suppress PhanTypeMismatchArgumentNullable + */ + public function create( + string $endpoint, + string $contentType, + array $headers = [], + $compression = null, + float $timeout = 10., + int $retryDelay = 100, + int $maxRetries = 3, + ?string $cacert = null, + ?string $cert = null, + ?string $key = null + ): PsrTransport { + if (!filter_var($endpoint, FILTER_VALIDATE_URL)) { + throw new InvalidArgumentException(sprintf('Invalid endpoint url "%s"', $endpoint)); + } + assert(!empty($endpoint)); + + return new PsrTransport( + $this->client, + $this->requestFactory, + $this->streamFactory, + $endpoint, + $contentType, + $headers, + PsrUtils::compression($compression), + $retryDelay, + $maxRetries, + ); + } + + public static function discover(): self + { + return new self( + Psr18ClientDiscovery::find(), + Psr17FactoryDiscovery::findRequestFactory(), + Psr17FactoryDiscovery::findStreamFactory(), + ); + } +} diff --git a/vendor/open-telemetry/sdk/Common/Export/Http/PsrUtils.php b/vendor/open-telemetry/sdk/Common/Export/Http/PsrUtils.php new file mode 100644 index 000000000..eaf2f3b47 --- /dev/null +++ b/vendor/open-telemetry/sdk/Common/Export/Http/PsrUtils.php @@ -0,0 +1,175 @@ +> 1, $delay) / 1000; + + return max($delay, self::parseRetryAfter($response)); + } + + private static function parseRetryAfter(?ResponseInterface $response): int + { + if (!$response || !$retryAfter = $response->getHeaderLine('Retry-After')) { + return 0; + } + + $retryAfter = trim($retryAfter, " \t"); + if ($retryAfter === (string) (int) $retryAfter) { + return (int) $retryAfter; + } + + if (($time = strtotime($retryAfter)) !== false) { + return $time - time(); + } + + return 0; + } + + /** + * @param list $encodings + * @param array|null $appliedEncodings + */ + public static function encode(string $value, array $encodings, ?array &$appliedEncodings = null): string + { + for ($i = 0, $n = count($encodings); $i < $n; $i++) { + if (!$encoder = self::encoder($encodings[$i])) { + unset($encodings[$i]); + + continue; + } + + try { + $value = $encoder($value); + } catch (Throwable $e) { + unset($encodings[$i]); + } + } + + $appliedEncodings = $encodings; + + return $value; + } + + /** + * @param list $encodings + */ + public static function decode(string $value, array $encodings): string + { + for ($i = count($encodings); --$i >= 0;) { + if (strcasecmp($encodings[$i], 'identity') === 0) { + continue; + } + if (!$decoder = self::decoder($encodings[$i])) { + throw new UnexpectedValueException(sprintf('Not supported decompression encoding "%s"', $encodings[$i])); + } + + $value = $decoder($value); + } + + return $value; + } + + /** + * Resolve an array or CSV of compression types to a list + */ + public static function compression($compression): array + { + if (is_array($compression)) { + return $compression; + } + if (!$compression) { + return []; + } + if (strpos($compression, ',') === false) { + return [$compression]; + } + + return array_map('trim', explode(',', $compression)); + } + + private static function encoder(string $encoding): ?callable + { + static $encoders; + + /** @noinspection SpellCheckingInspection */ + $encoders ??= array_map(fn (callable $callable): callable => self::throwOnErrorOrFalse($callable), array_filter([ + TransportFactoryInterface::COMPRESSION_GZIP => 'gzencode', + TransportFactoryInterface::COMPRESSION_DEFLATE => 'gzcompress', + TransportFactoryInterface::COMPRESSION_BROTLI => 'brotli_compress', + ], 'function_exists')); + + return $encoders[$encoding] ?? null; + } + + private static function decoder(string $encoding): ?callable + { + static $decoders; + + /** @noinspection SpellCheckingInspection */ + $decoders ??= array_map(fn (callable $callable): callable => self::throwOnErrorOrFalse($callable), array_filter([ + TransportFactoryInterface::COMPRESSION_GZIP => 'gzdecode', + TransportFactoryInterface::COMPRESSION_DEFLATE => 'gzuncompress', + TransportFactoryInterface::COMPRESSION_BROTLI => 'brotli_uncompress', + ], 'function_exists')); + + return $decoders[$encoding] ?? null; + } + + private static function throwOnErrorOrFalse(callable $callable): callable + { + return static function (...$args) use ($callable) { + set_error_handler(static function (int $errno, string $errstr, string $errfile, int $errline): bool { + throw new ErrorException($errstr, 0, $errno, $errfile, $errline); + }); + + try { + $result = $callable(...$args); + } finally { + restore_error_handler(); + } + + /** @phan-suppress-next-line PhanPossiblyUndeclaredVariable */ + if ($result === false) { + throw new LogicException(); + } + + /** @phan-suppress-next-line PhanPossiblyUndeclaredVariable */ + return $result; + }; + } +} diff --git a/vendor/open-telemetry/sdk/Common/Export/Stream/StreamTransport.php b/vendor/open-telemetry/sdk/Common/Export/Stream/StreamTransport.php new file mode 100644 index 000000000..4b99cf756 --- /dev/null +++ b/vendor/open-telemetry/sdk/Common/Export/Stream/StreamTransport.php @@ -0,0 +1,97 @@ + + */ +final class StreamTransport implements TransportInterface +{ + /** + * @var resource|null + */ + private $stream; + private string $contentType; + + /** + * @param resource $stream + * + * @psalm-param CONTENT_TYPE $contentType + */ + public function __construct($stream, string $contentType) + { + $this->stream = $stream; + $this->contentType = $contentType; + } + + public function contentType(): string + { + return $this->contentType; + } + + public function send(string $payload, ?CancellationInterface $cancellation = null): FutureInterface + { + if (!$this->stream) { + return new ErrorFuture(new BadMethodCallException('Transport closed')); + } + + set_error_handler(static function (int $errno, string $errstr, string $errfile, int $errline): bool { + throw new ErrorException($errstr, 0, $errno, $errfile, $errline); + }); + + try { + $bytesWritten = fwrite($this->stream, $payload); + } catch (Throwable $e) { + return new ErrorFuture($e); + } finally { + restore_error_handler(); + } + + if ($bytesWritten !== strlen($payload)) { + return new ErrorFuture(new RuntimeException(sprintf('Write failure, wrote %d of %d bytes', $bytesWritten, strlen($payload)))); + } + + return new CompletedFuture(null); + } + + public function shutdown(?CancellationInterface $cancellation = null): bool + { + if (!$this->stream) { + return false; + } + + $flush = @fflush($this->stream); + $this->stream = null; + + return $flush; + } + + public function forceFlush(?CancellationInterface $cancellation = null): bool + { + if (!$this->stream) { + return false; + } + + return @fflush($this->stream); + } +} diff --git a/vendor/open-telemetry/sdk/Common/Export/Stream/StreamTransportFactory.php b/vendor/open-telemetry/sdk/Common/Export/Stream/StreamTransportFactory.php new file mode 100644 index 000000000..59e411318 --- /dev/null +++ b/vendor/open-telemetry/sdk/Common/Export/Stream/StreamTransportFactory.php @@ -0,0 +1,118 @@ + $headers + * @param string|string[]|null $compression + * + * @psalm-template CONTENT_TYPE of string + * @psalm-param CONTENT_TYPE $contentType + * @psalm-return TransportInterface + */ + public function create( + $endpoint, + string $contentType, + array $headers = [], + $compression = null, + float $timeout = 10., + int $retryDelay = 100, + int $maxRetries = 3, + ?string $cacert = null, + ?string $cert = null, + ?string $key = null + ): TransportInterface { + assert(!empty($endpoint)); + $stream = is_resource($endpoint) + ? $endpoint + : self::createStream( + $endpoint, + $contentType, + $headers, + $timeout, + $cacert, + $cert, + $key, + ); + + return new StreamTransport($stream, $contentType); + } + + /** + * @throws ErrorException + * @return resource + */ + private static function createStream( + string $endpoint, + string $contentType, + array $headers = [], + float $timeout = 10., + ?string $cacert = null, + ?string $cert = null, + ?string $key = null + ) { + $context = stream_context_create([ + 'http' => [ + 'method' => 'POST', + 'header' => self::createHeaderArray($contentType, $headers), + 'timeout' => $timeout, + ], + 'ssl' => [ + 'cafile' => $cacert, + 'local_cert' => $cert, + 'local_pk' => $key, + ], + ]); + + set_error_handler(static function (int $errno, string $errstr, string $errfile, int $errline): bool { + throw new ErrorException($errstr, 0, $errno, $errfile, $errline); + }); + + /** + * @psalm-suppress PossiblyNullArgument + */ + try { + $stream = fopen($endpoint, 'ab', false, $context); + } finally { + restore_error_handler(); + } + + /** @phan-suppress-next-line PhanPossiblyUndeclaredVariable */ + if (!$stream) { + throw new LogicException(sprintf('Failed opening stream "%s"', $endpoint)); + } + + return $stream; + } + + private static function createHeaderArray(string $contentType, array $headers): array + { + $header = []; + $header[] = sprintf('Content-Type: %s', $contentType); + foreach ($headers as $name => $value) { + $header[] = sprintf('%s: %s', $name, implode(', ', (array) $value)); + } + + return $header; + } +} diff --git a/vendor/open-telemetry/sdk/Common/Export/TransportFactoryInterface.php b/vendor/open-telemetry/sdk/Common/Export/TransportFactoryInterface.php new file mode 100644 index 000000000..48e538443 --- /dev/null +++ b/vendor/open-telemetry/sdk/Common/Export/TransportFactoryInterface.php @@ -0,0 +1,32 @@ + $headers + * @psalm-param string|string[]|null $compression + * @psalm-return TransportInterface + */ + public function create( + string $endpoint, + string $contentType, + array $headers = [], + $compression = null, + float $timeout = 10., + int $retryDelay = 100, + int $maxRetries = 3, + ?string $cacert = null, + ?string $cert = null, + ?string $key = null + ): TransportInterface; +} diff --git a/vendor/open-telemetry/sdk/Common/Export/TransportInterface.php b/vendor/open-telemetry/sdk/Common/Export/TransportInterface.php new file mode 100644 index 000000000..5fb26eff8 --- /dev/null +++ b/vendor/open-telemetry/sdk/Common/Export/TransportInterface.php @@ -0,0 +1,22 @@ + + */ +final class CompletedFuture implements FutureInterface +{ + /** @var T */ + private $value; + + /** + * @param T $value + */ + public function __construct($value) + { + $this->value = $value; + } + + public function await() + { + return $this->value; + } + + public function map(Closure $closure): FutureInterface + { + $c = $closure; + unset($closure); + + try { + return new CompletedFuture($c($this->value)); + } catch (Throwable $e) { + return new ErrorFuture($e); + } + } + + public function catch(Closure $closure): FutureInterface + { + return $this; + } +} diff --git a/vendor/open-telemetry/sdk/Common/Future/ErrorFuture.php b/vendor/open-telemetry/sdk/Common/Future/ErrorFuture.php new file mode 100644 index 000000000..32cf3d995 --- /dev/null +++ b/vendor/open-telemetry/sdk/Common/Future/ErrorFuture.php @@ -0,0 +1,40 @@ +throwable = $throwable; + } + + public function await() + { + throw $this->throwable; + } + + public function map(Closure $closure): FutureInterface + { + return $this; + } + + public function catch(Closure $closure): FutureInterface + { + $c = $closure; + unset($closure); + + try { + return new CompletedFuture($c($this->throwable)); + } catch (Throwable $e) { + return new ErrorFuture($e); + } + } +} diff --git a/vendor/open-telemetry/sdk/Common/Future/FutureInterface.php b/vendor/open-telemetry/sdk/Common/Future/FutureInterface.php new file mode 100644 index 000000000..850699bf6 --- /dev/null +++ b/vendor/open-telemetry/sdk/Common/Future/FutureInterface.php @@ -0,0 +1,34 @@ + + * + * @psalm-suppress InvalidTemplateParam + */ + public function map(Closure $closure): FutureInterface; + + /** + * @psalm-template U + * @psalm-param Closure(\Throwable): U $closure + * @psalm-return FutureInterface + */ + public function catch(Closure $closure): FutureInterface; +} diff --git a/vendor/open-telemetry/sdk/Common/Future/NullCancellation.php b/vendor/open-telemetry/sdk/Common/Future/NullCancellation.php new file mode 100644 index 000000000..5e5b642f9 --- /dev/null +++ b/vendor/open-telemetry/sdk/Common/Future/NullCancellation.php @@ -0,0 +1,20 @@ +requestFactory = $requestFactory; + $this->responseFactory = $responseFactory; + $this->serverRequestFactory = $serverRequestFactory; + } + + public static function create( + RequestFactoryInterface $requestFactory, + ResponseFactoryInterface $responseFactory, + ServerRequestFactoryInterface $serverRequestFactory + ): self { + return new self($requestFactory, $responseFactory, $serverRequestFactory); + } + + public function createRequest(string $method, $uri): RequestInterface + { + return $this->requestFactory->createRequest($method, $uri); + } + + public function createResponse(int $code = 200, string $reasonPhrase = ''): ResponseInterface + { + return $this->responseFactory->createResponse($code, $reasonPhrase); + } + + public function createServerRequest(string $method, $uri, array $serverParams = []): ServerRequestInterface + { + return $this->serverRequestFactory->createServerRequest($method, $uri, $serverParams); + } +} diff --git a/vendor/open-telemetry/sdk/Common/Http/Psr/Message/MessageFactoryInterface.php b/vendor/open-telemetry/sdk/Common/Http/Psr/Message/MessageFactoryInterface.php new file mode 100644 index 000000000..97258491f --- /dev/null +++ b/vendor/open-telemetry/sdk/Common/Http/Psr/Message/MessageFactoryInterface.php @@ -0,0 +1,13 @@ +name = $name; + $this->version = $version; + $this->schemaUrl = $schemaUrl; + $this->attributes = $attributes; + } + + public function getName(): string + { + return $this->name; + } + + public function getVersion(): ?string + { + return $this->version; + } + + public function getSchemaUrl(): ?string + { + return $this->schemaUrl; + } + + public function getAttributes(): AttributesInterface + { + return $this->attributes; + } +} diff --git a/vendor/open-telemetry/sdk/Common/Instrumentation/InstrumentationScopeFactory.php b/vendor/open-telemetry/sdk/Common/Instrumentation/InstrumentationScopeFactory.php new file mode 100644 index 000000000..f1ae7c072 --- /dev/null +++ b/vendor/open-telemetry/sdk/Common/Instrumentation/InstrumentationScopeFactory.php @@ -0,0 +1,31 @@ +attributesFactory = $attributesFactory; + } + + public function create( + string $name, + ?string $version = null, + ?string $schemaUrl = null, + iterable $attributes = [] + ): InstrumentationScopeInterface { + return new InstrumentationScope( + $name, + $version, + $schemaUrl, + $this->attributesFactory->builder($attributes)->build(), + ); + } +} diff --git a/vendor/open-telemetry/sdk/Common/Instrumentation/InstrumentationScopeFactoryInterface.php b/vendor/open-telemetry/sdk/Common/Instrumentation/InstrumentationScopeFactoryInterface.php new file mode 100644 index 000000000..78292de58 --- /dev/null +++ b/vendor/open-telemetry/sdk/Common/Instrumentation/InstrumentationScopeFactoryInterface.php @@ -0,0 +1,15 @@ +build(); + } + + public static function setDefault(?ClockInterface $clock): void + { + self::$default = $clock; + } +} diff --git a/vendor/open-telemetry/sdk/Common/Time/ClockFactoryInterface.php b/vendor/open-telemetry/sdk/Common/Time/ClockFactoryInterface.php new file mode 100644 index 000000000..6d9afde91 --- /dev/null +++ b/vendor/open-telemetry/sdk/Common/Time/ClockFactoryInterface.php @@ -0,0 +1,16 @@ +clock = $clock; + $this->initialStartTime = $initialStartTime; + } + + public function isRunning(): bool + { + return $this->running; + } + + public function start(): void + { + // resolve start time as early as possible + $startTime = $this->time(); + + if ($this->isRunning()) { + return; + } + + $this->startTime = $startTime; + if (!$this->hasBeenStarted()) { + $this->initialStartTime = $startTime; + } + $this->running = true; + } + + public function stop(): void + { + if (!$this->isRunning()) { + return; + } + + $this->stopTime = $this->time(); + $this->running = false; + } + + public function reset(): void + { + $this->startTime = $this->initialStartTime = $this->isRunning() ? $this->time() : null; + } + + public function getElapsedTime(): int + { + if (!$this->hasBeenStarted()) { + return self::INITIAL_ELAPSED_TIME; + } + + return $this->calculateElapsedTime(); + } + + public function getLastElapsedTime(): int + { + if (!$this->hasBeenStarted()) { + return self::INITIAL_ELAPSED_TIME; + } + + return $this->calculateLastElapsedTime(); + } + + private function time(): int + { + return $this->clock->now(); + } + + private function hasBeenStarted(): bool + { + return $this->initialStartTime !== null; + } + + private function calculateElapsedTime(): int + { + $referenceTime = $this->isRunning() + ? $this->time() + : $this->getStopTime(); + + return $referenceTime - $this->getInitialStartTime(); + } + + private function calculateLastElapsedTime(): int + { + $referenceTime = $this->isRunning() + ? $this->time() + : $this->getStopTime(); + + return $referenceTime - $this->getStartTime(); + } + + private function getInitialStartTime(): ?int + { + return $this->initialStartTime; + } + + private function getStartTime(): ?int + { + return $this->startTime; + } + + private function getStopTime(): ?int + { + return $this->stopTime; + } +} diff --git a/vendor/open-telemetry/sdk/Common/Time/StopWatchFactory.php b/vendor/open-telemetry/sdk/Common/Time/StopWatchFactory.php new file mode 100644 index 000000000..f60c377fc --- /dev/null +++ b/vendor/open-telemetry/sdk/Common/Time/StopWatchFactory.php @@ -0,0 +1,44 @@ +clock = $clock ?? ClockFactory::getDefault(); + $this->initialStartTime = $initialStartTime; + } + + public static function create(?ClockInterface $clock = null, ?int $initialStartTime = null): self + { + return new self($clock, $initialStartTime); + } + + public static function fromClockFactory(ClockFactoryInterface $factory, ?int $initialStartTime = null): self + { + return self::create($factory->build(), $initialStartTime); + } + + public function build(): StopWatch + { + return new StopWatch($this->clock, $this->initialStartTime); + } + + public static function getDefault(): StopWatchInterface + { + return self::$default ?? self::$default = self::create()->build(); + } + + public static function setDefault(?StopWatchInterface $default): void + { + self::$default = $default; + } +} diff --git a/vendor/open-telemetry/sdk/Common/Time/StopWatchFactoryInterface.php b/vendor/open-telemetry/sdk/Common/Time/StopWatchFactoryInterface.php new file mode 100644 index 000000000..9750f5769 --- /dev/null +++ b/vendor/open-telemetry/sdk/Common/Time/StopWatchFactoryInterface.php @@ -0,0 +1,18 @@ + 0) { + return; + } + + self::$referenceTime = self::calculateReferenceTime( + microtime(true), + hrtime(true) + ); + } + + /** + * Calculates the reference time which is later used to calculate the current wall clock time in nanoseconds by adding the current uptime. + */ + private static function calculateReferenceTime(float $wallClockMicroTime, int $upTime): int + { + return ((int) ($wallClockMicroTime * ClockInterface::NANOS_PER_SECOND)) - $upTime; + } +} diff --git a/vendor/open-telemetry/sdk/Common/Time/Util.php b/vendor/open-telemetry/sdk/Common/Time/Util.php new file mode 100644 index 000000000..e1be1f750 --- /dev/null +++ b/vendor/open-telemetry/sdk/Common/Time/Util.php @@ -0,0 +1,32 @@ +|null */ + private static ?array $handlers = null; + /** @var ArrayAccess|null */ + private static ?ArrayAccess $weakMap = null; + + private array $ids = []; + + private function __construct() + { + } + + public function __destruct() + { + if (!self::$handlers) { + return; + } + foreach ($this->ids as $id) { + unset(self::$handlers[$id]); + } + } + + /** + * Registers a function that will be executed on shutdown. + * + * If the given function is bound to an object, then the function will only + * be executed if the bound object is still referenced on shutdown handler + * invocation. + * + * ```php + * ShutdownHandler::register([$tracerProvider, 'shutdown']); + * ``` + * + * @param callable $shutdownFunction function to register + * + * @see register_shutdown_function + */ + public static function register(callable $shutdownFunction): void + { + self::registerShutdownFunction(); + self::$handlers[] = weaken(closure($shutdownFunction), $target); + + if (!$object = $target) { + return; + } + + self::$weakMap ??= WeakMap::create(); + $handler = self::$weakMap[$object] ??= new self(); + $handler->ids[] = array_key_last(self::$handlers); + } + + private static function registerShutdownFunction(): void + { + if (self::$handlers === null) { + register_shutdown_function(static function (): void { + $handlers = self::$handlers; + self::$handlers = null; + self::$weakMap = null; + + // Push shutdown to end of queue + // @phan-suppress-next-line PhanTypeMismatchArgumentInternal + register_shutdown_function(static function (array $handlers): void { + foreach ($handlers as $handler) { + $handler(); + } + }, $handlers); + }); + } + } +} diff --git a/vendor/open-telemetry/sdk/Common/Util/WeakMap.php b/vendor/open-telemetry/sdk/Common/Util/WeakMap.php new file mode 100644 index 000000000..3b62d6d64 --- /dev/null +++ b/vendor/open-telemetry/sdk/Common/Util/WeakMap.php @@ -0,0 +1,175 @@ + + */ + private array $objects = []; + + private function __construct() + { + } + + /** + * @return ArrayAccess&Countable&IteratorAggregate + */ + public static function create(): ArrayAccess + { + if (PHP_VERSION_ID >= 80000) { + /** @phan-suppress-next-line PhanUndeclaredClassReference */ + assert(class_exists(\WeakMap::class, false)); + /** @phan-suppress-next-line PhanUndeclaredClassMethod */ + $map = new \WeakMap(); + assert($map instanceof ArrayAccess); + assert($map instanceof Countable); + assert($map instanceof IteratorAggregate); + + return $map; + } + + return new self(); + } + + public function offsetExists($offset): bool + { + if (!is_object($offset)) { + throw new TypeError('WeakMap key must be an object'); + } + + return isset($offset->{self::KEY}[spl_object_id($this)]); + } + + /** + * @phan-suppress PhanUndeclaredClassAttribute + */ + #[\ReturnTypeWillChange] + public function offsetGet($offset) + { + if (!is_object($offset)) { + throw new TypeError('WeakMap key must be an object'); + } + if (!$this->contains($offset)) { + throw new Error(sprintf('Object %s#%d not contained in WeakMap', get_class($offset), spl_object_id($offset))); + } + + return $offset->{self::KEY}[spl_object_id($this)]; + } + + public function offsetSet($offset, $value): void + { + if ($offset === null) { + throw new Error('Cannot append to WeakMap'); + } + if (!is_object($offset)) { + throw new TypeError('WeakMap key must be an object'); + } + if (!$this->contains($offset)) { + $this->expunge(); + } + + $offset->{self::KEY}[spl_object_id($this)] = $value; + $this->objects[spl_object_id($offset)] = WeakReference::create($offset); + } + + public function offsetUnset($offset): void + { + if (!is_object($offset)) { + throw new TypeError('WeakMap key must be an object'); + } + if (!$this->contains($offset)) { + return; + } + + unset( + $offset->{self::KEY}[spl_object_id($this)], + $this->objects[spl_object_id($offset)], + ); + if (!$offset->{self::KEY}) { + unset($offset->{self::KEY}); + } + } + + public function count(): int + { + $this->expunge(); + + return count($this->objects); + } + + public function getIterator(): Traversable + { + $this->expunge(); + + foreach ($this->objects as $reference) { + if (($object = $reference->get()) && $this->contains($object)) { + yield $object => $this[$object]; + } + } + } + + public function __debugInfo(): array + { + $debugInfo = []; + foreach ($this as $key => $value) { + $debugInfo[] = ['key' => $key, 'value' => $value]; + } + + return $debugInfo; + } + + public function __destruct() + { + foreach ($this->objects as $reference) { + if ($object = $reference->get()) { + unset($this[$object]); + } + } + } + + private function contains(object $offset): bool + { + $reference = $this->objects[spl_object_id($offset)] ?? null; + if ($reference && $reference->get() === $offset) { + return true; + } + + unset($this->objects[spl_object_id($offset)]); + + return false; + } + + private function expunge(): void + { + foreach ($this->objects as $id => $reference) { + if (!$reference->get()) { + unset($this->objects[$id]); + } + } + } +} diff --git a/vendor/open-telemetry/sdk/Common/Util/functions.php b/vendor/open-telemetry/sdk/Common/Util/functions.php new file mode 100644 index 000000000..f4fb13b80 --- /dev/null +++ b/vendor/open-telemetry/sdk/Common/Util/functions.php @@ -0,0 +1,52 @@ +getClosureThis()) { + return $closure; + } + + $scope = $reflection->getClosureScopeClass(); + $name = $reflection->getShortName(); + if ($name !== '{closure}') { + /** @psalm-suppress InvalidScope @phpstan-ignore-next-line @phan-suppress-next-line PhanUndeclaredThis */ + $closure = fn (...$args) => $this->$name(...$args); + if ($scope !== null) { + $closure = $closure->bindTo(null, $scope->name); + } + } + + static $placeholder; + $placeholder ??= new stdClass(); + $closure = $closure->bindTo($placeholder); + + $ref = WeakReference::create($target); + + /** @psalm-suppress PossiblyInvalidFunctionCall */ + return $scope && get_class($target) === $scope->name && !$scope->isInternal() + ? static fn (...$args) => ($obj = $ref->get()) ? $closure->call($obj, ...$args) : null + : static fn (...$args) => ($obj = $ref->get()) ? $closure->bindTo($obj)(...$args) : null; +} -- cgit v1.2.3