diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..621eaa5 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,81 @@ +name: CI + +on: + push: + branches: [ "*" ] + pull_request: + +permissions: + contents: read + +jobs: + tests: + name: Tests (PHP ${{ matrix.php }}) + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + php: [ '8.4', '8.5' ] + + steps: + - uses: actions/checkout@v4 + + - name: Set up PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php }} + extensions: sockets, apcu + ini-values: apc.enable_cli=1, error_reporting=-1 + coverage: xdebug + + - name: Install dependencies + uses: ramsey/composer-install@v3 + + - name: Run tests + run: vendor/bin/phpunit + + static-analysis: + name: Static analysis + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + + - name: Set up PHP + uses: shivammathur/setup-php@v2 + with: + php-version: '8.4' + extensions: sockets, apcu + coverage: none + + - name: Install dependencies + uses: ramsey/composer-install@v3 + + - name: Psalm + run: vendor/bin/psalm --output-format=github --no-cache + + coding-standards: + name: Coding standards + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + + - name: Set up PHP + uses: shivammathur/setup-php@v2 + with: + php-version: '8.4' + extensions: sockets, apcu + coverage: none + + - name: Install dependencies + uses: ramsey/composer-install@v3 + + - name: php-cs-fixer + run: vendor/bin/php-cs-fixer check --allow-risky=yes --using-cache=no --diff + + - name: Rector + run: vendor/bin/rector process --dry-run --clear-cache + + - name: Validate composer.json + run: composer validate --strict diff --git a/.gitignore b/.gitignore index 19c201d..e19c971 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,6 @@ /vendor/ composer.lock composer.phar +.php-cs-fixer.cache +/.phpunit.cache +/phpunit.xml diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php new file mode 100644 index 0000000..525c7ae --- /dev/null +++ b/.php-cs-fixer.dist.php @@ -0,0 +1,49 @@ +in([__DIR__ . '/src', __DIR__ . '/tests']) + // src/Thrift is generated by bin/thrift-gen.sh and must stay byte-for-byte reproducible from + // the IDL, so its shape is the thrift compiler's contract rather than ours. + ->exclude(['Thrift']) + ->append([__DIR__ . '/rector.php', __FILE__]); + +return new Config() + ->setFinder($finder) + ->setRiskyAllowed(true) + ->setParallelConfig(ParallelConfigFactory::detect()) + ->setRules([ + '@PER-CS2.0' => true, + '@PER-CS2.0:risky' => true, + '@PHP84Migration' => true, + '@PHPUnit100Migration:risky' => true, + 'declare_strict_types' => true, + 'strict_comparison' => true, + 'strict_param' => true, + 'yoda_style' => true, + 'native_function_invocation' => [ + 'include' => ['@compiler_optimized'], + 'scope' => 'namespaced', + 'strict' => true, + ], + 'global_namespace_import' => [ + 'import_classes' => true, + 'import_constants' => false, + 'import_functions' => false, + ], + 'ordered_imports' => ['sort_algorithm' => 'alpha'], + 'type_declaration_spaces' => true, + 'no_unused_imports' => true, + 'no_superfluous_phpdoc_tags' => true, + 'phpdoc_align' => false, + 'void_return' => true, + 'nullable_type_declaration_for_default_null_value' => true, + 'single_line_throw' => false, + 'concat_space' => ['spacing' => 'one'], + 'trailing_comma_in_multiline' => ['elements' => ['arrays', 'arguments', 'parameters']], + ]); diff --git a/bin/thrift-gen.sh b/bin/thrift-gen.sh index bbd9efc..a5395a6 100755 --- a/bin/thrift-gen.sh +++ b/bin/thrift-gen.sh @@ -1,20 +1,43 @@ -#!/bin/bash -set -e +#!/usr/bin/env bash +# +# Regenerates src/Thrift from the Jaeger IDL. +# +# The compiler version matters: 0.24 emits declare(strict_types=1) and native +# types, earlier releases emit untyped properties with @var docblocks only. +# +# brew install thrift +# +set -euo pipefail + +IDL_VERSION='v0.12.0' +THRIFT_MAJOR_MINOR='0.24' cd "$(dirname "$0")/.." +root="$(pwd)" + +if ! command -v thrift >/dev/null 2>&1; then + echo 'error: the thrift compiler is not installed (brew install thrift)' >&2 + exit 1 +fi + +thrift_version="$(thrift --version | awk '{print $NF}')" +if [[ "${thrift_version}" != "${THRIFT_MAJOR_MINOR}."* ]]; then + echo "error: thrift ${THRIFT_MAJOR_MINOR}.x is required, found ${thrift_version}" >&2 + exit 1 +fi -git clone https://github.com/jaegertracing/jaeger-idl -pushd jaeger-idl +workdir="$(mktemp -d)" +trap 'rm -rf "${workdir}"' EXIT -rm -rf ../src/Thrift +git clone --quiet --depth 1 --branch "${IDL_VERSION}" \ + https://github.com/jaegertracing/jaeger-idl.git "${workdir}/jaeger-idl" -FILES=thrift/*.thrift -for f in ${FILES}; do - thrift -r --gen php:psr4 ${f} +cd "${workdir}/jaeger-idl" +for definition in thrift/*.thrift; do + thrift -r --gen php "${definition}" done -rm -rf ../src/Jaeger/Thrift/ -mv ../jaeger-idl/gen-php/Jaeger/Thrift ../src/Thrift +rm -rf "${root}/src/Thrift" +mv gen-php/Jaeger/Thrift "${root}/src/Thrift" -popd -rm -rf jaeger-idl +echo "src/Thrift regenerated from jaeger-idl ${IDL_VERSION} using thrift ${thrift_version}" diff --git a/composer.json b/composer.json index 4a1851d..cfa801c 100644 --- a/composer.json +++ b/composer.json @@ -1,19 +1,36 @@ { "name": "code-tool/jaeger-client-php", + "description": "PHP OpenTracing client for Jaeger", "license": "MIT", - "autoload": { - "psr-4": { - "Jaeger\\": "src/" - } - }, + "type": "library", + "keywords": [ + "jaeger", + "opentracing", + "tracing", + "thrift" + ], "require": { - "php": ">=7.4", + "php": "^8.4", "ext-sockets": "*", - "apache/thrift": ">=0.11, <0.17" + "apache/thrift": "^0.24.0" }, "require-dev": { - "phpunit/phpunit": "@stable" + "friendsofphp/php-cs-fixer": "^3.95", + "phpunit/phpunit": "^13", + "rector/rector": "^2.6", + "vimeo/psalm": "^6" + }, + "suggest": { + "ext-apcu": "Required by RateLimitingSampler to share its rate counters between requests" }, - "minimum-stability": "dev", - "prefer-stable": true + "autoload": { + "psr-4": { + "Jaeger\\": "src/" + } + }, + "autoload-dev": { + "psr-4": { + "Jaeger\\Tests\\": "tests/" + } + } } diff --git a/phpunit.xml.dist b/phpunit.xml.dist new file mode 100644 index 0000000..187795f --- /dev/null +++ b/phpunit.xml.dist @@ -0,0 +1,32 @@ + + + + + + + + + + tests + + + + + + src + + + + src/Thrift + + + diff --git a/psalm.xml b/psalm.xml new file mode 100644 index 0000000..2d2ef17 --- /dev/null +++ b/psalm.xml @@ -0,0 +1,45 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/rector.php b/rector.php new file mode 100644 index 0000000..b3ef4b3 --- /dev/null +++ b/rector.php @@ -0,0 +1,28 @@ +withPaths([ + __DIR__ . '/src', + __DIR__ . '/tests', + __DIR__ . '/.php-cs-fixer.dist.php', + __FILE__, + ]) + // src/Thrift is generated by bin/thrift-gen.sh and must stay byte-for-byte reproducible from + // the IDL, so its shape is the thrift compiler's contract rather than ours. + ->withSkip([ + __DIR__ . '/src/Thrift', + ]) + ->withPhpSets(php84: true) + ->withPreparedSets( + deadCode: true, + codeQuality: true, + codingStyle: true, + typeDeclarations: true, + privatization: true, + earlyReturn: true, + ) + ->withImportNames(removeUnusedImports: true); diff --git a/src/Client/ClientInterface.php b/src/Client/ClientInterface.php index 956e6e4..c0f798c 100644 --- a/src/Client/ClientInterface.php +++ b/src/Client/ClientInterface.php @@ -1,4 +1,5 @@ + */ + private array $spans = []; - public function __construct(string $serviceName, AgentInterface $agent, $batch = self::MAX_BATCH_SIZE) - { - $this->serviceName = $serviceName; - $this->agent = $agent; - $this->batch = (int)$batch; - } + public function __construct( + private readonly string $serviceName, + private readonly AgentInterface $agent, + private readonly int $batch = self::MAX_BATCH_SIZE, + ) {} public function add(SpanInterface $span): ClientInterface { @@ -43,20 +40,15 @@ public function getSpans(): array public function flush(): ClientInterface { - switch (PHP_SAPI) { - case 'cli': - $process = new CliProcess($this->serviceName); - break; - case 'cli-server': - $process = new InternalServerProcess($this->serviceName); - break; - default: - $process = new FpmProcess($this->serviceName); - break; - } + $process = match (PHP_SAPI) { + 'cli' => new CliProcess($this->serviceName), + 'cli-server' => new InternalServerProcess($this->serviceName), + default => new FpmProcess($this->serviceName), + }; foreach (array_chunk($this->spans, $this->batch) as $batch) { $this->agent->emitBatch(new SpanBatch($process, $batch)); } + $this->spans = []; return $this; diff --git a/src/Codec/CodecInterface.php b/src/Codec/CodecInterface.php index ab7447d..4855d8b 100644 --- a/src/Codec/CodecInterface.php +++ b/src/Codec/CodecInterface.php @@ -1,4 +1,5 @@ + */ +class CodecRegistry implements ArrayAccess +{ /** - * @return bool + * @var array */ - #[\ReturnTypeWillChange] - public function offsetExists($offset) + private array $codecs = []; + + public function offsetExists(mixed $offset): bool { - return array_key_exists($offset, $this->codecs); + return \array_key_exists($offset, $this->codecs); } - /** - * @return mixed - */ - #[\ReturnTypeWillChange] - public function offsetGet($offset) + public function offsetGet(mixed $offset): ?CodecInterface { - if (false === array_key_exists($offset, $this->codecs)) { - return null; - } - - return $this->codecs[$offset]; + return $this->codecs[$offset] ?? null; } - /** - * @return $this - */ - #[\ReturnTypeWillChange] - public function offsetSet($offset, $value) + public function offsetSet(mixed $offset, mixed $value): void { - $this->codecs[$offset] = $value; + if (null === $offset) { + throw new InvalidArgumentException('A codec must be registered under a key, appending is not supported'); + } - return $this; + if (!$value instanceof CodecInterface) { + throw new InvalidArgumentException( + \sprintf('Codec must implement %s, %s given', CodecInterface::class, get_debug_type($value)), + ); + } + + $this->codecs[$offset] = $value; } - /** - * @return $this - */ - #[\ReturnTypeWillChange] - public function offsetUnset($offset) + public function offsetUnset(mixed $offset): void { - if (false === array_key_exists($offset, $this->codecs)) { - return $this; - } unset($this->codecs[$offset]); - - return $this; } } diff --git a/src/Codec/TextCodec.php b/src/Codec/TextCodec.php index f9b6b1d..730d248 100644 --- a/src/Codec/TextCodec.php +++ b/src/Codec/TextCodec.php @@ -1,21 +1,25 @@ convertInt128($elements[0]); return new SpanContext( @@ -23,20 +27,29 @@ public function decode($data): ?SpanContext $traceIdLow, $this->convertInt64($elements[1]), $this->convertInt64($elements[2]), - $this->convertInt64($elements[3]) + $this->convertInt64($elements[3]), ); } public function convertInt64(string $hex): int { - $hex8byte = \str_pad($hex, 16, '0', STR_PAD_LEFT); + $hex8byte = str_pad($hex, 16, '0', STR_PAD_LEFT); + $binary = pack('H*', $hex8byte); + $unpacked = unpack('Jint64', $binary); + + if (false === $unpacked) { + throw new InvalidArgumentException(\sprintf('Cannot unpack "%s" as a 64-bit integer', $hex)); + } - return \unpack('Jint64', pack('H*', $hex8byte))['int64']; + return (int) $unpacked['int64']; } + /** + * @return array{int, int} + */ public function convertInt128(string $hex): array { - $hex16byte = \str_pad($hex, 32, '0', STR_PAD_LEFT); + $hex16byte = str_pad($hex, 32, '0', STR_PAD_LEFT); return [ $this->convertInt64(substr($hex16byte, 0, 16)), @@ -52,7 +65,7 @@ public function encode(SpanContext $context): string $context->getTraceIdLow(), $context->getSpanId(), $context->getParentId(), - $context->getFlags() + $context->getFlags(), ); } } diff --git a/src/General/JaegerHostnameTag.php b/src/General/JaegerHostnameTag.php index 27e00f4..1d40f02 100644 --- a/src/General/JaegerHostnameTag.php +++ b/src/General/JaegerHostnameTag.php @@ -1,4 +1,5 @@ timestamp = 0 !== $timestamp ? $timestamp : (int)round(microtime(true) * 1000000); + /** + * @param list $tags + */ + public function __construct( + array $tags = [], + int $timestamp = 0, + ) { + $this->timestamp = 0 !== $timestamp ? $timestamp : (int) round(microtime(true) * 1000000.0); $this->fields = $tags; parent::__construct(); } diff --git a/src/Log/ErrorKindTag.php b/src/Log/ErrorKindTag.php index c346e14..0502cef 100644 --- a/src/Log/ErrorKindTag.php +++ b/src/Log/ErrorKindTag.php @@ -1,4 +1,5 @@ $tags + */ + public function __construct( + string $serviceName, + array $tags = [], + ) { $this->serviceName = $serviceName; $this->tags = array_merge( $tags, @@ -24,8 +31,8 @@ public function __construct(string $serviceName, array $tags = []) new ProcessPidTag(), new ProcessSapiTag(), new ProcessUidTag(), - new ProcessGidTag() - ] + new ProcessGidTag(), + ], ); parent::__construct(); } diff --git a/src/Process/CliProcess.php b/src/Process/CliProcess.php index 68f9cc2..6e33a10 100644 --- a/src/Process/CliProcess.php +++ b/src/Process/CliProcess.php @@ -1,6 +1,6 @@ getIp()); + parent::__construct( + 'ip', + $this->getIp(), + ); } } diff --git a/src/Process/ProcessPidTag.php b/src/Process/ProcessPidTag.php index 9deda12..6491f7b 100644 --- a/src/Process/ProcessPidTag.php +++ b/src/Process/ProcessPidTag.php @@ -1,4 +1,5 @@ rateLimit = $rateLimit; - $this->probabilistic = $probabilistic; - } + public function __construct( + private readonly SamplerInterface $rateLimit, + private readonly SamplerInterface $probabilistic, + ) {} - public function decide(int $tracerId, string $operationName, string $debugId): SamplerResult + public function decide(int $traceId, string $operationName, string $debugId): SamplerResult { - $rateLimitResult = $this->rateLimit->decide($tracerId, $operationName, $debugId); + $rateLimitResult = $this->rateLimit->decide($traceId, $operationName, $debugId); if ($rateLimitResult->isSampled()) { return new SamplerResult( true, $rateLimitResult->getFlags(), - array_merge([new SamplerTypeTag('adaptive'),], $rateLimitResult->getTags()) + array_merge([new SamplerTypeTag('adaptive'),], $rateLimitResult->getTags()), ); } - $probabilisticResult = $this->probabilistic->decide($tracerId, $operationName, $debugId); + $probabilisticResult = $this->probabilistic->decide($traceId, $operationName, $debugId); if ($probabilisticResult->isSampled()) { return new SamplerResult( true, $rateLimitResult->getFlags(), - array_merge([new SamplerTypeTag('adaptive'),], $rateLimitResult->getTags()) + array_merge([new SamplerTypeTag('adaptive'),], $rateLimitResult->getTags()), ); } @@ -42,7 +38,7 @@ public function decide(int $tracerId, string $operationName, string $debugId): S new SamplerTypeTag('adaptive'), new SamplerDecisionTag(false), new SamplerFlagsTag(0x00), - ] + ], ); } } diff --git a/src/Sampler/ConstGenerator.php b/src/Sampler/ConstGenerator.php index 88837e6..711476f 100644 --- a/src/Sampler/ConstGenerator.php +++ b/src/Sampler/ConstGenerator.php @@ -1,4 +1,5 @@ debugEnabled = (bool)$debugEnabled; - } + public function __construct(private readonly bool $debugEnabled) {} public function doDecide(int $tracerId, string $operationName): SamplerResult { @@ -23,7 +19,7 @@ public function doDecide(int $tracerId, string $operationName): SamplerResult new SamplerParamTag('False'), new SamplerDecisionTag(false), new SamplerFlagsTag(0x00), - ] + ], ); } @@ -35,7 +31,7 @@ public function doDecide(int $tracerId, string $operationName): SamplerResult new SamplerParamTag('True'), new SamplerDecisionTag(true), new SamplerFlagsTag(0x01), - ] + ], ); } } diff --git a/src/Sampler/GeneratorInterface.php b/src/Sampler/GeneratorInterface.php index 16cfd0f..3bff682 100644 --- a/src/Sampler/GeneratorInterface.php +++ b/src/Sampler/GeneratorInterface.php @@ -1,9 +1,10 @@ rate = $rate; - $this->threshold = 0.5 * $rate * PHP_INT_MAX; + $this->threshold = 0.5 * $this->rate * (float) PHP_INT_MAX; } public function doDecide(int $tracerId, string $operationName): SamplerResult @@ -23,10 +21,10 @@ public function doDecide(int $tracerId, string $operationName): SamplerResult 0x00, [ new SamplerTypeTag('probabilistic'), - new SamplerParamTag((string)$this->rate), + new SamplerParamTag((string) $this->rate), new SamplerDecisionTag(false), new SamplerFlagsTag(0x00), - ] + ], ); } @@ -37,8 +35,8 @@ public function doDecide(int $tracerId, string $operationName): SamplerResult new SamplerTypeTag('probabilistic'), new SamplerDecisionTag(true), new SamplerFlagsTag(0x01), - new SamplerParamTag((string)$this->rate) - ] + new SamplerParamTag((string) $this->rate), + ], ); } } diff --git a/src/Sampler/RateLimitingSampler.php b/src/Sampler/RateLimitingSampler.php index cb787cb..8bdf138 100644 --- a/src/Sampler/RateLimitingSampler.php +++ b/src/Sampler/RateLimitingSampler.php @@ -1,26 +1,25 @@ rate = $rate; - $this->generator = $generator; - } - - public function value(int $sec, int $count) + public function value(int $sec, int $count): int { return (($sec & 0xffffffff) << 16) + ($count & 0xffff); } - public function spec(int $value) + /** + * @return array{int, int} + */ + public function spec(int $value): array { return [$value >> 16, $value & 0xffff]; } @@ -28,42 +27,50 @@ public function spec(int $value) public function doDecide(int $tracerId, string $operationName): SamplerResult { $key = $this->generator->generate($tracerId, $operationName); - $ttl = max((int)(1 / $this->rate + 1), 1); + $ttl = max((int) (1.0 / $this->rate + 1.0), 1); if (apcu_add($key, $this->value(time(), 1), $ttl)) { return new SamplerResult( - true, 0x01, [ - new SamplerTypeTag('ratelimiting'), - new SamplerDecisionTag(true), - new SamplerFlagsTag(0x01), - new SamplerParamTag((string)$this->rate) - ] + true, + 0x01, + [ + new SamplerTypeTag('ratelimiting'), + new SamplerDecisionTag(true), + new SamplerFlagsTag(0x01), + new SamplerParamTag((string) $this->rate), + ], ); } $retries = 0; while ($retries < 5) { - if (false === ($current = apcu_fetch($key))) { + /** @var int|false $current */ + $current = apcu_fetch($key); + if (false === $current) { return $this->doDecide($tracerId, $operationName); } - list ($timestamp, $count) = $this->spec((int)$current); + + [$timestamp, $count] = $this->spec($current); $now = time(); $diff = ($now === $timestamp) ? 1 : $now - $timestamp; - if ($this->rate * $diff <= $count) { + if ($this->rate * (float) $diff <= (float) $count) { return new SamplerResult(false, 0); } - if (false === apcu_cas($key, (int)$current, $this->value($timestamp, $count + 1))) { + + if (false === apcu_cas($key, $current, $this->value($timestamp, $count + 1))) { $retries++; continue; } return new SamplerResult( - true, 0x01, [ - new SamplerTypeTag('ratelimiting'), - new SamplerDecisionTag(true), - new SamplerFlagsTag(0x01), - new SamplerParamTag($key), - new SamplerParamTag((string)$this->rate) - ] + true, + 0x01, + [ + new SamplerTypeTag('ratelimiting'), + new SamplerDecisionTag(true), + new SamplerFlagsTag(0x01), + new SamplerParamTag($key), + new SamplerParamTag((string) $this->rate), + ], ); } diff --git a/src/Sampler/SamplerDecisionTag.php b/src/Sampler/SamplerDecisionTag.php index 9b178fb..fb27158 100644 --- a/src/Sampler/SamplerDecisionTag.php +++ b/src/Sampler/SamplerDecisionTag.php @@ -1,4 +1,5 @@ sampled = $sampled; - $this->flags = $flags; - $this->tags = $tags; - } + /** + * @param array $tags + */ + public function __construct( + private readonly bool $sampled, + private readonly int $flags, + private readonly array $tags = [], + ) {} public function getFlags(): int { @@ -28,6 +27,9 @@ public function isSampled(): bool return $this->sampled; } + /** + * @return array + */ public function getTags(): array { return $this->tags; diff --git a/src/Sampler/SamplerTypeTag.php b/src/Sampler/SamplerTypeTag.php index 267a498..f20ce3e 100644 --- a/src/Sampler/SamplerTypeTag.php +++ b/src/Sampler/SamplerTypeTag.php @@ -1,4 +1,5 @@ $spans + * + * SpanInterface cannot declare that it extends the generated \Jaeger\Thrift\Span, even though + * its only implementation does, so this assignment has to be taken on trust. + * + * @psalm-suppress InvalidPropertyAssignmentValue + */ + public function __construct( + AbstractProcess $process, + array $spans = [], + ) { $this->process = $process; $this->spans = $spans; parent::__construct(); diff --git a/src/Span/Context/ContextAwareInterface.php b/src/Span/Context/ContextAwareInterface.php index e81690c..53be7c7 100644 --- a/src/Span/Context/ContextAwareInterface.php +++ b/src/Span/Context/ContextAwareInterface.php @@ -1,4 +1,5 @@ + */ +class SpanContext implements IteratorAggregate +{ + /** + * @param array $baggage + */ public function __construct( - int $traceIdHigh, - int $traceIdLow, - int $spanId, - int $parentId, - int $flags = 0, - array $baggage = [] - ) { - $this->traceIdHigh = $traceIdHigh; - $this->traceIdLow = $traceIdLow; - $this->spanId = $spanId; - $this->parentId = $parentId; - $this->flags = $flags; - $this->baggage = $baggage; - } + private int $traceIdHigh, + private int $traceIdLow, + private int $spanId, + private int $parentId, + private int $flags = 0, + private array $baggage = [], + ) {} public function getTraceId(): int { @@ -60,12 +52,12 @@ public function getParentId(): int public function isSampled(): bool { - return (bool)($this->flags & 0x01); + return (bool) ($this->flags & 0x01); } public function isDebug(): bool { - return (bool)($this->flags & 0x02); + return (bool) ($this->flags & 0x02); } public function getFlags(): int @@ -73,21 +65,23 @@ public function getFlags(): int return $this->flags; } + /** + * @return array + */ public function getBaggage(): array { return $this->baggage; } /** - * @return \Traversable + * @return Traversable */ - #[\ReturnTypeWillChange] - public function getIterator() + public function getIterator(): Traversable { - return new \ArrayIterator($this->baggage); + return new ArrayIterator($this->baggage); } - public function withItem(string $key, $item) + public function withItem(string $key, mixed $item): static { $copy = clone $this; $copy->baggage[$key] = $item; @@ -95,16 +89,16 @@ public function withItem(string $key, $item) return $copy; } - public function getItem(string $key, $default = null) + public function getItem(string $key, mixed $default = null): mixed { - if (false === array_key_exists($key, $this->baggage)) { + if (false === \array_key_exists($key, $this->baggage)) { return $default; } return $this->baggage[$key]; } - public function withoutItem(string $key) + public function withoutItem(string $key): static { $copy = clone $this; unset($copy->baggage[$key]); diff --git a/src/Span/Factory/SpanFactory.php b/src/Span/Factory/SpanFactory.php index 97e79f7..cafad3a 100644 --- a/src/Span/Factory/SpanFactory.php +++ b/src/Span/Factory/SpanFactory.php @@ -1,4 +1,5 @@ idGenerator = $idGenerator; - $this->sampler = $sampler; - $this->trace128 = $trace128; - } + public function __construct( + private readonly IdGeneratorInterface $idGenerator, + private readonly SamplerInterface $sampler, + private readonly bool $trace128 = false, + ) {} + /** + * @param array $tags + * @param array $logs + */ public function parent( TracerInterface $tracer, - string $operationName, - string $debugId, - array $tags = [], - array $logs = [] + string $operationName, + string $debugId, + array $tags = [], + array $logs = [], ): SpanInterface { $spanId = $this->idGenerator->next(); $traceId = $spanId; @@ -43,21 +43,25 @@ public function parent( $this->idGenerator->next(), $this->idGenerator->next(), 0, - (int)$samplerResult->getFlags() + $samplerResult->getFlags(), ), $operationName, - (int)(microtime(true) * 1000000), + (int) (microtime(true) * 1000000.0), array_merge($tags, $samplerResult->getTags()), - $logs + $logs, ); } + /** + * @param array $tags + * @param array $logs + */ public function child( TracerInterface $tracer, - string $operationName, - SpanContext $parentContext, - array $tags = [], - array $logs = [] + string $operationName, + SpanContext $parentContext, + array $tags = [], + array $logs = [], ): SpanInterface { return new Span( $tracer, @@ -67,12 +71,12 @@ public function child( $this->idGenerator->next(), $parentContext->getSpanId(), $parentContext->getFlags(), - $parentContext->getBaggage() + $parentContext->getBaggage(), ), $operationName, - (int)(microtime(true) * 1000000), + (int) (microtime(true) * 1000000.0), $tags, - $logs + $logs, ); } } diff --git a/src/Span/Factory/SpanFactoryInterface.php b/src/Span/Factory/SpanFactoryInterface.php index 0ee7564..0a1d36d 100644 --- a/src/Span/Factory/SpanFactoryInterface.php +++ b/src/Span/Factory/SpanFactoryInterface.php @@ -1,27 +1,38 @@ $tags + * @param array $logs + */ public function parent( TracerInterface $tracer, string $operationName, string $debugId, array $tags = [], - array $logs = [] + array $logs = [], ): SpanInterface; + /** + * @param array $tags + * @param array $logs + */ public function child( TracerInterface $tracer, string $operationName, SpanContext $parentContext, array $tags = [], - array $logs = [] + array $logs = [], ): SpanInterface; } diff --git a/src/Span/Options.php b/src/Span/Options.php index 8d99734..5e73d9c 100644 --- a/src/Span/Options.php +++ b/src/Span/Options.php @@ -1,9 +1,7 @@ $tags + * @param array $logs + */ public function __construct( - FinishableInterface $tracer, - SpanContext $context, - string $operationName, - int $startTime, - array $tags = [], - array $logs = [] + private readonly FinishableInterface $tracer, + private SpanContext $context, + string $operationName, + int $startTime, + array $tags = [], + array $logs = [], ) { - $this->tracer = $tracer; - $this->context = $context; - $this->traceIdLow = $context->getTraceIdLow(); - $this->traceIdHigh = $context->getTraceIdHigh(); - $this->spanId = $context->getSpanId(); - $this->parentSpanId = $context->getParentId(); - $this->flags = $context->getFlags(); + $this->traceIdLow = $this->context->getTraceIdLow(); + $this->traceIdHigh = $this->context->getTraceIdHigh(); + $this->spanId = $this->context->getSpanId(); + $this->parentSpanId = $this->context->getParentId(); + $this->flags = $this->context->getFlags(); $this->operationName = $operationName; $this->startTime = $startTime; $this->tags = $tags; @@ -43,6 +42,7 @@ public function __destruct() if (null !== $this->duration) { return; } + $this->tags[] = new ErrorTag(); $this->tags[] = new OutOfScopeTag(); $this->tracer->finish($this); @@ -67,7 +67,9 @@ public function start(int $startTimeUsec): SpanInterface public function finish(int $durationUsec = 0): SpanInterface { - $this->duration = $durationUsec ?: (microtime(true) * 1000000) - $this->startTime; + $this->duration = 0 !== $durationUsec + ? $durationUsec + : (int) (microtime(true) * 1000000.0) - (int) $this->startTime; $this->tracer->finish($this, -1); return $this; @@ -87,14 +89,14 @@ public function addLog(Log $log): SpanInterface return $this; } - public function withItem(string $key, $item): SpanInterface + public function withItem(string $key, mixed $item): SpanInterface { $this->context = $this->context->withItem($key, $item); return $this; } - public function getItem(string $key, $default = null) + public function getItem(string $key, mixed $default = null): mixed { return $this->context->getItem($key, $default); } diff --git a/src/Span/SpanAwareInterface.php b/src/Span/SpanAwareInterface.php index 39325fb..2a782a1 100644 --- a/src/Span/SpanAwareInterface.php +++ b/src/Span/SpanAwareInterface.php @@ -1,4 +1,5 @@ + */ + private SplStack $stack; - /** @var SpanContext|null */ - private $context; + private ?SpanContext $context = null; public function __construct() { - $this->stack = new \SplStack(); + $this->stack = $this->createStack(); } /** @@ -24,27 +28,25 @@ public function __construct() */ public function reset(): ResettableInterface { - $this->stack = new \SplStack(); + $this->stack = $this->createStack(); $this->context = null; return $this; } /** - * @param SpanContext $context * * @return self */ public function assign(SpanContext $context): InjectableInterface { $this->context = $context; - $this->stack = new \SplStack(); + $this->stack = $this->createStack(); return $this; } /** - * @param SpanContext $context * * @return self */ @@ -55,6 +57,7 @@ public function remove(SpanContext $context): InjectableInterface $this->stack->pop(); continue; } + break; } @@ -78,6 +81,17 @@ public function finish(SpanInterface $span): ?SpanInterface public function getContext(): ?SpanContext { - return ($span = $this->getSpan()) ? $span->getContext() : $this->context; + return (($span = $this->getSpan()) instanceof SpanInterface) ? $span->getContext() : $this->context; + } + + /** + * @return SplStack + */ + private function createStack(): SplStack + { + /** @var SplStack $stack */ + $stack = new SplStack(); + + return $stack; } } diff --git a/src/Tag/AbstractSpanKindTag.php b/src/Tag/AbstractSpanKindTag.php index ad1c54a..d81d08d 100644 --- a/src/Tag/AbstractSpanKindTag.php +++ b/src/Tag/AbstractSpanKindTag.php @@ -1,4 +1,5 @@ key = $key; $this->vType = $type; diff --git a/src/Tag/BinaryTag.php b/src/Tag/BinaryTag.php index 035a8b6..71ad6c1 100644 --- a/src/Tag/BinaryTag.php +++ b/src/Tag/BinaryTag.php @@ -1,4 +1,5 @@ input_ = $input; - $this->output_ = $output ? $output : $input; + $this->input = $input; + $this->output = $output ? $output : $input; } - public function emitZipkinBatch(array $spans) + public function emitZipkinBatch(?array $spans): void { $this->send_emitZipkinBatch($spans); } - public function send_emitZipkinBatch(array $spans) + public function send_emitZipkinBatch(?array $spans): void { $args = new \Jaeger\Thrift\Agent\Agent_emitZipkinBatch_args(); $args->spans = $spans; - $bin_accel = ($this->output_ instanceof TBinaryProtocolAccelerated) && function_exists('thrift_protocol_write_binary'); + $bin_accel = ($this->output instanceof TBinaryProtocolAccelerated) && function_exists('thrift_protocol_write_binary'); if ($bin_accel) { thrift_protocol_write_binary( - $this->output_, + $this->output, 'emitZipkinBatch', TMessageType::ONEWAY, $args, - $this->seqid_, - $this->output_->isStrictWrite() + $this->seqid, + $this->output->isStrictWrite() ); } else { - $this->output_->writeMessageBegin('emitZipkinBatch', TMessageType::ONEWAY, $this->seqid_); - $args->write($this->output_); - $this->output_->writeMessageEnd(); - $this->output_->getTransport()->flush(); + $this->output->writeMessageBegin('emitZipkinBatch', TMessageType::ONEWAY, $this->seqid); + $args->write($this->output); + $this->output->writeMessageEnd(); + $this->output->getTransport()->flush(); } } - public function emitBatch(\Jaeger\Thrift\Batch $batch) + public function emitBatch(?\Jaeger\Thrift\Batch $batch): void { $this->send_emitBatch($batch); } - public function send_emitBatch(\Jaeger\Thrift\Batch $batch) + public function send_emitBatch(?\Jaeger\Thrift\Batch $batch): void { $args = new \Jaeger\Thrift\Agent\Agent_emitBatch_args(); $args->batch = $batch; - $bin_accel = ($this->output_ instanceof TBinaryProtocolAccelerated) && function_exists('thrift_protocol_write_binary'); + $bin_accel = ($this->output instanceof TBinaryProtocolAccelerated) && function_exists('thrift_protocol_write_binary'); if ($bin_accel) { thrift_protocol_write_binary( - $this->output_, + $this->output, 'emitBatch', TMessageType::ONEWAY, $args, - $this->seqid_, - $this->output_->isStrictWrite() + $this->seqid, + $this->output->isStrictWrite() ); } else { - $this->output_->writeMessageBegin('emitBatch', TMessageType::ONEWAY, $this->seqid_); - $args->write($this->output_); - $this->output_->writeMessageEnd(); - $this->output_->getTransport()->flush(); + $this->output->writeMessageBegin('emitBatch', TMessageType::ONEWAY, $this->seqid); + $args->write($this->output); + $this->output->writeMessageEnd(); + $this->output->getTransport()->flush(); } } } diff --git a/src/Thrift/Agent/AgentIf.php b/src/Thrift/Agent/AgentIf.php index 55f7571..a316904 100644 --- a/src/Thrift/Agent/AgentIf.php +++ b/src/Thrift/Agent/AgentIf.php @@ -1,18 +1,23 @@ array( + public static array $tspec = [ + 1 => [ 'var' => 'batch', 'isRequired' => false, 'type' => TType::STRUCT, 'class' => '\Jaeger\Thrift\Batch', - ), - ); + ], + ]; - /** - * @var \Jaeger\Thrift\Batch - */ - public $batch = null; + public ?\Jaeger\Thrift\Batch $batch = null; - public function __construct($vals = null) + public function __construct(?array $vals = null) { if (is_array($vals)) { if (isset($vals['batch'])) { @@ -43,57 +47,68 @@ public function __construct($vals = null) } } - public function getName() + public function getName(): string { return 'Agent_emitBatch_args'; } - - public function read($input) + public function read(TProtocol $input): int { $xfer = 0; $fname = null; $ftype = 0; $fid = 0; - $xfer += $input->readStructBegin($fname); - while (true) { - $xfer += $input->readFieldBegin($fname, $ftype, $fid); - if ($ftype == TType::STOP) { - break; - } - switch ($fid) { - case 1: - if ($ftype == TType::STRUCT) { - $this->batch = new \Jaeger\Thrift\Batch(); - $xfer += $this->batch->read($input); - } else { - $xfer += $input->skip($ftype); - } - break; - default: - $xfer += $input->skip($ftype); + $input->incrementRecursionDepth(); + try { + $xfer += $input->readStructBegin($fname); + while (true) { + $xfer += $input->readFieldBegin($fname, $ftype, $fid); + if ($ftype == TType::STOP) { break; + } + switch ($fid) { + case 1: + if ($ftype == TType::STRUCT) { + $this->batch = new \Jaeger\Thrift\Batch(); + $xfer += $this->batch->read($input); + } else { + $xfer += $input->skip($ftype); + } + break; + default: + $xfer += $input->skip($ftype); + break; + } + $xfer += $input->readFieldEnd(); } - $xfer += $input->readFieldEnd(); + $xfer += $input->readStructEnd(); + } finally { + $input->decrementRecursionDepth(); } - $xfer += $input->readStructEnd(); + return $xfer; } - public function write($output) + public function write(TProtocol $output): int { $xfer = 0; - $xfer += $output->writeStructBegin('Agent_emitBatch_args'); - if ($this->batch !== null) { - if (!is_object($this->batch)) { - throw new TProtocolException('Bad type in structure.', TProtocolException::INVALID_DATA); + $output->incrementRecursionDepth(); + try { + $xfer += $output->writeStructBegin('Agent_emitBatch_args'); + if ($this->batch !== null) { + if (!is_object($this->batch)) { + throw new TProtocolException('Bad type in structure.', TProtocolException::INVALID_DATA); + } + $xfer += $output->writeFieldBegin('batch', TType::STRUCT, 1); + $xfer += $this->batch->write($output); + $xfer += $output->writeFieldEnd(); } - $xfer += $output->writeFieldBegin('batch', TType::STRUCT, 1); - $xfer += $this->batch->write($output); - $xfer += $output->writeFieldEnd(); + $xfer += $output->writeFieldStop(); + $xfer += $output->writeStructEnd(); + } finally { + $output->decrementRecursionDepth(); } - $xfer += $output->writeFieldStop(); - $xfer += $output->writeStructEnd(); + return $xfer; } } diff --git a/src/Thrift/Agent/Agent_emitZipkinBatch_args.php b/src/Thrift/Agent/Agent_emitZipkinBatch_args.php index f2245d5..31e28ba 100644 --- a/src/Thrift/Agent/Agent_emitZipkinBatch_args.php +++ b/src/Thrift/Agent/Agent_emitZipkinBatch_args.php @@ -1,44 +1,51 @@ array( + public static array $tspec = [ + 1 => [ 'var' => 'spans', 'isRequired' => false, 'type' => TType::LST, 'etype' => TType::STRUCT, - 'elem' => array( + 'elem' => [ 'type' => TType::STRUCT, 'class' => '\Jaeger\Thrift\Agent\Zipkin\Span', - ), - ), - ); + ], + ], + ]; /** * @var \Jaeger\Thrift\Agent\Zipkin\Span[] */ - public $spans = null; + public ?array $spans = null; - public function __construct($vals = null) + public function __construct(?array $vals = null) { if (is_array($vals)) { if (isset($vals['spans'])) { @@ -47,70 +54,81 @@ public function __construct($vals = null) } } - public function getName() + public function getName(): string { return 'Agent_emitZipkinBatch_args'; } - - public function read($input) + public function read(TProtocol $input): int { $xfer = 0; $fname = null; $ftype = 0; $fid = 0; - $xfer += $input->readStructBegin($fname); - while (true) { - $xfer += $input->readFieldBegin($fname, $ftype, $fid); - if ($ftype == TType::STOP) { - break; - } - switch ($fid) { - case 1: - if ($ftype == TType::LST) { - $this->spans = array(); - $_size0 = 0; - $_etype3 = 0; - $xfer += $input->readListBegin($_etype3, $_size0); - for ($_i4 = 0; $_i4 < $_size0; ++$_i4) { - $elem5 = null; - $elem5 = new \Jaeger\Thrift\Agent\Zipkin\Span(); - $xfer += $elem5->read($input); - $this->spans []= $elem5; + $input->incrementRecursionDepth(); + try { + $xfer += $input->readStructBegin($fname); + while (true) { + $xfer += $input->readFieldBegin($fname, $ftype, $fid); + if ($ftype == TType::STOP) { + break; + } + switch ($fid) { + case 1: + if ($ftype == TType::LST) { + $this->spans = []; + $_size0 = 0; + $_etype3 = 0; + $xfer += $input->readListBegin($_etype3, $_size0); + for ($_i4 = 0; $_i4 < $_size0; ++$_i4) { + $elem5 = null; + $elem5 = new \Jaeger\Thrift\Agent\Zipkin\Span(); + $xfer += $elem5->read($input); + $this->spans[] = $elem5; + } + $xfer += $input->readListEnd(); + } else { + $xfer += $input->skip($ftype); } - $xfer += $input->readListEnd(); - } else { + break; + default: $xfer += $input->skip($ftype); - } - break; - default: - $xfer += $input->skip($ftype); - break; + break; + } + $xfer += $input->readFieldEnd(); } - $xfer += $input->readFieldEnd(); + $xfer += $input->readStructEnd(); + } finally { + $input->decrementRecursionDepth(); } - $xfer += $input->readStructEnd(); + return $xfer; } - public function write($output) + public function write(TProtocol $output): int { $xfer = 0; - $xfer += $output->writeStructBegin('Agent_emitZipkinBatch_args'); - if ($this->spans !== null) { - if (!is_array($this->spans)) { - throw new TProtocolException('Bad type in structure.', TProtocolException::INVALID_DATA); - } - $xfer += $output->writeFieldBegin('spans', TType::LST, 1); - $output->writeListBegin(TType::STRUCT, count($this->spans)); - foreach ($this->spans as $iter6) { - $xfer += $iter6->write($output); + $output->incrementRecursionDepth(); + try { + $xfer += $output->writeStructBegin('Agent_emitZipkinBatch_args'); + if ($this->spans !== null) { + if (!is_array($this->spans)) { + throw new TProtocolException('Bad type in structure.', TProtocolException::INVALID_DATA); + } + $xfer += $output->writeFieldBegin('spans', TType::LST, 1); + $output->writeListBegin(TType::STRUCT, count($this->spans)); + foreach ($this->spans as $iter6) { + $xfer += $iter6->write($output); + } + $output->writeListEnd(); + $xfer += $output->writeFieldEnd(); } - $output->writeListEnd(); - $xfer += $output->writeFieldEnd(); + $xfer += $output->writeFieldStop(); + $xfer += $output->writeStructEnd(); + } finally { + $output->decrementRecursionDepth(); } - $xfer += $output->writeFieldStop(); - $xfer += $output->writeStructEnd(); + return $xfer; } } diff --git a/src/Thrift/Agent/AggregationValidatorClient.php b/src/Thrift/Agent/AggregationValidatorClient.php deleted file mode 100644 index 7b149a6..0000000 --- a/src/Thrift/Agent/AggregationValidatorClient.php +++ /dev/null @@ -1,91 +0,0 @@ -input_ = $input; - $this->output_ = $output ? $output : $input; - } - - - public function validateTrace($traceId) - { - $this->send_validateTrace($traceId); - return $this->recv_validateTrace(); - } - - public function send_validateTrace($traceId) - { - $args = new \Jaeger\Thrift\Agent\AggregationValidator_validateTrace_args(); - $args->traceId = $traceId; - $bin_accel = ($this->output_ instanceof TBinaryProtocolAccelerated) && function_exists('thrift_protocol_write_binary'); - if ($bin_accel) { - thrift_protocol_write_binary( - $this->output_, - 'validateTrace', - TMessageType::CALL, - $args, - $this->seqid_, - $this->output_->isStrictWrite() - ); - } else { - $this->output_->writeMessageBegin('validateTrace', TMessageType::CALL, $this->seqid_); - $args->write($this->output_); - $this->output_->writeMessageEnd(); - $this->output_->getTransport()->flush(); - } - } - - public function recv_validateTrace() - { - $bin_accel = ($this->input_ instanceof TBinaryProtocolAccelerated) && function_exists('thrift_protocol_read_binary'); - if ($bin_accel) { - $result = thrift_protocol_read_binary( - $this->input_, - '\Jaeger\Thrift\Agent\AggregationValidator_validateTrace_result', - $this->input_->isStrictRead() - ); - } else { - $rseqid = 0; - $fname = null; - $mtype = 0; - - $this->input_->readMessageBegin($fname, $mtype, $rseqid); - if ($mtype == TMessageType::EXCEPTION) { - $x = new TApplicationException(); - $x->read($this->input_); - $this->input_->readMessageEnd(); - throw $x; - } - $result = new \Jaeger\Thrift\Agent\AggregationValidator_validateTrace_result(); - $result->read($this->input_); - $this->input_->readMessageEnd(); - } - if ($result->success !== null) { - return $result->success; - } - throw new \Exception("validateTrace failed: unknown result"); - } -} diff --git a/src/Thrift/Agent/AggregationValidatorIf.php b/src/Thrift/Agent/AggregationValidatorIf.php deleted file mode 100644 index b336c62..0000000 --- a/src/Thrift/Agent/AggregationValidatorIf.php +++ /dev/null @@ -1,26 +0,0 @@ - array( - 'var' => 'traceId', - 'isRequired' => true, - 'type' => TType::STRING, - ), - ); - - /** - * @var string - */ - public $traceId = null; - - public function __construct($vals = null) - { - if (is_array($vals)) { - if (isset($vals['traceId'])) { - $this->traceId = $vals['traceId']; - } - } - } - - public function getName() - { - return 'AggregationValidator_validateTrace_args'; - } - - - public function read($input) - { - $xfer = 0; - $fname = null; - $ftype = 0; - $fid = 0; - $xfer += $input->readStructBegin($fname); - while (true) { - $xfer += $input->readFieldBegin($fname, $ftype, $fid); - if ($ftype == TType::STOP) { - break; - } - switch ($fid) { - case 1: - if ($ftype == TType::STRING) { - $xfer += $input->readString($this->traceId); - } else { - $xfer += $input->skip($ftype); - } - break; - default: - $xfer += $input->skip($ftype); - break; - } - $xfer += $input->readFieldEnd(); - } - $xfer += $input->readStructEnd(); - return $xfer; - } - - public function write($output) - { - $xfer = 0; - $xfer += $output->writeStructBegin('AggregationValidator_validateTrace_args'); - if ($this->traceId !== null) { - $xfer += $output->writeFieldBegin('traceId', TType::STRING, 1); - $xfer += $output->writeString($this->traceId); - $xfer += $output->writeFieldEnd(); - } - $xfer += $output->writeFieldStop(); - $xfer += $output->writeStructEnd(); - return $xfer; - } -} diff --git a/src/Thrift/Agent/AggregationValidator_validateTrace_result.php b/src/Thrift/Agent/AggregationValidator_validateTrace_result.php deleted file mode 100644 index 1900c0f..0000000 --- a/src/Thrift/Agent/AggregationValidator_validateTrace_result.php +++ /dev/null @@ -1,99 +0,0 @@ - array( - 'var' => 'success', - 'isRequired' => false, - 'type' => TType::STRUCT, - 'class' => '\Jaeger\Thrift\Agent\ValidateTraceResponse', - ), - ); - - /** - * @var \Jaeger\Thrift\Agent\ValidateTraceResponse - */ - public $success = null; - - public function __construct($vals = null) - { - if (is_array($vals)) { - if (isset($vals['success'])) { - $this->success = $vals['success']; - } - } - } - - public function getName() - { - return 'AggregationValidator_validateTrace_result'; - } - - - public function read($input) - { - $xfer = 0; - $fname = null; - $ftype = 0; - $fid = 0; - $xfer += $input->readStructBegin($fname); - while (true) { - $xfer += $input->readFieldBegin($fname, $ftype, $fid); - if ($ftype == TType::STOP) { - break; - } - switch ($fid) { - case 0: - if ($ftype == TType::STRUCT) { - $this->success = new \Jaeger\Thrift\Agent\ValidateTraceResponse(); - $xfer += $this->success->read($input); - } else { - $xfer += $input->skip($ftype); - } - break; - default: - $xfer += $input->skip($ftype); - break; - } - $xfer += $input->readFieldEnd(); - } - $xfer += $input->readStructEnd(); - return $xfer; - } - - public function write($output) - { - $xfer = 0; - $xfer += $output->writeStructBegin('AggregationValidator_validateTrace_result'); - if ($this->success !== null) { - if (!is_object($this->success)) { - throw new TProtocolException('Bad type in structure.', TProtocolException::INVALID_DATA); - } - $xfer += $output->writeFieldBegin('success', TType::STRUCT, 0); - $xfer += $this->success->write($output); - $xfer += $output->writeFieldEnd(); - } - $xfer += $output->writeFieldStop(); - $xfer += $output->writeStructEnd(); - return $xfer; - } -} diff --git a/src/Thrift/Agent/BaggageRestriction.php b/src/Thrift/Agent/BaggageRestriction.php deleted file mode 100644 index b66ab4f..0000000 --- a/src/Thrift/Agent/BaggageRestriction.php +++ /dev/null @@ -1,118 +0,0 @@ - array( - 'var' => 'baggageKey', - 'isRequired' => true, - 'type' => TType::STRING, - ), - 2 => array( - 'var' => 'maxValueLength', - 'isRequired' => true, - 'type' => TType::I32, - ), - ); - - /** - * @var string - */ - public $baggageKey = null; - /** - * @var int - */ - public $maxValueLength = null; - - public function __construct($vals = null) - { - if (is_array($vals)) { - if (isset($vals['baggageKey'])) { - $this->baggageKey = $vals['baggageKey']; - } - if (isset($vals['maxValueLength'])) { - $this->maxValueLength = $vals['maxValueLength']; - } - } - } - - public function getName() - { - return 'BaggageRestriction'; - } - - - public function read($input) - { - $xfer = 0; - $fname = null; - $ftype = 0; - $fid = 0; - $xfer += $input->readStructBegin($fname); - while (true) { - $xfer += $input->readFieldBegin($fname, $ftype, $fid); - if ($ftype == TType::STOP) { - break; - } - switch ($fid) { - case 1: - if ($ftype == TType::STRING) { - $xfer += $input->readString($this->baggageKey); - } else { - $xfer += $input->skip($ftype); - } - break; - case 2: - if ($ftype == TType::I32) { - $xfer += $input->readI32($this->maxValueLength); - } else { - $xfer += $input->skip($ftype); - } - break; - default: - $xfer += $input->skip($ftype); - break; - } - $xfer += $input->readFieldEnd(); - } - $xfer += $input->readStructEnd(); - return $xfer; - } - - public function write($output) - { - $xfer = 0; - $xfer += $output->writeStructBegin('BaggageRestriction'); - if ($this->baggageKey !== null) { - $xfer += $output->writeFieldBegin('baggageKey', TType::STRING, 1); - $xfer += $output->writeString($this->baggageKey); - $xfer += $output->writeFieldEnd(); - } - if ($this->maxValueLength !== null) { - $xfer += $output->writeFieldBegin('maxValueLength', TType::I32, 2); - $xfer += $output->writeI32($this->maxValueLength); - $xfer += $output->writeFieldEnd(); - } - $xfer += $output->writeFieldStop(); - $xfer += $output->writeStructEnd(); - return $xfer; - } -} diff --git a/src/Thrift/Agent/BaggageRestrictionManagerClient.php b/src/Thrift/Agent/BaggageRestrictionManagerClient.php deleted file mode 100644 index dcd835d..0000000 --- a/src/Thrift/Agent/BaggageRestrictionManagerClient.php +++ /dev/null @@ -1,91 +0,0 @@ -input_ = $input; - $this->output_ = $output ? $output : $input; - } - - - public function getBaggageRestrictions($serviceName) - { - $this->send_getBaggageRestrictions($serviceName); - return $this->recv_getBaggageRestrictions(); - } - - public function send_getBaggageRestrictions($serviceName) - { - $args = new \Jaeger\Thrift\Agent\BaggageRestrictionManager_getBaggageRestrictions_args(); - $args->serviceName = $serviceName; - $bin_accel = ($this->output_ instanceof TBinaryProtocolAccelerated) && function_exists('thrift_protocol_write_binary'); - if ($bin_accel) { - thrift_protocol_write_binary( - $this->output_, - 'getBaggageRestrictions', - TMessageType::CALL, - $args, - $this->seqid_, - $this->output_->isStrictWrite() - ); - } else { - $this->output_->writeMessageBegin('getBaggageRestrictions', TMessageType::CALL, $this->seqid_); - $args->write($this->output_); - $this->output_->writeMessageEnd(); - $this->output_->getTransport()->flush(); - } - } - - public function recv_getBaggageRestrictions() - { - $bin_accel = ($this->input_ instanceof TBinaryProtocolAccelerated) && function_exists('thrift_protocol_read_binary'); - if ($bin_accel) { - $result = thrift_protocol_read_binary( - $this->input_, - '\Jaeger\Thrift\Agent\BaggageRestrictionManager_getBaggageRestrictions_result', - $this->input_->isStrictRead() - ); - } else { - $rseqid = 0; - $fname = null; - $mtype = 0; - - $this->input_->readMessageBegin($fname, $mtype, $rseqid); - if ($mtype == TMessageType::EXCEPTION) { - $x = new TApplicationException(); - $x->read($this->input_); - $this->input_->readMessageEnd(); - throw $x; - } - $result = new \Jaeger\Thrift\Agent\BaggageRestrictionManager_getBaggageRestrictions_result(); - $result->read($this->input_); - $this->input_->readMessageEnd(); - } - if ($result->success !== null) { - return $result->success; - } - throw new \Exception("getBaggageRestrictions failed: unknown result"); - } -} diff --git a/src/Thrift/Agent/BaggageRestrictionManagerIf.php b/src/Thrift/Agent/BaggageRestrictionManagerIf.php deleted file mode 100644 index fe2cbb2..0000000 --- a/src/Thrift/Agent/BaggageRestrictionManagerIf.php +++ /dev/null @@ -1,30 +0,0 @@ - array( - 'var' => 'serviceName', - 'isRequired' => false, - 'type' => TType::STRING, - ), - ); - - /** - * @var string - */ - public $serviceName = null; - - public function __construct($vals = null) - { - if (is_array($vals)) { - if (isset($vals['serviceName'])) { - $this->serviceName = $vals['serviceName']; - } - } - } - - public function getName() - { - return 'BaggageRestrictionManager_getBaggageRestrictions_args'; - } - - - public function read($input) - { - $xfer = 0; - $fname = null; - $ftype = 0; - $fid = 0; - $xfer += $input->readStructBegin($fname); - while (true) { - $xfer += $input->readFieldBegin($fname, $ftype, $fid); - if ($ftype == TType::STOP) { - break; - } - switch ($fid) { - case 1: - if ($ftype == TType::STRING) { - $xfer += $input->readString($this->serviceName); - } else { - $xfer += $input->skip($ftype); - } - break; - default: - $xfer += $input->skip($ftype); - break; - } - $xfer += $input->readFieldEnd(); - } - $xfer += $input->readStructEnd(); - return $xfer; - } - - public function write($output) - { - $xfer = 0; - $xfer += $output->writeStructBegin('BaggageRestrictionManager_getBaggageRestrictions_args'); - if ($this->serviceName !== null) { - $xfer += $output->writeFieldBegin('serviceName', TType::STRING, 1); - $xfer += $output->writeString($this->serviceName); - $xfer += $output->writeFieldEnd(); - } - $xfer += $output->writeFieldStop(); - $xfer += $output->writeStructEnd(); - return $xfer; - } -} diff --git a/src/Thrift/Agent/BaggageRestrictionManager_getBaggageRestrictions_result.php b/src/Thrift/Agent/BaggageRestrictionManager_getBaggageRestrictions_result.php deleted file mode 100644 index d0e0da2..0000000 --- a/src/Thrift/Agent/BaggageRestrictionManager_getBaggageRestrictions_result.php +++ /dev/null @@ -1,116 +0,0 @@ - array( - 'var' => 'success', - 'isRequired' => false, - 'type' => TType::LST, - 'etype' => TType::STRUCT, - 'elem' => array( - 'type' => TType::STRUCT, - 'class' => '\Jaeger\Thrift\Agent\BaggageRestriction', - ), - ), - ); - - /** - * @var \Jaeger\Thrift\Agent\BaggageRestriction[] - */ - public $success = null; - - public function __construct($vals = null) - { - if (is_array($vals)) { - if (isset($vals['success'])) { - $this->success = $vals['success']; - } - } - } - - public function getName() - { - return 'BaggageRestrictionManager_getBaggageRestrictions_result'; - } - - - public function read($input) - { - $xfer = 0; - $fname = null; - $ftype = 0; - $fid = 0; - $xfer += $input->readStructBegin($fname); - while (true) { - $xfer += $input->readFieldBegin($fname, $ftype, $fid); - if ($ftype == TType::STOP) { - break; - } - switch ($fid) { - case 0: - if ($ftype == TType::LST) { - $this->success = array(); - $_size0 = 0; - $_etype3 = 0; - $xfer += $input->readListBegin($_etype3, $_size0); - for ($_i4 = 0; $_i4 < $_size0; ++$_i4) { - $elem5 = null; - $elem5 = new \Jaeger\Thrift\Agent\BaggageRestriction(); - $xfer += $elem5->read($input); - $this->success []= $elem5; - } - $xfer += $input->readListEnd(); - } else { - $xfer += $input->skip($ftype); - } - break; - default: - $xfer += $input->skip($ftype); - break; - } - $xfer += $input->readFieldEnd(); - } - $xfer += $input->readStructEnd(); - return $xfer; - } - - public function write($output) - { - $xfer = 0; - $xfer += $output->writeStructBegin('BaggageRestrictionManager_getBaggageRestrictions_result'); - if ($this->success !== null) { - if (!is_array($this->success)) { - throw new TProtocolException('Bad type in structure.', TProtocolException::INVALID_DATA); - } - $xfer += $output->writeFieldBegin('success', TType::LST, 0); - $output->writeListBegin(TType::STRUCT, count($this->success)); - foreach ($this->success as $iter6) { - $xfer += $iter6->write($output); - } - $output->writeListEnd(); - $xfer += $output->writeFieldEnd(); - } - $xfer += $output->writeFieldStop(); - $xfer += $output->writeStructEnd(); - return $xfer; - } -} diff --git a/src/Thrift/Agent/Dependencies.php b/src/Thrift/Agent/Dependencies.php deleted file mode 100644 index 5ef0105..0000000 --- a/src/Thrift/Agent/Dependencies.php +++ /dev/null @@ -1,116 +0,0 @@ - array( - 'var' => 'links', - 'isRequired' => true, - 'type' => TType::LST, - 'etype' => TType::STRUCT, - 'elem' => array( - 'type' => TType::STRUCT, - 'class' => '\Jaeger\Thrift\Agent\DependencyLink', - ), - ), - ); - - /** - * @var \Jaeger\Thrift\Agent\DependencyLink[] - */ - public $links = null; - - public function __construct($vals = null) - { - if (is_array($vals)) { - if (isset($vals['links'])) { - $this->links = $vals['links']; - } - } - } - - public function getName() - { - return 'Dependencies'; - } - - - public function read($input) - { - $xfer = 0; - $fname = null; - $ftype = 0; - $fid = 0; - $xfer += $input->readStructBegin($fname); - while (true) { - $xfer += $input->readFieldBegin($fname, $ftype, $fid); - if ($ftype == TType::STOP) { - break; - } - switch ($fid) { - case 1: - if ($ftype == TType::LST) { - $this->links = array(); - $_size0 = 0; - $_etype3 = 0; - $xfer += $input->readListBegin($_etype3, $_size0); - for ($_i4 = 0; $_i4 < $_size0; ++$_i4) { - $elem5 = null; - $elem5 = new \Jaeger\Thrift\Agent\DependencyLink(); - $xfer += $elem5->read($input); - $this->links []= $elem5; - } - $xfer += $input->readListEnd(); - } else { - $xfer += $input->skip($ftype); - } - break; - default: - $xfer += $input->skip($ftype); - break; - } - $xfer += $input->readFieldEnd(); - } - $xfer += $input->readStructEnd(); - return $xfer; - } - - public function write($output) - { - $xfer = 0; - $xfer += $output->writeStructBegin('Dependencies'); - if ($this->links !== null) { - if (!is_array($this->links)) { - throw new TProtocolException('Bad type in structure.', TProtocolException::INVALID_DATA); - } - $xfer += $output->writeFieldBegin('links', TType::LST, 1); - $output->writeListBegin(TType::STRUCT, count($this->links)); - foreach ($this->links as $iter6) { - $xfer += $iter6->write($output); - } - $output->writeListEnd(); - $xfer += $output->writeFieldEnd(); - } - $xfer += $output->writeFieldStop(); - $xfer += $output->writeStructEnd(); - return $xfer; - } -} diff --git a/src/Thrift/Agent/DependencyClient.php b/src/Thrift/Agent/DependencyClient.php deleted file mode 100644 index 2c19b74..0000000 --- a/src/Thrift/Agent/DependencyClient.php +++ /dev/null @@ -1,118 +0,0 @@ -input_ = $input; - $this->output_ = $output ? $output : $input; - } - - - public function getDependenciesForTrace($traceId) - { - $this->send_getDependenciesForTrace($traceId); - return $this->recv_getDependenciesForTrace(); - } - - public function send_getDependenciesForTrace($traceId) - { - $args = new \Jaeger\Thrift\Agent\Dependency_getDependenciesForTrace_args(); - $args->traceId = $traceId; - $bin_accel = ($this->output_ instanceof TBinaryProtocolAccelerated) && function_exists('thrift_protocol_write_binary'); - if ($bin_accel) { - thrift_protocol_write_binary( - $this->output_, - 'getDependenciesForTrace', - TMessageType::CALL, - $args, - $this->seqid_, - $this->output_->isStrictWrite() - ); - } else { - $this->output_->writeMessageBegin('getDependenciesForTrace', TMessageType::CALL, $this->seqid_); - $args->write($this->output_); - $this->output_->writeMessageEnd(); - $this->output_->getTransport()->flush(); - } - } - - public function recv_getDependenciesForTrace() - { - $bin_accel = ($this->input_ instanceof TBinaryProtocolAccelerated) && function_exists('thrift_protocol_read_binary'); - if ($bin_accel) { - $result = thrift_protocol_read_binary( - $this->input_, - '\Jaeger\Thrift\Agent\Dependency_getDependenciesForTrace_result', - $this->input_->isStrictRead() - ); - } else { - $rseqid = 0; - $fname = null; - $mtype = 0; - - $this->input_->readMessageBegin($fname, $mtype, $rseqid); - if ($mtype == TMessageType::EXCEPTION) { - $x = new TApplicationException(); - $x->read($this->input_); - $this->input_->readMessageEnd(); - throw $x; - } - $result = new \Jaeger\Thrift\Agent\Dependency_getDependenciesForTrace_result(); - $result->read($this->input_); - $this->input_->readMessageEnd(); - } - if ($result->success !== null) { - return $result->success; - } - throw new \Exception("getDependenciesForTrace failed: unknown result"); - } - - public function saveDependencies(\Jaeger\Thrift\Agent\Dependencies $dependencies) - { - $this->send_saveDependencies($dependencies); - } - - public function send_saveDependencies(\Jaeger\Thrift\Agent\Dependencies $dependencies) - { - $args = new \Jaeger\Thrift\Agent\Dependency_saveDependencies_args(); - $args->dependencies = $dependencies; - $bin_accel = ($this->output_ instanceof TBinaryProtocolAccelerated) && function_exists('thrift_protocol_write_binary'); - if ($bin_accel) { - thrift_protocol_write_binary( - $this->output_, - 'saveDependencies', - TMessageType::ONEWAY, - $args, - $this->seqid_, - $this->output_->isStrictWrite() - ); - } else { - $this->output_->writeMessageBegin('saveDependencies', TMessageType::ONEWAY, $this->seqid_); - $args->write($this->output_); - $this->output_->writeMessageEnd(); - $this->output_->getTransport()->flush(); - } - } -} diff --git a/src/Thrift/Agent/DependencyIf.php b/src/Thrift/Agent/DependencyIf.php deleted file mode 100644 index 8918b2f..0000000 --- a/src/Thrift/Agent/DependencyIf.php +++ /dev/null @@ -1,30 +0,0 @@ - array( - 'var' => 'parent', - 'isRequired' => true, - 'type' => TType::STRING, - ), - 2 => array( - 'var' => 'child', - 'isRequired' => true, - 'type' => TType::STRING, - ), - 4 => array( - 'var' => 'callCount', - 'isRequired' => true, - 'type' => TType::I64, - ), - ); - - /** - * @var string - */ - public $parent = null; - /** - * @var string - */ - public $child = null; - /** - * @var int - */ - public $callCount = null; - - public function __construct($vals = null) - { - if (is_array($vals)) { - if (isset($vals['parent'])) { - $this->parent = $vals['parent']; - } - if (isset($vals['child'])) { - $this->child = $vals['child']; - } - if (isset($vals['callCount'])) { - $this->callCount = $vals['callCount']; - } - } - } - - public function getName() - { - return 'DependencyLink'; - } - - - public function read($input) - { - $xfer = 0; - $fname = null; - $ftype = 0; - $fid = 0; - $xfer += $input->readStructBegin($fname); - while (true) { - $xfer += $input->readFieldBegin($fname, $ftype, $fid); - if ($ftype == TType::STOP) { - break; - } - switch ($fid) { - case 1: - if ($ftype == TType::STRING) { - $xfer += $input->readString($this->parent); - } else { - $xfer += $input->skip($ftype); - } - break; - case 2: - if ($ftype == TType::STRING) { - $xfer += $input->readString($this->child); - } else { - $xfer += $input->skip($ftype); - } - break; - case 4: - if ($ftype == TType::I64) { - $xfer += $input->readI64($this->callCount); - } else { - $xfer += $input->skip($ftype); - } - break; - default: - $xfer += $input->skip($ftype); - break; - } - $xfer += $input->readFieldEnd(); - } - $xfer += $input->readStructEnd(); - return $xfer; - } - - public function write($output) - { - $xfer = 0; - $xfer += $output->writeStructBegin('DependencyLink'); - if ($this->parent !== null) { - $xfer += $output->writeFieldBegin('parent', TType::STRING, 1); - $xfer += $output->writeString($this->parent); - $xfer += $output->writeFieldEnd(); - } - if ($this->child !== null) { - $xfer += $output->writeFieldBegin('child', TType::STRING, 2); - $xfer += $output->writeString($this->child); - $xfer += $output->writeFieldEnd(); - } - if ($this->callCount !== null) { - $xfer += $output->writeFieldBegin('callCount', TType::I64, 4); - $xfer += $output->writeI64($this->callCount); - $xfer += $output->writeFieldEnd(); - } - $xfer += $output->writeFieldStop(); - $xfer += $output->writeStructEnd(); - return $xfer; - } -} diff --git a/src/Thrift/Agent/Dependency_getDependenciesForTrace_args.php b/src/Thrift/Agent/Dependency_getDependenciesForTrace_args.php deleted file mode 100644 index 69693ab..0000000 --- a/src/Thrift/Agent/Dependency_getDependenciesForTrace_args.php +++ /dev/null @@ -1,94 +0,0 @@ - array( - 'var' => 'traceId', - 'isRequired' => true, - 'type' => TType::STRING, - ), - ); - - /** - * @var string - */ - public $traceId = null; - - public function __construct($vals = null) - { - if (is_array($vals)) { - if (isset($vals['traceId'])) { - $this->traceId = $vals['traceId']; - } - } - } - - public function getName() - { - return 'Dependency_getDependenciesForTrace_args'; - } - - - public function read($input) - { - $xfer = 0; - $fname = null; - $ftype = 0; - $fid = 0; - $xfer += $input->readStructBegin($fname); - while (true) { - $xfer += $input->readFieldBegin($fname, $ftype, $fid); - if ($ftype == TType::STOP) { - break; - } - switch ($fid) { - case 1: - if ($ftype == TType::STRING) { - $xfer += $input->readString($this->traceId); - } else { - $xfer += $input->skip($ftype); - } - break; - default: - $xfer += $input->skip($ftype); - break; - } - $xfer += $input->readFieldEnd(); - } - $xfer += $input->readStructEnd(); - return $xfer; - } - - public function write($output) - { - $xfer = 0; - $xfer += $output->writeStructBegin('Dependency_getDependenciesForTrace_args'); - if ($this->traceId !== null) { - $xfer += $output->writeFieldBegin('traceId', TType::STRING, 1); - $xfer += $output->writeString($this->traceId); - $xfer += $output->writeFieldEnd(); - } - $xfer += $output->writeFieldStop(); - $xfer += $output->writeStructEnd(); - return $xfer; - } -} diff --git a/src/Thrift/Agent/Dependency_getDependenciesForTrace_result.php b/src/Thrift/Agent/Dependency_getDependenciesForTrace_result.php deleted file mode 100644 index 1f737df..0000000 --- a/src/Thrift/Agent/Dependency_getDependenciesForTrace_result.php +++ /dev/null @@ -1,99 +0,0 @@ - array( - 'var' => 'success', - 'isRequired' => false, - 'type' => TType::STRUCT, - 'class' => '\Jaeger\Thrift\Agent\Dependencies', - ), - ); - - /** - * @var \Jaeger\Thrift\Agent\Dependencies - */ - public $success = null; - - public function __construct($vals = null) - { - if (is_array($vals)) { - if (isset($vals['success'])) { - $this->success = $vals['success']; - } - } - } - - public function getName() - { - return 'Dependency_getDependenciesForTrace_result'; - } - - - public function read($input) - { - $xfer = 0; - $fname = null; - $ftype = 0; - $fid = 0; - $xfer += $input->readStructBegin($fname); - while (true) { - $xfer += $input->readFieldBegin($fname, $ftype, $fid); - if ($ftype == TType::STOP) { - break; - } - switch ($fid) { - case 0: - if ($ftype == TType::STRUCT) { - $this->success = new \Jaeger\Thrift\Agent\Dependencies(); - $xfer += $this->success->read($input); - } else { - $xfer += $input->skip($ftype); - } - break; - default: - $xfer += $input->skip($ftype); - break; - } - $xfer += $input->readFieldEnd(); - } - $xfer += $input->readStructEnd(); - return $xfer; - } - - public function write($output) - { - $xfer = 0; - $xfer += $output->writeStructBegin('Dependency_getDependenciesForTrace_result'); - if ($this->success !== null) { - if (!is_object($this->success)) { - throw new TProtocolException('Bad type in structure.', TProtocolException::INVALID_DATA); - } - $xfer += $output->writeFieldBegin('success', TType::STRUCT, 0); - $xfer += $this->success->write($output); - $xfer += $output->writeFieldEnd(); - } - $xfer += $output->writeFieldStop(); - $xfer += $output->writeStructEnd(); - return $xfer; - } -} diff --git a/src/Thrift/Agent/Dependency_saveDependencies_args.php b/src/Thrift/Agent/Dependency_saveDependencies_args.php deleted file mode 100644 index 08c812c..0000000 --- a/src/Thrift/Agent/Dependency_saveDependencies_args.php +++ /dev/null @@ -1,99 +0,0 @@ - array( - 'var' => 'dependencies', - 'isRequired' => false, - 'type' => TType::STRUCT, - 'class' => '\Jaeger\Thrift\Agent\Dependencies', - ), - ); - - /** - * @var \Jaeger\Thrift\Agent\Dependencies - */ - public $dependencies = null; - - public function __construct($vals = null) - { - if (is_array($vals)) { - if (isset($vals['dependencies'])) { - $this->dependencies = $vals['dependencies']; - } - } - } - - public function getName() - { - return 'Dependency_saveDependencies_args'; - } - - - public function read($input) - { - $xfer = 0; - $fname = null; - $ftype = 0; - $fid = 0; - $xfer += $input->readStructBegin($fname); - while (true) { - $xfer += $input->readFieldBegin($fname, $ftype, $fid); - if ($ftype == TType::STOP) { - break; - } - switch ($fid) { - case 1: - if ($ftype == TType::STRUCT) { - $this->dependencies = new \Jaeger\Thrift\Agent\Dependencies(); - $xfer += $this->dependencies->read($input); - } else { - $xfer += $input->skip($ftype); - } - break; - default: - $xfer += $input->skip($ftype); - break; - } - $xfer += $input->readFieldEnd(); - } - $xfer += $input->readStructEnd(); - return $xfer; - } - - public function write($output) - { - $xfer = 0; - $xfer += $output->writeStructBegin('Dependency_saveDependencies_args'); - if ($this->dependencies !== null) { - if (!is_object($this->dependencies)) { - throw new TProtocolException('Bad type in structure.', TProtocolException::INVALID_DATA); - } - $xfer += $output->writeFieldBegin('dependencies', TType::STRUCT, 1); - $xfer += $this->dependencies->write($output); - $xfer += $output->writeFieldEnd(); - } - $xfer += $output->writeFieldStop(); - $xfer += $output->writeStructEnd(); - return $xfer; - } -} diff --git a/src/Thrift/Agent/OperationSamplingStrategy.php b/src/Thrift/Agent/OperationSamplingStrategy.php index 44f5b6f..24dcb77 100644 --- a/src/Thrift/Agent/OperationSamplingStrategy.php +++ b/src/Thrift/Agent/OperationSamplingStrategy.php @@ -1,53 +1,52 @@ array( + public static array $tspec = [ + 1 => [ 'var' => 'operation', 'isRequired' => true, 'type' => TType::STRING, - ), - 2 => array( + ], + 2 => [ 'var' => 'probabilisticSampling', 'isRequired' => true, 'type' => TType::STRUCT, 'class' => '\Jaeger\Thrift\Agent\ProbabilisticSamplingStrategy', - ), - ); + ], + ]; - /** - * @var string - */ - public $operation = null; - /** - * @var \Jaeger\Thrift\Agent\ProbabilisticSamplingStrategy - */ - public $probabilisticSampling = null; + public ?string $operation = null; + public ?ProbabilisticSamplingStrategy $probabilisticSampling = null; - public function __construct($vals = null) + public function __construct(?array $vals = null) { if (is_array($vals)) { if (isset($vals['operation'])) { - $this->operation = $vals['operation']; + $this->operation = (string)$vals['operation']; } if (isset($vals['probabilisticSampling'])) { $this->probabilisticSampling = $vals['probabilisticSampling']; @@ -55,69 +54,80 @@ public function __construct($vals = null) } } - public function getName() + public function getName(): string { return 'OperationSamplingStrategy'; } - - public function read($input) + public function read(TProtocol $input): int { $xfer = 0; $fname = null; $ftype = 0; $fid = 0; - $xfer += $input->readStructBegin($fname); - while (true) { - $xfer += $input->readFieldBegin($fname, $ftype, $fid); - if ($ftype == TType::STOP) { - break; - } - switch ($fid) { - case 1: - if ($ftype == TType::STRING) { - $xfer += $input->readString($this->operation); - } else { - $xfer += $input->skip($ftype); - } + $input->incrementRecursionDepth(); + try { + $xfer += $input->readStructBegin($fname); + while (true) { + $xfer += $input->readFieldBegin($fname, $ftype, $fid); + if ($ftype == TType::STOP) { break; - case 2: - if ($ftype == TType::STRUCT) { - $this->probabilisticSampling = new \Jaeger\Thrift\Agent\ProbabilisticSamplingStrategy(); - $xfer += $this->probabilisticSampling->read($input); - } else { + } + switch ($fid) { + case 1: + if ($ftype == TType::STRING) { + $xfer += $input->readString($this->operation); + } else { + $xfer += $input->skip($ftype); + } + break; + case 2: + if ($ftype == TType::STRUCT) { + $this->probabilisticSampling = new \Jaeger\Thrift\Agent\ProbabilisticSamplingStrategy(); + $xfer += $this->probabilisticSampling->read($input); + } else { + $xfer += $input->skip($ftype); + } + break; + default: $xfer += $input->skip($ftype); - } - break; - default: - $xfer += $input->skip($ftype); - break; + break; + } + $xfer += $input->readFieldEnd(); } - $xfer += $input->readFieldEnd(); + $xfer += $input->readStructEnd(); + } finally { + $input->decrementRecursionDepth(); } - $xfer += $input->readStructEnd(); + return $xfer; } - public function write($output) + public function write(TProtocol $output): int { $xfer = 0; - $xfer += $output->writeStructBegin('OperationSamplingStrategy'); - if ($this->operation !== null) { - $xfer += $output->writeFieldBegin('operation', TType::STRING, 1); - $xfer += $output->writeString($this->operation); - $xfer += $output->writeFieldEnd(); - } - if ($this->probabilisticSampling !== null) { - if (!is_object($this->probabilisticSampling)) { - throw new TProtocolException('Bad type in structure.', TProtocolException::INVALID_DATA); + $output->incrementRecursionDepth(); + try { + $xfer += $output->writeStructBegin('OperationSamplingStrategy'); + if ($this->operation !== null) { + $xfer += $output->writeFieldBegin('operation', TType::STRING, 1); + $xfer += $output->writeString($this->operation); + $xfer += $output->writeFieldEnd(); + } + if ($this->probabilisticSampling !== null) { + if (!is_object($this->probabilisticSampling)) { + throw new TProtocolException('Bad type in structure.', TProtocolException::INVALID_DATA); + } + $xfer += $output->writeFieldBegin('probabilisticSampling', TType::STRUCT, 2); + $xfer += $this->probabilisticSampling->write($output); + $xfer += $output->writeFieldEnd(); } - $xfer += $output->writeFieldBegin('probabilisticSampling', TType::STRUCT, 2); - $xfer += $this->probabilisticSampling->write($output); - $xfer += $output->writeFieldEnd(); + $xfer += $output->writeFieldStop(); + $xfer += $output->writeStructEnd(); + } finally { + $output->decrementRecursionDepth(); } - $xfer += $output->writeFieldStop(); - $xfer += $output->writeStructEnd(); + return $xfer; } } diff --git a/src/Thrift/Agent/PerOperationSamplingStrategies.php b/src/Thrift/Agent/PerOperationSamplingStrategies.php index 02a6aa4..dc1528c 100644 --- a/src/Thrift/Agent/PerOperationSamplingStrategies.php +++ b/src/Thrift/Agent/PerOperationSamplingStrategies.php @@ -1,188 +1,195 @@ array( + public static array $tspec = [ + 1 => [ 'var' => 'defaultSamplingProbability', 'isRequired' => true, 'type' => TType::DOUBLE, - ), - 2 => array( + ], + 2 => [ 'var' => 'defaultLowerBoundTracesPerSecond', 'isRequired' => true, 'type' => TType::DOUBLE, - ), - 3 => array( + ], + 3 => [ 'var' => 'perOperationStrategies', 'isRequired' => true, 'type' => TType::LST, 'etype' => TType::STRUCT, - 'elem' => array( + 'elem' => [ 'type' => TType::STRUCT, 'class' => '\Jaeger\Thrift\Agent\OperationSamplingStrategy', - ), - ), - 4 => array( + ], + ], + 4 => [ 'var' => 'defaultUpperBoundTracesPerSecond', 'isRequired' => false, 'type' => TType::DOUBLE, - ), - ); + ], + ]; - /** - * @var double - */ - public $defaultSamplingProbability = null; - /** - * @var double - */ - public $defaultLowerBoundTracesPerSecond = null; + public ?float $defaultSamplingProbability = null; + public ?float $defaultLowerBoundTracesPerSecond = null; /** * @var \Jaeger\Thrift\Agent\OperationSamplingStrategy[] */ - public $perOperationStrategies = null; - /** - * @var double - */ - public $defaultUpperBoundTracesPerSecond = null; + public ?array $perOperationStrategies = null; + public ?float $defaultUpperBoundTracesPerSecond = null; - public function __construct($vals = null) + public function __construct(?array $vals = null) { if (is_array($vals)) { if (isset($vals['defaultSamplingProbability'])) { - $this->defaultSamplingProbability = $vals['defaultSamplingProbability']; + $this->defaultSamplingProbability = (float)$vals['defaultSamplingProbability']; } if (isset($vals['defaultLowerBoundTracesPerSecond'])) { - $this->defaultLowerBoundTracesPerSecond = $vals['defaultLowerBoundTracesPerSecond']; + $this->defaultLowerBoundTracesPerSecond = (float)$vals['defaultLowerBoundTracesPerSecond']; } if (isset($vals['perOperationStrategies'])) { $this->perOperationStrategies = $vals['perOperationStrategies']; } if (isset($vals['defaultUpperBoundTracesPerSecond'])) { - $this->defaultUpperBoundTracesPerSecond = $vals['defaultUpperBoundTracesPerSecond']; + $this->defaultUpperBoundTracesPerSecond = (float)$vals['defaultUpperBoundTracesPerSecond']; } } } - public function getName() + public function getName(): string { return 'PerOperationSamplingStrategies'; } - - public function read($input) + public function read(TProtocol $input): int { $xfer = 0; $fname = null; $ftype = 0; $fid = 0; - $xfer += $input->readStructBegin($fname); - while (true) { - $xfer += $input->readFieldBegin($fname, $ftype, $fid); - if ($ftype == TType::STOP) { - break; - } - switch ($fid) { - case 1: - if ($ftype == TType::DOUBLE) { - $xfer += $input->readDouble($this->defaultSamplingProbability); - } else { - $xfer += $input->skip($ftype); - } - break; - case 2: - if ($ftype == TType::DOUBLE) { - $xfer += $input->readDouble($this->defaultLowerBoundTracesPerSecond); - } else { - $xfer += $input->skip($ftype); - } + $input->incrementRecursionDepth(); + try { + $xfer += $input->readStructBegin($fname); + while (true) { + $xfer += $input->readFieldBegin($fname, $ftype, $fid); + if ($ftype == TType::STOP) { break; - case 3: - if ($ftype == TType::LST) { - $this->perOperationStrategies = array(); - $_size0 = 0; - $_etype3 = 0; - $xfer += $input->readListBegin($_etype3, $_size0); - for ($_i4 = 0; $_i4 < $_size0; ++$_i4) { - $elem5 = null; - $elem5 = new \Jaeger\Thrift\Agent\OperationSamplingStrategy(); - $xfer += $elem5->read($input); - $this->perOperationStrategies []= $elem5; + } + switch ($fid) { + case 1: + if ($ftype == TType::DOUBLE) { + $xfer += $input->readDouble($this->defaultSamplingProbability); + } else { + $xfer += $input->skip($ftype); } - $xfer += $input->readListEnd(); - } else { - $xfer += $input->skip($ftype); - } - break; - case 4: - if ($ftype == TType::DOUBLE) { - $xfer += $input->readDouble($this->defaultUpperBoundTracesPerSecond); - } else { + break; + case 2: + if ($ftype == TType::DOUBLE) { + $xfer += $input->readDouble($this->defaultLowerBoundTracesPerSecond); + } else { + $xfer += $input->skip($ftype); + } + break; + case 3: + if ($ftype == TType::LST) { + $this->perOperationStrategies = []; + $_size0 = 0; + $_etype3 = 0; + $xfer += $input->readListBegin($_etype3, $_size0); + for ($_i4 = 0; $_i4 < $_size0; ++$_i4) { + $elem5 = null; + $elem5 = new \Jaeger\Thrift\Agent\OperationSamplingStrategy(); + $xfer += $elem5->read($input); + $this->perOperationStrategies[] = $elem5; + } + $xfer += $input->readListEnd(); + } else { + $xfer += $input->skip($ftype); + } + break; + case 4: + if ($ftype == TType::DOUBLE) { + $xfer += $input->readDouble($this->defaultUpperBoundTracesPerSecond); + } else { + $xfer += $input->skip($ftype); + } + break; + default: $xfer += $input->skip($ftype); - } - break; - default: - $xfer += $input->skip($ftype); - break; + break; + } + $xfer += $input->readFieldEnd(); } - $xfer += $input->readFieldEnd(); + $xfer += $input->readStructEnd(); + } finally { + $input->decrementRecursionDepth(); } - $xfer += $input->readStructEnd(); + return $xfer; } - public function write($output) + public function write(TProtocol $output): int { $xfer = 0; - $xfer += $output->writeStructBegin('PerOperationSamplingStrategies'); - if ($this->defaultSamplingProbability !== null) { - $xfer += $output->writeFieldBegin('defaultSamplingProbability', TType::DOUBLE, 1); - $xfer += $output->writeDouble($this->defaultSamplingProbability); - $xfer += $output->writeFieldEnd(); - } - if ($this->defaultLowerBoundTracesPerSecond !== null) { - $xfer += $output->writeFieldBegin('defaultLowerBoundTracesPerSecond', TType::DOUBLE, 2); - $xfer += $output->writeDouble($this->defaultLowerBoundTracesPerSecond); - $xfer += $output->writeFieldEnd(); - } - if ($this->perOperationStrategies !== null) { - if (!is_array($this->perOperationStrategies)) { - throw new TProtocolException('Bad type in structure.', TProtocolException::INVALID_DATA); + $output->incrementRecursionDepth(); + try { + $xfer += $output->writeStructBegin('PerOperationSamplingStrategies'); + if ($this->defaultSamplingProbability !== null) { + $xfer += $output->writeFieldBegin('defaultSamplingProbability', TType::DOUBLE, 1); + $xfer += $output->writeDouble($this->defaultSamplingProbability); + $xfer += $output->writeFieldEnd(); } - $xfer += $output->writeFieldBegin('perOperationStrategies', TType::LST, 3); - $output->writeListBegin(TType::STRUCT, count($this->perOperationStrategies)); - foreach ($this->perOperationStrategies as $iter6) { - $xfer += $iter6->write($output); + if ($this->defaultLowerBoundTracesPerSecond !== null) { + $xfer += $output->writeFieldBegin('defaultLowerBoundTracesPerSecond', TType::DOUBLE, 2); + $xfer += $output->writeDouble($this->defaultLowerBoundTracesPerSecond); + $xfer += $output->writeFieldEnd(); } - $output->writeListEnd(); - $xfer += $output->writeFieldEnd(); - } - if ($this->defaultUpperBoundTracesPerSecond !== null) { - $xfer += $output->writeFieldBegin('defaultUpperBoundTracesPerSecond', TType::DOUBLE, 4); - $xfer += $output->writeDouble($this->defaultUpperBoundTracesPerSecond); - $xfer += $output->writeFieldEnd(); + if ($this->perOperationStrategies !== null) { + if (!is_array($this->perOperationStrategies)) { + throw new TProtocolException('Bad type in structure.', TProtocolException::INVALID_DATA); + } + $xfer += $output->writeFieldBegin('perOperationStrategies', TType::LST, 3); + $output->writeListBegin(TType::STRUCT, count($this->perOperationStrategies)); + foreach ($this->perOperationStrategies as $iter6) { + $xfer += $iter6->write($output); + } + $output->writeListEnd(); + $xfer += $output->writeFieldEnd(); + } + if ($this->defaultUpperBoundTracesPerSecond !== null) { + $xfer += $output->writeFieldBegin('defaultUpperBoundTracesPerSecond', TType::DOUBLE, 4); + $xfer += $output->writeDouble($this->defaultUpperBoundTracesPerSecond); + $xfer += $output->writeFieldEnd(); + } + $xfer += $output->writeFieldStop(); + $xfer += $output->writeStructEnd(); + } finally { + $output->decrementRecursionDepth(); } - $xfer += $output->writeFieldStop(); - $xfer += $output->writeStructEnd(); + return $xfer; } } diff --git a/src/Thrift/Agent/ProbabilisticSamplingStrategy.php b/src/Thrift/Agent/ProbabilisticSamplingStrategy.php index e4d98ea..cd3b056 100644 --- a/src/Thrift/Agent/ProbabilisticSamplingStrategy.php +++ b/src/Thrift/Agent/ProbabilisticSamplingStrategy.php @@ -1,94 +1,107 @@ array( + public static array $tspec = [ + 1 => [ 'var' => 'samplingRate', 'isRequired' => true, 'type' => TType::DOUBLE, - ), - ); + ], + ]; - /** - * @var double - */ - public $samplingRate = null; + public ?float $samplingRate = null; - public function __construct($vals = null) + public function __construct(?array $vals = null) { if (is_array($vals)) { if (isset($vals['samplingRate'])) { - $this->samplingRate = $vals['samplingRate']; + $this->samplingRate = (float)$vals['samplingRate']; } } } - public function getName() + public function getName(): string { return 'ProbabilisticSamplingStrategy'; } - - public function read($input) + public function read(TProtocol $input): int { $xfer = 0; $fname = null; $ftype = 0; $fid = 0; - $xfer += $input->readStructBegin($fname); - while (true) { - $xfer += $input->readFieldBegin($fname, $ftype, $fid); - if ($ftype == TType::STOP) { - break; - } - switch ($fid) { - case 1: - if ($ftype == TType::DOUBLE) { - $xfer += $input->readDouble($this->samplingRate); - } else { - $xfer += $input->skip($ftype); - } - break; - default: - $xfer += $input->skip($ftype); + $input->incrementRecursionDepth(); + try { + $xfer += $input->readStructBegin($fname); + while (true) { + $xfer += $input->readFieldBegin($fname, $ftype, $fid); + if ($ftype == TType::STOP) { break; + } + switch ($fid) { + case 1: + if ($ftype == TType::DOUBLE) { + $xfer += $input->readDouble($this->samplingRate); + } else { + $xfer += $input->skip($ftype); + } + break; + default: + $xfer += $input->skip($ftype); + break; + } + $xfer += $input->readFieldEnd(); } - $xfer += $input->readFieldEnd(); + $xfer += $input->readStructEnd(); + } finally { + $input->decrementRecursionDepth(); } - $xfer += $input->readStructEnd(); + return $xfer; } - public function write($output) + public function write(TProtocol $output): int { $xfer = 0; - $xfer += $output->writeStructBegin('ProbabilisticSamplingStrategy'); - if ($this->samplingRate !== null) { - $xfer += $output->writeFieldBegin('samplingRate', TType::DOUBLE, 1); - $xfer += $output->writeDouble($this->samplingRate); - $xfer += $output->writeFieldEnd(); + $output->incrementRecursionDepth(); + try { + $xfer += $output->writeStructBegin('ProbabilisticSamplingStrategy'); + if ($this->samplingRate !== null) { + $xfer += $output->writeFieldBegin('samplingRate', TType::DOUBLE, 1); + $xfer += $output->writeDouble($this->samplingRate); + $xfer += $output->writeFieldEnd(); + } + $xfer += $output->writeFieldStop(); + $xfer += $output->writeStructEnd(); + } finally { + $output->decrementRecursionDepth(); } - $xfer += $output->writeFieldStop(); - $xfer += $output->writeStructEnd(); + return $xfer; } } diff --git a/src/Thrift/Agent/RateLimitingSamplingStrategy.php b/src/Thrift/Agent/RateLimitingSamplingStrategy.php index 6d63490..8d3e2b2 100644 --- a/src/Thrift/Agent/RateLimitingSamplingStrategy.php +++ b/src/Thrift/Agent/RateLimitingSamplingStrategy.php @@ -1,94 +1,107 @@ array( + public static array $tspec = [ + 1 => [ 'var' => 'maxTracesPerSecond', 'isRequired' => true, 'type' => TType::I16, - ), - ); + ], + ]; - /** - * @var int - */ - public $maxTracesPerSecond = null; + public ?int $maxTracesPerSecond = null; - public function __construct($vals = null) + public function __construct(?array $vals = null) { if (is_array($vals)) { if (isset($vals['maxTracesPerSecond'])) { - $this->maxTracesPerSecond = $vals['maxTracesPerSecond']; + $this->maxTracesPerSecond = (int)$vals['maxTracesPerSecond']; } } } - public function getName() + public function getName(): string { return 'RateLimitingSamplingStrategy'; } - - public function read($input) + public function read(TProtocol $input): int { $xfer = 0; $fname = null; $ftype = 0; $fid = 0; - $xfer += $input->readStructBegin($fname); - while (true) { - $xfer += $input->readFieldBegin($fname, $ftype, $fid); - if ($ftype == TType::STOP) { - break; - } - switch ($fid) { - case 1: - if ($ftype == TType::I16) { - $xfer += $input->readI16($this->maxTracesPerSecond); - } else { - $xfer += $input->skip($ftype); - } - break; - default: - $xfer += $input->skip($ftype); + $input->incrementRecursionDepth(); + try { + $xfer += $input->readStructBegin($fname); + while (true) { + $xfer += $input->readFieldBegin($fname, $ftype, $fid); + if ($ftype == TType::STOP) { break; + } + switch ($fid) { + case 1: + if ($ftype == TType::I16) { + $xfer += $input->readI16($this->maxTracesPerSecond); + } else { + $xfer += $input->skip($ftype); + } + break; + default: + $xfer += $input->skip($ftype); + break; + } + $xfer += $input->readFieldEnd(); } - $xfer += $input->readFieldEnd(); + $xfer += $input->readStructEnd(); + } finally { + $input->decrementRecursionDepth(); } - $xfer += $input->readStructEnd(); + return $xfer; } - public function write($output) + public function write(TProtocol $output): int { $xfer = 0; - $xfer += $output->writeStructBegin('RateLimitingSamplingStrategy'); - if ($this->maxTracesPerSecond !== null) { - $xfer += $output->writeFieldBegin('maxTracesPerSecond', TType::I16, 1); - $xfer += $output->writeI16($this->maxTracesPerSecond); - $xfer += $output->writeFieldEnd(); + $output->incrementRecursionDepth(); + try { + $xfer += $output->writeStructBegin('RateLimitingSamplingStrategy'); + if ($this->maxTracesPerSecond !== null) { + $xfer += $output->writeFieldBegin('maxTracesPerSecond', TType::I16, 1); + $xfer += $output->writeI16($this->maxTracesPerSecond); + $xfer += $output->writeFieldEnd(); + } + $xfer += $output->writeFieldStop(); + $xfer += $output->writeStructEnd(); + } finally { + $output->decrementRecursionDepth(); } - $xfer += $output->writeFieldStop(); - $xfer += $output->writeStructEnd(); + return $xfer; } } diff --git a/src/Thrift/Agent/SamplingManagerClient.php b/src/Thrift/Agent/SamplingManagerClient.php index 43b9533..12b3660 100644 --- a/src/Thrift/Agent/SamplingManagerClient.php +++ b/src/Thrift/Agent/SamplingManagerClient.php @@ -1,87 +1,94 @@ input_ = $input; - $this->output_ = $output ? $output : $input; + $this->input = $input; + $this->output = $output ? $output : $input; } - public function getSamplingStrategy($serviceName) + public function getSamplingStrategy(?string $serviceName): ?SamplingStrategyResponse { $this->send_getSamplingStrategy($serviceName); return $this->recv_getSamplingStrategy(); } - public function send_getSamplingStrategy($serviceName) + public function send_getSamplingStrategy(?string $serviceName): void { $args = new \Jaeger\Thrift\Agent\SamplingManager_getSamplingStrategy_args(); $args->serviceName = $serviceName; - $bin_accel = ($this->output_ instanceof TBinaryProtocolAccelerated) && function_exists('thrift_protocol_write_binary'); + $bin_accel = ($this->output instanceof TBinaryProtocolAccelerated) && function_exists('thrift_protocol_write_binary'); if ($bin_accel) { thrift_protocol_write_binary( - $this->output_, + $this->output, 'getSamplingStrategy', TMessageType::CALL, $args, - $this->seqid_, - $this->output_->isStrictWrite() + $this->seqid, + $this->output->isStrictWrite() ); } else { - $this->output_->writeMessageBegin('getSamplingStrategy', TMessageType::CALL, $this->seqid_); - $args->write($this->output_); - $this->output_->writeMessageEnd(); - $this->output_->getTransport()->flush(); + $this->output->writeMessageBegin('getSamplingStrategy', TMessageType::CALL, $this->seqid); + $args->write($this->output); + $this->output->writeMessageEnd(); + $this->output->getTransport()->flush(); } } - public function recv_getSamplingStrategy() + public function recv_getSamplingStrategy(): ?SamplingStrategyResponse { - $bin_accel = ($this->input_ instanceof TBinaryProtocolAccelerated) && function_exists('thrift_protocol_read_binary'); + $bin_accel = ($this->input instanceof TBinaryProtocolAccelerated) && function_exists('thrift_protocol_read_binary'); if ($bin_accel) { $result = thrift_protocol_read_binary( - $this->input_, + $this->input, '\Jaeger\Thrift\Agent\SamplingManager_getSamplingStrategy_result', - $this->input_->isStrictRead() + $this->input->isStrictRead() ); } else { $rseqid = 0; $fname = null; $mtype = 0; - $this->input_->readMessageBegin($fname, $mtype, $rseqid); + $this->input->readMessageBegin($fname, $mtype, $rseqid); if ($mtype == TMessageType::EXCEPTION) { $x = new TApplicationException(); - $x->read($this->input_); - $this->input_->readMessageEnd(); + $x->read($this->input); + $this->input->readMessageEnd(); throw $x; } $result = new \Jaeger\Thrift\Agent\SamplingManager_getSamplingStrategy_result(); - $result->read($this->input_); - $this->input_->readMessageEnd(); + $result->read($this->input); + $this->input->readMessageEnd(); } if ($result->success !== null) { return $result->success; diff --git a/src/Thrift/Agent/SamplingManagerIf.php b/src/Thrift/Agent/SamplingManagerIf.php index bde2a27..b89bbc3 100644 --- a/src/Thrift/Agent/SamplingManagerIf.php +++ b/src/Thrift/Agent/SamplingManagerIf.php @@ -1,18 +1,23 @@ array( + public static array $tspec = [ + 1 => [ 'var' => 'serviceName', 'isRequired' => false, 'type' => TType::STRING, - ), - ); + ], + ]; - /** - * @var string - */ - public $serviceName = null; + public ?string $serviceName = null; - public function __construct($vals = null) + public function __construct(?array $vals = null) { if (is_array($vals)) { if (isset($vals['serviceName'])) { - $this->serviceName = $vals['serviceName']; + $this->serviceName = (string)$vals['serviceName']; } } } - public function getName() + public function getName(): string { return 'SamplingManager_getSamplingStrategy_args'; } - - public function read($input) + public function read(TProtocol $input): int { $xfer = 0; $fname = null; $ftype = 0; $fid = 0; - $xfer += $input->readStructBegin($fname); - while (true) { - $xfer += $input->readFieldBegin($fname, $ftype, $fid); - if ($ftype == TType::STOP) { - break; - } - switch ($fid) { - case 1: - if ($ftype == TType::STRING) { - $xfer += $input->readString($this->serviceName); - } else { - $xfer += $input->skip($ftype); - } - break; - default: - $xfer += $input->skip($ftype); + $input->incrementRecursionDepth(); + try { + $xfer += $input->readStructBegin($fname); + while (true) { + $xfer += $input->readFieldBegin($fname, $ftype, $fid); + if ($ftype == TType::STOP) { break; + } + switch ($fid) { + case 1: + if ($ftype == TType::STRING) { + $xfer += $input->readString($this->serviceName); + } else { + $xfer += $input->skip($ftype); + } + break; + default: + $xfer += $input->skip($ftype); + break; + } + $xfer += $input->readFieldEnd(); } - $xfer += $input->readFieldEnd(); + $xfer += $input->readStructEnd(); + } finally { + $input->decrementRecursionDepth(); } - $xfer += $input->readStructEnd(); + return $xfer; } - public function write($output) + public function write(TProtocol $output): int { $xfer = 0; - $xfer += $output->writeStructBegin('SamplingManager_getSamplingStrategy_args'); - if ($this->serviceName !== null) { - $xfer += $output->writeFieldBegin('serviceName', TType::STRING, 1); - $xfer += $output->writeString($this->serviceName); - $xfer += $output->writeFieldEnd(); + $output->incrementRecursionDepth(); + try { + $xfer += $output->writeStructBegin('SamplingManager_getSamplingStrategy_args'); + if ($this->serviceName !== null) { + $xfer += $output->writeFieldBegin('serviceName', TType::STRING, 1); + $xfer += $output->writeString($this->serviceName); + $xfer += $output->writeFieldEnd(); + } + $xfer += $output->writeFieldStop(); + $xfer += $output->writeStructEnd(); + } finally { + $output->decrementRecursionDepth(); } - $xfer += $output->writeFieldStop(); - $xfer += $output->writeStructEnd(); + return $xfer; } } diff --git a/src/Thrift/Agent/SamplingManager_getSamplingStrategy_result.php b/src/Thrift/Agent/SamplingManager_getSamplingStrategy_result.php index 3c15c14..836a663 100644 --- a/src/Thrift/Agent/SamplingManager_getSamplingStrategy_result.php +++ b/src/Thrift/Agent/SamplingManager_getSamplingStrategy_result.php @@ -1,40 +1,44 @@ array( + public static array $tspec = [ + 0 => [ 'var' => 'success', 'isRequired' => false, 'type' => TType::STRUCT, 'class' => '\Jaeger\Thrift\Agent\SamplingStrategyResponse', - ), - ); + ], + ]; - /** - * @var \Jaeger\Thrift\Agent\SamplingStrategyResponse - */ - public $success = null; + public ?SamplingStrategyResponse $success = null; - public function __construct($vals = null) + public function __construct(?array $vals = null) { if (is_array($vals)) { if (isset($vals['success'])) { @@ -43,57 +47,68 @@ public function __construct($vals = null) } } - public function getName() + public function getName(): string { return 'SamplingManager_getSamplingStrategy_result'; } - - public function read($input) + public function read(TProtocol $input): int { $xfer = 0; $fname = null; $ftype = 0; $fid = 0; - $xfer += $input->readStructBegin($fname); - while (true) { - $xfer += $input->readFieldBegin($fname, $ftype, $fid); - if ($ftype == TType::STOP) { - break; - } - switch ($fid) { - case 0: - if ($ftype == TType::STRUCT) { - $this->success = new \Jaeger\Thrift\Agent\SamplingStrategyResponse(); - $xfer += $this->success->read($input); - } else { - $xfer += $input->skip($ftype); - } - break; - default: - $xfer += $input->skip($ftype); + $input->incrementRecursionDepth(); + try { + $xfer += $input->readStructBegin($fname); + while (true) { + $xfer += $input->readFieldBegin($fname, $ftype, $fid); + if ($ftype == TType::STOP) { break; + } + switch ($fid) { + case 0: + if ($ftype == TType::STRUCT) { + $this->success = new \Jaeger\Thrift\Agent\SamplingStrategyResponse(); + $xfer += $this->success->read($input); + } else { + $xfer += $input->skip($ftype); + } + break; + default: + $xfer += $input->skip($ftype); + break; + } + $xfer += $input->readFieldEnd(); } - $xfer += $input->readFieldEnd(); + $xfer += $input->readStructEnd(); + } finally { + $input->decrementRecursionDepth(); } - $xfer += $input->readStructEnd(); + return $xfer; } - public function write($output) + public function write(TProtocol $output): int { $xfer = 0; - $xfer += $output->writeStructBegin('SamplingManager_getSamplingStrategy_result'); - if ($this->success !== null) { - if (!is_object($this->success)) { - throw new TProtocolException('Bad type in structure.', TProtocolException::INVALID_DATA); + $output->incrementRecursionDepth(); + try { + $xfer += $output->writeStructBegin('SamplingManager_getSamplingStrategy_result'); + if ($this->success !== null) { + if (!is_object($this->success)) { + throw new TProtocolException('Bad type in structure.', TProtocolException::INVALID_DATA); + } + $xfer += $output->writeFieldBegin('success', TType::STRUCT, 0); + $xfer += $this->success->write($output); + $xfer += $output->writeFieldEnd(); } - $xfer += $output->writeFieldBegin('success', TType::STRUCT, 0); - $xfer += $this->success->write($output); - $xfer += $output->writeFieldEnd(); + $xfer += $output->writeFieldStop(); + $xfer += $output->writeStructEnd(); + } finally { + $output->decrementRecursionDepth(); } - $xfer += $output->writeFieldStop(); - $xfer += $output->writeStructEnd(); + return $xfer; } } diff --git a/src/Thrift/Agent/SamplingStrategyResponse.php b/src/Thrift/Agent/SamplingStrategyResponse.php index e622eed..b3f2ba6 100644 --- a/src/Thrift/Agent/SamplingStrategyResponse.php +++ b/src/Thrift/Agent/SamplingStrategyResponse.php @@ -1,74 +1,67 @@ array( + public static array $tspec = [ + 1 => [ 'var' => 'strategyType', 'isRequired' => true, 'type' => TType::I32, 'class' => '\Jaeger\Thrift\Agent\SamplingStrategyType', - ), - 2 => array( + ], + 2 => [ 'var' => 'probabilisticSampling', 'isRequired' => false, 'type' => TType::STRUCT, 'class' => '\Jaeger\Thrift\Agent\ProbabilisticSamplingStrategy', - ), - 3 => array( + ], + 3 => [ 'var' => 'rateLimitingSampling', 'isRequired' => false, 'type' => TType::STRUCT, 'class' => '\Jaeger\Thrift\Agent\RateLimitingSamplingStrategy', - ), - 4 => array( + ], + 4 => [ 'var' => 'operationSampling', 'isRequired' => false, 'type' => TType::STRUCT, 'class' => '\Jaeger\Thrift\Agent\PerOperationSamplingStrategies', - ), - ); + ], + ]; - /** - * @var int - */ - public $strategyType = null; - /** - * @var \Jaeger\Thrift\Agent\ProbabilisticSamplingStrategy - */ - public $probabilisticSampling = null; - /** - * @var \Jaeger\Thrift\Agent\RateLimitingSamplingStrategy - */ - public $rateLimitingSampling = null; - /** - * @var \Jaeger\Thrift\Agent\PerOperationSamplingStrategies - */ - public $operationSampling = null; + public ?int $strategyType = null; + public ?ProbabilisticSamplingStrategy $probabilisticSampling = null; + public ?RateLimitingSamplingStrategy $rateLimitingSampling = null; + public ?PerOperationSamplingStrategies $operationSampling = null; - public function __construct($vals = null) + public function __construct(?array $vals = null) { if (is_array($vals)) { if (isset($vals['strategyType'])) { - $this->strategyType = $vals['strategyType']; + $this->strategyType = (int)$vals['strategyType']; } if (isset($vals['probabilisticSampling'])) { $this->probabilisticSampling = $vals['probabilisticSampling']; @@ -82,101 +75,112 @@ public function __construct($vals = null) } } - public function getName() + public function getName(): string { return 'SamplingStrategyResponse'; } - - public function read($input) + public function read(TProtocol $input): int { $xfer = 0; $fname = null; $ftype = 0; $fid = 0; - $xfer += $input->readStructBegin($fname); - while (true) { - $xfer += $input->readFieldBegin($fname, $ftype, $fid); - if ($ftype == TType::STOP) { - break; - } - switch ($fid) { - case 1: - if ($ftype == TType::I32) { - $xfer += $input->readI32($this->strategyType); - } else { - $xfer += $input->skip($ftype); - } - break; - case 2: - if ($ftype == TType::STRUCT) { - $this->probabilisticSampling = new \Jaeger\Thrift\Agent\ProbabilisticSamplingStrategy(); - $xfer += $this->probabilisticSampling->read($input); - } else { - $xfer += $input->skip($ftype); - } + $input->incrementRecursionDepth(); + try { + $xfer += $input->readStructBegin($fname); + while (true) { + $xfer += $input->readFieldBegin($fname, $ftype, $fid); + if ($ftype == TType::STOP) { break; - case 3: - if ($ftype == TType::STRUCT) { - $this->rateLimitingSampling = new \Jaeger\Thrift\Agent\RateLimitingSamplingStrategy(); - $xfer += $this->rateLimitingSampling->read($input); - } else { + } + switch ($fid) { + case 1: + if ($ftype == TType::I32) { + $xfer += $input->readI32($this->strategyType); + } else { + $xfer += $input->skip($ftype); + } + break; + case 2: + if ($ftype == TType::STRUCT) { + $this->probabilisticSampling = new \Jaeger\Thrift\Agent\ProbabilisticSamplingStrategy(); + $xfer += $this->probabilisticSampling->read($input); + } else { + $xfer += $input->skip($ftype); + } + break; + case 3: + if ($ftype == TType::STRUCT) { + $this->rateLimitingSampling = new \Jaeger\Thrift\Agent\RateLimitingSamplingStrategy(); + $xfer += $this->rateLimitingSampling->read($input); + } else { + $xfer += $input->skip($ftype); + } + break; + case 4: + if ($ftype == TType::STRUCT) { + $this->operationSampling = new \Jaeger\Thrift\Agent\PerOperationSamplingStrategies(); + $xfer += $this->operationSampling->read($input); + } else { + $xfer += $input->skip($ftype); + } + break; + default: $xfer += $input->skip($ftype); - } - break; - case 4: - if ($ftype == TType::STRUCT) { - $this->operationSampling = new \Jaeger\Thrift\Agent\PerOperationSamplingStrategies(); - $xfer += $this->operationSampling->read($input); - } else { - $xfer += $input->skip($ftype); - } - break; - default: - $xfer += $input->skip($ftype); - break; + break; + } + $xfer += $input->readFieldEnd(); } - $xfer += $input->readFieldEnd(); + $xfer += $input->readStructEnd(); + } finally { + $input->decrementRecursionDepth(); } - $xfer += $input->readStructEnd(); + return $xfer; } - public function write($output) + public function write(TProtocol $output): int { $xfer = 0; - $xfer += $output->writeStructBegin('SamplingStrategyResponse'); - if ($this->strategyType !== null) { - $xfer += $output->writeFieldBegin('strategyType', TType::I32, 1); - $xfer += $output->writeI32($this->strategyType); - $xfer += $output->writeFieldEnd(); - } - if ($this->probabilisticSampling !== null) { - if (!is_object($this->probabilisticSampling)) { - throw new TProtocolException('Bad type in structure.', TProtocolException::INVALID_DATA); + $output->incrementRecursionDepth(); + try { + $xfer += $output->writeStructBegin('SamplingStrategyResponse'); + if ($this->strategyType !== null) { + $xfer += $output->writeFieldBegin('strategyType', TType::I32, 1); + $xfer += $output->writeI32($this->strategyType); + $xfer += $output->writeFieldEnd(); } - $xfer += $output->writeFieldBegin('probabilisticSampling', TType::STRUCT, 2); - $xfer += $this->probabilisticSampling->write($output); - $xfer += $output->writeFieldEnd(); - } - if ($this->rateLimitingSampling !== null) { - if (!is_object($this->rateLimitingSampling)) { - throw new TProtocolException('Bad type in structure.', TProtocolException::INVALID_DATA); + if ($this->probabilisticSampling !== null) { + if (!is_object($this->probabilisticSampling)) { + throw new TProtocolException('Bad type in structure.', TProtocolException::INVALID_DATA); + } + $xfer += $output->writeFieldBegin('probabilisticSampling', TType::STRUCT, 2); + $xfer += $this->probabilisticSampling->write($output); + $xfer += $output->writeFieldEnd(); } - $xfer += $output->writeFieldBegin('rateLimitingSampling', TType::STRUCT, 3); - $xfer += $this->rateLimitingSampling->write($output); - $xfer += $output->writeFieldEnd(); - } - if ($this->operationSampling !== null) { - if (!is_object($this->operationSampling)) { - throw new TProtocolException('Bad type in structure.', TProtocolException::INVALID_DATA); + if ($this->rateLimitingSampling !== null) { + if (!is_object($this->rateLimitingSampling)) { + throw new TProtocolException('Bad type in structure.', TProtocolException::INVALID_DATA); + } + $xfer += $output->writeFieldBegin('rateLimitingSampling', TType::STRUCT, 3); + $xfer += $this->rateLimitingSampling->write($output); + $xfer += $output->writeFieldEnd(); } - $xfer += $output->writeFieldBegin('operationSampling', TType::STRUCT, 4); - $xfer += $this->operationSampling->write($output); - $xfer += $output->writeFieldEnd(); + if ($this->operationSampling !== null) { + if (!is_object($this->operationSampling)) { + throw new TProtocolException('Bad type in structure.', TProtocolException::INVALID_DATA); + } + $xfer += $output->writeFieldBegin('operationSampling', TType::STRUCT, 4); + $xfer += $this->operationSampling->write($output); + $xfer += $output->writeFieldEnd(); + } + $xfer += $output->writeFieldStop(); + $xfer += $output->writeStructEnd(); + } finally { + $output->decrementRecursionDepth(); } - $xfer += $output->writeFieldStop(); - $xfer += $output->writeStructEnd(); + return $xfer; } } diff --git a/src/Thrift/Agent/SamplingStrategyType.php b/src/Thrift/Agent/SamplingStrategyType.php index 03978ec..dedb6cb 100644 --- a/src/Thrift/Agent/SamplingStrategyType.php +++ b/src/Thrift/Agent/SamplingStrategyType.php @@ -1,30 +1,34 @@ 'PROBABILISTIC', 1 => 'RATE_LIMITING', - ); + ]; } - diff --git a/src/Thrift/Agent/ServiceThrottlingConfig.php b/src/Thrift/Agent/ServiceThrottlingConfig.php deleted file mode 100644 index 29cf535..0000000 --- a/src/Thrift/Agent/ServiceThrottlingConfig.php +++ /dev/null @@ -1,123 +0,0 @@ - array( - 'var' => 'serviceName', - 'isRequired' => true, - 'type' => TType::STRING, - ), - 2 => array( - 'var' => 'config', - 'isRequired' => true, - 'type' => TType::STRUCT, - 'class' => '\Jaeger\Thrift\Agent\ThrottlingConfig', - ), - ); - - /** - * @var string - */ - public $serviceName = null; - /** - * @var \Jaeger\Thrift\Agent\ThrottlingConfig - */ - public $config = null; - - public function __construct($vals = null) - { - if (is_array($vals)) { - if (isset($vals['serviceName'])) { - $this->serviceName = $vals['serviceName']; - } - if (isset($vals['config'])) { - $this->config = $vals['config']; - } - } - } - - public function getName() - { - return 'ServiceThrottlingConfig'; - } - - - public function read($input) - { - $xfer = 0; - $fname = null; - $ftype = 0; - $fid = 0; - $xfer += $input->readStructBegin($fname); - while (true) { - $xfer += $input->readFieldBegin($fname, $ftype, $fid); - if ($ftype == TType::STOP) { - break; - } - switch ($fid) { - case 1: - if ($ftype == TType::STRING) { - $xfer += $input->readString($this->serviceName); - } else { - $xfer += $input->skip($ftype); - } - break; - case 2: - if ($ftype == TType::STRUCT) { - $this->config = new \Jaeger\Thrift\Agent\ThrottlingConfig(); - $xfer += $this->config->read($input); - } else { - $xfer += $input->skip($ftype); - } - break; - default: - $xfer += $input->skip($ftype); - break; - } - $xfer += $input->readFieldEnd(); - } - $xfer += $input->readStructEnd(); - return $xfer; - } - - public function write($output) - { - $xfer = 0; - $xfer += $output->writeStructBegin('ServiceThrottlingConfig'); - if ($this->serviceName !== null) { - $xfer += $output->writeFieldBegin('serviceName', TType::STRING, 1); - $xfer += $output->writeString($this->serviceName); - $xfer += $output->writeFieldEnd(); - } - if ($this->config !== null) { - if (!is_object($this->config)) { - throw new TProtocolException('Bad type in structure.', TProtocolException::INVALID_DATA); - } - $xfer += $output->writeFieldBegin('config', TType::STRUCT, 2); - $xfer += $this->config->write($output); - $xfer += $output->writeFieldEnd(); - } - $xfer += $output->writeFieldStop(); - $xfer += $output->writeStructEnd(); - return $xfer; - } -} diff --git a/src/Thrift/Agent/ThrottlingConfig.php b/src/Thrift/Agent/ThrottlingConfig.php deleted file mode 100644 index 5b563d4..0000000 --- a/src/Thrift/Agent/ThrottlingConfig.php +++ /dev/null @@ -1,142 +0,0 @@ - array( - 'var' => 'maxOperations', - 'isRequired' => true, - 'type' => TType::I32, - ), - 2 => array( - 'var' => 'creditsPerSecond', - 'isRequired' => true, - 'type' => TType::DOUBLE, - ), - 3 => array( - 'var' => 'maxBalance', - 'isRequired' => true, - 'type' => TType::DOUBLE, - ), - ); - - /** - * @var int - */ - public $maxOperations = null; - /** - * @var double - */ - public $creditsPerSecond = null; - /** - * @var double - */ - public $maxBalance = null; - - public function __construct($vals = null) - { - if (is_array($vals)) { - if (isset($vals['maxOperations'])) { - $this->maxOperations = $vals['maxOperations']; - } - if (isset($vals['creditsPerSecond'])) { - $this->creditsPerSecond = $vals['creditsPerSecond']; - } - if (isset($vals['maxBalance'])) { - $this->maxBalance = $vals['maxBalance']; - } - } - } - - public function getName() - { - return 'ThrottlingConfig'; - } - - - public function read($input) - { - $xfer = 0; - $fname = null; - $ftype = 0; - $fid = 0; - $xfer += $input->readStructBegin($fname); - while (true) { - $xfer += $input->readFieldBegin($fname, $ftype, $fid); - if ($ftype == TType::STOP) { - break; - } - switch ($fid) { - case 1: - if ($ftype == TType::I32) { - $xfer += $input->readI32($this->maxOperations); - } else { - $xfer += $input->skip($ftype); - } - break; - case 2: - if ($ftype == TType::DOUBLE) { - $xfer += $input->readDouble($this->creditsPerSecond); - } else { - $xfer += $input->skip($ftype); - } - break; - case 3: - if ($ftype == TType::DOUBLE) { - $xfer += $input->readDouble($this->maxBalance); - } else { - $xfer += $input->skip($ftype); - } - break; - default: - $xfer += $input->skip($ftype); - break; - } - $xfer += $input->readFieldEnd(); - } - $xfer += $input->readStructEnd(); - return $xfer; - } - - public function write($output) - { - $xfer = 0; - $xfer += $output->writeStructBegin('ThrottlingConfig'); - if ($this->maxOperations !== null) { - $xfer += $output->writeFieldBegin('maxOperations', TType::I32, 1); - $xfer += $output->writeI32($this->maxOperations); - $xfer += $output->writeFieldEnd(); - } - if ($this->creditsPerSecond !== null) { - $xfer += $output->writeFieldBegin('creditsPerSecond', TType::DOUBLE, 2); - $xfer += $output->writeDouble($this->creditsPerSecond); - $xfer += $output->writeFieldEnd(); - } - if ($this->maxBalance !== null) { - $xfer += $output->writeFieldBegin('maxBalance', TType::DOUBLE, 3); - $xfer += $output->writeDouble($this->maxBalance); - $xfer += $output->writeFieldEnd(); - } - $xfer += $output->writeFieldStop(); - $xfer += $output->writeStructEnd(); - return $xfer; - } -} diff --git a/src/Thrift/Agent/ThrottlingResponse.php b/src/Thrift/Agent/ThrottlingResponse.php deleted file mode 100644 index 0b0dbe9..0000000 --- a/src/Thrift/Agent/ThrottlingResponse.php +++ /dev/null @@ -1,145 +0,0 @@ - array( - 'var' => 'defaultConfig', - 'isRequired' => true, - 'type' => TType::STRUCT, - 'class' => '\Jaeger\Thrift\Agent\ThrottlingConfig', - ), - 2 => array( - 'var' => 'serviceConfigs', - 'isRequired' => true, - 'type' => TType::LST, - 'etype' => TType::STRUCT, - 'elem' => array( - 'type' => TType::STRUCT, - 'class' => '\Jaeger\Thrift\Agent\ServiceThrottlingConfig', - ), - ), - ); - - /** - * @var \Jaeger\Thrift\Agent\ThrottlingConfig - */ - public $defaultConfig = null; - /** - * @var \Jaeger\Thrift\Agent\ServiceThrottlingConfig[] - */ - public $serviceConfigs = null; - - public function __construct($vals = null) - { - if (is_array($vals)) { - if (isset($vals['defaultConfig'])) { - $this->defaultConfig = $vals['defaultConfig']; - } - if (isset($vals['serviceConfigs'])) { - $this->serviceConfigs = $vals['serviceConfigs']; - } - } - } - - public function getName() - { - return 'ThrottlingResponse'; - } - - - public function read($input) - { - $xfer = 0; - $fname = null; - $ftype = 0; - $fid = 0; - $xfer += $input->readStructBegin($fname); - while (true) { - $xfer += $input->readFieldBegin($fname, $ftype, $fid); - if ($ftype == TType::STOP) { - break; - } - switch ($fid) { - case 1: - if ($ftype == TType::STRUCT) { - $this->defaultConfig = new \Jaeger\Thrift\Agent\ThrottlingConfig(); - $xfer += $this->defaultConfig->read($input); - } else { - $xfer += $input->skip($ftype); - } - break; - case 2: - if ($ftype == TType::LST) { - $this->serviceConfigs = array(); - $_size0 = 0; - $_etype3 = 0; - $xfer += $input->readListBegin($_etype3, $_size0); - for ($_i4 = 0; $_i4 < $_size0; ++$_i4) { - $elem5 = null; - $elem5 = new \Jaeger\Thrift\Agent\ServiceThrottlingConfig(); - $xfer += $elem5->read($input); - $this->serviceConfigs []= $elem5; - } - $xfer += $input->readListEnd(); - } else { - $xfer += $input->skip($ftype); - } - break; - default: - $xfer += $input->skip($ftype); - break; - } - $xfer += $input->readFieldEnd(); - } - $xfer += $input->readStructEnd(); - return $xfer; - } - - public function write($output) - { - $xfer = 0; - $xfer += $output->writeStructBegin('ThrottlingResponse'); - if ($this->defaultConfig !== null) { - if (!is_object($this->defaultConfig)) { - throw new TProtocolException('Bad type in structure.', TProtocolException::INVALID_DATA); - } - $xfer += $output->writeFieldBegin('defaultConfig', TType::STRUCT, 1); - $xfer += $this->defaultConfig->write($output); - $xfer += $output->writeFieldEnd(); - } - if ($this->serviceConfigs !== null) { - if (!is_array($this->serviceConfigs)) { - throw new TProtocolException('Bad type in structure.', TProtocolException::INVALID_DATA); - } - $xfer += $output->writeFieldBegin('serviceConfigs', TType::LST, 2); - $output->writeListBegin(TType::STRUCT, count($this->serviceConfigs)); - foreach ($this->serviceConfigs as $iter6) { - $xfer += $iter6->write($output); - } - $output->writeListEnd(); - $xfer += $output->writeFieldEnd(); - } - $xfer += $output->writeFieldStop(); - $xfer += $output->writeStructEnd(); - return $xfer; - } -} diff --git a/src/Thrift/Agent/ThrottlingServiceClient.php b/src/Thrift/Agent/ThrottlingServiceClient.php deleted file mode 100644 index 5806151..0000000 --- a/src/Thrift/Agent/ThrottlingServiceClient.php +++ /dev/null @@ -1,91 +0,0 @@ -input_ = $input; - $this->output_ = $output ? $output : $input; - } - - - public function getThrottlingConfigs(array $serviceNames) - { - $this->send_getThrottlingConfigs($serviceNames); - return $this->recv_getThrottlingConfigs(); - } - - public function send_getThrottlingConfigs(array $serviceNames) - { - $args = new \Jaeger\Thrift\Agent\ThrottlingService_getThrottlingConfigs_args(); - $args->serviceNames = $serviceNames; - $bin_accel = ($this->output_ instanceof TBinaryProtocolAccelerated) && function_exists('thrift_protocol_write_binary'); - if ($bin_accel) { - thrift_protocol_write_binary( - $this->output_, - 'getThrottlingConfigs', - TMessageType::CALL, - $args, - $this->seqid_, - $this->output_->isStrictWrite() - ); - } else { - $this->output_->writeMessageBegin('getThrottlingConfigs', TMessageType::CALL, $this->seqid_); - $args->write($this->output_); - $this->output_->writeMessageEnd(); - $this->output_->getTransport()->flush(); - } - } - - public function recv_getThrottlingConfigs() - { - $bin_accel = ($this->input_ instanceof TBinaryProtocolAccelerated) && function_exists('thrift_protocol_read_binary'); - if ($bin_accel) { - $result = thrift_protocol_read_binary( - $this->input_, - '\Jaeger\Thrift\Agent\ThrottlingService_getThrottlingConfigs_result', - $this->input_->isStrictRead() - ); - } else { - $rseqid = 0; - $fname = null; - $mtype = 0; - - $this->input_->readMessageBegin($fname, $mtype, $rseqid); - if ($mtype == TMessageType::EXCEPTION) { - $x = new TApplicationException(); - $x->read($this->input_); - $this->input_->readMessageEnd(); - throw $x; - } - $result = new \Jaeger\Thrift\Agent\ThrottlingService_getThrottlingConfigs_result(); - $result->read($this->input_); - $this->input_->readMessageEnd(); - } - if ($result->success !== null) { - return $result->success; - } - throw new \Exception("getThrottlingConfigs failed: unknown result"); - } -} diff --git a/src/Thrift/Agent/ThrottlingServiceIf.php b/src/Thrift/Agent/ThrottlingServiceIf.php deleted file mode 100644 index 558d51e..0000000 --- a/src/Thrift/Agent/ThrottlingServiceIf.php +++ /dev/null @@ -1,26 +0,0 @@ - array( - 'var' => 'serviceNames', - 'isRequired' => false, - 'type' => TType::LST, - 'etype' => TType::STRING, - 'elem' => array( - 'type' => TType::STRING, - ), - ), - ); - - /** - * @var string[] - */ - public $serviceNames = null; - - public function __construct($vals = null) - { - if (is_array($vals)) { - if (isset($vals['serviceNames'])) { - $this->serviceNames = $vals['serviceNames']; - } - } - } - - public function getName() - { - return 'ThrottlingService_getThrottlingConfigs_args'; - } - - - public function read($input) - { - $xfer = 0; - $fname = null; - $ftype = 0; - $fid = 0; - $xfer += $input->readStructBegin($fname); - while (true) { - $xfer += $input->readFieldBegin($fname, $ftype, $fid); - if ($ftype == TType::STOP) { - break; - } - switch ($fid) { - case 1: - if ($ftype == TType::LST) { - $this->serviceNames = array(); - $_size7 = 0; - $_etype10 = 0; - $xfer += $input->readListBegin($_etype10, $_size7); - for ($_i11 = 0; $_i11 < $_size7; ++$_i11) { - $elem12 = null; - $xfer += $input->readString($elem12); - $this->serviceNames []= $elem12; - } - $xfer += $input->readListEnd(); - } else { - $xfer += $input->skip($ftype); - } - break; - default: - $xfer += $input->skip($ftype); - break; - } - $xfer += $input->readFieldEnd(); - } - $xfer += $input->readStructEnd(); - return $xfer; - } - - public function write($output) - { - $xfer = 0; - $xfer += $output->writeStructBegin('ThrottlingService_getThrottlingConfigs_args'); - if ($this->serviceNames !== null) { - if (!is_array($this->serviceNames)) { - throw new TProtocolException('Bad type in structure.', TProtocolException::INVALID_DATA); - } - $xfer += $output->writeFieldBegin('serviceNames', TType::LST, 1); - $output->writeListBegin(TType::STRING, count($this->serviceNames)); - foreach ($this->serviceNames as $iter13) { - $xfer += $output->writeString($iter13); - } - $output->writeListEnd(); - $xfer += $output->writeFieldEnd(); - } - $xfer += $output->writeFieldStop(); - $xfer += $output->writeStructEnd(); - return $xfer; - } -} diff --git a/src/Thrift/Agent/ThrottlingService_getThrottlingConfigs_result.php b/src/Thrift/Agent/ThrottlingService_getThrottlingConfigs_result.php deleted file mode 100644 index 33dad47..0000000 --- a/src/Thrift/Agent/ThrottlingService_getThrottlingConfigs_result.php +++ /dev/null @@ -1,99 +0,0 @@ - array( - 'var' => 'success', - 'isRequired' => false, - 'type' => TType::STRUCT, - 'class' => '\Jaeger\Thrift\Agent\ThrottlingResponse', - ), - ); - - /** - * @var \Jaeger\Thrift\Agent\ThrottlingResponse - */ - public $success = null; - - public function __construct($vals = null) - { - if (is_array($vals)) { - if (isset($vals['success'])) { - $this->success = $vals['success']; - } - } - } - - public function getName() - { - return 'ThrottlingService_getThrottlingConfigs_result'; - } - - - public function read($input) - { - $xfer = 0; - $fname = null; - $ftype = 0; - $fid = 0; - $xfer += $input->readStructBegin($fname); - while (true) { - $xfer += $input->readFieldBegin($fname, $ftype, $fid); - if ($ftype == TType::STOP) { - break; - } - switch ($fid) { - case 0: - if ($ftype == TType::STRUCT) { - $this->success = new \Jaeger\Thrift\Agent\ThrottlingResponse(); - $xfer += $this->success->read($input); - } else { - $xfer += $input->skip($ftype); - } - break; - default: - $xfer += $input->skip($ftype); - break; - } - $xfer += $input->readFieldEnd(); - } - $xfer += $input->readStructEnd(); - return $xfer; - } - - public function write($output) - { - $xfer = 0; - $xfer += $output->writeStructBegin('ThrottlingService_getThrottlingConfigs_result'); - if ($this->success !== null) { - if (!is_object($this->success)) { - throw new TProtocolException('Bad type in structure.', TProtocolException::INVALID_DATA); - } - $xfer += $output->writeFieldBegin('success', TType::STRUCT, 0); - $xfer += $this->success->write($output); - $xfer += $output->writeFieldEnd(); - } - $xfer += $output->writeFieldStop(); - $xfer += $output->writeStructEnd(); - return $xfer; - } -} diff --git a/src/Thrift/Agent/ValidateTraceResponse.php b/src/Thrift/Agent/ValidateTraceResponse.php deleted file mode 100644 index 58674c6..0000000 --- a/src/Thrift/Agent/ValidateTraceResponse.php +++ /dev/null @@ -1,118 +0,0 @@ - array( - 'var' => 'ok', - 'isRequired' => true, - 'type' => TType::BOOL, - ), - 2 => array( - 'var' => 'traceCount', - 'isRequired' => true, - 'type' => TType::I64, - ), - ); - - /** - * @var bool - */ - public $ok = null; - /** - * @var int - */ - public $traceCount = null; - - public function __construct($vals = null) - { - if (is_array($vals)) { - if (isset($vals['ok'])) { - $this->ok = $vals['ok']; - } - if (isset($vals['traceCount'])) { - $this->traceCount = $vals['traceCount']; - } - } - } - - public function getName() - { - return 'ValidateTraceResponse'; - } - - - public function read($input) - { - $xfer = 0; - $fname = null; - $ftype = 0; - $fid = 0; - $xfer += $input->readStructBegin($fname); - while (true) { - $xfer += $input->readFieldBegin($fname, $ftype, $fid); - if ($ftype == TType::STOP) { - break; - } - switch ($fid) { - case 1: - if ($ftype == TType::BOOL) { - $xfer += $input->readBool($this->ok); - } else { - $xfer += $input->skip($ftype); - } - break; - case 2: - if ($ftype == TType::I64) { - $xfer += $input->readI64($this->traceCount); - } else { - $xfer += $input->skip($ftype); - } - break; - default: - $xfer += $input->skip($ftype); - break; - } - $xfer += $input->readFieldEnd(); - } - $xfer += $input->readStructEnd(); - return $xfer; - } - - public function write($output) - { - $xfer = 0; - $xfer += $output->writeStructBegin('ValidateTraceResponse'); - if ($this->ok !== null) { - $xfer += $output->writeFieldBegin('ok', TType::BOOL, 1); - $xfer += $output->writeBool($this->ok); - $xfer += $output->writeFieldEnd(); - } - if ($this->traceCount !== null) { - $xfer += $output->writeFieldBegin('traceCount', TType::I64, 2); - $xfer += $output->writeI64($this->traceCount); - $xfer += $output->writeFieldEnd(); - } - $xfer += $output->writeFieldStop(); - $xfer += $output->writeStructEnd(); - return $xfer; - } -} diff --git a/src/Thrift/Agent/Zipkin/Annotation.php b/src/Thrift/Agent/Zipkin/Annotation.php index 8568bd8..0cb2059 100644 --- a/src/Thrift/Agent/Zipkin/Annotation.php +++ b/src/Thrift/Agent/Zipkin/Annotation.php @@ -1,18 +1,23 @@ array( + public static array $tspec = [ + 1 => [ 'var' => 'timestamp', 'isRequired' => false, 'type' => TType::I64, - ), - 2 => array( + ], + 2 => [ 'var' => 'value', 'isRequired' => false, 'type' => TType::STRING, - ), - 3 => array( + ], + 3 => [ 'var' => 'host', 'isRequired' => false, 'type' => TType::STRUCT, 'class' => '\Jaeger\Thrift\Agent\Zipkin\Endpoint', - ), - ); + ], + ]; /** * Microseconds from epoch. - * + * * This value should use the most precise value possible. For example, * gettimeofday or syncing nanoTime against a tick of currentTimeMillis. - * - * @var int + * */ - public $timestamp = null; - /** - * @var string - */ - public $value = null; + public ?int $timestamp = null; + public ?string $value = null; /** * Always the host that recorded the event. By specifying the host you allow * rollup of all events (such as client requests to a service) by IP address. - * - * @var \Jaeger\Thrift\Agent\Zipkin\Endpoint + * */ - public $host = null; + public ?Endpoint $host = null; - public function __construct($vals = null) + public function __construct(?array $vals = null) { if (is_array($vals)) { if (isset($vals['timestamp'])) { - $this->timestamp = $vals['timestamp']; + $this->timestamp = (int)$vals['timestamp']; } if (isset($vals['value'])) { - $this->value = $vals['value']; + $this->value = (string)$vals['value']; } if (isset($vals['host'])) { $this->host = $vals['host']; @@ -79,81 +79,92 @@ public function __construct($vals = null) } } - public function getName() + public function getName(): string { return 'Annotation'; } - - public function read($input) + public function read(TProtocol $input): int { $xfer = 0; $fname = null; $ftype = 0; $fid = 0; - $xfer += $input->readStructBegin($fname); - while (true) { - $xfer += $input->readFieldBegin($fname, $ftype, $fid); - if ($ftype == TType::STOP) { - break; - } - switch ($fid) { - case 1: - if ($ftype == TType::I64) { - $xfer += $input->readI64($this->timestamp); - } else { - $xfer += $input->skip($ftype); - } + $input->incrementRecursionDepth(); + try { + $xfer += $input->readStructBegin($fname); + while (true) { + $xfer += $input->readFieldBegin($fname, $ftype, $fid); + if ($ftype == TType::STOP) { break; - case 2: - if ($ftype == TType::STRING) { - $xfer += $input->readString($this->value); - } else { + } + switch ($fid) { + case 1: + if ($ftype == TType::I64) { + $xfer += $input->readI64($this->timestamp); + } else { + $xfer += $input->skip($ftype); + } + break; + case 2: + if ($ftype == TType::STRING) { + $xfer += $input->readString($this->value); + } else { + $xfer += $input->skip($ftype); + } + break; + case 3: + if ($ftype == TType::STRUCT) { + $this->host = new \Jaeger\Thrift\Agent\Zipkin\Endpoint(); + $xfer += $this->host->read($input); + } else { + $xfer += $input->skip($ftype); + } + break; + default: $xfer += $input->skip($ftype); - } - break; - case 3: - if ($ftype == TType::STRUCT) { - $this->host = new \Jaeger\Thrift\Agent\Zipkin\Endpoint(); - $xfer += $this->host->read($input); - } else { - $xfer += $input->skip($ftype); - } - break; - default: - $xfer += $input->skip($ftype); - break; + break; + } + $xfer += $input->readFieldEnd(); } - $xfer += $input->readFieldEnd(); + $xfer += $input->readStructEnd(); + } finally { + $input->decrementRecursionDepth(); } - $xfer += $input->readStructEnd(); + return $xfer; } - public function write($output) + public function write(TProtocol $output): int { $xfer = 0; - $xfer += $output->writeStructBegin('Annotation'); - if ($this->timestamp !== null) { - $xfer += $output->writeFieldBegin('timestamp', TType::I64, 1); - $xfer += $output->writeI64($this->timestamp); - $xfer += $output->writeFieldEnd(); - } - if ($this->value !== null) { - $xfer += $output->writeFieldBegin('value', TType::STRING, 2); - $xfer += $output->writeString($this->value); - $xfer += $output->writeFieldEnd(); - } - if ($this->host !== null) { - if (!is_object($this->host)) { - throw new TProtocolException('Bad type in structure.', TProtocolException::INVALID_DATA); + $output->incrementRecursionDepth(); + try { + $xfer += $output->writeStructBegin('Annotation'); + if ($this->timestamp !== null) { + $xfer += $output->writeFieldBegin('timestamp', TType::I64, 1); + $xfer += $output->writeI64($this->timestamp); + $xfer += $output->writeFieldEnd(); + } + if ($this->value !== null) { + $xfer += $output->writeFieldBegin('value', TType::STRING, 2); + $xfer += $output->writeString($this->value); + $xfer += $output->writeFieldEnd(); } - $xfer += $output->writeFieldBegin('host', TType::STRUCT, 3); - $xfer += $this->host->write($output); - $xfer += $output->writeFieldEnd(); + if ($this->host !== null) { + if (!is_object($this->host)) { + throw new TProtocolException('Bad type in structure.', TProtocolException::INVALID_DATA); + } + $xfer += $output->writeFieldBegin('host', TType::STRUCT, 3); + $xfer += $this->host->write($output); + $xfer += $output->writeFieldEnd(); + } + $xfer += $output->writeFieldStop(); + $xfer += $output->writeStructEnd(); + } finally { + $output->decrementRecursionDepth(); } - $xfer += $output->writeFieldStop(); - $xfer += $output->writeStructEnd(); + return $xfer; } } diff --git a/src/Thrift/Agent/Zipkin/AnnotationType.php b/src/Thrift/Agent/Zipkin/AnnotationType.php index 6a5058a..78faff9 100644 --- a/src/Thrift/Agent/Zipkin/AnnotationType.php +++ b/src/Thrift/Agent/Zipkin/AnnotationType.php @@ -1,38 +1,43 @@ 'BOOL', 1 => 'BYTES', 2 => 'I16', @@ -40,6 +45,5 @@ final class AnnotationType 4 => 'I64', 5 => 'DOUBLE', 6 => 'STRING', - ); + ]; } - diff --git a/src/Thrift/Agent/Zipkin/BinaryAnnotation.php b/src/Thrift/Agent/Zipkin/BinaryAnnotation.php index 64cb0f4..77d30ae 100644 --- a/src/Thrift/Agent/Zipkin/BinaryAnnotation.php +++ b/src/Thrift/Agent/Zipkin/BinaryAnnotation.php @@ -1,18 +1,23 @@ array( + public static array $tspec = [ + 1 => [ 'var' => 'key', 'isRequired' => false, 'type' => TType::STRING, - ), - 2 => array( + ], + 2 => [ 'var' => 'value', 'isRequired' => false, 'type' => TType::STRING, - ), - 3 => array( + ], + 3 => [ 'var' => 'annotation_type', 'isRequired' => false, 'type' => TType::I32, 'class' => '\Jaeger\Thrift\Agent\Zipkin\AnnotationType', - ), - 4 => array( + ], + 4 => [ 'var' => 'host', 'isRequired' => false, 'type' => TType::STRUCT, 'class' => '\Jaeger\Thrift\Agent\Zipkin\Endpoint', - ), - ); + ], + ]; - /** - * @var string - */ - public $key = null; - /** - * @var string - */ - public $value = null; - /** - * @var int - */ - public $annotation_type = null; + public ?string $key = null; + public ?string $value = null; + public ?int $annotation_type = null; /** * The host that recorded tag, which allows you to differentiate between * multiple tags with the same key. There are two exceptions to this. - * + * * When the key is CLIENT_ADDR or SERVER_ADDR, host indicates the source or * destination of an RPC. This exception allows zipkin to display network * context of uninstrumented services, or clients such as web browsers. - * - * @var \Jaeger\Thrift\Agent\Zipkin\Endpoint + * */ - public $host = null; + public ?Endpoint $host = null; - public function __construct($vals = null) + public function __construct(?array $vals = null) { if (is_array($vals)) { if (isset($vals['key'])) { - $this->key = $vals['key']; + $this->key = (string)$vals['key']; } if (isset($vals['value'])) { - $this->value = $vals['value']; + $this->value = (string)$vals['value']; } if (isset($vals['annotation_type'])) { - $this->annotation_type = $vals['annotation_type']; + $this->annotation_type = (int)$vals['annotation_type']; } if (isset($vals['host'])) { $this->host = $vals['host']; @@ -102,93 +97,104 @@ public function __construct($vals = null) } } - public function getName() + public function getName(): string { return 'BinaryAnnotation'; } - - public function read($input) + public function read(TProtocol $input): int { $xfer = 0; $fname = null; $ftype = 0; $fid = 0; - $xfer += $input->readStructBegin($fname); - while (true) { - $xfer += $input->readFieldBegin($fname, $ftype, $fid); - if ($ftype == TType::STOP) { - break; - } - switch ($fid) { - case 1: - if ($ftype == TType::STRING) { - $xfer += $input->readString($this->key); - } else { - $xfer += $input->skip($ftype); - } - break; - case 2: - if ($ftype == TType::STRING) { - $xfer += $input->readString($this->value); - } else { - $xfer += $input->skip($ftype); - } - break; - case 3: - if ($ftype == TType::I32) { - $xfer += $input->readI32($this->annotation_type); - } else { - $xfer += $input->skip($ftype); - } + $input->incrementRecursionDepth(); + try { + $xfer += $input->readStructBegin($fname); + while (true) { + $xfer += $input->readFieldBegin($fname, $ftype, $fid); + if ($ftype == TType::STOP) { break; - case 4: - if ($ftype == TType::STRUCT) { - $this->host = new \Jaeger\Thrift\Agent\Zipkin\Endpoint(); - $xfer += $this->host->read($input); - } else { + } + switch ($fid) { + case 1: + if ($ftype == TType::STRING) { + $xfer += $input->readString($this->key); + } else { + $xfer += $input->skip($ftype); + } + break; + case 2: + if ($ftype == TType::STRING) { + $xfer += $input->readString($this->value); + } else { + $xfer += $input->skip($ftype); + } + break; + case 3: + if ($ftype == TType::I32) { + $xfer += $input->readI32($this->annotation_type); + } else { + $xfer += $input->skip($ftype); + } + break; + case 4: + if ($ftype == TType::STRUCT) { + $this->host = new \Jaeger\Thrift\Agent\Zipkin\Endpoint(); + $xfer += $this->host->read($input); + } else { + $xfer += $input->skip($ftype); + } + break; + default: $xfer += $input->skip($ftype); - } - break; - default: - $xfer += $input->skip($ftype); - break; + break; + } + $xfer += $input->readFieldEnd(); } - $xfer += $input->readFieldEnd(); + $xfer += $input->readStructEnd(); + } finally { + $input->decrementRecursionDepth(); } - $xfer += $input->readStructEnd(); + return $xfer; } - public function write($output) + public function write(TProtocol $output): int { $xfer = 0; - $xfer += $output->writeStructBegin('BinaryAnnotation'); - if ($this->key !== null) { - $xfer += $output->writeFieldBegin('key', TType::STRING, 1); - $xfer += $output->writeString($this->key); - $xfer += $output->writeFieldEnd(); - } - if ($this->value !== null) { - $xfer += $output->writeFieldBegin('value', TType::STRING, 2); - $xfer += $output->writeString($this->value); - $xfer += $output->writeFieldEnd(); - } - if ($this->annotation_type !== null) { - $xfer += $output->writeFieldBegin('annotation_type', TType::I32, 3); - $xfer += $output->writeI32($this->annotation_type); - $xfer += $output->writeFieldEnd(); - } - if ($this->host !== null) { - if (!is_object($this->host)) { - throw new TProtocolException('Bad type in structure.', TProtocolException::INVALID_DATA); + $output->incrementRecursionDepth(); + try { + $xfer += $output->writeStructBegin('BinaryAnnotation'); + if ($this->key !== null) { + $xfer += $output->writeFieldBegin('key', TType::STRING, 1); + $xfer += $output->writeString($this->key); + $xfer += $output->writeFieldEnd(); + } + if ($this->value !== null) { + $xfer += $output->writeFieldBegin('value', TType::STRING, 2); + $xfer += $output->writeString($this->value); + $xfer += $output->writeFieldEnd(); } - $xfer += $output->writeFieldBegin('host', TType::STRUCT, 4); - $xfer += $this->host->write($output); - $xfer += $output->writeFieldEnd(); + if ($this->annotation_type !== null) { + $xfer += $output->writeFieldBegin('annotation_type', TType::I32, 3); + $xfer += $output->writeI32($this->annotation_type); + $xfer += $output->writeFieldEnd(); + } + if ($this->host !== null) { + if (!is_object($this->host)) { + throw new TProtocolException('Bad type in structure.', TProtocolException::INVALID_DATA); + } + $xfer += $output->writeFieldBegin('host', TType::STRUCT, 4); + $xfer += $this->host->write($output); + $xfer += $output->writeFieldEnd(); + } + $xfer += $output->writeFieldStop(); + $xfer += $output->writeStructEnd(); + } finally { + $output->decrementRecursionDepth(); } - $xfer += $output->writeFieldStop(); - $xfer += $output->writeStructEnd(); + return $xfer; } } diff --git a/src/Thrift/Agent/Zipkin/Constant.php b/src/Thrift/Agent/Zipkin/Constant.php index 9a9b3a1..4872250 100644 --- a/src/Thrift/Agent/Zipkin/Constant.php +++ b/src/Thrift/Agent/Zipkin/Constant.php @@ -1,39 +1,46 @@ array( + public static array $tspec = [ + 1 => [ 'var' => 'ipv4', 'isRequired' => false, 'type' => TType::I32, - ), - 2 => array( + ], + 2 => [ 'var' => 'port', 'isRequired' => false, 'type' => TType::I16, - ), - 3 => array( + ], + 3 => [ 'var' => 'service_name', 'isRequired' => false, 'type' => TType::STRING, - ), - 4 => array( + ], + 4 => [ 'var' => 'ipv6', 'isRequired' => false, 'type' => TType::STRING, - ), - ); + ], + ]; /** * IPv4 host address packed into 4 bytes. - * + * * Ex for the ip 1.2.3.4, it would be (1 << 24) | (2 << 16) | (3 << 8) | 4 - * - * @var int + * */ - public $ipv4 = null; + public ?int $ipv4 = null; /** * IPv4 port - * + * * Note: this is to be treated as an unsigned integer, so watch for negatives. - * + * * Conventionally, when the port isn't known, port = 0. - * - * @var int + * */ - public $port = null; + public ?int $port = null; /** * Service name in lowercase, such as "memcache" or "zipkin-web" - * + * * Conventionally, when the service name isn't known, service_name = "unknown". - * - * @var string + * */ - public $service_name = null; + public ?string $service_name = null; /** * IPv6 host address packed into 16 bytes. Ex Inet6Address.getBytes() - * - * @var string + * */ - public $ipv6 = null; + public ?string $ipv6 = null; - public function __construct($vals = null) + public function __construct(?array $vals = null) { if (is_array($vals)) { if (isset($vals['ipv4'])) { - $this->ipv4 = $vals['ipv4']; + $this->ipv4 = (int)$vals['ipv4']; } if (isset($vals['port'])) { - $this->port = $vals['port']; + $this->port = (int)$vals['port']; } if (isset($vals['service_name'])) { - $this->service_name = $vals['service_name']; + $this->service_name = (string)$vals['service_name']; } if (isset($vals['ipv6'])) { - $this->ipv6 = $vals['ipv6']; + $this->ipv6 = (string)$vals['ipv6']; } } } - public function getName() + public function getName(): string { return 'Endpoint'; } - - public function read($input) + public function read(TProtocol $input): int { $xfer = 0; $fname = null; $ftype = 0; $fid = 0; - $xfer += $input->readStructBegin($fname); - while (true) { - $xfer += $input->readFieldBegin($fname, $ftype, $fid); - if ($ftype == TType::STOP) { - break; - } - switch ($fid) { - case 1: - if ($ftype == TType::I32) { - $xfer += $input->readI32($this->ipv4); - } else { - $xfer += $input->skip($ftype); - } - break; - case 2: - if ($ftype == TType::I16) { - $xfer += $input->readI16($this->port); - } else { - $xfer += $input->skip($ftype); - } - break; - case 3: - if ($ftype == TType::STRING) { - $xfer += $input->readString($this->service_name); - } else { - $xfer += $input->skip($ftype); - } + $input->incrementRecursionDepth(); + try { + $xfer += $input->readStructBegin($fname); + while (true) { + $xfer += $input->readFieldBegin($fname, $ftype, $fid); + if ($ftype == TType::STOP) { break; - case 4: - if ($ftype == TType::STRING) { - $xfer += $input->readString($this->ipv6); - } else { + } + switch ($fid) { + case 1: + if ($ftype == TType::I32) { + $xfer += $input->readI32($this->ipv4); + } else { + $xfer += $input->skip($ftype); + } + break; + case 2: + if ($ftype == TType::I16) { + $xfer += $input->readI16($this->port); + } else { + $xfer += $input->skip($ftype); + } + break; + case 3: + if ($ftype == TType::STRING) { + $xfer += $input->readString($this->service_name); + } else { + $xfer += $input->skip($ftype); + } + break; + case 4: + if ($ftype == TType::STRING) { + $xfer += $input->readString($this->ipv6); + } else { + $xfer += $input->skip($ftype); + } + break; + default: $xfer += $input->skip($ftype); - } - break; - default: - $xfer += $input->skip($ftype); - break; + break; + } + $xfer += $input->readFieldEnd(); } - $xfer += $input->readFieldEnd(); + $xfer += $input->readStructEnd(); + } finally { + $input->decrementRecursionDepth(); } - $xfer += $input->readStructEnd(); + return $xfer; } - public function write($output) + public function write(TProtocol $output): int { $xfer = 0; - $xfer += $output->writeStructBegin('Endpoint'); - if ($this->ipv4 !== null) { - $xfer += $output->writeFieldBegin('ipv4', TType::I32, 1); - $xfer += $output->writeI32($this->ipv4); - $xfer += $output->writeFieldEnd(); - } - if ($this->port !== null) { - $xfer += $output->writeFieldBegin('port', TType::I16, 2); - $xfer += $output->writeI16($this->port); - $xfer += $output->writeFieldEnd(); - } - if ($this->service_name !== null) { - $xfer += $output->writeFieldBegin('service_name', TType::STRING, 3); - $xfer += $output->writeString($this->service_name); - $xfer += $output->writeFieldEnd(); - } - if ($this->ipv6 !== null) { - $xfer += $output->writeFieldBegin('ipv6', TType::STRING, 4); - $xfer += $output->writeString($this->ipv6); - $xfer += $output->writeFieldEnd(); + $output->incrementRecursionDepth(); + try { + $xfer += $output->writeStructBegin('Endpoint'); + if ($this->ipv4 !== null) { + $xfer += $output->writeFieldBegin('ipv4', TType::I32, 1); + $xfer += $output->writeI32($this->ipv4); + $xfer += $output->writeFieldEnd(); + } + if ($this->port !== null) { + $xfer += $output->writeFieldBegin('port', TType::I16, 2); + $xfer += $output->writeI16($this->port); + $xfer += $output->writeFieldEnd(); + } + if ($this->service_name !== null) { + $xfer += $output->writeFieldBegin('service_name', TType::STRING, 3); + $xfer += $output->writeString($this->service_name); + $xfer += $output->writeFieldEnd(); + } + if ($this->ipv6 !== null) { + $xfer += $output->writeFieldBegin('ipv6', TType::STRING, 4); + $xfer += $output->writeString($this->ipv6); + $xfer += $output->writeFieldEnd(); + } + $xfer += $output->writeFieldStop(); + $xfer += $output->writeStructEnd(); + } finally { + $output->decrementRecursionDepth(); } - $xfer += $output->writeFieldStop(); - $xfer += $output->writeStructEnd(); + return $xfer; } } diff --git a/src/Thrift/Agent/Zipkin/Response.php b/src/Thrift/Agent/Zipkin/Response.php index 8823592..99cd7dc 100644 --- a/src/Thrift/Agent/Zipkin/Response.php +++ b/src/Thrift/Agent/Zipkin/Response.php @@ -1,94 +1,107 @@ array( + public static array $tspec = [ + 1 => [ 'var' => 'ok', 'isRequired' => true, 'type' => TType::BOOL, - ), - ); + ], + ]; - /** - * @var bool - */ - public $ok = null; + public ?bool $ok = null; - public function __construct($vals = null) + public function __construct(?array $vals = null) { if (is_array($vals)) { if (isset($vals['ok'])) { - $this->ok = $vals['ok']; + $this->ok = (bool)$vals['ok']; } } } - public function getName() + public function getName(): string { return 'Response'; } - - public function read($input) + public function read(TProtocol $input): int { $xfer = 0; $fname = null; $ftype = 0; $fid = 0; - $xfer += $input->readStructBegin($fname); - while (true) { - $xfer += $input->readFieldBegin($fname, $ftype, $fid); - if ($ftype == TType::STOP) { - break; - } - switch ($fid) { - case 1: - if ($ftype == TType::BOOL) { - $xfer += $input->readBool($this->ok); - } else { - $xfer += $input->skip($ftype); - } - break; - default: - $xfer += $input->skip($ftype); + $input->incrementRecursionDepth(); + try { + $xfer += $input->readStructBegin($fname); + while (true) { + $xfer += $input->readFieldBegin($fname, $ftype, $fid); + if ($ftype == TType::STOP) { break; + } + switch ($fid) { + case 1: + if ($ftype == TType::BOOL) { + $xfer += $input->readBool($this->ok); + } else { + $xfer += $input->skip($ftype); + } + break; + default: + $xfer += $input->skip($ftype); + break; + } + $xfer += $input->readFieldEnd(); } - $xfer += $input->readFieldEnd(); + $xfer += $input->readStructEnd(); + } finally { + $input->decrementRecursionDepth(); } - $xfer += $input->readStructEnd(); + return $xfer; } - public function write($output) + public function write(TProtocol $output): int { $xfer = 0; - $xfer += $output->writeStructBegin('Response'); - if ($this->ok !== null) { - $xfer += $output->writeFieldBegin('ok', TType::BOOL, 1); - $xfer += $output->writeBool($this->ok); - $xfer += $output->writeFieldEnd(); + $output->incrementRecursionDepth(); + try { + $xfer += $output->writeStructBegin('Response'); + if ($this->ok !== null) { + $xfer += $output->writeFieldBegin('ok', TType::BOOL, 1); + $xfer += $output->writeBool($this->ok); + $xfer += $output->writeFieldEnd(); + } + $xfer += $output->writeFieldStop(); + $xfer += $output->writeStructEnd(); + } finally { + $output->decrementRecursionDepth(); } - $xfer += $output->writeFieldStop(); - $xfer += $output->writeStructEnd(); + return $xfer; } } diff --git a/src/Thrift/Agent/Zipkin/Span.php b/src/Thrift/Agent/Zipkin/Span.php index 9ecd1ca..823537d 100644 --- a/src/Thrift/Agent/Zipkin/Span.php +++ b/src/Thrift/Agent/Zipkin/Span.php @@ -1,186 +1,175 @@ array( + public static array $tspec = [ + 1 => [ 'var' => 'trace_id', 'isRequired' => false, 'type' => TType::I64, - ), - 3 => array( + ], + 3 => [ 'var' => 'name', 'isRequired' => false, 'type' => TType::STRING, - ), - 4 => array( + ], + 4 => [ 'var' => 'id', 'isRequired' => false, 'type' => TType::I64, - ), - 5 => array( + ], + 5 => [ 'var' => 'parent_id', 'isRequired' => false, 'type' => TType::I64, - ), - 6 => array( + ], + 6 => [ 'var' => 'annotations', 'isRequired' => false, 'type' => TType::LST, 'etype' => TType::STRUCT, - 'elem' => array( + 'elem' => [ 'type' => TType::STRUCT, 'class' => '\Jaeger\Thrift\Agent\Zipkin\Annotation', - ), - ), - 8 => array( + ], + ], + 8 => [ 'var' => 'binary_annotations', 'isRequired' => false, 'type' => TType::LST, 'etype' => TType::STRUCT, - 'elem' => array( + 'elem' => [ 'type' => TType::STRUCT, 'class' => '\Jaeger\Thrift\Agent\Zipkin\BinaryAnnotation', - ), - ), - 9 => array( + ], + ], + 9 => [ 'var' => 'debug', 'isRequired' => false, 'type' => TType::BOOL, - ), - 10 => array( + ], + 10 => [ 'var' => 'timestamp', 'isRequired' => false, 'type' => TType::I64, - ), - 11 => array( + ], + 11 => [ 'var' => 'duration', 'isRequired' => false, 'type' => TType::I64, - ), - 12 => array( + ], + 12 => [ 'var' => 'trace_id_high', 'isRequired' => false, 'type' => TType::I64, - ), - ); + ], + ]; - /** - * @var int - */ - public $trace_id = null; + public ?int $trace_id = null; /** * Span name in lowercase, rpc method for example - * + * * Conventionally, when the span name isn't known, name = "unknown". - * - * @var string + * */ - public $name = null; - /** - * @var int - */ - public $id = null; - /** - * @var int - */ - public $parent_id = null; + public ?string $name = null; + public ?int $id = null; + public ?int $parent_id = null; /** * @var \Jaeger\Thrift\Agent\Zipkin\Annotation[] */ - public $annotations = null; + public ?array $annotations = null; /** * @var \Jaeger\Thrift\Agent\Zipkin\BinaryAnnotation[] */ - public $binary_annotations = null; - /** - * @var bool - */ - public $debug = false; + public ?array $binary_annotations = null; + public ?bool $debug = false; /** * Microseconds from epoch of the creation of this span. - * + * * This value should be set directly by instrumentation, using the most * precise value possible. For example, gettimeofday or syncing nanoTime * against a tick of currentTimeMillis. - * + * * For compatibility with instrumentation that precede this field, collectors * or span stores can derive this via Annotation.timestamp. * For example, SERVER_RECV.timestamp or CLIENT_SEND.timestamp. - * + * * This field is optional for compatibility with old data: first-party span * stores are expected to support this at time of introduction. - * - * @var int + * */ - public $timestamp = null; + public ?int $timestamp = null; /** * Measurement of duration in microseconds, used to support queries. - * + * * This value should be set directly, where possible. Doing so encourages * precise measurement decoupled from problems of clocks, such as skew or NTP * updates causing time to move backwards. - * + * * For compatibility with instrumentation that precede this field, collectors * or span stores can derive this by subtracting Annotation.timestamp. * For example, SERVER_SEND.timestamp - SERVER_RECV.timestamp. - * + * * If this field is persisted as unset, zipkin will continue to work, except * duration query support will be implementation-specific. Similarly, setting * this field non-atomically is implementation-specific. - * + * * This field is i64 vs i32 to support spans longer than 35 minutes. - * - * @var int + * */ - public $duration = null; + public ?int $duration = null; /** * Optional unique 8-byte additional identifier for a trace. If non zero, this * means the trace uses 128 bit traceIds instead of 64 bit. - * - * @var int + * */ - public $trace_id_high = null; + public ?int $trace_id_high = null; - public function __construct($vals = null) + public function __construct(?array $vals = null) { if (is_array($vals)) { if (isset($vals['trace_id'])) { - $this->trace_id = $vals['trace_id']; + $this->trace_id = (int)$vals['trace_id']; } if (isset($vals['name'])) { - $this->name = $vals['name']; + $this->name = (string)$vals['name']; } if (isset($vals['id'])) { - $this->id = $vals['id']; + $this->id = (int)$vals['id']; } if (isset($vals['parent_id'])) { - $this->parent_id = $vals['parent_id']; + $this->parent_id = (int)$vals['parent_id']; } if (isset($vals['annotations'])) { $this->annotations = $vals['annotations']; @@ -189,209 +178,220 @@ public function __construct($vals = null) $this->binary_annotations = $vals['binary_annotations']; } if (isset($vals['debug'])) { - $this->debug = $vals['debug']; + $this->debug = (bool)$vals['debug']; } if (isset($vals['timestamp'])) { - $this->timestamp = $vals['timestamp']; + $this->timestamp = (int)$vals['timestamp']; } if (isset($vals['duration'])) { - $this->duration = $vals['duration']; + $this->duration = (int)$vals['duration']; } if (isset($vals['trace_id_high'])) { - $this->trace_id_high = $vals['trace_id_high']; + $this->trace_id_high = (int)$vals['trace_id_high']; } } } - public function getName() + public function getName(): string { return 'Span'; } - - public function read($input) + public function read(TProtocol $input): int { $xfer = 0; $fname = null; $ftype = 0; $fid = 0; - $xfer += $input->readStructBegin($fname); - while (true) { - $xfer += $input->readFieldBegin($fname, $ftype, $fid); - if ($ftype == TType::STOP) { - break; - } - switch ($fid) { - case 1: - if ($ftype == TType::I64) { - $xfer += $input->readI64($this->trace_id); - } else { - $xfer += $input->skip($ftype); - } - break; - case 3: - if ($ftype == TType::STRING) { - $xfer += $input->readString($this->name); - } else { - $xfer += $input->skip($ftype); - } - break; - case 4: - if ($ftype == TType::I64) { - $xfer += $input->readI64($this->id); - } else { - $xfer += $input->skip($ftype); - } - break; - case 5: - if ($ftype == TType::I64) { - $xfer += $input->readI64($this->parent_id); - } else { - $xfer += $input->skip($ftype); - } + $input->incrementRecursionDepth(); + try { + $xfer += $input->readStructBegin($fname); + while (true) { + $xfer += $input->readFieldBegin($fname, $ftype, $fid); + if ($ftype == TType::STOP) { break; - case 6: - if ($ftype == TType::LST) { - $this->annotations = array(); - $_size0 = 0; - $_etype3 = 0; - $xfer += $input->readListBegin($_etype3, $_size0); - for ($_i4 = 0; $_i4 < $_size0; ++$_i4) { - $elem5 = null; - $elem5 = new \Jaeger\Thrift\Agent\Zipkin\Annotation(); - $xfer += $elem5->read($input); - $this->annotations []= $elem5; + } + switch ($fid) { + case 1: + if ($ftype == TType::I64) { + $xfer += $input->readI64($this->trace_id); + } else { + $xfer += $input->skip($ftype); } - $xfer += $input->readListEnd(); - } else { - $xfer += $input->skip($ftype); - } - break; - case 8: - if ($ftype == TType::LST) { - $this->binary_annotations = array(); - $_size6 = 0; - $_etype9 = 0; - $xfer += $input->readListBegin($_etype9, $_size6); - for ($_i10 = 0; $_i10 < $_size6; ++$_i10) { - $elem11 = null; - $elem11 = new \Jaeger\Thrift\Agent\Zipkin\BinaryAnnotation(); - $xfer += $elem11->read($input); - $this->binary_annotations []= $elem11; + break; + case 3: + if ($ftype == TType::STRING) { + $xfer += $input->readString($this->name); + } else { + $xfer += $input->skip($ftype); } - $xfer += $input->readListEnd(); - } else { - $xfer += $input->skip($ftype); - } - break; - case 9: - if ($ftype == TType::BOOL) { - $xfer += $input->readBool($this->debug); - } else { - $xfer += $input->skip($ftype); - } - break; - case 10: - if ($ftype == TType::I64) { - $xfer += $input->readI64($this->timestamp); - } else { - $xfer += $input->skip($ftype); - } - break; - case 11: - if ($ftype == TType::I64) { - $xfer += $input->readI64($this->duration); - } else { - $xfer += $input->skip($ftype); - } - break; - case 12: - if ($ftype == TType::I64) { - $xfer += $input->readI64($this->trace_id_high); - } else { + break; + case 4: + if ($ftype == TType::I64) { + $xfer += $input->readI64($this->id); + } else { + $xfer += $input->skip($ftype); + } + break; + case 5: + if ($ftype == TType::I64) { + $xfer += $input->readI64($this->parent_id); + } else { + $xfer += $input->skip($ftype); + } + break; + case 6: + if ($ftype == TType::LST) { + $this->annotations = []; + $_size0 = 0; + $_etype3 = 0; + $xfer += $input->readListBegin($_etype3, $_size0); + for ($_i4 = 0; $_i4 < $_size0; ++$_i4) { + $elem5 = null; + $elem5 = new \Jaeger\Thrift\Agent\Zipkin\Annotation(); + $xfer += $elem5->read($input); + $this->annotations[] = $elem5; + } + $xfer += $input->readListEnd(); + } else { + $xfer += $input->skip($ftype); + } + break; + case 8: + if ($ftype == TType::LST) { + $this->binary_annotations = []; + $_size6 = 0; + $_etype9 = 0; + $xfer += $input->readListBegin($_etype9, $_size6); + for ($_i10 = 0; $_i10 < $_size6; ++$_i10) { + $elem11 = null; + $elem11 = new \Jaeger\Thrift\Agent\Zipkin\BinaryAnnotation(); + $xfer += $elem11->read($input); + $this->binary_annotations[] = $elem11; + } + $xfer += $input->readListEnd(); + } else { + $xfer += $input->skip($ftype); + } + break; + case 9: + if ($ftype == TType::BOOL) { + $xfer += $input->readBool($this->debug); + } else { + $xfer += $input->skip($ftype); + } + break; + case 10: + if ($ftype == TType::I64) { + $xfer += $input->readI64($this->timestamp); + } else { + $xfer += $input->skip($ftype); + } + break; + case 11: + if ($ftype == TType::I64) { + $xfer += $input->readI64($this->duration); + } else { + $xfer += $input->skip($ftype); + } + break; + case 12: + if ($ftype == TType::I64) { + $xfer += $input->readI64($this->trace_id_high); + } else { + $xfer += $input->skip($ftype); + } + break; + default: $xfer += $input->skip($ftype); - } - break; - default: - $xfer += $input->skip($ftype); - break; + break; + } + $xfer += $input->readFieldEnd(); } - $xfer += $input->readFieldEnd(); + $xfer += $input->readStructEnd(); + } finally { + $input->decrementRecursionDepth(); } - $xfer += $input->readStructEnd(); + return $xfer; } - public function write($output) + public function write(TProtocol $output): int { $xfer = 0; - $xfer += $output->writeStructBegin('Span'); - if ($this->trace_id !== null) { - $xfer += $output->writeFieldBegin('trace_id', TType::I64, 1); - $xfer += $output->writeI64($this->trace_id); - $xfer += $output->writeFieldEnd(); - } - if ($this->name !== null) { - $xfer += $output->writeFieldBegin('name', TType::STRING, 3); - $xfer += $output->writeString($this->name); - $xfer += $output->writeFieldEnd(); - } - if ($this->id !== null) { - $xfer += $output->writeFieldBegin('id', TType::I64, 4); - $xfer += $output->writeI64($this->id); - $xfer += $output->writeFieldEnd(); - } - if ($this->parent_id !== null) { - $xfer += $output->writeFieldBegin('parent_id', TType::I64, 5); - $xfer += $output->writeI64($this->parent_id); - $xfer += $output->writeFieldEnd(); - } - if ($this->annotations !== null) { - if (!is_array($this->annotations)) { - throw new TProtocolException('Bad type in structure.', TProtocolException::INVALID_DATA); + $output->incrementRecursionDepth(); + try { + $xfer += $output->writeStructBegin('Span'); + if ($this->trace_id !== null) { + $xfer += $output->writeFieldBegin('trace_id', TType::I64, 1); + $xfer += $output->writeI64($this->trace_id); + $xfer += $output->writeFieldEnd(); } - $xfer += $output->writeFieldBegin('annotations', TType::LST, 6); - $output->writeListBegin(TType::STRUCT, count($this->annotations)); - foreach ($this->annotations as $iter12) { - $xfer += $iter12->write($output); + if ($this->name !== null) { + $xfer += $output->writeFieldBegin('name', TType::STRING, 3); + $xfer += $output->writeString($this->name); + $xfer += $output->writeFieldEnd(); } - $output->writeListEnd(); - $xfer += $output->writeFieldEnd(); - } - if ($this->binary_annotations !== null) { - if (!is_array($this->binary_annotations)) { - throw new TProtocolException('Bad type in structure.', TProtocolException::INVALID_DATA); + if ($this->id !== null) { + $xfer += $output->writeFieldBegin('id', TType::I64, 4); + $xfer += $output->writeI64($this->id); + $xfer += $output->writeFieldEnd(); } - $xfer += $output->writeFieldBegin('binary_annotations', TType::LST, 8); - $output->writeListBegin(TType::STRUCT, count($this->binary_annotations)); - foreach ($this->binary_annotations as $iter13) { - $xfer += $iter13->write($output); + if ($this->parent_id !== null) { + $xfer += $output->writeFieldBegin('parent_id', TType::I64, 5); + $xfer += $output->writeI64($this->parent_id); + $xfer += $output->writeFieldEnd(); } - $output->writeListEnd(); - $xfer += $output->writeFieldEnd(); - } - if ($this->debug !== null) { - $xfer += $output->writeFieldBegin('debug', TType::BOOL, 9); - $xfer += $output->writeBool($this->debug); - $xfer += $output->writeFieldEnd(); - } - if ($this->timestamp !== null) { - $xfer += $output->writeFieldBegin('timestamp', TType::I64, 10); - $xfer += $output->writeI64($this->timestamp); - $xfer += $output->writeFieldEnd(); - } - if ($this->duration !== null) { - $xfer += $output->writeFieldBegin('duration', TType::I64, 11); - $xfer += $output->writeI64($this->duration); - $xfer += $output->writeFieldEnd(); - } - if ($this->trace_id_high !== null) { - $xfer += $output->writeFieldBegin('trace_id_high', TType::I64, 12); - $xfer += $output->writeI64($this->trace_id_high); - $xfer += $output->writeFieldEnd(); + if ($this->annotations !== null) { + if (!is_array($this->annotations)) { + throw new TProtocolException('Bad type in structure.', TProtocolException::INVALID_DATA); + } + $xfer += $output->writeFieldBegin('annotations', TType::LST, 6); + $output->writeListBegin(TType::STRUCT, count($this->annotations)); + foreach ($this->annotations as $iter12) { + $xfer += $iter12->write($output); + } + $output->writeListEnd(); + $xfer += $output->writeFieldEnd(); + } + if ($this->binary_annotations !== null) { + if (!is_array($this->binary_annotations)) { + throw new TProtocolException('Bad type in structure.', TProtocolException::INVALID_DATA); + } + $xfer += $output->writeFieldBegin('binary_annotations', TType::LST, 8); + $output->writeListBegin(TType::STRUCT, count($this->binary_annotations)); + foreach ($this->binary_annotations as $iter13) { + $xfer += $iter13->write($output); + } + $output->writeListEnd(); + $xfer += $output->writeFieldEnd(); + } + if ($this->debug !== null) { + $xfer += $output->writeFieldBegin('debug', TType::BOOL, 9); + $xfer += $output->writeBool($this->debug); + $xfer += $output->writeFieldEnd(); + } + if ($this->timestamp !== null) { + $xfer += $output->writeFieldBegin('timestamp', TType::I64, 10); + $xfer += $output->writeI64($this->timestamp); + $xfer += $output->writeFieldEnd(); + } + if ($this->duration !== null) { + $xfer += $output->writeFieldBegin('duration', TType::I64, 11); + $xfer += $output->writeI64($this->duration); + $xfer += $output->writeFieldEnd(); + } + if ($this->trace_id_high !== null) { + $xfer += $output->writeFieldBegin('trace_id_high', TType::I64, 12); + $xfer += $output->writeI64($this->trace_id_high); + $xfer += $output->writeFieldEnd(); + } + $xfer += $output->writeFieldStop(); + $xfer += $output->writeStructEnd(); + } finally { + $output->decrementRecursionDepth(); } - $xfer += $output->writeFieldStop(); - $xfer += $output->writeStructEnd(); + return $xfer; } } diff --git a/src/Thrift/Agent/Zipkin/ZipkinCollectorClient.php b/src/Thrift/Agent/Zipkin/ZipkinCollectorClient.php index dff0acb..edb5050 100644 --- a/src/Thrift/Agent/Zipkin/ZipkinCollectorClient.php +++ b/src/Thrift/Agent/Zipkin/ZipkinCollectorClient.php @@ -1,87 +1,94 @@ input_ = $input; - $this->output_ = $output ? $output : $input; + $this->input = $input; + $this->output = $output ? $output : $input; } - public function submitZipkinBatch(array $spans) + public function submitZipkinBatch(?array $spans): ?array { $this->send_submitZipkinBatch($spans); return $this->recv_submitZipkinBatch(); } - public function send_submitZipkinBatch(array $spans) + public function send_submitZipkinBatch(?array $spans): void { $args = new \Jaeger\Thrift\Agent\Zipkin\ZipkinCollector_submitZipkinBatch_args(); $args->spans = $spans; - $bin_accel = ($this->output_ instanceof TBinaryProtocolAccelerated) && function_exists('thrift_protocol_write_binary'); + $bin_accel = ($this->output instanceof TBinaryProtocolAccelerated) && function_exists('thrift_protocol_write_binary'); if ($bin_accel) { thrift_protocol_write_binary( - $this->output_, + $this->output, 'submitZipkinBatch', TMessageType::CALL, $args, - $this->seqid_, - $this->output_->isStrictWrite() + $this->seqid, + $this->output->isStrictWrite() ); } else { - $this->output_->writeMessageBegin('submitZipkinBatch', TMessageType::CALL, $this->seqid_); - $args->write($this->output_); - $this->output_->writeMessageEnd(); - $this->output_->getTransport()->flush(); + $this->output->writeMessageBegin('submitZipkinBatch', TMessageType::CALL, $this->seqid); + $args->write($this->output); + $this->output->writeMessageEnd(); + $this->output->getTransport()->flush(); } } - public function recv_submitZipkinBatch() + public function recv_submitZipkinBatch(): ?array { - $bin_accel = ($this->input_ instanceof TBinaryProtocolAccelerated) && function_exists('thrift_protocol_read_binary'); + $bin_accel = ($this->input instanceof TBinaryProtocolAccelerated) && function_exists('thrift_protocol_read_binary'); if ($bin_accel) { $result = thrift_protocol_read_binary( - $this->input_, + $this->input, '\Jaeger\Thrift\Agent\Zipkin\ZipkinCollector_submitZipkinBatch_result', - $this->input_->isStrictRead() + $this->input->isStrictRead() ); } else { $rseqid = 0; $fname = null; $mtype = 0; - $this->input_->readMessageBegin($fname, $mtype, $rseqid); + $this->input->readMessageBegin($fname, $mtype, $rseqid); if ($mtype == TMessageType::EXCEPTION) { $x = new TApplicationException(); - $x->read($this->input_); - $this->input_->readMessageEnd(); + $x->read($this->input); + $this->input->readMessageEnd(); throw $x; } $result = new \Jaeger\Thrift\Agent\Zipkin\ZipkinCollector_submitZipkinBatch_result(); - $result->read($this->input_); - $this->input_->readMessageEnd(); + $result->read($this->input); + $this->input->readMessageEnd(); } if ($result->success !== null) { return $result->success; diff --git a/src/Thrift/Agent/Zipkin/ZipkinCollectorIf.php b/src/Thrift/Agent/Zipkin/ZipkinCollectorIf.php index cec23c5..d299fc1 100644 --- a/src/Thrift/Agent/Zipkin/ZipkinCollectorIf.php +++ b/src/Thrift/Agent/Zipkin/ZipkinCollectorIf.php @@ -1,18 +1,23 @@ array( + public static array $tspec = [ + 1 => [ 'var' => 'spans', 'isRequired' => false, 'type' => TType::LST, 'etype' => TType::STRUCT, - 'elem' => array( + 'elem' => [ 'type' => TType::STRUCT, 'class' => '\Jaeger\Thrift\Agent\Zipkin\Span', - ), - ), - ); + ], + ], + ]; /** * @var \Jaeger\Thrift\Agent\Zipkin\Span[] */ - public $spans = null; + public ?array $spans = null; - public function __construct($vals = null) + public function __construct(?array $vals = null) { if (is_array($vals)) { if (isset($vals['spans'])) { @@ -47,70 +54,81 @@ public function __construct($vals = null) } } - public function getName() + public function getName(): string { return 'ZipkinCollector_submitZipkinBatch_args'; } - - public function read($input) + public function read(TProtocol $input): int { $xfer = 0; $fname = null; $ftype = 0; $fid = 0; - $xfer += $input->readStructBegin($fname); - while (true) { - $xfer += $input->readFieldBegin($fname, $ftype, $fid); - if ($ftype == TType::STOP) { - break; - } - switch ($fid) { - case 1: - if ($ftype == TType::LST) { - $this->spans = array(); - $_size14 = 0; - $_etype17 = 0; - $xfer += $input->readListBegin($_etype17, $_size14); - for ($_i18 = 0; $_i18 < $_size14; ++$_i18) { - $elem19 = null; - $elem19 = new \Jaeger\Thrift\Agent\Zipkin\Span(); - $xfer += $elem19->read($input); - $this->spans []= $elem19; + $input->incrementRecursionDepth(); + try { + $xfer += $input->readStructBegin($fname); + while (true) { + $xfer += $input->readFieldBegin($fname, $ftype, $fid); + if ($ftype == TType::STOP) { + break; + } + switch ($fid) { + case 1: + if ($ftype == TType::LST) { + $this->spans = []; + $_size14 = 0; + $_etype17 = 0; + $xfer += $input->readListBegin($_etype17, $_size14); + for ($_i18 = 0; $_i18 < $_size14; ++$_i18) { + $elem19 = null; + $elem19 = new \Jaeger\Thrift\Agent\Zipkin\Span(); + $xfer += $elem19->read($input); + $this->spans[] = $elem19; + } + $xfer += $input->readListEnd(); + } else { + $xfer += $input->skip($ftype); } - $xfer += $input->readListEnd(); - } else { + break; + default: $xfer += $input->skip($ftype); - } - break; - default: - $xfer += $input->skip($ftype); - break; + break; + } + $xfer += $input->readFieldEnd(); } - $xfer += $input->readFieldEnd(); + $xfer += $input->readStructEnd(); + } finally { + $input->decrementRecursionDepth(); } - $xfer += $input->readStructEnd(); + return $xfer; } - public function write($output) + public function write(TProtocol $output): int { $xfer = 0; - $xfer += $output->writeStructBegin('ZipkinCollector_submitZipkinBatch_args'); - if ($this->spans !== null) { - if (!is_array($this->spans)) { - throw new TProtocolException('Bad type in structure.', TProtocolException::INVALID_DATA); - } - $xfer += $output->writeFieldBegin('spans', TType::LST, 1); - $output->writeListBegin(TType::STRUCT, count($this->spans)); - foreach ($this->spans as $iter20) { - $xfer += $iter20->write($output); + $output->incrementRecursionDepth(); + try { + $xfer += $output->writeStructBegin('ZipkinCollector_submitZipkinBatch_args'); + if ($this->spans !== null) { + if (!is_array($this->spans)) { + throw new TProtocolException('Bad type in structure.', TProtocolException::INVALID_DATA); + } + $xfer += $output->writeFieldBegin('spans', TType::LST, 1); + $output->writeListBegin(TType::STRUCT, count($this->spans)); + foreach ($this->spans as $iter20) { + $xfer += $iter20->write($output); + } + $output->writeListEnd(); + $xfer += $output->writeFieldEnd(); } - $output->writeListEnd(); - $xfer += $output->writeFieldEnd(); + $xfer += $output->writeFieldStop(); + $xfer += $output->writeStructEnd(); + } finally { + $output->decrementRecursionDepth(); } - $xfer += $output->writeFieldStop(); - $xfer += $output->writeStructEnd(); + return $xfer; } } diff --git a/src/Thrift/Agent/Zipkin/ZipkinCollector_submitZipkinBatch_result.php b/src/Thrift/Agent/Zipkin/ZipkinCollector_submitZipkinBatch_result.php index e674845..d547b47 100644 --- a/src/Thrift/Agent/Zipkin/ZipkinCollector_submitZipkinBatch_result.php +++ b/src/Thrift/Agent/Zipkin/ZipkinCollector_submitZipkinBatch_result.php @@ -1,44 +1,51 @@ array( + public static array $tspec = [ + 0 => [ 'var' => 'success', 'isRequired' => false, 'type' => TType::LST, 'etype' => TType::STRUCT, - 'elem' => array( + 'elem' => [ 'type' => TType::STRUCT, 'class' => '\Jaeger\Thrift\Agent\Zipkin\Response', - ), - ), - ); + ], + ], + ]; /** * @var \Jaeger\Thrift\Agent\Zipkin\Response[] */ - public $success = null; + public ?array $success = null; - public function __construct($vals = null) + public function __construct(?array $vals = null) { if (is_array($vals)) { if (isset($vals['success'])) { @@ -47,70 +54,81 @@ public function __construct($vals = null) } } - public function getName() + public function getName(): string { return 'ZipkinCollector_submitZipkinBatch_result'; } - - public function read($input) + public function read(TProtocol $input): int { $xfer = 0; $fname = null; $ftype = 0; $fid = 0; - $xfer += $input->readStructBegin($fname); - while (true) { - $xfer += $input->readFieldBegin($fname, $ftype, $fid); - if ($ftype == TType::STOP) { - break; - } - switch ($fid) { - case 0: - if ($ftype == TType::LST) { - $this->success = array(); - $_size21 = 0; - $_etype24 = 0; - $xfer += $input->readListBegin($_etype24, $_size21); - for ($_i25 = 0; $_i25 < $_size21; ++$_i25) { - $elem26 = null; - $elem26 = new \Jaeger\Thrift\Agent\Zipkin\Response(); - $xfer += $elem26->read($input); - $this->success []= $elem26; + $input->incrementRecursionDepth(); + try { + $xfer += $input->readStructBegin($fname); + while (true) { + $xfer += $input->readFieldBegin($fname, $ftype, $fid); + if ($ftype == TType::STOP) { + break; + } + switch ($fid) { + case 0: + if ($ftype == TType::LST) { + $this->success = []; + $_size21 = 0; + $_etype24 = 0; + $xfer += $input->readListBegin($_etype24, $_size21); + for ($_i25 = 0; $_i25 < $_size21; ++$_i25) { + $elem26 = null; + $elem26 = new \Jaeger\Thrift\Agent\Zipkin\Response(); + $xfer += $elem26->read($input); + $this->success[] = $elem26; + } + $xfer += $input->readListEnd(); + } else { + $xfer += $input->skip($ftype); } - $xfer += $input->readListEnd(); - } else { + break; + default: $xfer += $input->skip($ftype); - } - break; - default: - $xfer += $input->skip($ftype); - break; + break; + } + $xfer += $input->readFieldEnd(); } - $xfer += $input->readFieldEnd(); + $xfer += $input->readStructEnd(); + } finally { + $input->decrementRecursionDepth(); } - $xfer += $input->readStructEnd(); + return $xfer; } - public function write($output) + public function write(TProtocol $output): int { $xfer = 0; - $xfer += $output->writeStructBegin('ZipkinCollector_submitZipkinBatch_result'); - if ($this->success !== null) { - if (!is_array($this->success)) { - throw new TProtocolException('Bad type in structure.', TProtocolException::INVALID_DATA); - } - $xfer += $output->writeFieldBegin('success', TType::LST, 0); - $output->writeListBegin(TType::STRUCT, count($this->success)); - foreach ($this->success as $iter27) { - $xfer += $iter27->write($output); + $output->incrementRecursionDepth(); + try { + $xfer += $output->writeStructBegin('ZipkinCollector_submitZipkinBatch_result'); + if ($this->success !== null) { + if (!is_array($this->success)) { + throw new TProtocolException('Bad type in structure.', TProtocolException::INVALID_DATA); + } + $xfer += $output->writeFieldBegin('success', TType::LST, 0); + $output->writeListBegin(TType::STRUCT, count($this->success)); + foreach ($this->success as $iter27) { + $xfer += $iter27->write($output); + } + $output->writeListEnd(); + $xfer += $output->writeFieldEnd(); } - $output->writeListEnd(); - $xfer += $output->writeFieldEnd(); + $xfer += $output->writeFieldStop(); + $xfer += $output->writeStructEnd(); + } finally { + $output->decrementRecursionDepth(); } - $xfer += $output->writeFieldStop(); - $xfer += $output->writeStructEnd(); + return $xfer; } } diff --git a/src/Thrift/Batch.php b/src/Thrift/Batch.php index b2d0b2a..c70d430 100644 --- a/src/Thrift/Batch.php +++ b/src/Thrift/Batch.php @@ -1,73 +1,69 @@ array( + public static array $tspec = [ + 1 => [ 'var' => 'process', 'isRequired' => true, 'type' => TType::STRUCT, 'class' => '\Jaeger\Thrift\Process', - ), - 2 => array( + ], + 2 => [ 'var' => 'spans', 'isRequired' => true, 'type' => TType::LST, 'etype' => TType::STRUCT, - 'elem' => array( + 'elem' => [ 'type' => TType::STRUCT, 'class' => '\Jaeger\Thrift\Span', - ), - ), - 3 => array( + ], + ], + 3 => [ 'var' => 'seqNo', 'isRequired' => false, 'type' => TType::I64, - ), - 4 => array( + ], + 4 => [ 'var' => 'stats', 'isRequired' => false, 'type' => TType::STRUCT, 'class' => '\Jaeger\Thrift\ClientStats', - ), - ); + ], + ]; - /** - * @var \Jaeger\Thrift\Process - */ - public $process = null; + public ?Process $process = null; /** * @var \Jaeger\Thrift\Span[] */ - public $spans = null; - /** - * @var int - */ - public $seqNo = null; - /** - * @var \Jaeger\Thrift\ClientStats - */ - public $stats = null; + public ?array $spans = null; + public ?int $seqNo = null; + public ?ClientStats $stats = null; - public function __construct($vals = null) + public function __construct(?array $vals = null) { if (is_array($vals)) { if (isset($vals['process'])) { @@ -77,7 +73,7 @@ public function __construct($vals = null) $this->spans = $vals['spans']; } if (isset($vals['seqNo'])) { - $this->seqNo = $vals['seqNo']; + $this->seqNo = (int)$vals['seqNo']; } if (isset($vals['stats'])) { $this->stats = $vals['stats']; @@ -85,114 +81,125 @@ public function __construct($vals = null) } } - public function getName() + public function getName(): string { return 'Batch'; } - - public function read($input) + public function read(TProtocol $input): int { $xfer = 0; $fname = null; $ftype = 0; $fid = 0; - $xfer += $input->readStructBegin($fname); - while (true) { - $xfer += $input->readFieldBegin($fname, $ftype, $fid); - if ($ftype == TType::STOP) { - break; - } - switch ($fid) { - case 1: - if ($ftype == TType::STRUCT) { - $this->process = new \Jaeger\Thrift\Process(); - $xfer += $this->process->read($input); - } else { - $xfer += $input->skip($ftype); - } + $input->incrementRecursionDepth(); + try { + $xfer += $input->readStructBegin($fname); + while (true) { + $xfer += $input->readFieldBegin($fname, $ftype, $fid); + if ($ftype == TType::STOP) { break; - case 2: - if ($ftype == TType::LST) { - $this->spans = array(); - $_size35 = 0; - $_etype38 = 0; - $xfer += $input->readListBegin($_etype38, $_size35); - for ($_i39 = 0; $_i39 < $_size35; ++$_i39) { - $elem40 = null; - $elem40 = new \Jaeger\Thrift\Span(); - $xfer += $elem40->read($input); - $this->spans []= $elem40; + } + switch ($fid) { + case 1: + if ($ftype == TType::STRUCT) { + $this->process = new \Jaeger\Thrift\Process(); + $xfer += $this->process->read($input); + } else { + $xfer += $input->skip($ftype); } - $xfer += $input->readListEnd(); - } else { - $xfer += $input->skip($ftype); - } - break; - case 3: - if ($ftype == TType::I64) { - $xfer += $input->readI64($this->seqNo); - } else { - $xfer += $input->skip($ftype); - } - break; - case 4: - if ($ftype == TType::STRUCT) { - $this->stats = new \Jaeger\Thrift\ClientStats(); - $xfer += $this->stats->read($input); - } else { + break; + case 2: + if ($ftype == TType::LST) { + $this->spans = []; + $_size35 = 0; + $_etype38 = 0; + $xfer += $input->readListBegin($_etype38, $_size35); + for ($_i39 = 0; $_i39 < $_size35; ++$_i39) { + $elem40 = null; + $elem40 = new \Jaeger\Thrift\Span(); + $xfer += $elem40->read($input); + $this->spans[] = $elem40; + } + $xfer += $input->readListEnd(); + } else { + $xfer += $input->skip($ftype); + } + break; + case 3: + if ($ftype == TType::I64) { + $xfer += $input->readI64($this->seqNo); + } else { + $xfer += $input->skip($ftype); + } + break; + case 4: + if ($ftype == TType::STRUCT) { + $this->stats = new \Jaeger\Thrift\ClientStats(); + $xfer += $this->stats->read($input); + } else { + $xfer += $input->skip($ftype); + } + break; + default: $xfer += $input->skip($ftype); - } - break; - default: - $xfer += $input->skip($ftype); - break; + break; + } + $xfer += $input->readFieldEnd(); } - $xfer += $input->readFieldEnd(); + $xfer += $input->readStructEnd(); + } finally { + $input->decrementRecursionDepth(); } - $xfer += $input->readStructEnd(); + return $xfer; } - public function write($output) + public function write(TProtocol $output): int { $xfer = 0; - $xfer += $output->writeStructBegin('Batch'); - if ($this->process !== null) { - if (!is_object($this->process)) { - throw new TProtocolException('Bad type in structure.', TProtocolException::INVALID_DATA); + $output->incrementRecursionDepth(); + try { + $xfer += $output->writeStructBegin('Batch'); + if ($this->process !== null) { + if (!is_object($this->process)) { + throw new TProtocolException('Bad type in structure.', TProtocolException::INVALID_DATA); + } + $xfer += $output->writeFieldBegin('process', TType::STRUCT, 1); + $xfer += $this->process->write($output); + $xfer += $output->writeFieldEnd(); } - $xfer += $output->writeFieldBegin('process', TType::STRUCT, 1); - $xfer += $this->process->write($output); - $xfer += $output->writeFieldEnd(); - } - if ($this->spans !== null) { - if (!is_array($this->spans)) { - throw new TProtocolException('Bad type in structure.', TProtocolException::INVALID_DATA); + if ($this->spans !== null) { + if (!is_array($this->spans)) { + throw new TProtocolException('Bad type in structure.', TProtocolException::INVALID_DATA); + } + $xfer += $output->writeFieldBegin('spans', TType::LST, 2); + $output->writeListBegin(TType::STRUCT, count($this->spans)); + foreach ($this->spans as $iter41) { + $xfer += $iter41->write($output); + } + $output->writeListEnd(); + $xfer += $output->writeFieldEnd(); } - $xfer += $output->writeFieldBegin('spans', TType::LST, 2); - $output->writeListBegin(TType::STRUCT, count($this->spans)); - foreach ($this->spans as $iter41) { - $xfer += $iter41->write($output); + if ($this->seqNo !== null) { + $xfer += $output->writeFieldBegin('seqNo', TType::I64, 3); + $xfer += $output->writeI64($this->seqNo); + $xfer += $output->writeFieldEnd(); } - $output->writeListEnd(); - $xfer += $output->writeFieldEnd(); - } - if ($this->seqNo !== null) { - $xfer += $output->writeFieldBegin('seqNo', TType::I64, 3); - $xfer += $output->writeI64($this->seqNo); - $xfer += $output->writeFieldEnd(); - } - if ($this->stats !== null) { - if (!is_object($this->stats)) { - throw new TProtocolException('Bad type in structure.', TProtocolException::INVALID_DATA); + if ($this->stats !== null) { + if (!is_object($this->stats)) { + throw new TProtocolException('Bad type in structure.', TProtocolException::INVALID_DATA); + } + $xfer += $output->writeFieldBegin('stats', TType::STRUCT, 4); + $xfer += $this->stats->write($output); + $xfer += $output->writeFieldEnd(); } - $xfer += $output->writeFieldBegin('stats', TType::STRUCT, 4); - $xfer += $this->stats->write($output); - $xfer += $output->writeFieldEnd(); + $xfer += $output->writeFieldStop(); + $xfer += $output->writeStructEnd(); + } finally { + $output->decrementRecursionDepth(); } - $xfer += $output->writeFieldStop(); - $xfer += $output->writeStructEnd(); + return $xfer; } } diff --git a/src/Thrift/BatchSubmitResponse.php b/src/Thrift/BatchSubmitResponse.php index 8463e05..c08be8b 100644 --- a/src/Thrift/BatchSubmitResponse.php +++ b/src/Thrift/BatchSubmitResponse.php @@ -1,94 +1,107 @@ array( + public static array $tspec = [ + 1 => [ 'var' => 'ok', 'isRequired' => true, 'type' => TType::BOOL, - ), - ); + ], + ]; - /** - * @var bool - */ - public $ok = null; + public ?bool $ok = null; - public function __construct($vals = null) + public function __construct(?array $vals = null) { if (is_array($vals)) { if (isset($vals['ok'])) { - $this->ok = $vals['ok']; + $this->ok = (bool)$vals['ok']; } } } - public function getName() + public function getName(): string { return 'BatchSubmitResponse'; } - - public function read($input) + public function read(TProtocol $input): int { $xfer = 0; $fname = null; $ftype = 0; $fid = 0; - $xfer += $input->readStructBegin($fname); - while (true) { - $xfer += $input->readFieldBegin($fname, $ftype, $fid); - if ($ftype == TType::STOP) { - break; - } - switch ($fid) { - case 1: - if ($ftype == TType::BOOL) { - $xfer += $input->readBool($this->ok); - } else { - $xfer += $input->skip($ftype); - } - break; - default: - $xfer += $input->skip($ftype); + $input->incrementRecursionDepth(); + try { + $xfer += $input->readStructBegin($fname); + while (true) { + $xfer += $input->readFieldBegin($fname, $ftype, $fid); + if ($ftype == TType::STOP) { break; + } + switch ($fid) { + case 1: + if ($ftype == TType::BOOL) { + $xfer += $input->readBool($this->ok); + } else { + $xfer += $input->skip($ftype); + } + break; + default: + $xfer += $input->skip($ftype); + break; + } + $xfer += $input->readFieldEnd(); } - $xfer += $input->readFieldEnd(); + $xfer += $input->readStructEnd(); + } finally { + $input->decrementRecursionDepth(); } - $xfer += $input->readStructEnd(); + return $xfer; } - public function write($output) + public function write(TProtocol $output): int { $xfer = 0; - $xfer += $output->writeStructBegin('BatchSubmitResponse'); - if ($this->ok !== null) { - $xfer += $output->writeFieldBegin('ok', TType::BOOL, 1); - $xfer += $output->writeBool($this->ok); - $xfer += $output->writeFieldEnd(); + $output->incrementRecursionDepth(); + try { + $xfer += $output->writeStructBegin('BatchSubmitResponse'); + if ($this->ok !== null) { + $xfer += $output->writeFieldBegin('ok', TType::BOOL, 1); + $xfer += $output->writeBool($this->ok); + $xfer += $output->writeFieldEnd(); + } + $xfer += $output->writeFieldStop(); + $xfer += $output->writeStructEnd(); + } finally { + $output->decrementRecursionDepth(); } - $xfer += $output->writeFieldStop(); - $xfer += $output->writeStructEnd(); + return $xfer; } } diff --git a/src/Thrift/ClientStats.php b/src/Thrift/ClientStats.php index 4daeaf3..def92de 100644 --- a/src/Thrift/ClientStats.php +++ b/src/Thrift/ClientStats.php @@ -1,142 +1,149 @@ array( + public static array $tspec = [ + 1 => [ 'var' => 'fullQueueDroppedSpans', 'isRequired' => true, 'type' => TType::I64, - ), - 2 => array( + ], + 2 => [ 'var' => 'tooLargeDroppedSpans', 'isRequired' => true, 'type' => TType::I64, - ), - 3 => array( + ], + 3 => [ 'var' => 'failedToEmitSpans', 'isRequired' => true, 'type' => TType::I64, - ), - ); + ], + ]; - /** - * @var int - */ - public $fullQueueDroppedSpans = null; - /** - * @var int - */ - public $tooLargeDroppedSpans = null; - /** - * @var int - */ - public $failedToEmitSpans = null; + public ?int $fullQueueDroppedSpans = null; + public ?int $tooLargeDroppedSpans = null; + public ?int $failedToEmitSpans = null; - public function __construct($vals = null) + public function __construct(?array $vals = null) { if (is_array($vals)) { if (isset($vals['fullQueueDroppedSpans'])) { - $this->fullQueueDroppedSpans = $vals['fullQueueDroppedSpans']; + $this->fullQueueDroppedSpans = (int)$vals['fullQueueDroppedSpans']; } if (isset($vals['tooLargeDroppedSpans'])) { - $this->tooLargeDroppedSpans = $vals['tooLargeDroppedSpans']; + $this->tooLargeDroppedSpans = (int)$vals['tooLargeDroppedSpans']; } if (isset($vals['failedToEmitSpans'])) { - $this->failedToEmitSpans = $vals['failedToEmitSpans']; + $this->failedToEmitSpans = (int)$vals['failedToEmitSpans']; } } } - public function getName() + public function getName(): string { return 'ClientStats'; } - - public function read($input) + public function read(TProtocol $input): int { $xfer = 0; $fname = null; $ftype = 0; $fid = 0; - $xfer += $input->readStructBegin($fname); - while (true) { - $xfer += $input->readFieldBegin($fname, $ftype, $fid); - if ($ftype == TType::STOP) { - break; - } - switch ($fid) { - case 1: - if ($ftype == TType::I64) { - $xfer += $input->readI64($this->fullQueueDroppedSpans); - } else { - $xfer += $input->skip($ftype); - } - break; - case 2: - if ($ftype == TType::I64) { - $xfer += $input->readI64($this->tooLargeDroppedSpans); - } else { - $xfer += $input->skip($ftype); - } + $input->incrementRecursionDepth(); + try { + $xfer += $input->readStructBegin($fname); + while (true) { + $xfer += $input->readFieldBegin($fname, $ftype, $fid); + if ($ftype == TType::STOP) { break; - case 3: - if ($ftype == TType::I64) { - $xfer += $input->readI64($this->failedToEmitSpans); - } else { + } + switch ($fid) { + case 1: + if ($ftype == TType::I64) { + $xfer += $input->readI64($this->fullQueueDroppedSpans); + } else { + $xfer += $input->skip($ftype); + } + break; + case 2: + if ($ftype == TType::I64) { + $xfer += $input->readI64($this->tooLargeDroppedSpans); + } else { + $xfer += $input->skip($ftype); + } + break; + case 3: + if ($ftype == TType::I64) { + $xfer += $input->readI64($this->failedToEmitSpans); + } else { + $xfer += $input->skip($ftype); + } + break; + default: $xfer += $input->skip($ftype); - } - break; - default: - $xfer += $input->skip($ftype); - break; + break; + } + $xfer += $input->readFieldEnd(); } - $xfer += $input->readFieldEnd(); + $xfer += $input->readStructEnd(); + } finally { + $input->decrementRecursionDepth(); } - $xfer += $input->readStructEnd(); + return $xfer; } - public function write($output) + public function write(TProtocol $output): int { $xfer = 0; - $xfer += $output->writeStructBegin('ClientStats'); - if ($this->fullQueueDroppedSpans !== null) { - $xfer += $output->writeFieldBegin('fullQueueDroppedSpans', TType::I64, 1); - $xfer += $output->writeI64($this->fullQueueDroppedSpans); - $xfer += $output->writeFieldEnd(); - } - if ($this->tooLargeDroppedSpans !== null) { - $xfer += $output->writeFieldBegin('tooLargeDroppedSpans', TType::I64, 2); - $xfer += $output->writeI64($this->tooLargeDroppedSpans); - $xfer += $output->writeFieldEnd(); - } - if ($this->failedToEmitSpans !== null) { - $xfer += $output->writeFieldBegin('failedToEmitSpans', TType::I64, 3); - $xfer += $output->writeI64($this->failedToEmitSpans); - $xfer += $output->writeFieldEnd(); + $output->incrementRecursionDepth(); + try { + $xfer += $output->writeStructBegin('ClientStats'); + if ($this->fullQueueDroppedSpans !== null) { + $xfer += $output->writeFieldBegin('fullQueueDroppedSpans', TType::I64, 1); + $xfer += $output->writeI64($this->fullQueueDroppedSpans); + $xfer += $output->writeFieldEnd(); + } + if ($this->tooLargeDroppedSpans !== null) { + $xfer += $output->writeFieldBegin('tooLargeDroppedSpans', TType::I64, 2); + $xfer += $output->writeI64($this->tooLargeDroppedSpans); + $xfer += $output->writeFieldEnd(); + } + if ($this->failedToEmitSpans !== null) { + $xfer += $output->writeFieldBegin('failedToEmitSpans', TType::I64, 3); + $xfer += $output->writeI64($this->failedToEmitSpans); + $xfer += $output->writeFieldEnd(); + } + $xfer += $output->writeFieldStop(); + $xfer += $output->writeStructEnd(); + } finally { + $output->decrementRecursionDepth(); } - $xfer += $output->writeFieldStop(); - $xfer += $output->writeStructEnd(); + return $xfer; } } diff --git a/src/Thrift/CollectorClient.php b/src/Thrift/CollectorClient.php index e3b241c..12997af 100644 --- a/src/Thrift/CollectorClient.php +++ b/src/Thrift/CollectorClient.php @@ -1,87 +1,94 @@ input_ = $input; - $this->output_ = $output ? $output : $input; + $this->input = $input; + $this->output = $output ? $output : $input; } - public function submitBatches(array $batches) + public function submitBatches(?array $batches): ?array { $this->send_submitBatches($batches); return $this->recv_submitBatches(); } - public function send_submitBatches(array $batches) + public function send_submitBatches(?array $batches): void { $args = new \Jaeger\Thrift\Collector_submitBatches_args(); $args->batches = $batches; - $bin_accel = ($this->output_ instanceof TBinaryProtocolAccelerated) && function_exists('thrift_protocol_write_binary'); + $bin_accel = ($this->output instanceof TBinaryProtocolAccelerated) && function_exists('thrift_protocol_write_binary'); if ($bin_accel) { thrift_protocol_write_binary( - $this->output_, + $this->output, 'submitBatches', TMessageType::CALL, $args, - $this->seqid_, - $this->output_->isStrictWrite() + $this->seqid, + $this->output->isStrictWrite() ); } else { - $this->output_->writeMessageBegin('submitBatches', TMessageType::CALL, $this->seqid_); - $args->write($this->output_); - $this->output_->writeMessageEnd(); - $this->output_->getTransport()->flush(); + $this->output->writeMessageBegin('submitBatches', TMessageType::CALL, $this->seqid); + $args->write($this->output); + $this->output->writeMessageEnd(); + $this->output->getTransport()->flush(); } } - public function recv_submitBatches() + public function recv_submitBatches(): ?array { - $bin_accel = ($this->input_ instanceof TBinaryProtocolAccelerated) && function_exists('thrift_protocol_read_binary'); + $bin_accel = ($this->input instanceof TBinaryProtocolAccelerated) && function_exists('thrift_protocol_read_binary'); if ($bin_accel) { $result = thrift_protocol_read_binary( - $this->input_, + $this->input, '\Jaeger\Thrift\Collector_submitBatches_result', - $this->input_->isStrictRead() + $this->input->isStrictRead() ); } else { $rseqid = 0; $fname = null; $mtype = 0; - $this->input_->readMessageBegin($fname, $mtype, $rseqid); + $this->input->readMessageBegin($fname, $mtype, $rseqid); if ($mtype == TMessageType::EXCEPTION) { $x = new TApplicationException(); - $x->read($this->input_); - $this->input_->readMessageEnd(); + $x->read($this->input); + $this->input->readMessageEnd(); throw $x; } $result = new \Jaeger\Thrift\Collector_submitBatches_result(); - $result->read($this->input_); - $this->input_->readMessageEnd(); + $result->read($this->input); + $this->input->readMessageEnd(); } if ($result->success !== null) { return $result->success; diff --git a/src/Thrift/CollectorIf.php b/src/Thrift/CollectorIf.php index 461a1d4..8830a8c 100644 --- a/src/Thrift/CollectorIf.php +++ b/src/Thrift/CollectorIf.php @@ -1,18 +1,23 @@ array( + public static array $tspec = [ + 1 => [ 'var' => 'batches', 'isRequired' => false, 'type' => TType::LST, 'etype' => TType::STRUCT, - 'elem' => array( + 'elem' => [ 'type' => TType::STRUCT, 'class' => '\Jaeger\Thrift\Batch', - ), - ), - ); + ], + ], + ]; /** * @var \Jaeger\Thrift\Batch[] */ - public $batches = null; + public ?array $batches = null; - public function __construct($vals = null) + public function __construct(?array $vals = null) { if (is_array($vals)) { if (isset($vals['batches'])) { @@ -47,70 +54,81 @@ public function __construct($vals = null) } } - public function getName() + public function getName(): string { return 'Collector_submitBatches_args'; } - - public function read($input) + public function read(TProtocol $input): int { $xfer = 0; $fname = null; $ftype = 0; $fid = 0; - $xfer += $input->readStructBegin($fname); - while (true) { - $xfer += $input->readFieldBegin($fname, $ftype, $fid); - if ($ftype == TType::STOP) { - break; - } - switch ($fid) { - case 1: - if ($ftype == TType::LST) { - $this->batches = array(); - $_size42 = 0; - $_etype45 = 0; - $xfer += $input->readListBegin($_etype45, $_size42); - for ($_i46 = 0; $_i46 < $_size42; ++$_i46) { - $elem47 = null; - $elem47 = new \Jaeger\Thrift\Batch(); - $xfer += $elem47->read($input); - $this->batches []= $elem47; + $input->incrementRecursionDepth(); + try { + $xfer += $input->readStructBegin($fname); + while (true) { + $xfer += $input->readFieldBegin($fname, $ftype, $fid); + if ($ftype == TType::STOP) { + break; + } + switch ($fid) { + case 1: + if ($ftype == TType::LST) { + $this->batches = []; + $_size42 = 0; + $_etype45 = 0; + $xfer += $input->readListBegin($_etype45, $_size42); + for ($_i46 = 0; $_i46 < $_size42; ++$_i46) { + $elem47 = null; + $elem47 = new \Jaeger\Thrift\Batch(); + $xfer += $elem47->read($input); + $this->batches[] = $elem47; + } + $xfer += $input->readListEnd(); + } else { + $xfer += $input->skip($ftype); } - $xfer += $input->readListEnd(); - } else { + break; + default: $xfer += $input->skip($ftype); - } - break; - default: - $xfer += $input->skip($ftype); - break; + break; + } + $xfer += $input->readFieldEnd(); } - $xfer += $input->readFieldEnd(); + $xfer += $input->readStructEnd(); + } finally { + $input->decrementRecursionDepth(); } - $xfer += $input->readStructEnd(); + return $xfer; } - public function write($output) + public function write(TProtocol $output): int { $xfer = 0; - $xfer += $output->writeStructBegin('Collector_submitBatches_args'); - if ($this->batches !== null) { - if (!is_array($this->batches)) { - throw new TProtocolException('Bad type in structure.', TProtocolException::INVALID_DATA); - } - $xfer += $output->writeFieldBegin('batches', TType::LST, 1); - $output->writeListBegin(TType::STRUCT, count($this->batches)); - foreach ($this->batches as $iter48) { - $xfer += $iter48->write($output); + $output->incrementRecursionDepth(); + try { + $xfer += $output->writeStructBegin('Collector_submitBatches_args'); + if ($this->batches !== null) { + if (!is_array($this->batches)) { + throw new TProtocolException('Bad type in structure.', TProtocolException::INVALID_DATA); + } + $xfer += $output->writeFieldBegin('batches', TType::LST, 1); + $output->writeListBegin(TType::STRUCT, count($this->batches)); + foreach ($this->batches as $iter48) { + $xfer += $iter48->write($output); + } + $output->writeListEnd(); + $xfer += $output->writeFieldEnd(); } - $output->writeListEnd(); - $xfer += $output->writeFieldEnd(); + $xfer += $output->writeFieldStop(); + $xfer += $output->writeStructEnd(); + } finally { + $output->decrementRecursionDepth(); } - $xfer += $output->writeFieldStop(); - $xfer += $output->writeStructEnd(); + return $xfer; } } diff --git a/src/Thrift/Collector_submitBatches_result.php b/src/Thrift/Collector_submitBatches_result.php index b1b99d6..2c0e7ae 100644 --- a/src/Thrift/Collector_submitBatches_result.php +++ b/src/Thrift/Collector_submitBatches_result.php @@ -1,44 +1,51 @@ array( + public static array $tspec = [ + 0 => [ 'var' => 'success', 'isRequired' => false, 'type' => TType::LST, 'etype' => TType::STRUCT, - 'elem' => array( + 'elem' => [ 'type' => TType::STRUCT, 'class' => '\Jaeger\Thrift\BatchSubmitResponse', - ), - ), - ); + ], + ], + ]; /** * @var \Jaeger\Thrift\BatchSubmitResponse[] */ - public $success = null; + public ?array $success = null; - public function __construct($vals = null) + public function __construct(?array $vals = null) { if (is_array($vals)) { if (isset($vals['success'])) { @@ -47,70 +54,81 @@ public function __construct($vals = null) } } - public function getName() + public function getName(): string { return 'Collector_submitBatches_result'; } - - public function read($input) + public function read(TProtocol $input): int { $xfer = 0; $fname = null; $ftype = 0; $fid = 0; - $xfer += $input->readStructBegin($fname); - while (true) { - $xfer += $input->readFieldBegin($fname, $ftype, $fid); - if ($ftype == TType::STOP) { - break; - } - switch ($fid) { - case 0: - if ($ftype == TType::LST) { - $this->success = array(); - $_size49 = 0; - $_etype52 = 0; - $xfer += $input->readListBegin($_etype52, $_size49); - for ($_i53 = 0; $_i53 < $_size49; ++$_i53) { - $elem54 = null; - $elem54 = new \Jaeger\Thrift\BatchSubmitResponse(); - $xfer += $elem54->read($input); - $this->success []= $elem54; + $input->incrementRecursionDepth(); + try { + $xfer += $input->readStructBegin($fname); + while (true) { + $xfer += $input->readFieldBegin($fname, $ftype, $fid); + if ($ftype == TType::STOP) { + break; + } + switch ($fid) { + case 0: + if ($ftype == TType::LST) { + $this->success = []; + $_size49 = 0; + $_etype52 = 0; + $xfer += $input->readListBegin($_etype52, $_size49); + for ($_i53 = 0; $_i53 < $_size49; ++$_i53) { + $elem54 = null; + $elem54 = new \Jaeger\Thrift\BatchSubmitResponse(); + $xfer += $elem54->read($input); + $this->success[] = $elem54; + } + $xfer += $input->readListEnd(); + } else { + $xfer += $input->skip($ftype); } - $xfer += $input->readListEnd(); - } else { + break; + default: $xfer += $input->skip($ftype); - } - break; - default: - $xfer += $input->skip($ftype); - break; + break; + } + $xfer += $input->readFieldEnd(); } - $xfer += $input->readFieldEnd(); + $xfer += $input->readStructEnd(); + } finally { + $input->decrementRecursionDepth(); } - $xfer += $input->readStructEnd(); + return $xfer; } - public function write($output) + public function write(TProtocol $output): int { $xfer = 0; - $xfer += $output->writeStructBegin('Collector_submitBatches_result'); - if ($this->success !== null) { - if (!is_array($this->success)) { - throw new TProtocolException('Bad type in structure.', TProtocolException::INVALID_DATA); - } - $xfer += $output->writeFieldBegin('success', TType::LST, 0); - $output->writeListBegin(TType::STRUCT, count($this->success)); - foreach ($this->success as $iter55) { - $xfer += $iter55->write($output); + $output->incrementRecursionDepth(); + try { + $xfer += $output->writeStructBegin('Collector_submitBatches_result'); + if ($this->success !== null) { + if (!is_array($this->success)) { + throw new TProtocolException('Bad type in structure.', TProtocolException::INVALID_DATA); + } + $xfer += $output->writeFieldBegin('success', TType::LST, 0); + $output->writeListBegin(TType::STRUCT, count($this->success)); + foreach ($this->success as $iter55) { + $xfer += $iter55->write($output); + } + $output->writeListEnd(); + $xfer += $output->writeFieldEnd(); } - $output->writeListEnd(); - $xfer += $output->writeFieldEnd(); + $xfer += $output->writeFieldStop(); + $xfer += $output->writeStructEnd(); + } finally { + $output->decrementRecursionDepth(); } - $xfer += $output->writeFieldStop(); - $xfer += $output->writeStructEnd(); + return $xfer; } } diff --git a/src/Thrift/Log.php b/src/Thrift/Log.php index 6d5cc33..53e3774 100644 --- a/src/Thrift/Log.php +++ b/src/Thrift/Log.php @@ -1,57 +1,59 @@ array( + public static array $tspec = [ + 1 => [ 'var' => 'timestamp', 'isRequired' => true, 'type' => TType::I64, - ), - 2 => array( + ], + 2 => [ 'var' => 'fields', 'isRequired' => true, 'type' => TType::LST, 'etype' => TType::STRUCT, - 'elem' => array( + 'elem' => [ 'type' => TType::STRUCT, 'class' => '\Jaeger\Thrift\Tag', - ), - ), - ); + ], + ], + ]; - /** - * @var int - */ - public $timestamp = null; + public ?int $timestamp = null; /** * @var \Jaeger\Thrift\Tag[] */ - public $fields = null; + public ?array $fields = null; - public function __construct($vals = null) + public function __construct(?array $vals = null) { if (is_array($vals)) { if (isset($vals['timestamp'])) { - $this->timestamp = $vals['timestamp']; + $this->timestamp = (int)$vals['timestamp']; } if (isset($vals['fields'])) { $this->fields = $vals['fields']; @@ -59,82 +61,93 @@ public function __construct($vals = null) } } - public function getName() + public function getName(): string { return 'Log'; } - - public function read($input) + public function read(TProtocol $input): int { $xfer = 0; $fname = null; $ftype = 0; $fid = 0; - $xfer += $input->readStructBegin($fname); - while (true) { - $xfer += $input->readFieldBegin($fname, $ftype, $fid); - if ($ftype == TType::STOP) { - break; - } - switch ($fid) { - case 1: - if ($ftype == TType::I64) { - $xfer += $input->readI64($this->timestamp); - } else { - $xfer += $input->skip($ftype); - } + $input->incrementRecursionDepth(); + try { + $xfer += $input->readStructBegin($fname); + while (true) { + $xfer += $input->readFieldBegin($fname, $ftype, $fid); + if ($ftype == TType::STOP) { break; - case 2: - if ($ftype == TType::LST) { - $this->fields = array(); - $_size0 = 0; - $_etype3 = 0; - $xfer += $input->readListBegin($_etype3, $_size0); - for ($_i4 = 0; $_i4 < $_size0; ++$_i4) { - $elem5 = null; - $elem5 = new \Jaeger\Thrift\Tag(); - $xfer += $elem5->read($input); - $this->fields []= $elem5; + } + switch ($fid) { + case 1: + if ($ftype == TType::I64) { + $xfer += $input->readI64($this->timestamp); + } else { + $xfer += $input->skip($ftype); } - $xfer += $input->readListEnd(); - } else { + break; + case 2: + if ($ftype == TType::LST) { + $this->fields = []; + $_size0 = 0; + $_etype3 = 0; + $xfer += $input->readListBegin($_etype3, $_size0); + for ($_i4 = 0; $_i4 < $_size0; ++$_i4) { + $elem5 = null; + $elem5 = new \Jaeger\Thrift\Tag(); + $xfer += $elem5->read($input); + $this->fields[] = $elem5; + } + $xfer += $input->readListEnd(); + } else { + $xfer += $input->skip($ftype); + } + break; + default: $xfer += $input->skip($ftype); - } - break; - default: - $xfer += $input->skip($ftype); - break; + break; + } + $xfer += $input->readFieldEnd(); } - $xfer += $input->readFieldEnd(); + $xfer += $input->readStructEnd(); + } finally { + $input->decrementRecursionDepth(); } - $xfer += $input->readStructEnd(); + return $xfer; } - public function write($output) + public function write(TProtocol $output): int { $xfer = 0; - $xfer += $output->writeStructBegin('Log'); - if ($this->timestamp !== null) { - $xfer += $output->writeFieldBegin('timestamp', TType::I64, 1); - $xfer += $output->writeI64($this->timestamp); - $xfer += $output->writeFieldEnd(); - } - if ($this->fields !== null) { - if (!is_array($this->fields)) { - throw new TProtocolException('Bad type in structure.', TProtocolException::INVALID_DATA); + $output->incrementRecursionDepth(); + try { + $xfer += $output->writeStructBegin('Log'); + if ($this->timestamp !== null) { + $xfer += $output->writeFieldBegin('timestamp', TType::I64, 1); + $xfer += $output->writeI64($this->timestamp); + $xfer += $output->writeFieldEnd(); } - $xfer += $output->writeFieldBegin('fields', TType::LST, 2); - $output->writeListBegin(TType::STRUCT, count($this->fields)); - foreach ($this->fields as $iter6) { - $xfer += $iter6->write($output); + if ($this->fields !== null) { + if (!is_array($this->fields)) { + throw new TProtocolException('Bad type in structure.', TProtocolException::INVALID_DATA); + } + $xfer += $output->writeFieldBegin('fields', TType::LST, 2); + $output->writeListBegin(TType::STRUCT, count($this->fields)); + foreach ($this->fields as $iter6) { + $xfer += $iter6->write($output); + } + $output->writeListEnd(); + $xfer += $output->writeFieldEnd(); } - $output->writeListEnd(); - $xfer += $output->writeFieldEnd(); + $xfer += $output->writeFieldStop(); + $xfer += $output->writeStructEnd(); + } finally { + $output->decrementRecursionDepth(); } - $xfer += $output->writeFieldStop(); - $xfer += $output->writeStructEnd(); + return $xfer; } } diff --git a/src/Thrift/Process.php b/src/Thrift/Process.php index ffc994f..16d589c 100644 --- a/src/Thrift/Process.php +++ b/src/Thrift/Process.php @@ -1,57 +1,59 @@ array( + public static array $tspec = [ + 1 => [ 'var' => 'serviceName', 'isRequired' => true, 'type' => TType::STRING, - ), - 2 => array( + ], + 2 => [ 'var' => 'tags', 'isRequired' => false, 'type' => TType::LST, 'etype' => TType::STRUCT, - 'elem' => array( + 'elem' => [ 'type' => TType::STRUCT, 'class' => '\Jaeger\Thrift\Tag', - ), - ), - ); + ], + ], + ]; - /** - * @var string - */ - public $serviceName = null; + public ?string $serviceName = null; /** * @var \Jaeger\Thrift\Tag[] */ - public $tags = null; + public ?array $tags = null; - public function __construct($vals = null) + public function __construct(?array $vals = null) { if (is_array($vals)) { if (isset($vals['serviceName'])) { - $this->serviceName = $vals['serviceName']; + $this->serviceName = (string)$vals['serviceName']; } if (isset($vals['tags'])) { $this->tags = $vals['tags']; @@ -59,82 +61,93 @@ public function __construct($vals = null) } } - public function getName() + public function getName(): string { return 'Process'; } - - public function read($input) + public function read(TProtocol $input): int { $xfer = 0; $fname = null; $ftype = 0; $fid = 0; - $xfer += $input->readStructBegin($fname); - while (true) { - $xfer += $input->readFieldBegin($fname, $ftype, $fid); - if ($ftype == TType::STOP) { - break; - } - switch ($fid) { - case 1: - if ($ftype == TType::STRING) { - $xfer += $input->readString($this->serviceName); - } else { - $xfer += $input->skip($ftype); - } + $input->incrementRecursionDepth(); + try { + $xfer += $input->readStructBegin($fname); + while (true) { + $xfer += $input->readFieldBegin($fname, $ftype, $fid); + if ($ftype == TType::STOP) { break; - case 2: - if ($ftype == TType::LST) { - $this->tags = array(); - $_size28 = 0; - $_etype31 = 0; - $xfer += $input->readListBegin($_etype31, $_size28); - for ($_i32 = 0; $_i32 < $_size28; ++$_i32) { - $elem33 = null; - $elem33 = new \Jaeger\Thrift\Tag(); - $xfer += $elem33->read($input); - $this->tags []= $elem33; + } + switch ($fid) { + case 1: + if ($ftype == TType::STRING) { + $xfer += $input->readString($this->serviceName); + } else { + $xfer += $input->skip($ftype); } - $xfer += $input->readListEnd(); - } else { + break; + case 2: + if ($ftype == TType::LST) { + $this->tags = []; + $_size28 = 0; + $_etype31 = 0; + $xfer += $input->readListBegin($_etype31, $_size28); + for ($_i32 = 0; $_i32 < $_size28; ++$_i32) { + $elem33 = null; + $elem33 = new \Jaeger\Thrift\Tag(); + $xfer += $elem33->read($input); + $this->tags[] = $elem33; + } + $xfer += $input->readListEnd(); + } else { + $xfer += $input->skip($ftype); + } + break; + default: $xfer += $input->skip($ftype); - } - break; - default: - $xfer += $input->skip($ftype); - break; + break; + } + $xfer += $input->readFieldEnd(); } - $xfer += $input->readFieldEnd(); + $xfer += $input->readStructEnd(); + } finally { + $input->decrementRecursionDepth(); } - $xfer += $input->readStructEnd(); + return $xfer; } - public function write($output) + public function write(TProtocol $output): int { $xfer = 0; - $xfer += $output->writeStructBegin('Process'); - if ($this->serviceName !== null) { - $xfer += $output->writeFieldBegin('serviceName', TType::STRING, 1); - $xfer += $output->writeString($this->serviceName); - $xfer += $output->writeFieldEnd(); - } - if ($this->tags !== null) { - if (!is_array($this->tags)) { - throw new TProtocolException('Bad type in structure.', TProtocolException::INVALID_DATA); + $output->incrementRecursionDepth(); + try { + $xfer += $output->writeStructBegin('Process'); + if ($this->serviceName !== null) { + $xfer += $output->writeFieldBegin('serviceName', TType::STRING, 1); + $xfer += $output->writeString($this->serviceName); + $xfer += $output->writeFieldEnd(); } - $xfer += $output->writeFieldBegin('tags', TType::LST, 2); - $output->writeListBegin(TType::STRUCT, count($this->tags)); - foreach ($this->tags as $iter34) { - $xfer += $iter34->write($output); + if ($this->tags !== null) { + if (!is_array($this->tags)) { + throw new TProtocolException('Bad type in structure.', TProtocolException::INVALID_DATA); + } + $xfer += $output->writeFieldBegin('tags', TType::LST, 2); + $output->writeListBegin(TType::STRUCT, count($this->tags)); + foreach ($this->tags as $iter34) { + $xfer += $iter34->write($output); + } + $output->writeListEnd(); + $xfer += $output->writeFieldEnd(); } - $output->writeListEnd(); - $xfer += $output->writeFieldEnd(); + $xfer += $output->writeFieldStop(); + $xfer += $output->writeStructEnd(); + } finally { + $output->decrementRecursionDepth(); } - $xfer += $output->writeFieldStop(); - $xfer += $output->writeStructEnd(); + return $xfer; } } diff --git a/src/Thrift/Span.php b/src/Thrift/Span.php index 8ca2031..6d3c351 100644 --- a/src/Thrift/Span.php +++ b/src/Thrift/Span.php @@ -1,172 +1,153 @@ array( + public static array $tspec = [ + 1 => [ 'var' => 'traceIdLow', 'isRequired' => true, 'type' => TType::I64, - ), - 2 => array( + ], + 2 => [ 'var' => 'traceIdHigh', 'isRequired' => true, 'type' => TType::I64, - ), - 3 => array( + ], + 3 => [ 'var' => 'spanId', 'isRequired' => true, 'type' => TType::I64, - ), - 4 => array( + ], + 4 => [ 'var' => 'parentSpanId', 'isRequired' => true, 'type' => TType::I64, - ), - 5 => array( + ], + 5 => [ 'var' => 'operationName', 'isRequired' => true, 'type' => TType::STRING, - ), - 6 => array( + ], + 6 => [ 'var' => 'references', 'isRequired' => false, 'type' => TType::LST, 'etype' => TType::STRUCT, - 'elem' => array( + 'elem' => [ 'type' => TType::STRUCT, 'class' => '\Jaeger\Thrift\SpanRef', - ), - ), - 7 => array( + ], + ], + 7 => [ 'var' => 'flags', 'isRequired' => true, 'type' => TType::I32, - ), - 8 => array( + ], + 8 => [ 'var' => 'startTime', 'isRequired' => true, 'type' => TType::I64, - ), - 9 => array( + ], + 9 => [ 'var' => 'duration', 'isRequired' => true, 'type' => TType::I64, - ), - 10 => array( + ], + 10 => [ 'var' => 'tags', 'isRequired' => false, 'type' => TType::LST, 'etype' => TType::STRUCT, - 'elem' => array( + 'elem' => [ 'type' => TType::STRUCT, 'class' => '\Jaeger\Thrift\Tag', - ), - ), - 11 => array( + ], + ], + 11 => [ 'var' => 'logs', 'isRequired' => false, 'type' => TType::LST, 'etype' => TType::STRUCT, - 'elem' => array( + 'elem' => [ 'type' => TType::STRUCT, 'class' => '\Jaeger\Thrift\Log', - ), - ), - ); + ], + ], + ]; - /** - * @var int - */ - public $traceIdLow = null; - /** - * @var int - */ - public $traceIdHigh = null; - /** - * @var int - */ - public $spanId = null; - /** - * @var int - */ - public $parentSpanId = null; - /** - * @var string - */ - public $operationName = null; + public ?int $traceIdLow = null; + public ?int $traceIdHigh = null; + public ?int $spanId = null; + public ?int $parentSpanId = null; + public ?string $operationName = null; /** * @var \Jaeger\Thrift\SpanRef[] */ - public $references = null; - /** - * @var int - */ - public $flags = null; - /** - * @var int - */ - public $startTime = null; - /** - * @var int - */ - public $duration = null; + public ?array $references = null; + public ?int $flags = null; + public ?int $startTime = null; + public ?int $duration = null; /** * @var \Jaeger\Thrift\Tag[] */ - public $tags = null; + public ?array $tags = null; /** * @var \Jaeger\Thrift\Log[] */ - public $logs = null; + public ?array $logs = null; - public function __construct($vals = null) + public function __construct(?array $vals = null) { if (is_array($vals)) { if (isset($vals['traceIdLow'])) { - $this->traceIdLow = $vals['traceIdLow']; + $this->traceIdLow = (int)$vals['traceIdLow']; } if (isset($vals['traceIdHigh'])) { - $this->traceIdHigh = $vals['traceIdHigh']; + $this->traceIdHigh = (int)$vals['traceIdHigh']; } if (isset($vals['spanId'])) { - $this->spanId = $vals['spanId']; + $this->spanId = (int)$vals['spanId']; } if (isset($vals['parentSpanId'])) { - $this->parentSpanId = $vals['parentSpanId']; + $this->parentSpanId = (int)$vals['parentSpanId']; } if (isset($vals['operationName'])) { - $this->operationName = $vals['operationName']; + $this->operationName = (string)$vals['operationName']; } if (isset($vals['references'])) { $this->references = $vals['references']; } if (isset($vals['flags'])) { - $this->flags = $vals['flags']; + $this->flags = (int)$vals['flags']; } if (isset($vals['startTime'])) { - $this->startTime = $vals['startTime']; + $this->startTime = (int)$vals['startTime']; } if (isset($vals['duration'])) { - $this->duration = $vals['duration']; + $this->duration = (int)$vals['duration']; } if (isset($vals['tags'])) { $this->tags = $vals['tags']; @@ -177,224 +158,235 @@ public function __construct($vals = null) } } - public function getName() + public function getName(): string { return 'Span'; } - - public function read($input) + public function read(TProtocol $input): int { $xfer = 0; $fname = null; $ftype = 0; $fid = 0; - $xfer += $input->readStructBegin($fname); - while (true) { - $xfer += $input->readFieldBegin($fname, $ftype, $fid); - if ($ftype == TType::STOP) { - break; - } - switch ($fid) { - case 1: - if ($ftype == TType::I64) { - $xfer += $input->readI64($this->traceIdLow); - } else { - $xfer += $input->skip($ftype); - } - break; - case 2: - if ($ftype == TType::I64) { - $xfer += $input->readI64($this->traceIdHigh); - } else { - $xfer += $input->skip($ftype); - } + $input->incrementRecursionDepth(); + try { + $xfer += $input->readStructBegin($fname); + while (true) { + $xfer += $input->readFieldBegin($fname, $ftype, $fid); + if ($ftype == TType::STOP) { break; - case 3: - if ($ftype == TType::I64) { - $xfer += $input->readI64($this->spanId); - } else { - $xfer += $input->skip($ftype); - } - break; - case 4: - if ($ftype == TType::I64) { - $xfer += $input->readI64($this->parentSpanId); - } else { - $xfer += $input->skip($ftype); - } - break; - case 5: - if ($ftype == TType::STRING) { - $xfer += $input->readString($this->operationName); - } else { - $xfer += $input->skip($ftype); - } - break; - case 6: - if ($ftype == TType::LST) { - $this->references = array(); - $_size7 = 0; - $_etype10 = 0; - $xfer += $input->readListBegin($_etype10, $_size7); - for ($_i11 = 0; $_i11 < $_size7; ++$_i11) { - $elem12 = null; - $elem12 = new \Jaeger\Thrift\SpanRef(); - $xfer += $elem12->read($input); - $this->references []= $elem12; + } + switch ($fid) { + case 1: + if ($ftype == TType::I64) { + $xfer += $input->readI64($this->traceIdLow); + } else { + $xfer += $input->skip($ftype); } - $xfer += $input->readListEnd(); - } else { - $xfer += $input->skip($ftype); - } - break; - case 7: - if ($ftype == TType::I32) { - $xfer += $input->readI32($this->flags); - } else { - $xfer += $input->skip($ftype); - } - break; - case 8: - if ($ftype == TType::I64) { - $xfer += $input->readI64($this->startTime); - } else { - $xfer += $input->skip($ftype); - } - break; - case 9: - if ($ftype == TType::I64) { - $xfer += $input->readI64($this->duration); - } else { - $xfer += $input->skip($ftype); - } - break; - case 10: - if ($ftype == TType::LST) { - $this->tags = array(); - $_size13 = 0; - $_etype16 = 0; - $xfer += $input->readListBegin($_etype16, $_size13); - for ($_i17 = 0; $_i17 < $_size13; ++$_i17) { - $elem18 = null; - $elem18 = new \Jaeger\Thrift\Tag(); - $xfer += $elem18->read($input); - $this->tags []= $elem18; + break; + case 2: + if ($ftype == TType::I64) { + $xfer += $input->readI64($this->traceIdHigh); + } else { + $xfer += $input->skip($ftype); } - $xfer += $input->readListEnd(); - } else { - $xfer += $input->skip($ftype); - } - break; - case 11: - if ($ftype == TType::LST) { - $this->logs = array(); - $_size19 = 0; - $_etype22 = 0; - $xfer += $input->readListBegin($_etype22, $_size19); - for ($_i23 = 0; $_i23 < $_size19; ++$_i23) { - $elem24 = null; - $elem24 = new \Jaeger\Thrift\Log(); - $xfer += $elem24->read($input); - $this->logs []= $elem24; + break; + case 3: + if ($ftype == TType::I64) { + $xfer += $input->readI64($this->spanId); + } else { + $xfer += $input->skip($ftype); + } + break; + case 4: + if ($ftype == TType::I64) { + $xfer += $input->readI64($this->parentSpanId); + } else { + $xfer += $input->skip($ftype); + } + break; + case 5: + if ($ftype == TType::STRING) { + $xfer += $input->readString($this->operationName); + } else { + $xfer += $input->skip($ftype); } - $xfer += $input->readListEnd(); - } else { + break; + case 6: + if ($ftype == TType::LST) { + $this->references = []; + $_size7 = 0; + $_etype10 = 0; + $xfer += $input->readListBegin($_etype10, $_size7); + for ($_i11 = 0; $_i11 < $_size7; ++$_i11) { + $elem12 = null; + $elem12 = new \Jaeger\Thrift\SpanRef(); + $xfer += $elem12->read($input); + $this->references[] = $elem12; + } + $xfer += $input->readListEnd(); + } else { + $xfer += $input->skip($ftype); + } + break; + case 7: + if ($ftype == TType::I32) { + $xfer += $input->readI32($this->flags); + } else { + $xfer += $input->skip($ftype); + } + break; + case 8: + if ($ftype == TType::I64) { + $xfer += $input->readI64($this->startTime); + } else { + $xfer += $input->skip($ftype); + } + break; + case 9: + if ($ftype == TType::I64) { + $xfer += $input->readI64($this->duration); + } else { + $xfer += $input->skip($ftype); + } + break; + case 10: + if ($ftype == TType::LST) { + $this->tags = []; + $_size13 = 0; + $_etype16 = 0; + $xfer += $input->readListBegin($_etype16, $_size13); + for ($_i17 = 0; $_i17 < $_size13; ++$_i17) { + $elem18 = null; + $elem18 = new \Jaeger\Thrift\Tag(); + $xfer += $elem18->read($input); + $this->tags[] = $elem18; + } + $xfer += $input->readListEnd(); + } else { + $xfer += $input->skip($ftype); + } + break; + case 11: + if ($ftype == TType::LST) { + $this->logs = []; + $_size19 = 0; + $_etype22 = 0; + $xfer += $input->readListBegin($_etype22, $_size19); + for ($_i23 = 0; $_i23 < $_size19; ++$_i23) { + $elem24 = null; + $elem24 = new \Jaeger\Thrift\Log(); + $xfer += $elem24->read($input); + $this->logs[] = $elem24; + } + $xfer += $input->readListEnd(); + } else { + $xfer += $input->skip($ftype); + } + break; + default: $xfer += $input->skip($ftype); - } - break; - default: - $xfer += $input->skip($ftype); - break; + break; + } + $xfer += $input->readFieldEnd(); } - $xfer += $input->readFieldEnd(); + $xfer += $input->readStructEnd(); + } finally { + $input->decrementRecursionDepth(); } - $xfer += $input->readStructEnd(); + return $xfer; } - public function write($output) + public function write(TProtocol $output): int { $xfer = 0; - $xfer += $output->writeStructBegin('Span'); - if ($this->traceIdLow !== null) { - $xfer += $output->writeFieldBegin('traceIdLow', TType::I64, 1); - $xfer += $output->writeI64($this->traceIdLow); - $xfer += $output->writeFieldEnd(); - } - if ($this->traceIdHigh !== null) { - $xfer += $output->writeFieldBegin('traceIdHigh', TType::I64, 2); - $xfer += $output->writeI64($this->traceIdHigh); - $xfer += $output->writeFieldEnd(); - } - if ($this->spanId !== null) { - $xfer += $output->writeFieldBegin('spanId', TType::I64, 3); - $xfer += $output->writeI64($this->spanId); - $xfer += $output->writeFieldEnd(); - } - if ($this->parentSpanId !== null) { - $xfer += $output->writeFieldBegin('parentSpanId', TType::I64, 4); - $xfer += $output->writeI64($this->parentSpanId); - $xfer += $output->writeFieldEnd(); - } - if ($this->operationName !== null) { - $xfer += $output->writeFieldBegin('operationName', TType::STRING, 5); - $xfer += $output->writeString($this->operationName); - $xfer += $output->writeFieldEnd(); - } - if ($this->references !== null) { - if (!is_array($this->references)) { - throw new TProtocolException('Bad type in structure.', TProtocolException::INVALID_DATA); + $output->incrementRecursionDepth(); + try { + $xfer += $output->writeStructBegin('Span'); + if ($this->traceIdLow !== null) { + $xfer += $output->writeFieldBegin('traceIdLow', TType::I64, 1); + $xfer += $output->writeI64($this->traceIdLow); + $xfer += $output->writeFieldEnd(); } - $xfer += $output->writeFieldBegin('references', TType::LST, 6); - $output->writeListBegin(TType::STRUCT, count($this->references)); - foreach ($this->references as $iter25) { - $xfer += $iter25->write($output); + if ($this->traceIdHigh !== null) { + $xfer += $output->writeFieldBegin('traceIdHigh', TType::I64, 2); + $xfer += $output->writeI64($this->traceIdHigh); + $xfer += $output->writeFieldEnd(); } - $output->writeListEnd(); - $xfer += $output->writeFieldEnd(); - } - if ($this->flags !== null) { - $xfer += $output->writeFieldBegin('flags', TType::I32, 7); - $xfer += $output->writeI32($this->flags); - $xfer += $output->writeFieldEnd(); - } - if ($this->startTime !== null) { - $xfer += $output->writeFieldBegin('startTime', TType::I64, 8); - $xfer += $output->writeI64($this->startTime); - $xfer += $output->writeFieldEnd(); - } - if ($this->duration !== null) { - $xfer += $output->writeFieldBegin('duration', TType::I64, 9); - $xfer += $output->writeI64($this->duration); - $xfer += $output->writeFieldEnd(); - } - if ($this->tags !== null) { - if (!is_array($this->tags)) { - throw new TProtocolException('Bad type in structure.', TProtocolException::INVALID_DATA); + if ($this->spanId !== null) { + $xfer += $output->writeFieldBegin('spanId', TType::I64, 3); + $xfer += $output->writeI64($this->spanId); + $xfer += $output->writeFieldEnd(); } - $xfer += $output->writeFieldBegin('tags', TType::LST, 10); - $output->writeListBegin(TType::STRUCT, count($this->tags)); - foreach ($this->tags as $iter26) { - $xfer += $iter26->write($output); + if ($this->parentSpanId !== null) { + $xfer += $output->writeFieldBegin('parentSpanId', TType::I64, 4); + $xfer += $output->writeI64($this->parentSpanId); + $xfer += $output->writeFieldEnd(); } - $output->writeListEnd(); - $xfer += $output->writeFieldEnd(); - } - if ($this->logs !== null) { - if (!is_array($this->logs)) { - throw new TProtocolException('Bad type in structure.', TProtocolException::INVALID_DATA); + if ($this->operationName !== null) { + $xfer += $output->writeFieldBegin('operationName', TType::STRING, 5); + $xfer += $output->writeString($this->operationName); + $xfer += $output->writeFieldEnd(); + } + if ($this->references !== null) { + if (!is_array($this->references)) { + throw new TProtocolException('Bad type in structure.', TProtocolException::INVALID_DATA); + } + $xfer += $output->writeFieldBegin('references', TType::LST, 6); + $output->writeListBegin(TType::STRUCT, count($this->references)); + foreach ($this->references as $iter25) { + $xfer += $iter25->write($output); + } + $output->writeListEnd(); + $xfer += $output->writeFieldEnd(); + } + if ($this->flags !== null) { + $xfer += $output->writeFieldBegin('flags', TType::I32, 7); + $xfer += $output->writeI32($this->flags); + $xfer += $output->writeFieldEnd(); } - $xfer += $output->writeFieldBegin('logs', TType::LST, 11); - $output->writeListBegin(TType::STRUCT, count($this->logs)); - foreach ($this->logs as $iter27) { - $xfer += $iter27->write($output); + if ($this->startTime !== null) { + $xfer += $output->writeFieldBegin('startTime', TType::I64, 8); + $xfer += $output->writeI64($this->startTime); + $xfer += $output->writeFieldEnd(); } - $output->writeListEnd(); - $xfer += $output->writeFieldEnd(); + if ($this->duration !== null) { + $xfer += $output->writeFieldBegin('duration', TType::I64, 9); + $xfer += $output->writeI64($this->duration); + $xfer += $output->writeFieldEnd(); + } + if ($this->tags !== null) { + if (!is_array($this->tags)) { + throw new TProtocolException('Bad type in structure.', TProtocolException::INVALID_DATA); + } + $xfer += $output->writeFieldBegin('tags', TType::LST, 10); + $output->writeListBegin(TType::STRUCT, count($this->tags)); + foreach ($this->tags as $iter26) { + $xfer += $iter26->write($output); + } + $output->writeListEnd(); + $xfer += $output->writeFieldEnd(); + } + if ($this->logs !== null) { + if (!is_array($this->logs)) { + throw new TProtocolException('Bad type in structure.', TProtocolException::INVALID_DATA); + } + $xfer += $output->writeFieldBegin('logs', TType::LST, 11); + $output->writeListBegin(TType::STRUCT, count($this->logs)); + foreach ($this->logs as $iter27) { + $xfer += $iter27->write($output); + } + $output->writeListEnd(); + $xfer += $output->writeFieldEnd(); + } + $xfer += $output->writeFieldStop(); + $xfer += $output->writeStructEnd(); + } finally { + $output->decrementRecursionDepth(); } - $xfer += $output->writeFieldStop(); - $xfer += $output->writeStructEnd(); + return $xfer; } } diff --git a/src/Thrift/SpanRef.php b/src/Thrift/SpanRef.php index 2d7fa4d..1bb1bda 100644 --- a/src/Thrift/SpanRef.php +++ b/src/Thrift/SpanRef.php @@ -1,167 +1,171 @@ array( + public static array $tspec = [ + 1 => [ 'var' => 'refType', 'isRequired' => true, 'type' => TType::I32, 'class' => '\Jaeger\Thrift\SpanRefType', - ), - 2 => array( + ], + 2 => [ 'var' => 'traceIdLow', 'isRequired' => true, 'type' => TType::I64, - ), - 3 => array( + ], + 3 => [ 'var' => 'traceIdHigh', 'isRequired' => true, 'type' => TType::I64, - ), - 4 => array( + ], + 4 => [ 'var' => 'spanId', 'isRequired' => true, 'type' => TType::I64, - ), - ); + ], + ]; - /** - * @var int - */ - public $refType = null; - /** - * @var int - */ - public $traceIdLow = null; - /** - * @var int - */ - public $traceIdHigh = null; - /** - * @var int - */ - public $spanId = null; + public ?int $refType = null; + public ?int $traceIdLow = null; + public ?int $traceIdHigh = null; + public ?int $spanId = null; - public function __construct($vals = null) + public function __construct(?array $vals = null) { if (is_array($vals)) { if (isset($vals['refType'])) { - $this->refType = $vals['refType']; + $this->refType = (int)$vals['refType']; } if (isset($vals['traceIdLow'])) { - $this->traceIdLow = $vals['traceIdLow']; + $this->traceIdLow = (int)$vals['traceIdLow']; } if (isset($vals['traceIdHigh'])) { - $this->traceIdHigh = $vals['traceIdHigh']; + $this->traceIdHigh = (int)$vals['traceIdHigh']; } if (isset($vals['spanId'])) { - $this->spanId = $vals['spanId']; + $this->spanId = (int)$vals['spanId']; } } } - public function getName() + public function getName(): string { return 'SpanRef'; } - - public function read($input) + public function read(TProtocol $input): int { $xfer = 0; $fname = null; $ftype = 0; $fid = 0; - $xfer += $input->readStructBegin($fname); - while (true) { - $xfer += $input->readFieldBegin($fname, $ftype, $fid); - if ($ftype == TType::STOP) { - break; - } - switch ($fid) { - case 1: - if ($ftype == TType::I32) { - $xfer += $input->readI32($this->refType); - } else { - $xfer += $input->skip($ftype); - } - break; - case 2: - if ($ftype == TType::I64) { - $xfer += $input->readI64($this->traceIdLow); - } else { - $xfer += $input->skip($ftype); - } - break; - case 3: - if ($ftype == TType::I64) { - $xfer += $input->readI64($this->traceIdHigh); - } else { - $xfer += $input->skip($ftype); - } + $input->incrementRecursionDepth(); + try { + $xfer += $input->readStructBegin($fname); + while (true) { + $xfer += $input->readFieldBegin($fname, $ftype, $fid); + if ($ftype == TType::STOP) { break; - case 4: - if ($ftype == TType::I64) { - $xfer += $input->readI64($this->spanId); - } else { + } + switch ($fid) { + case 1: + if ($ftype == TType::I32) { + $xfer += $input->readI32($this->refType); + } else { + $xfer += $input->skip($ftype); + } + break; + case 2: + if ($ftype == TType::I64) { + $xfer += $input->readI64($this->traceIdLow); + } else { + $xfer += $input->skip($ftype); + } + break; + case 3: + if ($ftype == TType::I64) { + $xfer += $input->readI64($this->traceIdHigh); + } else { + $xfer += $input->skip($ftype); + } + break; + case 4: + if ($ftype == TType::I64) { + $xfer += $input->readI64($this->spanId); + } else { + $xfer += $input->skip($ftype); + } + break; + default: $xfer += $input->skip($ftype); - } - break; - default: - $xfer += $input->skip($ftype); - break; + break; + } + $xfer += $input->readFieldEnd(); } - $xfer += $input->readFieldEnd(); + $xfer += $input->readStructEnd(); + } finally { + $input->decrementRecursionDepth(); } - $xfer += $input->readStructEnd(); + return $xfer; } - public function write($output) + public function write(TProtocol $output): int { $xfer = 0; - $xfer += $output->writeStructBegin('SpanRef'); - if ($this->refType !== null) { - $xfer += $output->writeFieldBegin('refType', TType::I32, 1); - $xfer += $output->writeI32($this->refType); - $xfer += $output->writeFieldEnd(); - } - if ($this->traceIdLow !== null) { - $xfer += $output->writeFieldBegin('traceIdLow', TType::I64, 2); - $xfer += $output->writeI64($this->traceIdLow); - $xfer += $output->writeFieldEnd(); - } - if ($this->traceIdHigh !== null) { - $xfer += $output->writeFieldBegin('traceIdHigh', TType::I64, 3); - $xfer += $output->writeI64($this->traceIdHigh); - $xfer += $output->writeFieldEnd(); - } - if ($this->spanId !== null) { - $xfer += $output->writeFieldBegin('spanId', TType::I64, 4); - $xfer += $output->writeI64($this->spanId); - $xfer += $output->writeFieldEnd(); + $output->incrementRecursionDepth(); + try { + $xfer += $output->writeStructBegin('SpanRef'); + if ($this->refType !== null) { + $xfer += $output->writeFieldBegin('refType', TType::I32, 1); + $xfer += $output->writeI32($this->refType); + $xfer += $output->writeFieldEnd(); + } + if ($this->traceIdLow !== null) { + $xfer += $output->writeFieldBegin('traceIdLow', TType::I64, 2); + $xfer += $output->writeI64($this->traceIdLow); + $xfer += $output->writeFieldEnd(); + } + if ($this->traceIdHigh !== null) { + $xfer += $output->writeFieldBegin('traceIdHigh', TType::I64, 3); + $xfer += $output->writeI64($this->traceIdHigh); + $xfer += $output->writeFieldEnd(); + } + if ($this->spanId !== null) { + $xfer += $output->writeFieldBegin('spanId', TType::I64, 4); + $xfer += $output->writeI64($this->spanId); + $xfer += $output->writeFieldEnd(); + } + $xfer += $output->writeFieldStop(); + $xfer += $output->writeStructEnd(); + } finally { + $output->decrementRecursionDepth(); } - $xfer += $output->writeFieldStop(); - $xfer += $output->writeStructEnd(); + return $xfer; } } diff --git a/src/Thrift/SpanRefType.php b/src/Thrift/SpanRefType.php index 9d881fc..5230aac 100644 --- a/src/Thrift/SpanRefType.php +++ b/src/Thrift/SpanRefType.php @@ -1,30 +1,34 @@ 'CHILD_OF', 1 => 'FOLLOWS_FROM', - ); + ]; } - diff --git a/src/Thrift/Tag.php b/src/Thrift/Tag.php index 8eaaa42..9b0886f 100644 --- a/src/Thrift/Tag.php +++ b/src/Thrift/Tag.php @@ -1,239 +1,234 @@ array( + public static array $tspec = [ + 1 => [ 'var' => 'key', 'isRequired' => true, 'type' => TType::STRING, - ), - 2 => array( + ], + 2 => [ 'var' => 'vType', 'isRequired' => true, 'type' => TType::I32, 'class' => '\Jaeger\Thrift\TagType', - ), - 3 => array( + ], + 3 => [ 'var' => 'vStr', 'isRequired' => false, 'type' => TType::STRING, - ), - 4 => array( + ], + 4 => [ 'var' => 'vDouble', 'isRequired' => false, 'type' => TType::DOUBLE, - ), - 5 => array( + ], + 5 => [ 'var' => 'vBool', 'isRequired' => false, 'type' => TType::BOOL, - ), - 6 => array( + ], + 6 => [ 'var' => 'vLong', 'isRequired' => false, 'type' => TType::I64, - ), - 7 => array( + ], + 7 => [ 'var' => 'vBinary', 'isRequired' => false, 'type' => TType::STRING, - ), - ); + ], + ]; - /** - * @var string - */ - public $key = null; - /** - * @var int - */ - public $vType = null; - /** - * @var string - */ - public $vStr = null; - /** - * @var double - */ - public $vDouble = null; - /** - * @var bool - */ - public $vBool = null; - /** - * @var int - */ - public $vLong = null; - /** - * @var string - */ - public $vBinary = null; + public ?string $key = null; + public ?int $vType = null; + public ?string $vStr = null; + public ?float $vDouble = null; + public ?bool $vBool = null; + public ?int $vLong = null; + public ?string $vBinary = null; - public function __construct($vals = null) + public function __construct(?array $vals = null) { if (is_array($vals)) { if (isset($vals['key'])) { - $this->key = $vals['key']; + $this->key = (string)$vals['key']; } if (isset($vals['vType'])) { - $this->vType = $vals['vType']; + $this->vType = (int)$vals['vType']; } if (isset($vals['vStr'])) { - $this->vStr = $vals['vStr']; + $this->vStr = (string)$vals['vStr']; } if (isset($vals['vDouble'])) { - $this->vDouble = $vals['vDouble']; + $this->vDouble = (float)$vals['vDouble']; } if (isset($vals['vBool'])) { - $this->vBool = $vals['vBool']; + $this->vBool = (bool)$vals['vBool']; } if (isset($vals['vLong'])) { - $this->vLong = $vals['vLong']; + $this->vLong = (int)$vals['vLong']; } if (isset($vals['vBinary'])) { - $this->vBinary = $vals['vBinary']; + $this->vBinary = (string)$vals['vBinary']; } } } - public function getName() + public function getName(): string { return 'Tag'; } - - public function read($input) + public function read(TProtocol $input): int { $xfer = 0; $fname = null; $ftype = 0; $fid = 0; - $xfer += $input->readStructBegin($fname); - while (true) { - $xfer += $input->readFieldBegin($fname, $ftype, $fid); - if ($ftype == TType::STOP) { - break; - } - switch ($fid) { - case 1: - if ($ftype == TType::STRING) { - $xfer += $input->readString($this->key); - } else { - $xfer += $input->skip($ftype); - } - break; - case 2: - if ($ftype == TType::I32) { - $xfer += $input->readI32($this->vType); - } else { - $xfer += $input->skip($ftype); - } - break; - case 3: - if ($ftype == TType::STRING) { - $xfer += $input->readString($this->vStr); - } else { - $xfer += $input->skip($ftype); - } - break; - case 4: - if ($ftype == TType::DOUBLE) { - $xfer += $input->readDouble($this->vDouble); - } else { - $xfer += $input->skip($ftype); - } - break; - case 5: - if ($ftype == TType::BOOL) { - $xfer += $input->readBool($this->vBool); - } else { - $xfer += $input->skip($ftype); - } - break; - case 6: - if ($ftype == TType::I64) { - $xfer += $input->readI64($this->vLong); - } else { - $xfer += $input->skip($ftype); - } + $input->incrementRecursionDepth(); + try { + $xfer += $input->readStructBegin($fname); + while (true) { + $xfer += $input->readFieldBegin($fname, $ftype, $fid); + if ($ftype == TType::STOP) { break; - case 7: - if ($ftype == TType::STRING) { - $xfer += $input->readString($this->vBinary); - } else { + } + switch ($fid) { + case 1: + if ($ftype == TType::STRING) { + $xfer += $input->readString($this->key); + } else { + $xfer += $input->skip($ftype); + } + break; + case 2: + if ($ftype == TType::I32) { + $xfer += $input->readI32($this->vType); + } else { + $xfer += $input->skip($ftype); + } + break; + case 3: + if ($ftype == TType::STRING) { + $xfer += $input->readString($this->vStr); + } else { + $xfer += $input->skip($ftype); + } + break; + case 4: + if ($ftype == TType::DOUBLE) { + $xfer += $input->readDouble($this->vDouble); + } else { + $xfer += $input->skip($ftype); + } + break; + case 5: + if ($ftype == TType::BOOL) { + $xfer += $input->readBool($this->vBool); + } else { + $xfer += $input->skip($ftype); + } + break; + case 6: + if ($ftype == TType::I64) { + $xfer += $input->readI64($this->vLong); + } else { + $xfer += $input->skip($ftype); + } + break; + case 7: + if ($ftype == TType::STRING) { + $xfer += $input->readString($this->vBinary); + } else { + $xfer += $input->skip($ftype); + } + break; + default: $xfer += $input->skip($ftype); - } - break; - default: - $xfer += $input->skip($ftype); - break; + break; + } + $xfer += $input->readFieldEnd(); } - $xfer += $input->readFieldEnd(); + $xfer += $input->readStructEnd(); + } finally { + $input->decrementRecursionDepth(); } - $xfer += $input->readStructEnd(); + return $xfer; } - public function write($output) + public function write(TProtocol $output): int { $xfer = 0; - $xfer += $output->writeStructBegin('Tag'); - if ($this->key !== null) { - $xfer += $output->writeFieldBegin('key', TType::STRING, 1); - $xfer += $output->writeString($this->key); - $xfer += $output->writeFieldEnd(); - } - if ($this->vType !== null) { - $xfer += $output->writeFieldBegin('vType', TType::I32, 2); - $xfer += $output->writeI32($this->vType); - $xfer += $output->writeFieldEnd(); - } - if ($this->vStr !== null) { - $xfer += $output->writeFieldBegin('vStr', TType::STRING, 3); - $xfer += $output->writeString($this->vStr); - $xfer += $output->writeFieldEnd(); - } - if ($this->vDouble !== null) { - $xfer += $output->writeFieldBegin('vDouble', TType::DOUBLE, 4); - $xfer += $output->writeDouble($this->vDouble); - $xfer += $output->writeFieldEnd(); - } - if ($this->vBool !== null) { - $xfer += $output->writeFieldBegin('vBool', TType::BOOL, 5); - $xfer += $output->writeBool($this->vBool); - $xfer += $output->writeFieldEnd(); - } - if ($this->vLong !== null) { - $xfer += $output->writeFieldBegin('vLong', TType::I64, 6); - $xfer += $output->writeI64($this->vLong); - $xfer += $output->writeFieldEnd(); - } - if ($this->vBinary !== null) { - $xfer += $output->writeFieldBegin('vBinary', TType::STRING, 7); - $xfer += $output->writeString($this->vBinary); - $xfer += $output->writeFieldEnd(); + $output->incrementRecursionDepth(); + try { + $xfer += $output->writeStructBegin('Tag'); + if ($this->key !== null) { + $xfer += $output->writeFieldBegin('key', TType::STRING, 1); + $xfer += $output->writeString($this->key); + $xfer += $output->writeFieldEnd(); + } + if ($this->vType !== null) { + $xfer += $output->writeFieldBegin('vType', TType::I32, 2); + $xfer += $output->writeI32($this->vType); + $xfer += $output->writeFieldEnd(); + } + if ($this->vStr !== null) { + $xfer += $output->writeFieldBegin('vStr', TType::STRING, 3); + $xfer += $output->writeString($this->vStr); + $xfer += $output->writeFieldEnd(); + } + if ($this->vDouble !== null) { + $xfer += $output->writeFieldBegin('vDouble', TType::DOUBLE, 4); + $xfer += $output->writeDouble($this->vDouble); + $xfer += $output->writeFieldEnd(); + } + if ($this->vBool !== null) { + $xfer += $output->writeFieldBegin('vBool', TType::BOOL, 5); + $xfer += $output->writeBool($this->vBool); + $xfer += $output->writeFieldEnd(); + } + if ($this->vLong !== null) { + $xfer += $output->writeFieldBegin('vLong', TType::I64, 6); + $xfer += $output->writeI64($this->vLong); + $xfer += $output->writeFieldEnd(); + } + if ($this->vBinary !== null) { + $xfer += $output->writeFieldBegin('vBinary', TType::STRING, 7); + $xfer += $output->writeString($this->vBinary); + $xfer += $output->writeFieldEnd(); + } + $xfer += $output->writeFieldStop(); + $xfer += $output->writeStructEnd(); + } finally { + $output->decrementRecursionDepth(); } - $xfer += $output->writeFieldStop(); - $xfer += $output->writeStructEnd(); + return $xfer; } } diff --git a/src/Thrift/TagType.php b/src/Thrift/TagType.php index bd2c32d..6831b01 100644 --- a/src/Thrift/TagType.php +++ b/src/Thrift/TagType.php @@ -1,39 +1,43 @@ 'STRING', 1 => 'DOUBLE', 2 => 'BOOL', 3 => 'LONG', 4 => 'BINARY', - ); + ]; } - diff --git a/src/Tracer/DebuggableInterface.php b/src/Tracer/DebuggableInterface.php index 5386161..633c4d0 100644 --- a/src/Tracer/DebuggableInterface.php +++ b/src/Tracer/DebuggableInterface.php @@ -1,15 +1,20 @@ $tags + */ public function debug(string $operationName, array $tags = []): SpanInterface; } diff --git a/src/Tracer/FinishableInterface.php b/src/Tracer/FinishableInterface.php index 459482e..3efa320 100644 --- a/src/Tracer/FinishableInterface.php +++ b/src/Tracer/FinishableInterface.php @@ -1,4 +1,5 @@ manager = $manager; - $this->factory = $factory; - $this->client = $client; - } + public function __construct( + private readonly SpanManagerInterface $manager, + private readonly SpanFactoryInterface $factory, + private readonly ClientInterface $client, + ) {} public function enable(string $debugId): DebuggableInterface { @@ -81,6 +76,9 @@ public function getClient(): ClientInterface return $this->client; } + /** + * @param array $tags + */ public function debug(string $operationName, array $tags = []): SpanInterface { $span = $this->factory->parent($this, $operationName, str_shuffle('01234567890abcdef'), $tags); @@ -89,13 +87,18 @@ public function debug(string $operationName, array $tags = []): SpanInterface return $span; } - public function start(string $operationName, array $tags = [], ?SpanContext $userContext = null): SpanInterface + /** + * @param array $tags + */ + public function start(string $operationName, array $tags = [], ?SpanContext $context = null): SpanInterface { - if (null === ($context = $userContext ?: $this->manager->getContext())) { + $spanContext = $context ?? $this->manager->getContext(); + if (!$spanContext instanceof SpanContext) { $span = $this->factory->parent($this, $operationName, $this->debugId, $tags); } else { - $span = $this->factory->child($this, $operationName, $context, $tags); + $span = $this->factory->child($this, $operationName, $spanContext, $tags); } + $this->manager->new($span); return $span; @@ -113,10 +116,12 @@ public function finish(SpanInterface $span, int $duration = 0): void return; } + $this->manager->finish($span); if (false === $span->isSampled()) { return; } + $this->client->add($span); } } diff --git a/src/Tracer/TracerInterface.php b/src/Tracer/TracerInterface.php index e1008af..e5c6ed6 100644 --- a/src/Tracer/TracerInterface.php +++ b/src/Tracer/TracerInterface.php @@ -1,12 +1,17 @@ $tags + */ public function start(string $operationName, array $tags = [], ?SpanContext $context = null): SpanInterface; } diff --git a/src/Transport/TUDPTransport.php b/src/Transport/TUDPTransport.php index 2c4b34c..9fd3cf0 100644 --- a/src/Transport/TUDPTransport.php +++ b/src/Transport/TUDPTransport.php @@ -1,53 +1,47 @@ host = $host; - $this->port = $port; - } + public function __construct( + private readonly string $host, + private readonly int $port, + ) {} public function isOpen(): bool { return true; } - public function open(): void - { - } + public function open(): void {} public function close(): void { - if (null === $this->socket) { + if (!$this->socket instanceof Socket) { return; } - \socket_close($this->socket); + + socket_close($this->socket); $this->socket = null; } - public function read($len): string + public function read(int $len): string { - return ''; + throw new TTransportException('TUDPTransport is write-only', TTransportException::UNKNOWN); } - public function write($buf): void + public function write(string $buf): void { $this->buffer .= $buf; } @@ -58,41 +52,47 @@ public function flush(): void if ('' === $this->buffer) { return; } + $this->doWrite($this->buffer); $this->buffer = ''; } - private function doWrite($buf): void + private function doWrite(string $buf): void { - if (null === ($socket = $this->connect())) { + if (!($socket = $this->connect()) instanceof Socket) { return; } + $length = \strlen($buf); while (true) { - if (false === ($result = @\socket_write($socket, $buf))) { + $result = @socket_write($socket, $buf); + if (false === $result) { break; } + if ($result >= $length) { break; } - $buf = \substr($buf, $result); + + $buf = substr($buf, $result); $length -= $result; } } - private function connect() + private function connect(): ?Socket { $count = 0; - while (false === \is_resource($this->socket) && $count < 5) { - if (false !== ($socket = \socket_create(AF_INET, SOCK_DGRAM, SOL_UDP))) { - @\socket_connect($socket, $this->host, $this->port); + while (!$this->socket instanceof Socket && $count < 5) { + if (false !== ($socket = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP))) { + @socket_connect($socket, $this->host, $this->port); $this->socket = $socket; break; } + $count++; usleep(10); } - return $this->socket ?: null; + return $this->socket; } } diff --git a/tests/Client/ThriftClientTest.php b/tests/Client/ThriftClientTest.php new file mode 100644 index 0000000..3d087dd --- /dev/null +++ b/tests/Client/ThriftClientTest.php @@ -0,0 +1,151 @@ +tracer = new RecordingTracer(); + } + + public function testShouldStartWithNoSpans(): void + { + self::assertSame([], new ThriftClient('a-service', new RecordingAgent())->getSpans()); + } + + public function testShouldCollectSpansWithoutEmittingThem(): void + { + $agent = new RecordingAgent(); + $client = new ThriftClient('a-service', $agent); + $span = $this->makeSpan(); + + self::assertSame($client, $client->add($span)); + + self::assertSame([$span], $client->getSpans()); + self::assertSame([], $agent->batches(), 'nothing leaves the client until flush()'); + $span->finish(); + } + + public function testShouldEmitCollectedSpansOnFlush(): void + { + $agent = new RecordingAgent(); + $client = new ThriftClient('a-service', $agent); + $spans = [$this->makeSpan(), $this->makeSpan()]; + foreach ($spans as $span) { + $client->add($span); + } + + self::assertSame($client, $client->flush()); + + self::assertCount(1, $agent->batches()); + self::assertSame($spans, $agent->batches()[0]->spans ?? []); + foreach ($spans as $span) { + $span->finish(); + } + } + + public function testShouldNameTheProcessAfterTheService(): void + { + $agent = new RecordingAgent(); + $client = new ThriftClient('a-service', $agent); + $span = $this->makeSpan(); + $client->add($span); + + $client->flush(); + + self::assertSame('a-service', $agent->batches()[0]->process?->serviceName); + $span->finish(); + } + + public function testShouldForgetItsSpansAfterFlushing(): void + { + $agent = new RecordingAgent(); + $client = new ThriftClient('a-service', $agent); + $span = $this->makeSpan(); + $client->add($span); + + $client->flush(); + $client->flush(); + + self::assertSame([], $client->getSpans()); + self::assertCount(1, $agent->batches(), 'a second flush has nothing left to emit'); + $span->finish(); + } + + public function testShouldEmitNothingWhenThereAreNoSpans(): void + { + $agent = new RecordingAgent(); + + new ThriftClient('a-service', $agent)->flush(); + + self::assertSame([], $agent->batches()); + } + + #[DataProvider('chunkingCases')] + public function testShouldSplitSpansIntoBatchesOfTheConfiguredSize( + int $spanCount, + int $batchSize, + int $expectedBatches, + ): void { + $agent = new RecordingAgent(); + $client = new ThriftClient('a-service', $agent, $batchSize); + $spans = []; + for ($i = 0; $i < $spanCount; $i++) { + $span = $this->makeSpan(); + $spans[] = $span; + $client->add($span); + } + + $client->flush(); + + self::assertCount($expectedBatches, $agent->batches()); + $emitted = 0; + foreach ($agent->batches() as $batch) { + $emitted += \count($batch->spans ?? []); + } + + self::assertSame($spanCount, $emitted); + foreach ($spans as $span) { + $span->finish(); + } + } + + /** + * @return iterable + */ + public static function chunkingCases(): iterable + { + yield 'βœ… one batch, partially full' => [3, 5, 1]; + yield 'βœ… exactly one full batch' => [5, 5, 1]; + yield 'βœ… two batches' => [6, 5, 2]; + yield 'βœ… every span in its own batch' => [4, 1, 4]; + yield 'βœ… default batch size holds 32' => [32, ThriftClient::MAX_BATCH_SIZE, 1]; + yield 'βœ… default batch size splits at 33' => [33, ThriftClient::MAX_BATCH_SIZE, 2]; + } + + public function testShouldDefaultToABatchSizeOfThirtyTwo(): void + { + self::assertSame(32, ThriftClient::MAX_BATCH_SIZE); + } + + private function makeSpan(): SpanInterface + { + return new Span($this->tracer, new SpanContext(1, 2, 3, 4, 1), 'an-operation', 1); + } +} diff --git a/tests/Codec/CodecRegistryTest.php b/tests/Codec/CodecRegistryTest.php new file mode 100644 index 0000000..8896520 --- /dev/null +++ b/tests/Codec/CodecRegistryTest.php @@ -0,0 +1,87 @@ +expectException(InvalidArgumentException::class); + $this->expectExceptionMessageIsOrContains('Codec must implement'); + + /** @psalm-suppress InvalidArgument β€” the point of the test is to pass the wrong type */ + $registry['text'] = 'not a codec'; + } + + public function testShouldRejectAppendingWithoutAKey(): void + { + $registry = new CodecRegistry(); + + $this->expectException(InvalidArgumentException::class); + $this->expectExceptionMessageIsOrContains('appending is not supported'); + + $registry[] = new TextCodec(); + } +} diff --git a/tests/Codec/TextCodecTest.php b/tests/Codec/TextCodecTest.php new file mode 100644 index 0000000..a921433 --- /dev/null +++ b/tests/Codec/TextCodecTest.php @@ -0,0 +1,111 @@ +encode($context)); + } + + #[DataProvider('encodingCases')] + public function testShouldDecodeWireFormatBackToContext(SpanContext $expected, string $encoded): void + { + $decoded = new TextCodec()->decode($encoded); + + self::assertInstanceOf(SpanContext::class, $decoded); + self::assertSame($expected->getTraceIdHigh(), $decoded->getTraceIdHigh()); + self::assertSame($expected->getTraceIdLow(), $decoded->getTraceIdLow()); + self::assertSame($expected->getSpanId(), $decoded->getSpanId()); + self::assertSame($expected->getParentId(), $decoded->getParentId()); + self::assertSame($expected->getFlags(), $decoded->getFlags()); + } + + /** + * @return iterable + */ + public static function encodingCases(): iterable + { + yield 'πŸ“­ all zeroes' => [new SpanContext(0, 0, 0, 0, 0), '00:0:0:0']; + yield 'βœ… sampled context' => [new SpanContext(0, 0x1a, 0x2b, 0x3c, 1), '01a:2b:3c:1']; + // traceIdLow must occupy a full 16 hex digits for the high/low boundary to survive a round trip. + yield 'βœ… 128-bit trace id' => [ + new SpanContext(0xaa, 0x7abcdef012345678, 0xcc, 0xdd, 3), + 'aa7abcdef012345678:cc:dd:3', + ]; + } + + #[DataProvider('undecodableCases')] + public function testShouldRejectInputItCannotDecode(mixed $data): void + { + self::assertNull(new TextCodec()->decode($data)); + } + + /** + * @return iterable + */ + public static function undecodableCases(): iterable + { + yield '🚫 not a string' => [42]; + yield '🚫 null' => [null]; + yield '🚫 array' => [['1', '2', '3', '4']]; + yield '🚫 too few segments' => ['1:2:3']; + yield '🚫 too many segments' => ['1:2:3:4:5']; + yield '🚫 empty string' => ['']; + } + + public function testShouldRoundTripA128BitTraceIdThroughEncodeAndDecode(): void + { + $codec = new TextCodec(); + $original = new SpanContext(0x1122334455667788, 0x7abcdef012345678, 0x1234, 0x5678, 1); + + $decoded = $codec->decode($codec->encode($original)); + + self::assertInstanceOf(SpanContext::class, $decoded); + self::assertSame($original->getTraceIdHigh(), $decoded->getTraceIdHigh()); + self::assertSame($original->getTraceIdLow(), $decoded->getTraceIdLow()); + } + + /** + * encode() writes the trace id as '%x%x' with no padding, so a traceIdLow shorter than + * 16 hex digits makes the high/low boundary unrecoverable. This pins that known asymmetry. + */ + public function testShouldLoseTheHighLowBoundaryWhenTraceIdLowIsNotPadded(): void + { + $codec = new TextCodec(); + $original = new SpanContext(0xaa, 0xbb, 0xcc, 0xdd, 3); + + $decoded = $codec->decode($codec->encode($original)); + + self::assertInstanceOf(SpanContext::class, $decoded); + self::assertSame(0, $decoded->getTraceIdHigh()); + self::assertSame(0xaabb, $decoded->getTraceIdLow()); + } + + public function testShouldConvertHexToSignedInt64(): void + { + $codec = new TextCodec(); + + self::assertSame(0, $codec->convertInt64('0')); + self::assertSame(255, $codec->convertInt64('ff')); + self::assertSame(-1, $codec->convertInt64('ffffffffffffffff')); + self::assertSame(PHP_INT_MAX, $codec->convertInt64('7fffffffffffffff')); + } + + public function testShouldSplitHexIntoHighAndLowHalves(): void + { + self::assertSame([0, 255], new TextCodec()->convertInt128('ff')); + self::assertSame([1, 0], new TextCodec()->convertInt128('10000000000000000')); + } +} diff --git a/tests/Fixture/RecordingAgent.php b/tests/Fixture/RecordingAgent.php new file mode 100644 index 0000000..7288f8d --- /dev/null +++ b/tests/Fixture/RecordingAgent.php @@ -0,0 +1,42 @@ + + */ + private array $batches = []; + + public function emitZipkinBatch(?array $spans): void + { + throw new LogicException('ThriftClient never emits Zipkin batches'); + } + + public function emitBatch(?Batch $batch): void + { + if (!$batch instanceof Batch) { + throw new LogicException('ThriftClient never emits a null batch'); + } + + $this->batches[] = $batch; + } + + /** + * @return list + */ + public function batches(): array + { + return $this->batches; + } +} diff --git a/tests/Fixture/RecordingClient.php b/tests/Fixture/RecordingClient.php new file mode 100644 index 0000000..16249c9 --- /dev/null +++ b/tests/Fixture/RecordingClient.php @@ -0,0 +1,49 @@ + + */ + private array $spans = []; + + private int $flushCount = 0; + + public function add(SpanInterface $span): ClientInterface + { + $this->spans[] = $span; + + return $this; + } + + /** + * @return list + */ + public function getSpans(): array + { + return $this->spans; + } + + public function flush(): ClientInterface + { + $this->flushCount++; + $this->spans = []; + + return $this; + } + + public function flushCount(): int + { + return $this->flushCount; + } +} diff --git a/tests/Fixture/RecordingTracer.php b/tests/Fixture/RecordingTracer.php new file mode 100644 index 0000000..29f0afd --- /dev/null +++ b/tests/Fixture/RecordingTracer.php @@ -0,0 +1,57 @@ + + */ + private array $finished = []; + + private int $nextSpanId = 1; + + /** + * @param array $tags + */ + public function start(string $operationName, array $tags = [], ?SpanContext $context = null): SpanInterface + { + return new Span( + $this, + $context ?? new SpanContext(0, 1, $this->nextSpanId++, 0, 1), + $operationName, + (int) (microtime(true) * 1000000.0), + $tags, + ); + } + + public function finish(SpanInterface $span, int $duration = 0): void + { + $this->finished[] = [$span, $duration]; + } + + /** + * @return list + */ + public function finishedCalls(): array + { + return $this->finished; + } + + public function finishedCount(): int + { + return \count($this->finished); + } +} diff --git a/tests/Fixture/SequenceIdGenerator.php b/tests/Fixture/SequenceIdGenerator.php new file mode 100644 index 0000000..3e9963a --- /dev/null +++ b/tests/Fixture/SequenceIdGenerator.php @@ -0,0 +1,35 @@ + $ids + */ + public function __construct(private readonly array $ids) {} + + public function next(): int + { + if (!\array_key_exists($this->position, $this->ids)) { + throw new RuntimeException(\sprintf('SequenceIdGenerator ran out of ids after %d calls', $this->position)); + } + + return $this->ids[$this->position++]; + } + + public function callCount(): int + { + return $this->position; + } +} diff --git a/tests/Fixture/UdpListener.php b/tests/Fixture/UdpListener.php new file mode 100644 index 0000000..ce0b247 --- /dev/null +++ b/tests/Fixture/UdpListener.php @@ -0,0 +1,59 @@ + 0, 'usec' => 300000]); + socket_getsockname($socket, $address, $port); + + $this->socket = $socket; + $this->port = $port; + } + + public function port(): int + { + return $this->port; + } + + /** + * Blocks for at most 300ms; returns null when nothing arrives. + */ + public function receive(): ?string + { + $buffer = ''; + $from = ''; + $fromPort = 0; + $read = socket_recvfrom($this->socket, $buffer, 65535, 0, $from, $fromPort); + + return false === $read ? null : $buffer; + } + + public function close(): void + { + socket_close($this->socket); + } +} diff --git a/tests/Id/RandomIntGeneratorTest.php b/tests/Id/RandomIntGeneratorTest.php new file mode 100644 index 0000000..cbec422 --- /dev/null +++ b/tests/Id/RandomIntGeneratorTest.php @@ -0,0 +1,54 @@ +next()); + } + + public function testShouldSpanTheWholeSignedRange(): void + { + $generator = new RandomIntGenerator(); + + for ($i = 0; $i < 100; $i++) { + $id = $generator->next(); + self::assertGreaterThanOrEqual(PHP_INT_MIN, $id); + self::assertLessThanOrEqual(PHP_INT_MAX, $id); + } + } + + public function testShouldNotRepeatItselfAcrossCalls(): void + { + $generator = new RandomIntGenerator(); + + $ids = []; + for ($i = 0; $i < 50; $i++) { + $ids[] = $generator->next(); + } + + self::assertCount(50, array_unique($ids), 'a 64-bit random id must not collide in 50 draws'); + } + + public function testShouldProduceBothPositiveAndNegativeIds(): void + { + $generator = new RandomIntGenerator(); + + $signs = []; + for ($i = 0; $i < 200; $i++) { + $signs[$generator->next() < 0 ? 'negative' : 'positive'] = true; + } + + self::assertArrayHasKey('negative', $signs); + self::assertArrayHasKey('positive', $signs); + } +} diff --git a/tests/Log/LogTest.php b/tests/Log/LogTest.php new file mode 100644 index 0000000..e2370e9 --- /dev/null +++ b/tests/Log/LogTest.php @@ -0,0 +1,129 @@ +fields ?? [] as $tag) { + $fields[(string) $tag->key] = $tag->vStr; + } + + self::assertSame($expectedFields, $fields); + } + + /** + * @return iterable}> + */ + public static function logCases(): iterable + { + yield 'βœ… ErrorLog' => [ + new ErrorLog('it broke', '#0 main()', 1_700_000_000_000_000), + ['event' => 'error', 'message' => 'it broke', 'stack' => '#0 main()'], + ]; + yield 'πŸ“­ ErrorLog β€” empty strings' => [ + new ErrorLog('', '', 1), + ['event' => 'error', 'message' => '', 'stack' => ''], + ]; + yield 'βœ… UserLog' => [ + new UserLog('user.created', 'info', 'a message', 1_700_000_000_000_000), + ['event' => 'user.created', 'level' => 'info', 'message' => 'a message'], + ]; + } + + #[DataProvider('timestampCases')] + public function testShouldUseAnExplicitTimestampWhenGiven(AbstractLog $log, int $expected): void + { + self::assertSame($expected, $log->timestamp); + } + + /** + * @return iterable + */ + public static function timestampCases(): iterable + { + yield 'βœ… ErrorLog' => [new ErrorLog('m', 's', 1_700_000_000_000_000), 1_700_000_000_000_000]; + yield 'βœ… UserLog' => [new UserLog('e', 'l', 'm', 42), 42]; + } + + public function testShouldStampTheCurrentTimeWhenNoTimestampIsGiven(): void + { + $before = (int) round(microtime(true) * 1000000.0); + + $log = new ErrorLog('it broke', '#0 main()'); + + $after = (int) round(microtime(true) * 1000000.0); + self::assertGreaterThanOrEqual($before, $log->timestamp); + self::assertLessThanOrEqual($after, $log->timestamp); + } + + public function testShouldTreatTimestampZeroAsMeaningNow(): void + { + $log = new UserLog('e', 'l', 'm', 0); + + self::assertGreaterThan(0, $log->timestamp); + } + + public function testShouldAcceptAnEmptyFieldList(): void + { + $log = new class ([], 42) extends AbstractLog {}; + + self::assertSame([], $log->fields); + self::assertSame(42, $log->timestamp); + } + + public function testShouldKeepArbitraryFieldTags(): void + { + $tag = new StringTag('custom', 'value'); + + $log = new class ([$tag], 1) extends AbstractLog {}; + + self::assertSame([$tag], $log->fields); + } + + public function testShouldSerialiseAJsonObjectIntoAnErrorObjectTag(): void + { + $value = new class implements JsonSerializable { + public function jsonSerialize(): array + { + return ['code' => 500, 'reason' => 'boom']; + } + }; + + $tag = new ErrorObjectTag($value); + + self::assertSame('error.object', $tag->key); + self::assertSame('{"code":500,"reason":"boom"}', $tag->vStr); + } + + public function testShouldFallBackToAnEmptyStringWhenTheObjectCannotBeEncoded(): void + { + $value = new class implements JsonSerializable { + public function jsonSerialize(): string + { + return "\xB1\x31"; + } + }; + + self::assertSame('', new ErrorObjectTag($value)->vStr); + } +} diff --git a/tests/Process/ProcessTest.php b/tests/Process/ProcessTest.php new file mode 100644 index 0000000..db3a6c4 --- /dev/null +++ b/tests/Process/ProcessTest.php @@ -0,0 +1,176 @@ + $processClass + */ + #[DataProvider('processCases')] + public function testShouldCarryItsServiceName(string $processClass): void + { + self::assertSame('a-service', new $processClass('a-service')->serviceName); + } + + /** + * Every process describes its runtime, so a trace can be attributed to a host and PHP build. + */ + /** + * @param class-string $processClass + */ + #[DataProvider('processCases')] + public function testShouldDescribeItsRuntime(string $processClass): void + { + $process = new $processClass('a-service'); + /** @var array $processTags */ + $processTags = $process->tags; + $keys = array_map(static fn(Tag $tag): string => (string) $tag->key, $processTags); + + foreach ([ + 'jaeger.version', + 'jaeger.hostname', + 'php.bin', + 'php.version', + 'process.pid', + 'process.sapi', + 'process.uid', + 'process.gid', + ] as $expected) { + self::assertContains($expected, $keys); + } + } + + /** + * @param class-string $processClass + */ + #[DataProvider('processCases')] + public function testShouldReportTheProcessIp(string $processClass): void + { + $process = new $processClass('a-service'); + /** @var array $processTags */ + $processTags = $process->tags; + $keys = array_map(static fn(Tag $tag): string => (string) $tag->key, $processTags); + + self::assertContains('ip', $keys); + } + + /** + * @return iterable}> + */ + public static function processCases(): iterable + { + yield 'βœ… CliProcess' => [CliProcess::class]; + yield 'βœ… FpmProcess' => [FpmProcess::class]; + yield 'βœ… InternalServerProcess' => [InternalServerProcess::class]; + } + + public function testShouldKeepCallerSuppliedTagsAlongsideTheRuntimeTags(): void + { + $process = new CliProcess('a-service'); + /** @var array $processTags */ + $processTags = $process->tags; + $keys = array_map(static fn(Tag $tag): string => (string) $tag->key, $processTags); + + self::assertSame('ip', $keys[0], 'caller tags come first'); + self::assertGreaterThan(8, \count($keys)); + } + + public function testShouldReportTheHostnameItIsRunningOn(): void + { + $tag = new JaegerHostnameTag(); + + self::assertSame('jaeger.hostname', $tag->key); + self::assertSame(gethostname(), $tag->vStr); + } + + public function testShouldReportANonEmptyIp(): void + { + $tag = new ProcessIpTag(); + + self::assertSame('ip', $tag->key); + self::assertSame(TagType::STRING, $tag->vType); + self::assertNotSame('', $tag->vStr); + } + + public function testShouldPreferTheServerAddressForTheIpWhenAvailable(): void + { + $original = $_SERVER['SERVER_ADDR'] ?? null; + $_SERVER['SERVER_ADDR'] = '10.11.12.13'; + + try { + self::assertSame('10.11.12.13', new ProcessIpTag()->vStr); + } finally { + if (null === $original) { + unset($_SERVER['SERVER_ADDR']); + } else { + $_SERVER['SERVER_ADDR'] = $original; + } + } + } + + public function testShouldFallBackToTheHostnameWhenServerAddressIsEmpty(): void + { + $original = $_SERVER['SERVER_ADDR'] ?? null; + $_SERVER['SERVER_ADDR'] = ''; + + try { + self::assertNotSame('', new ProcessIpTag()->vStr); + } finally { + if (null === $original) { + unset($_SERVER['SERVER_ADDR']); + } else { + $_SERVER['SERVER_ADDR'] = $original; + } + } + } + + public function testShouldReportTheRunningProcessIdentity(): void + { + self::assertSame(getmypid(), new ProcessPidTag()->vLong); + self::assertSame(getmyuid(), new ProcessUidTag()->vLong); + self::assertSame(getmygid(), new ProcessGidTag()->vLong); + } + + public function testShouldAcceptAnEmptyExtraTagList(): void + { + $process = new class ('a-service') extends AbstractProcess {}; + + self::assertSame('a-service', $process->serviceName); + self::assertCount(8, $process->tags ?? [], 'only the runtime tags are present'); + } + + public function testShouldPlaceCallerTagsBeforeRuntimeTags(): void + { + $process = new class ('a-service', [new ComponentTag('db')]) extends AbstractProcess {}; + + self::assertSame('component', ($process->tags ?? [])[0]->key); + } +} diff --git a/tests/Sampler/AdaptiveSamplerTest.php b/tests/Sampler/AdaptiveSamplerTest.php new file mode 100644 index 0000000..c91f0af --- /dev/null +++ b/tests/Sampler/AdaptiveSamplerTest.php @@ -0,0 +1,102 @@ +decide(1, 'an-operation', ''); + + self::assertTrue($result->isSampled()); + self::assertSame(0x01, $result->getFlags()); + } + + public function testShouldLabelARateLimitedDecisionAsAdaptive(): void + { + $sampler = new AdaptiveSampler(new ConstSampler(true), new ConstSampler(false)); + + $types = $this->tagValues($sampler->decide(1, 'an-operation', ''), 'sampler.type'); + + self::assertSame(['adaptive', 'const'], $types); + } + + public function testShouldFallBackToTheProbabilisticSampler(): void + { + $sampler = new AdaptiveSampler(new ConstSampler(false), new ConstSampler(true)); + + self::assertTrue($sampler->decide(1, 'an-operation', '')->isSampled()); + } + + /** + * KNOWN DEFECT: when the probabilistic sampler is the one that decides to sample, + * AdaptiveSampler still copies flags and tags from the rate limiter that just rejected + * the trace. The span is marked sampled but carries flags 0 and the rejecting sampler's + * tags. Pinned here so the behaviour cannot change silently. + */ + public function testShouldCopyTheRateLimiterFlagsEvenWhenTheProbabilisticSamplerDecides(): void + { + $sampler = new AdaptiveSampler(new ConstSampler(false), new ConstSampler(true)); + + $result = $sampler->decide(1, 'an-operation', ''); + + self::assertTrue($result->isSampled()); + self::assertSame(0, $result->getFlags(), 'flags come from the rejecting rate limiter'); + self::assertSame([false], $this->tagValues($result, 'sampler.decision')); + } + + public function testShouldRejectWhenNeitherSamplerSamples(): void + { + $sampler = new AdaptiveSampler(new ConstSampler(false), new ConstSampler(false)); + + $result = $sampler->decide(1, 'an-operation', ''); + + self::assertFalse($result->isSampled()); + self::assertSame(0, $result->getFlags()); + } + + public function testShouldLabelARejectionAsAdaptive(): void + { + $sampler = new AdaptiveSampler(new ConstSampler(false), new ConstSampler(false)); + + $result = $sampler->decide(1, 'an-operation', ''); + + self::assertSame(['adaptive'], $this->tagValues($result, 'sampler.type')); + self::assertSame([false], $this->tagValues($result, 'sampler.decision')); + } + + public function testShouldPassTheDebugIdThroughToTheUnderlyingSamplers(): void + { + $sampler = new AdaptiveSampler(new ConstSampler(false), new ConstSampler(false)); + + $result = $sampler->decide(1, 'an-operation', 'debug-id-42'); + + self::assertTrue($result->isSampled(), 'the rate limiter honours the debug id'); + } + + /** + * @return list + */ + private function tagValues(SamplerResult $result, string $key): array + { + $values = []; + foreach ($result->getTags() as $tag) { + if ($key === $tag->key) { + $values[] = $tag->vStr ?? $tag->vBool ?? $tag->vLong; + } + } + + return $values; + } +} diff --git a/tests/Sampler/ConstSamplerTest.php b/tests/Sampler/ConstSamplerTest.php new file mode 100644 index 0000000..1e002c7 --- /dev/null +++ b/tests/Sampler/ConstSamplerTest.php @@ -0,0 +1,94 @@ +decide($traceId, 'an-operation', ''); + + self::assertSame($expectedSampled, $result->isSampled()); + self::assertSame($expectedFlags, $result->getFlags()); + } + + /** + * @return iterable + */ + public static function decisionCases(): iterable + { + yield 'βœ… enabled β€” zero id' => [true, 0, true, 0x01]; + yield 'βœ… enabled β€” max id' => [true, PHP_INT_MAX, true, 0x01]; + yield 'βœ… enabled β€” min id' => [true, PHP_INT_MIN, true, 0x01]; + yield 'πŸ“­ disabled β€” zero id' => [false, 0, false, 0]; + yield 'πŸ“­ disabled β€” max id' => [false, PHP_INT_MAX, false, 0]; + } + + #[DataProvider('tagCases')] + public function testShouldDescribeItselfThroughTags(bool $debugEnabled, string $expectedParam): void + { + $result = new ConstSampler($debugEnabled)->decide(1, 'an-operation', ''); + + $tags = []; + foreach ($result->getTags() as $tag) { + $tags[(string) $tag->key] = $tag->vStr ?? $tag->vBool ?? $tag->vLong; + } + + self::assertSame('const', $tags['sampler.type']); + self::assertSame($expectedParam, $tags['sampler.param']); + self::assertSame($debugEnabled, $tags['sampler.decision']); + } + + /** + * @return iterable + */ + public static function tagCases(): iterable + { + yield 'βœ… enabled' => [true, 'True']; + yield 'πŸ“­ disabled' => [false, 'False']; + } + + public function testShouldAlwaysSampleWhenADebugIdIsSupplied(): void + { + $result = new ConstSampler(false)->decide(1, 'an-operation', 'debug-id-42'); + + self::assertTrue($result->isSampled()); + self::assertSame(0x03, $result->getFlags()); + } + + public function testShouldTagADebugDecisionWithTheSuppliedDebugId(): void + { + $result = new ConstSampler(false)->decide(1, 'an-operation', 'debug-id-42'); + + $tags = []; + foreach ($result->getTags() as $tag) { + $tags[(string) $tag->key] = $tag->vStr ?? $tag->vBool ?? $tag->vLong; + } + + self::assertSame('debug', $tags['sampler.type']); + self::assertSame('debug-id-42', $tags['debug']); + self::assertSame(1, $tags['sampling.priority']); + self::assertTrue($tags['sampler.decision']); + } + + public function testShouldReturnASamplerResult(): void + { + self::assertInstanceOf(SamplerResult::class, new ConstSampler(true)->decide(1, 'op', '')); + } +} diff --git a/tests/Sampler/GeneratorTest.php b/tests/Sampler/GeneratorTest.php new file mode 100644 index 0000000..69ee262 --- /dev/null +++ b/tests/Sampler/GeneratorTest.php @@ -0,0 +1,51 @@ +generate($traceId, $operationName)); + } + + /** + * @return iterable + */ + public static function constCases(): iterable + { + yield 'πŸ“­ zero id, empty operation' => [0, '']; + yield 'βœ… populated' => [42, 'an-operation']; + yield 'βœ… negative id' => [-42, 'another-operation']; + } + + #[DataProvider('operationCases')] + public function testOperationGeneratorShouldKeyOnTheOperationName( + int $traceId, + string $operationName, + string $expected, + ): void { + self::assertSame($expected, new OperationGenerator()->generate($traceId, $operationName)); + } + + /** + * @return iterable + */ + public static function operationCases(): iterable + { + yield 'πŸ“­ empty operation' => [0, '', 'operation:']; + yield 'βœ… populated' => [42, 'an-operation', 'operation:an-operation']; + yield 'βœ… id does not affect the key' => [-1, 'an-operation', 'operation:an-operation']; + } +} diff --git a/tests/Sampler/ProbabilisticSamplerTest.php b/tests/Sampler/ProbabilisticSamplerTest.php new file mode 100644 index 0000000..94fd790 --- /dev/null +++ b/tests/Sampler/ProbabilisticSamplerTest.php @@ -0,0 +1,80 @@ +decide($traceId, 'an-operation', ''); + + self::assertSame($expectedSampled, $result->isSampled()); + } + + /** + * @return iterable + */ + public static function decisionCases(): iterable + { + yield 'πŸ“­ rate 0 β€” id 0 still inside' => [0.0, 0, true]; + yield '🚫 rate 0 β€” any other id is out' => [0.0, 1, false]; + yield '🚫 rate 0 β€” max id is out' => [0.0, PHP_INT_MAX, false]; + yield 'βœ… rate 1 β€” small id' => [1.0, 1, true]; + yield 'βœ… rate 1 β€” just inside half of PHP_INT_MAX' => [1.0, (int) (0.4 * (float) PHP_INT_MAX), true]; + yield '🚫 rate 1 β€” beyond half of PHP_INT_MAX' => [1.0, (int) (0.6 * (float) PHP_INT_MAX), false]; + yield 'βœ… rate 1 β€” negative ids use absolute value' => [1.0, -1, true]; + yield '🚫 rate 0.001 β€” mid-range id is out' => [0.001, (int) (0.5 * (float) PHP_INT_MAX), false]; + } + + public function testShouldFlagASampledTraceAsSampled(): void + { + $result = new ProbabilisticSampler(1.0)->decide(1, 'an-operation', ''); + + self::assertTrue($result->isSampled()); + self::assertSame(0x01, $result->getFlags()); + } + + public function testShouldNotFlagARejectedTrace(): void + { + $result = new ProbabilisticSampler(0.0)->decide(PHP_INT_MAX, 'an-operation', ''); + + self::assertFalse($result->isSampled()); + self::assertSame(0x00, $result->getFlags()); + } + + #[DataProvider('tagCases')] + public function testShouldReportItsRateThroughTags(float $rate, int $traceId, string $expectedParam): void + { + $result = new ProbabilisticSampler($rate)->decide($traceId, 'an-operation', ''); + + $tags = []; + foreach ($result->getTags() as $tag) { + $tags[(string) $tag->key] = $tag->vStr ?? $tag->vBool ?? $tag->vLong; + } + + self::assertSame('probabilistic', $tags['sampler.type']); + self::assertSame($expectedParam, $tags['sampler.param']); + } + + /** + * @return iterable + */ + public static function tagCases(): iterable + { + yield 'βœ… sampled' => [1.0, 1, '1']; + yield '🚫 rejected' => [0.0, PHP_INT_MAX, '0']; + yield 'βœ… fractional rate' => [0.5, 1, '0.5']; + } +} diff --git a/tests/Sampler/RateLimitingSamplerTest.php b/tests/Sampler/RateLimitingSamplerTest.php new file mode 100644 index 0000000..ae5ea4b --- /dev/null +++ b/tests/Sampler/RateLimitingSamplerTest.php @@ -0,0 +1,132 @@ +spec($sampler->value($seconds, $count))); + } + + /** + * @return iterable + */ + public static function packingCases(): iterable + { + yield 'πŸ“­ zero' => [0, 0]; + yield 'βœ… typical' => [1700000000, 7]; + yield 'βœ… max count in 16 bits' => [1700000000, 0xffff]; + yield 'βœ… count of one' => [1, 1]; + } + + public function testShouldSampleTheFirstTraceForAKey(): void + { + $sampler = new RateLimitingSampler(1.0, new ConstGenerator()); + + $result = $sampler->decide(1, 'an-operation', ''); + + self::assertTrue($result->isSampled()); + self::assertSame(0x01, $result->getFlags()); + } + + public function testShouldRejectTracesOnceTheRateIsExhausted(): void + { + $sampler = new RateLimitingSampler(1.0, new ConstGenerator()); + + $sampler->decide(1, 'an-operation', ''); + + $second = $sampler->decide(2, 'an-operation', ''); + + self::assertFalse($second->isSampled(), 'a rate of 1/s must not admit a second trace in the same second'); + } + + public function testShouldKeepSeparateBudgetsPerOperation(): void + { + $sampler = new RateLimitingSampler(1.0, new OperationGenerator()); + + $first = $sampler->decide(1, 'operation-a', ''); + $second = $sampler->decide(2, 'operation-b', ''); + + self::assertTrue($first->isSampled()); + self::assertTrue($second->isSampled(), 'a different operation has its own budget'); + } + + public function testShouldDescribeItselfThroughTags(): void + { + $sampler = new RateLimitingSampler(2.5, new ConstGenerator()); + + $tags = []; + foreach ($sampler->decide(1, 'an-operation', '')->getTags() as $tag) { + $tags[(string) $tag->key] = $tag->vStr ?? $tag->vBool ?? $tag->vLong; + } + + self::assertSame('ratelimiting', $tags['sampler.type']); + self::assertSame('2.5', $tags['sampler.param']); + self::assertTrue($tags['sampler.decision']); + } + + /** + * A generous rate lets later traces through the compare-and-swap path rather than the + * initial apcu_add, which is a different branch of doDecide(). + */ + public function testShouldKeepAdmittingTracesWhileTheRateAllowsIt(): void + { + $sampler = new RateLimitingSampler(1000.0, new ConstGenerator()); + + $decisions = []; + for ($i = 0; $i < 5; $i++) { + $decisions[] = $sampler->decide($i, 'an-operation', '')->isSampled(); + } + + self::assertSame([true, true, true, true, true], $decisions); + } + + public function testShouldTagAnAdmittedTraceWithItsCounterKey(): void + { + $sampler = new RateLimitingSampler(1000.0, new ConstGenerator()); + $sampler->decide(1, 'an-operation', ''); + + $tags = []; + foreach ($sampler->decide(2, 'an-operation', '')->getTags() as $tag) { + $tags[(string) $tag->key][] = $tag->vStr ?? $tag->vBool ?? $tag->vLong; + } + + self::assertContains('const', $tags['sampler.param'], 'the counter key is reported'); + self::assertSame(['ratelimiting'], $tags['sampler.type']); + } + + public function testShouldAlwaysSampleWhenADebugIdIsSupplied(): void + { + $sampler = new RateLimitingSampler(1.0, new ConstGenerator()); + + $sampler->decide(1, 'an-operation', ''); + + $debug = $sampler->decide(2, 'an-operation', 'debug-id-42'); + + self::assertTrue($debug->isSampled()); + self::assertSame(0x03, $debug->getFlags()); + } +} diff --git a/tests/Sampler/SamplerResultTest.php b/tests/Sampler/SamplerResultTest.php new file mode 100644 index 0000000..c60ec2a --- /dev/null +++ b/tests/Sampler/SamplerResultTest.php @@ -0,0 +1,48 @@ +isSampled()); + self::assertSame($expectedFlags, $result->getFlags()); + self::assertCount($expectedTagCount, $result->getTags()); + } + + /** + * @return iterable + */ + public static function resultCases(): iterable + { + yield 'πŸ“­ rejected, no tags' => [new SamplerResult(false, 0), false, 0, 0]; + yield 'βœ… sampled with flags' => [new SamplerResult(true, 0x03), true, 0x03, 0]; + yield 'βœ… sampled with tags' => [ + new SamplerResult(true, 0x01, [new SamplerTypeTag('const'), new StringTag('a', 'b')]), + true, + 0x01, + 2, + ]; + } + + public function testShouldDefaultToAnEmptyTagList(): void + { + self::assertSame([], new SamplerResult(true, 1)->getTags()); + } +} diff --git a/tests/Span/Batch/SpanBatchTest.php b/tests/Span/Batch/SpanBatchTest.php new file mode 100644 index 0000000..9fb60a8 --- /dev/null +++ b/tests/Span/Batch/SpanBatchTest.php @@ -0,0 +1,42 @@ +process); + self::assertSame($spans, $batch->spans); + foreach ($spans as $span) { + $span->finish(); + } + } + + public function testShouldAcceptAnEmptySpanList(): void + { + $batch = new SpanBatch(new CliProcess('a-service')); + + self::assertSame([], $batch->spans); + } +} diff --git a/tests/Span/Context/SpanContextTest.php b/tests/Span/Context/SpanContextTest.php new file mode 100644 index 0000000..ed89a88 --- /dev/null +++ b/tests/Span/Context/SpanContextTest.php @@ -0,0 +1,152 @@ +getTraceIdHigh()); + self::assertSame($traceIdLow, $context->getTraceIdLow()); + self::assertSame($traceIdLow, $context->getTraceId(), 'getTraceId() returns the low half'); + self::assertSame($spanId, $context->getSpanId()); + self::assertSame($parentId, $context->getParentId()); + self::assertSame($flags, $context->getFlags()); + } + + /** + * @return iterable + */ + public static function contextCases(): iterable + { + yield 'πŸ“­ all zeroes' => [new SpanContext(0, 0, 0, 0), 0, 0, 0, 0, 0]; + yield 'βœ… populated' => [new SpanContext(1, 2, 3, 4, 5), 1, 2, 3, 4, 5]; + yield 'βœ… extreme ids' => [ + new SpanContext(PHP_INT_MAX, PHP_INT_MIN, PHP_INT_MAX, PHP_INT_MIN, 3), + PHP_INT_MAX, PHP_INT_MIN, PHP_INT_MAX, PHP_INT_MIN, 3, + ]; + } + + #[DataProvider('flagCases')] + public function testShouldDecodeTheFlagBits(int $flags, bool $sampled, bool $debug): void + { + $context = new SpanContext(0, 0, 0, 0, $flags); + + self::assertSame($sampled, $context->isSampled()); + self::assertSame($debug, $context->isDebug()); + } + + /** + * @return iterable + */ + public static function flagCases(): iterable + { + yield 'πŸ“­ no flags' => [0x00, false, false]; + yield 'βœ… sampled' => [0x01, true, false]; + yield 'βœ… debug' => [0x02, false, true]; + yield 'βœ… sampled and debug' => [0x03, true, true]; + yield 'βœ… unrelated high bits are ignored' => [0xf0, false, false]; + } + + public function testShouldDefaultFlagsAndBaggageToEmpty(): void + { + $context = new SpanContext(1, 2, 3, 4); + + self::assertSame(0, $context->getFlags()); + self::assertSame([], $context->getBaggage()); + } + + public function testShouldReturnACopyWhenAddingBaggageInsteadOfMutating(): void + { + $original = new SpanContext(1, 2, 3, 4); + + $copy = $original->withItem('key', 'value'); + + self::assertNotSame($original, $copy); + self::assertSame([], $original->getBaggage(), 'the original must stay untouched'); + self::assertSame(['key' => 'value'], $copy->getBaggage()); + } + + public function testShouldReturnACopyWhenRemovingBaggage(): void + { + $original = new SpanContext(1, 2, 3, 4)->withItem('key', 'value'); + + $copy = $original->withoutItem('key'); + + self::assertNotSame($original, $copy); + self::assertSame(['key' => 'value'], $original->getBaggage()); + self::assertSame([], $copy->getBaggage()); + } + + public function testShouldKeepIdentifiersWhenCopyingBaggage(): void + { + $copy = new SpanContext(1, 2, 3, 4, 5)->withItem('key', 'value'); + + self::assertSame(1, $copy->getTraceIdHigh()); + self::assertSame(2, $copy->getTraceIdLow()); + self::assertSame(3, $copy->getSpanId()); + self::assertSame(4, $copy->getParentId()); + self::assertSame(5, $copy->getFlags()); + } + + #[DataProvider('baggageValueCases')] + public function testShouldStoreAnyBaggageValue(mixed $value): void + { + self::assertSame($value, new SpanContext(1, 2, 3, 4)->withItem('key', $value)->getItem('key')); + } + + /** + * @return iterable + */ + public static function baggageValueCases(): iterable + { + yield 'βœ… string' => ['a value']; + yield 'βœ… int' => [42]; + yield 'βœ… float' => [4.2]; + yield 'βœ… bool' => [true]; + yield 'πŸ“­ null' => [null]; + yield 'βœ… array' => [['a', 'b']]; + } + + public function testShouldFallBackToTheDefaultForAnUnknownBaggageKey(): void + { + $context = new SpanContext(1, 2, 3, 4); + + self::assertNull($context->getItem('missing')); + self::assertSame('fallback', $context->getItem('missing', 'fallback')); + } + + public function testShouldPreferAStoredNullOverTheDefault(): void + { + $context = new SpanContext(1, 2, 3, 4)->withItem('key', null); + + self::assertNull($context->getItem('key', 'fallback')); + } + + public function testShouldTolerateRemovingAKeyThatWasNeverSet(): void + { + self::assertSame([], new SpanContext(1, 2, 3, 4)->withoutItem('missing')->getBaggage()); + } + + public function testShouldIterateOverItsBaggage(): void + { + $context = new SpanContext(1, 2, 3, 4)->withItem('a', 1)->withItem('b', 2); + + self::assertSame(['a' => 1, 'b' => 2], iterator_to_array($context)); + } +} diff --git a/tests/Span/Factory/SpanFactoryTest.php b/tests/Span/Factory/SpanFactoryTest.php new file mode 100644 index 0000000..4a64dd1 --- /dev/null +++ b/tests/Span/Factory/SpanFactoryTest.php @@ -0,0 +1,160 @@ +parent(new RecordingTracer(), 'an-operation', ''); + + self::assertSame(0, $span->traceIdHigh, 'a 64-bit trace leaves the high half at zero'); + self::assertSame(20, $span->traceIdLow); + self::assertSame(30, $span->spanId); + self::assertSame(0, $span->parentSpanId); + self::assertSame('an-operation', $span->operationName); + $span->finish(); + } + + public function testShouldBuildA128BitTraceIdWhenAskedTo(): void + { + $factory = new SpanFactory(new SequenceIdGenerator([10, 20, 30, 40]), new ConstSampler(true), true); + + $span = $factory->parent(new RecordingTracer(), 'an-operation', ''); + + self::assertSame(20, $span->traceIdHigh); + self::assertSame(30, $span->traceIdLow); + self::assertSame(40, $span->spanId); + $span->finish(); + } + + public function testShouldStampTheSamplerFlagsOntoARootSpan(): void + { + $factory = new SpanFactory(new SequenceIdGenerator([1, 2, 3]), new ConstSampler(true)); + + $span = $factory->parent(new RecordingTracer(), 'an-operation', ''); + + self::assertSame(0x01, $span->flags); + self::assertTrue($span->isSampled()); + $span->finish(); + } + + public function testShouldLeaveAnUnsampledRootSpanUnflagged(): void + { + $factory = new SpanFactory(new SequenceIdGenerator([1, 2, 3]), new ConstSampler(false)); + + $span = $factory->parent(new RecordingTracer(), 'an-operation', ''); + + self::assertSame(0, $span->flags); + self::assertFalse($span->isSampled()); + $span->finish(); + } + + public function testShouldMergeCallerTagsWithSamplerTags(): void + { + $factory = new SpanFactory(new SequenceIdGenerator([1, 2, 3]), new ConstSampler(true)); + $callerTag = new ComponentTag('db'); + + $span = $factory->parent(new RecordingTracer(), 'an-operation', '', [$callerTag]); + + /** @var array $tags */ + $tags = $span->tags; + $keys = array_map(static fn(Tag $tag): string => (string) $tag->key, $tags); + self::assertContains('component', $keys); + self::assertContains('sampler.type', $keys); + $span->finish(); + } + + public function testShouldHonourADebugIdOnARootSpan(): void + { + $factory = new SpanFactory(new SequenceIdGenerator([1, 2, 3]), new ConstSampler(false)); + + $span = $factory->parent(new RecordingTracer(), 'an-operation', 'debug-id-42'); + + self::assertSame(0x03, $span->flags, 'a debug request is force-sampled'); + $span->finish(); + } + + public function testShouldInheritTheTraceFromTheParentContext(): void + { + $factory = new SpanFactory(new SequenceIdGenerator([99]), new ConstSampler(true)); + $parent = new SpanContext(1, 2, 3, 4, 1, ['key' => 'value']); + + $span = $factory->child(new RecordingTracer(), 'a-child', $parent); + + self::assertSame(1, $span->traceIdHigh); + self::assertSame(2, $span->traceIdLow); + self::assertSame(99, $span->spanId, 'a child gets a fresh span id'); + self::assertSame(3, $span->parentSpanId, "the parent's span id becomes the parent link"); + self::assertSame(1, $span->flags); + $span->finish(); + } + + public function testShouldCarryParentBaggageIntoTheChild(): void + { + $factory = new SpanFactory(new SequenceIdGenerator([99]), new ConstSampler(true)); + $parent = new SpanContext(1, 2, 3, 4, 1, ['key' => 'value']); + + $span = $factory->child(new RecordingTracer(), 'a-child', $parent); + + self::assertSame('value', $span->getItem('key')); + $span->finish(); + } + + public function testShouldNotConsultTheSamplerForAChildSpan(): void + { + $generator = new SequenceIdGenerator([99]); + $factory = new SpanFactory($generator, new ConstSampler(false)); + + $span = $factory->child(new RecordingTracer(), 'a-child', new SpanContext(1, 2, 3, 4, 1)); + + self::assertSame(1, $generator->callCount(), 'only the span id is generated'); + self::assertSame(1, $span->flags, 'the child inherits the parent sampling decision'); + $span->finish(); + } + + public function testShouldKeepCallerTagsAndLogsOnAChildSpan(): void + { + $factory = new SpanFactory(new SequenceIdGenerator([99]), new ConstSampler(true)); + $tag = new ComponentTag('db'); + $log = new Log(['timestamp' => 1, 'fields' => []]); + + $span = $factory->child(new RecordingTracer(), 'a-child', new SpanContext(1, 2, 3, 4), [$tag], [$log]); + + self::assertSame([$tag], $span->tags, 'no sampler tags are merged into a child'); + self::assertSame([$log], $span->logs); + $span->finish(); + } + + public function testShouldStampAStartTimeInMicroseconds(): void + { + $factory = new SpanFactory(new SequenceIdGenerator([1, 2, 3]), new ConstSampler(true)); + $before = (int) (microtime(true) * 1000000.0); + + $span = $factory->parent(new RecordingTracer(), 'an-operation', ''); + + $after = (int) (microtime(true) * 1000000.0); + self::assertGreaterThanOrEqual($before, $span->startTime); + self::assertLessThanOrEqual($after, $span->startTime); + $span->finish(); + } +} diff --git a/tests/Span/SpanTest.php b/tests/Span/SpanTest.php new file mode 100644 index 0000000..72b28fb --- /dev/null +++ b/tests/Span/SpanTest.php @@ -0,0 +1,208 @@ +makeSpan(new RecordingTracer(), new SpanContext(1, 2, 3, 4, 1)); + + self::assertSame(2, $span->traceIdLow); + self::assertSame(1, $span->traceIdHigh); + self::assertSame(3, $span->spanId); + self::assertSame(4, $span->parentSpanId); + self::assertSame(1, $span->flags); + $span->finish(); + } + + public function testShouldCarryItsOperationNameAndStartTime(): void + { + $span = $this->makeSpan(new RecordingTracer(), startTime: 1_700_000_000_000_000); + + self::assertSame('an-operation', $span->operationName); + self::assertSame(1_700_000_000_000_000, $span->startTime); + $span->finish(); + } + + public function testShouldExposeItsContext(): void + { + $context = new SpanContext(1, 2, 3, 4); + $span = $this->makeSpan(new RecordingTracer(), $context); + + self::assertSame($context, $span->getContext()); + $span->finish(); + } + + public function testShouldReportSampledFromItsContextFlags(): void + { + $tracer = new RecordingTracer(); + $sampled = $this->makeSpan($tracer, new SpanContext(1, 2, 3, 4, 1)); + $unsampled = $this->makeSpan($tracer, new SpanContext(1, 2, 3, 4, 0)); + + self::assertTrue($sampled->isSampled()); + self::assertFalse($unsampled->isSampled()); + $sampled->finish(); + $unsampled->finish(); + } + + public function testShouldOverwriteItsStartTime(): void + { + $span = $this->makeSpan(new RecordingTracer(), startTime: 1); + + self::assertSame($span, $span->start(999)); + self::assertSame(999, $span->startTime); + $span->finish(); + } + + public function testShouldUseAnExplicitDurationWhenGiven(): void + { + $span = $this->makeSpan(new RecordingTracer()); + + $span->finish(1234); + + self::assertSame(1234, $span->duration); + } + + public function testShouldComputeADurationFromTheClockWhenNoneIsGiven(): void + { + $span = $this->makeSpan(new RecordingTracer(), startTime: (int) (microtime(true) * 1000000.0)); + + $span->finish(); + + self::assertIsInt($span->duration); + self::assertGreaterThanOrEqual(0, $span->duration); + } + + public function testShouldNotifyItsTracerOnFinish(): void + { + $tracer = new RecordingTracer(); + $span = $this->makeSpan($tracer); + + $span->finish(10); + + self::assertSame(1, $tracer->finishedCount()); + [$finishedSpan, $duration] = $tracer->finishedCalls()[0]; + self::assertSame($span, $finishedSpan); + self::assertSame(-1, $duration); + } + + public function testShouldAccumulateTags(): void + { + $span = $this->makeSpan(new RecordingTracer()); + $tag = new ComponentTag('db'); + + self::assertSame($span, $span->addTag($tag)); + + self::assertContains($tag, $span->tags ?? []); + $span->finish(); + } + + public function testShouldAccumulateLogs(): void + { + $span = $this->makeSpan(new RecordingTracer()); + $log = new Log(['timestamp' => 1, 'fields' => []]); + + self::assertSame($span, $span->addLog($log)); + + self::assertContains($log, $span->logs ?? []); + $span->finish(); + } + + public function testShouldStartFromTheTagsAndLogsItWasGiven(): void + { + $tag = new StringTag('a', 'b'); + $log = new Log(['timestamp' => 1, 'fields' => []]); + $span = new Span(new RecordingTracer(), new SpanContext(1, 2, 3, 4), 'an-operation', 1, [$tag], [$log]); + + self::assertSame([$tag], $span->tags); + self::assertSame([$log], $span->logs); + $span->finish(); + } + + public function testShouldSwapInANewContextWhenBaggageIsAdded(): void + { + $span = $this->makeSpan(new RecordingTracer()); + $before = $span->getContext(); + + self::assertSame($span, $span->withItem('key', 'value')); + + self::assertNotSame($before, $span->getContext()); + self::assertSame('value', $span->getItem('key')); + $span->finish(); + } + + public function testShouldSwapInANewContextWhenBaggageIsRemoved(): void + { + $span = $this->makeSpan(new RecordingTracer()); + $span->withItem('key', 'value'); + + self::assertSame($span, $span->withoutItem('key')); + + self::assertNull($span->getItem('key')); + $span->finish(); + } + + public function testShouldFallBackToTheDefaultForUnknownBaggage(): void + { + $span = $this->makeSpan(new RecordingTracer()); + + self::assertSame('fallback', $span->getItem('missing', 'fallback')); + $span->finish(); + } + + /** + * A span that leaves scope without being finished reports itself as an error. + */ + public function testShouldSelfReportWhenDestroyedUnfinished(): void + { + $tracer = new RecordingTracer(); + + (function () use ($tracer): void { + $this->makeSpan($tracer); + })(); + + gc_collect_cycles(); + + self::assertSame(1, $tracer->finishedCount()); + /** @var array $tags */ + $tags = $tracer->finishedCalls()[0][0]->tags; + $keys = array_map(static fn(Tag $tag): string => (string) $tag->key, $tags); + self::assertContains('error', $keys); + self::assertContains('scope.missing', $keys); + } + + public function testShouldNotSelfReportWhenAlreadyFinished(): void + { + $tracer = new RecordingTracer(); + + (function () use ($tracer): void { + $this->makeSpan($tracer)->finish(5); + })(); + + gc_collect_cycles(); + + self::assertSame(1, $tracer->finishedCount(), 'only the explicit finish() is reported'); + } + + private function makeSpan( + RecordingTracer $tracer, + ?SpanContext $context = null, + int $startTime = 1_700_000_000_000_000, + ): Span { + return new Span($tracer, $context ?? new SpanContext(1, 2, 3, 4), 'an-operation', $startTime); + } +} diff --git a/tests/Span/StackSpanManagerTest.php b/tests/Span/StackSpanManagerTest.php new file mode 100644 index 0000000..c1f593b --- /dev/null +++ b/tests/Span/StackSpanManagerTest.php @@ -0,0 +1,158 @@ +tracer = new RecordingTracer(); + } + + public function testShouldStartEmpty(): void + { + $manager = new StackSpanManager(); + + self::assertNull($manager->getSpan()); + self::assertNull($manager->getContext()); + } + + public function testShouldReturnTheMostRecentlyPushedSpan(): void + { + $manager = new StackSpanManager(); + $first = $this->makeSpan(); + $second = $this->makeSpan(); + + $manager->new($first); + $manager->new($second); + + self::assertSame($second, $manager->getSpan()); + } + + public function testShouldPopSpansInReverseOrder(): void + { + $manager = new StackSpanManager(); + $first = $this->makeSpan(); + $second = $this->makeSpan(); + $manager->new($first); + $manager->new($second); + + self::assertSame($second, $manager->finish($second)); + self::assertSame($first, $manager->finish($first)); + self::assertNull($manager->getSpan()); + } + + public function testShouldReturnNullWhenFinishingAnEmptyStack(): void + { + self::assertNull(new StackSpanManager()->finish($this->makeSpan())); + } + + public function testShouldTakeItsContextFromTheCurrentSpan(): void + { + $manager = new StackSpanManager(); + $span = $this->makeSpan(new SpanContext(9, 8, 7, 6, 1)); + + $manager->new($span); + + self::assertSame($span->getContext(), $manager->getContext()); + } + + public function testShouldFallBackToAnAssignedContextWhenNoSpanIsActive(): void + { + $manager = new StackSpanManager(); + $context = new SpanContext(9, 8, 7, 6, 1); + + self::assertSame($manager, $manager->assign($context)); + + self::assertSame($context, $manager->getContext()); + } + + public function testShouldPreferTheActiveSpanOverAnAssignedContext(): void + { + $manager = new StackSpanManager(); + $assigned = new SpanContext(9, 8, 7, 6, 1); + $span = $this->makeSpan(new SpanContext(1, 2, 3, 4, 1)); + + $manager->assign($assigned); + $manager->new($span); + + self::assertSame($span->getContext(), $manager->getContext()); + } + + public function testShouldDropAnyActiveSpansWhenAContextIsAssigned(): void + { + $manager = new StackSpanManager(); + $manager->new($this->makeSpan()); + + $manager->assign(new SpanContext(9, 8, 7, 6)); + + self::assertNull($manager->getSpan()); + } + + public function testShouldClearEverythingOnReset(): void + { + $manager = new StackSpanManager(); + $manager->assign(new SpanContext(9, 8, 7, 6)); + $manager->new($this->makeSpan()); + + self::assertSame($manager, $manager->reset()); + + self::assertNull($manager->getSpan()); + self::assertNull($manager->getContext()); + } + + /** + * KNOWN DEFECT: remove() never unwinds anything. Two independent bugs cause it: + * 1. `while ($this->stack->valid())` β€” SplStack::valid() is an iterator method and returns + * false until rewind() is called, so the loop body never runs; + * 2. even if it ran, it compares spl_object_hash() of a Span against spl_object_hash() of a + * SpanContext, which can never match. + * These tests pin the current no-op behaviour so a fix is a deliberate, visible change. + */ + public function testShouldLeaveTheStackUntouchedWhenRemovingAMatchingContext(): void + { + $manager = new StackSpanManager(); + $bottom = $this->makeSpan(); + $middle = $this->makeSpan(); + $top = $this->makeSpan(); + $manager->new($bottom); + $manager->new($middle); + $manager->new($top); + + $middleContext = $middle->getContext(); + self::assertInstanceOf(SpanContext::class, $middleContext); + self::assertSame($manager, $manager->remove($middleContext)); + + self::assertSame($top, $manager->getSpan(), 'remove() is currently a no-op'); + } + + public function testShouldLeaveTheStackUntouchedWhenNoSpanMatches(): void + { + $manager = new StackSpanManager(); + $manager->new($this->makeSpan()); + + $top = $this->makeSpan(); + $manager->new($top); + + $manager->remove(new SpanContext(99, 99, 99, 99)); + + self::assertSame($top, $manager->getSpan(), 'remove() is currently a no-op'); + } + + private function makeSpan(?SpanContext $context = null): Span + { + return new Span($this->tracer, $context ?? new SpanContext(1, 2, 3, 4), 'an-operation', 1); + } +} diff --git a/tests/Tag/TagTest.php b/tests/Tag/TagTest.php new file mode 100644 index 0000000..83fd2c3 --- /dev/null +++ b/tests/Tag/TagTest.php @@ -0,0 +1,207 @@ + $tagClass + * @param list $arguments + */ + #[DataProvider('tagCases')] + public function testShouldCarryKeyTypeAndValue( + string $tagClass, + array $arguments, + string $expectedKey, + int $expectedType, + string $populatedField, + mixed $expectedValue, + ): void { + $tag = new $tagClass(...$arguments); + + self::assertSame($expectedKey, $tag->key); + self::assertSame($expectedType, $tag->vType); + self::assertSame($expectedValue, $tag->{$populatedField}); + } + + /** + * A tag carries exactly one value; every field that does not match its vType stays null. + */ + /** + * @param class-string $tagClass + * @param list $arguments + */ + #[DataProvider('tagCases')] + public function testShouldLeaveEveryOtherValueFieldNull( + string $tagClass, + array $arguments, + string $expectedKey, + int $expectedType, + string $populatedField, + mixed $expectedValue, + ): void { + $tag = new $tagClass(...$arguments); + + foreach (['vStr', 'vDouble', 'vBool', 'vLong', 'vBinary'] as $field) { + if ($field === $populatedField) { + continue; + } + + self::assertNull($tag->{$field}, \sprintf('%s should be null on %s', $field, $tag::class)); + } + } + + /** + * Cases yield a class name plus constructor arguments rather than a built object, so the + * constructors run inside the test and are counted as covered. + * + * @return iterable, list, string, int, string, mixed}> + */ + public static function tagCases(): iterable + { + yield 'βœ… StringTag' => [StringTag::class, ['a.key', 'a value'], 'a.key', TagType::STRING, 'vStr', 'a value']; + yield 'πŸ“­ StringTag β€” empty value' => [StringTag::class, ['a.key', ''], 'a.key', TagType::STRING, 'vStr', '']; + yield 'βœ… LongTag' => [LongTag::class, ['a.key', 42], 'a.key', TagType::LONG, 'vLong', 42]; + yield 'πŸ“­ LongTag β€” zero' => [LongTag::class, ['a.key', 0], 'a.key', TagType::LONG, 'vLong', 0]; + yield 'βœ… LongTag β€” PHP_INT_MAX' => [LongTag::class, ['a.key', PHP_INT_MAX], 'a.key', TagType::LONG, 'vLong', PHP_INT_MAX]; + yield 'βœ… BoolTag β€” true' => [BoolTag::class, ['a.key', true], 'a.key', TagType::BOOL, 'vBool', true]; + yield 'πŸ“­ BoolTag β€” false' => [BoolTag::class, ['a.key', false], 'a.key', TagType::BOOL, 'vBool', false]; + yield 'βœ… DoubleTag' => [DoubleTag::class, ['a.key', 3.5], 'a.key', TagType::DOUBLE, 'vDouble', 3.5]; + yield 'πŸ“­ DoubleTag β€” zero' => [DoubleTag::class, ['a.key', 0.0], 'a.key', TagType::DOUBLE, 'vDouble', 0.0]; + yield 'βœ… BinaryTag β€” non-UTF-8 bytes' => [BinaryTag::class, ['a.key', "\x00\x01\xff"], 'a.key', TagType::BINARY, 'vBinary', "\x00\x01\xff"]; + + yield 'βœ… ComponentTag' => [ComponentTag::class, ['db'], 'component', TagType::STRING, 'vStr', 'db']; + yield 'βœ… DbInstanceTag' => [DbInstanceTag::class, ['main'], 'db.instance', TagType::STRING, 'vStr', 'main']; + yield 'βœ… DbStatementTag' => [DbStatementTag::class, ['SELECT 1'], 'db.statement', TagType::STRING, 'vStr', 'SELECT 1']; + yield 'βœ… DbType' => [DbType::class, ['mysql'], 'db.type', TagType::STRING, 'vStr', 'mysql']; + yield 'βœ… DbUser' => [DbUser::class, ['root'], 'db.user', TagType::STRING, 'vStr', 'root']; + yield 'βœ… DebugRequestTag' => [DebugRequestTag::class, ['abc123'], 'debug', TagType::STRING, 'vStr', 'abc123']; + yield 'βœ… ErrorTag' => [ErrorTag::class, [], 'error', TagType::BOOL, 'vBool', true]; + yield 'βœ… MessageBusDestinationTag' => [MessageBusDestinationTag::class, ['queue'], 'message_bus.destination', TagType::STRING, 'vStr', 'queue']; + yield 'βœ… OutOfScopeTag' => [OutOfScopeTag::class, [], 'scope.missing', TagType::BOOL, 'vBool', true]; + // NOTE: 'peer.adress' is a typo in the library and 'peer.ip' deviates from the OpenTracing + // convention ('peer.ipv4'). Both are pinned here so the current wire format is not changed by accident. + yield 'βœ… PeerAddressTag' => [PeerAddressTag::class, ['1.2.3.4:80'], 'peer.adress', TagType::STRING, 'vStr', '1.2.3.4:80']; + yield 'βœ… PeerHostnameTag' => [PeerHostnameTag::class, ['example.test'], 'peer.hostname', TagType::STRING, 'vStr', 'example.test']; + yield 'βœ… PeerIpv4Tag' => [PeerIpv4Tag::class, ['1.2.3.4'], 'peer.ip', TagType::STRING, 'vStr', '1.2.3.4']; + yield 'βœ… PeerPortTag' => [PeerPortTag::class, [8080], 'peer.port', TagType::LONG, 'vLong', 8080]; + yield 'βœ… PeerServiceTag' => [PeerServiceTag::class, ['svc'], 'peer.service', TagType::STRING, 'vStr', 'svc']; + + yield 'βœ… SpanKindClientTag' => [SpanKindClientTag::class, [], 'span.kind', TagType::STRING, 'vStr', 'client']; + yield 'βœ… SpanKindServerTag' => [SpanKindServerTag::class, [], 'span.kind', TagType::STRING, 'vStr', 'server']; + yield 'βœ… SpanKindProducerTag' => [SpanKindProducerTag::class, [], 'span.kind', TagType::STRING, 'vStr', 'producer']; + yield 'βœ… SpanKindConsumerTag' => [SpanKindConsumerTag::class, [], 'span.kind', TagType::STRING, 'vStr', 'consumer']; + + yield 'βœ… HttpCodeTag' => [HttpCodeTag::class, [404], 'http.status_code', TagType::LONG, 'vLong', 404]; + yield 'βœ… HttpMethodTag' => [HttpMethodTag::class, ['POST'], 'http.method', TagType::STRING, 'vStr', 'POST']; + yield 'βœ… HttpUriTag' => [HttpUriTag::class, ['/a/b'], 'http.url', TagType::STRING, 'vStr', '/a/b']; + + yield 'βœ… ErrorKindTag' => [ErrorKindTag::class, ['RuntimeException'], 'error.kind', TagType::STRING, 'vStr', 'RuntimeException']; + yield 'βœ… EventTag' => [EventTag::class, ['error'], 'event', TagType::STRING, 'vStr', 'error']; + yield 'βœ… LevelTag' => [LevelTag::class, ['warning'], 'level', TagType::STRING, 'vStr', 'warning']; + yield 'βœ… MessageTag' => [MessageTag::class, ['boom'], 'message', TagType::STRING, 'vStr', 'boom']; + yield 'βœ… StackTag' => [StackTag::class, ['#0 main()'], 'stack', TagType::STRING, 'vStr', '#0 main()']; + + yield 'βœ… SamplerDecisionTag' => [SamplerDecisionTag::class, [true], 'sampler.decision', TagType::BOOL, 'vBool', true]; + yield 'βœ… SamplerFlagsTag' => [SamplerFlagsTag::class, [0x01], 'sampler.flags', TagType::LONG, 'vLong', 1]; + yield 'βœ… SamplerParamTag' => [SamplerParamTag::class, ['0.5'], 'sampler.param', TagType::STRING, 'vStr', '0.5']; + yield 'βœ… SamplerTypeTag' => [SamplerTypeTag::class, ['const'], 'sampler.type', TagType::STRING, 'vStr', 'const']; + yield 'βœ… SamplingPriorityTag' => [SamplingPriorityTag::class, [1], 'sampling.priority', TagType::LONG, 'vLong', 1]; + + yield 'βœ… JaegerVersionTag' => [JaegerVersionTag::class, [], 'jaeger.version', TagType::STRING, 'vStr', 'PHP']; + yield 'βœ… PhpBinaryTag' => [PhpBinaryTag::class, [], 'php.bin', TagType::STRING, 'vStr', PHP_BINARY]; + yield 'βœ… PhpVersionTag' => [PhpVersionTag::class, [], 'php.version', TagType::STRING, 'vStr', PHP_VERSION]; + yield 'βœ… ProcessSapiTag' => [ProcessSapiTag::class, [], 'process.sapi', TagType::STRING, 'vStr', PHP_SAPI]; + } +} diff --git a/tests/Thrift/SerializationTest.php b/tests/Thrift/SerializationTest.php new file mode 100644 index 0000000..9ea2a97 --- /dev/null +++ b/tests/Thrift/SerializationTest.php @@ -0,0 +1,273 @@ +}> + */ + public static function protocolCases(): iterable + { + yield 'βœ… binary protocol' => [TBinaryProtocol::class]; + yield 'βœ… compact protocol' => [TCompactProtocol::class]; + } + + /** + * @param class-string $protocolClass + */ + #[DataProvider('protocolCases')] + public function testShouldRoundTripABatchThroughTheWire(string $protocolClass): void + { + $batch = $this->makeBatch(); + $buffer = new TMemoryBuffer(); + + $batch->write(new $protocolClass($buffer)); + $decoded = new Batch(); + $decoded->read(new $protocolClass(new TMemoryBuffer($buffer->getBuffer()))); + + self::assertSame('a-service', self::processOf($decoded)->serviceName); + self::assertCount(1, self::spansOf($decoded)); + self::assertSame('an-operation', self::firstSpanOf($decoded)->operationName); + } + + /** + * @param class-string $protocolClass + */ + #[DataProvider('protocolCases')] + public function testShouldPreserveEveryIdentifierIncludingNegativeOnes(string $protocolClass): void + { + $span = $this->firstSpanOf($this->roundTrip($this->makeBatch(), $protocolClass)); + + self::assertSame(-1, $span->traceIdLow); + self::assertSame(PHP_INT_MAX, $span->traceIdHigh); + self::assertSame(3, $span->spanId); + self::assertSame(4, $span->parentSpanId); + self::assertSame(1, $span->flags); + } + + /** + * @param class-string $protocolClass + */ + #[DataProvider('protocolCases')] + public function testShouldPreserveEveryTagType(string $protocolClass): void + { + $span = $this->firstSpanOf($this->roundTrip($this->makeBatch(), $protocolClass)); + + $tags = []; + foreach ($span->tags ?? [] as $tag) { + $tags[(string) $tag->key] = [$tag->vType, $tag->vStr ?? $tag->vDouble ?? $tag->vBool ?? $tag->vLong ?? $tag->vBinary]; + } + + self::assertSame([TagType::STRING, 'a value'], $tags['t.str']); + self::assertSame([TagType::DOUBLE, 3.5], $tags['t.dbl']); + self::assertSame([TagType::BOOL, true], $tags['t.bool']); + self::assertSame([TagType::LONG, PHP_INT_MAX], $tags['t.long']); + self::assertSame([TagType::BINARY, "\x00\x01\xff\xfe"], $tags['t.bin']); + } + + /** + * @param class-string $protocolClass + */ + #[DataProvider('protocolCases')] + public function testShouldPreserveLogsAndReferences(string $protocolClass): void + { + $span = $this->firstSpanOf($this->roundTrip($this->makeBatch(), $protocolClass)); + + $logs = $span->logs ?? []; + $references = $span->references ?? []; + self::assertCount(1, $logs); + self::assertSame(1_700_000_000_000_000, $logs[0]->timestamp); + self::assertCount(1, $references); + self::assertSame(SpanRefType::CHILD_OF, $references[0]->refType); + self::assertSame(9, $references[0]->spanId); + } + + /** + * @param class-string $protocolClass + */ + #[DataProvider('protocolCases')] + public function testShouldPreserveNonAsciiText(string $protocolClass): void + { + $process = $this->processOf($this->roundTrip($this->makeBatch(), $protocolClass)); + + $tags = []; + foreach ($process->tags ?? [] as $tag) { + $tags[(string) $tag->key] = $tag->vStr; + } + + self::assertSame('ΠΏΡ–Π΄Π½Ρ–ΠΌΠ°ΠΉ βœ“', $tags['unicode']); + } + + public function testShouldEmitARealBatchOverUdp(): void + { + $listener = new UdpListener(); + $transport = new TUDPTransport('127.0.0.1', $listener->port()); + $agent = new AgentClient(new TCompactProtocol($transport)); + + try { + $agent->emitBatch($this->makeBatch()); + $transport->flush(); + + $datagram = $listener->receive(); + + self::assertIsString($datagram); + self::assertStringContainsString('an-operation', $datagram); + self::assertStringContainsString('a-service', $datagram); + } finally { + $transport->close(); + $listener->close(); + } + } + + public function testShouldEmitARealSpanBatchBuiltFromLibraryObjects(): void + { + $listener = new UdpListener(); + $transport = new TUDPTransport('127.0.0.1', $listener->port()); + $agent = new AgentClient(new TCompactProtocol($transport)); + $tracer = new RecordingTracer(); + $span = new Span($tracer, new SpanContext(1, 2, 3, 4, 1), 'library-span', 1_700_000_000_000_000); + + try { + $agent->emitBatch(new SpanBatch(new CliProcess('a-service'), [$span])); + $transport->flush(); + + $datagram = $listener->receive(); + + self::assertIsString($datagram); + self::assertStringContainsString('library-span', $datagram); + } finally { + $span->finish(); + $transport->close(); + $listener->close(); + } + } + + /** + * @param class-string $protocolClass + */ + #[DataProvider('protocolCases')] + public function testShouldRoundTripAnEmptyBatch(string $protocolClass): void + { + $decoded = $this->roundTrip(new Batch(['process' => new CliProcess('a-service'), 'spans' => []]), $protocolClass); + + self::assertSame([], $decoded->spans); + self::assertSame('a-service', $this->processOf($decoded)->serviceName); + } + + /** + * Every field read below is `required` in the IDL, so a round trip must return it non-null. + */ + private function processOf(Batch $batch): Process + { + $process = $batch->process; + self::assertInstanceOf(Process::class, $process); + + return $process; + } + + /** + * @return array + */ + private function spansOf(Batch $batch): array + { + $spans = $batch->spans; + self::assertIsArray($spans); + + return $spans; + } + + private function firstSpanOf(Batch $batch): \Jaeger\Thrift\Span + { + $spans = $this->spansOf($batch); + self::assertArrayHasKey(0, $spans); + + return $spans[0]; + } + + /** + * @param class-string $protocolClass + */ + private function roundTrip(Batch $batch, string $protocolClass): Batch + { + $buffer = new TMemoryBuffer(); + $batch->write(new $protocolClass($buffer)); + + $decoded = new Batch(); + $decoded->read(new $protocolClass(new TMemoryBuffer($buffer->getBuffer()))); + + return $decoded; + } + + private function makeBatch(): Batch + { + $tags = [ + new StringTag('t.str', 'a value'), + new DoubleTag('t.dbl', 3.5), + new BoolTag('t.bool', true), + new LongTag('t.long', PHP_INT_MAX), + new BinaryTag('t.bin', "\x00\x01\xff\xfe"), + ]; + + $span = new \Jaeger\Thrift\Span([ + 'traceIdLow' => -1, + 'traceIdHigh' => PHP_INT_MAX, + 'spanId' => 3, + 'parentSpanId' => 4, + 'operationName' => 'an-operation', + 'flags' => 1, + 'startTime' => 1_700_000_000_000_000, + 'duration' => 1234, + 'tags' => $tags, + 'logs' => [new Log(['timestamp' => 1_700_000_000_000_000, 'fields' => $tags])], + 'references' => [new SpanRef([ + 'refType' => SpanRefType::CHILD_OF, + 'traceIdLow' => 7, + 'traceIdHigh' => 8, + 'spanId' => 9, + ])], + ]); + + return new Batch([ + 'process' => new Process([ + 'serviceName' => 'a-service', + 'tags' => [new StringTag('unicode', 'ΠΏΡ–Π΄Π½Ρ–ΠΌΠ°ΠΉ βœ“')], + ]), + 'spans' => [$span], + ]); + } +} diff --git a/tests/Tracer/TracerTest.php b/tests/Tracer/TracerTest.php new file mode 100644 index 0000000..542b2c5 --- /dev/null +++ b/tests/Tracer/TracerTest.php @@ -0,0 +1,212 @@ +client = new RecordingClient(); + $this->manager = new StackSpanManager(); + } + + public function testShouldStartARootSpanWhenNothingIsActive(): void + { + $tracer = $this->makeTracer(); + + $span = $tracer->start('an-operation'); + + self::assertSame(0, $span->parentSpanId, 'no active context means no parent'); + self::assertSame($span, $this->manager->getSpan()); + $tracer->finish($span); + } + + public function testShouldNestASecondSpanUnderTheFirst(): void + { + $tracer = $this->makeTracer(); + $parent = $tracer->start('parent'); + + $child = $tracer->start('child'); + + self::assertSame((int) $parent->spanId, (int) $child->parentSpanId); + self::assertSame((int) $parent->traceIdLow, (int) $child->traceIdLow); + $tracer->finish($child); + $tracer->finish($parent); + } + + public function testShouldUseAnExplicitContextAsTheParent(): void + { + $tracer = $this->makeTracer(); + $context = new SpanContext(7, 8, 9, 10, 1); + + $span = $tracer->start('an-operation', [], $context); + + self::assertSame(7, $span->traceIdHigh); + self::assertSame(8, $span->traceIdLow); + self::assertSame(9, $span->parentSpanId); + $tracer->finish($span); + } + + public function testShouldPassTagsThroughToTheSpan(): void + { + $tracer = $this->makeTracer(); + + $span = $tracer->start('an-operation', [new ComponentTag('db')]); + + /** @var array $tags */ + $tags = $span->tags; + $keys = array_map(static fn(Tag $tag): string => (string) $tag->key, $tags); + self::assertContains('component', $keys); + $tracer->finish($span); + } + + public function testShouldHandASampledSpanToTheClientOnFinish(): void + { + $tracer = $this->makeTracer(sampled: true); + $span = $tracer->start('an-operation'); + + $tracer->finish($span); + + self::assertSame([$span], $this->client->getSpans()); + } + + public function testShouldNotReportAnUnsampledSpan(): void + { + $tracer = $this->makeTracer(sampled: false); + $span = $tracer->start('an-operation'); + + $tracer->finish($span); + + self::assertSame([], $this->client->getSpans()); + } + + public function testShouldPopTheSpanFromTheManagerOnFinish(): void + { + $tracer = $this->makeTracer(); + $span = $tracer->start('an-operation'); + + $tracer->finish($span); + + self::assertNull($this->manager->getSpan()); + } + + public function testShouldDelegateFlushToTheClient(): void + { + $tracer = $this->makeTracer(); + + self::assertSame($tracer, $tracer->flush()); + + self::assertSame(1, $this->client->flushCount()); + } + + public function testShouldExposeItsClient(): void + { + $tracer = $this->makeTracer(); + + self::assertSame($this->client, $tracer->getClient()); + } + + public function testShouldForceSamplingWhileDebugIsEnabled(): void + { + $tracer = $this->makeTracer(sampled: false); + + self::assertSame($tracer, $tracer->enable('debug-id-42')); + $span = $tracer->start('an-operation'); + + self::assertSame(0x03, $span->flags); + $tracer->finish($span); + } + + public function testShouldStopForcingSamplingOnceDebugIsDisabled(): void + { + $tracer = $this->makeTracer(sampled: false); + $tracer->enable('debug-id-42'); + + self::assertSame($tracer, $tracer->disable()); + $span = $tracer->start('an-operation'); + + self::assertSame(0, $span->flags); + $tracer->finish($span); + } + + public function testShouldStartADebugSpanWithARandomDebugId(): void + { + $tracer = $this->makeTracer(sampled: false); + + $span = $tracer->debug('an-operation'); + + self::assertSame(0x03, $span->flags); + self::assertSame($span, $this->manager->getSpan()); + $tracer->finish($span); + } + + public function testShouldExposeTheActiveContext(): void + { + $tracer = $this->makeTracer(); + $span = $tracer->start('an-operation'); + + self::assertSame($span->getContext(), $tracer->getContext()); + $tracer->finish($span); + } + + public function testShouldAdoptAnInjectedContext(): void + { + $tracer = $this->makeTracer(); + $context = new SpanContext(7, 8, 9, 10, 1); + + self::assertSame($tracer, $tracer->assign($context)); + + self::assertSame($context, $tracer->getContext()); + } + + public function testShouldClearItsStateOnReset(): void + { + $tracer = $this->makeTracer(); + $tracer->assign(new SpanContext(7, 8, 9, 10, 1)); + $tracer->start('an-operation'); + + self::assertSame($tracer, $tracer->reset()); + + self::assertNull($tracer->getContext()); + } + + public function testShouldDelegateContextRemovalToTheManager(): void + { + $tracer = $this->makeTracer(); + $span = $tracer->start('an-operation'); + $context = $span->getContext(); + self::assertInstanceOf(SpanContext::class, $context); + + self::assertSame($tracer, $tracer->remove($context)); + + $tracer->finish($span); + } + + private function makeTracer(bool $sampled = true): Tracer + { + return new Tracer( + $this->manager, + new SpanFactory(new SequenceIdGenerator(range(1, 200)), new ConstSampler($sampled)), + $this->client, + ); + } +} diff --git a/tests/Transport/TUDPTransportTest.php b/tests/Transport/TUDPTransportTest.php new file mode 100644 index 0000000..4452e4b --- /dev/null +++ b/tests/Transport/TUDPTransportTest.php @@ -0,0 +1,189 @@ +listener = new UdpListener(); + } + + protected function tearDown(): void + { + $this->listener->close(); + } + + public function testShouldAlwaysReportItselfAsOpen(): void + { + self::assertTrue($this->makeTransport()->isOpen()); + } + + public function testShouldTreatOpenAsANoOp(): void + { + $transport = $this->makeTransport(); + + $transport->open(); + + self::assertTrue($transport->isOpen()); + } + + #[DataProvider('payloadCases')] + public function testShouldDeliverWhatWasWritten(string $payload): void + { + $transport = $this->makeTransport(); + + $transport->write($payload); + $transport->flush(); + + self::assertSame($payload, $this->listener->receive()); + } + + /** + * @return iterable + */ + public static function payloadCases(): iterable + { + yield 'βœ… ascii' => ['hello']; + yield 'βœ… binary bytes' => ["\x00\x01\xff\xfe"]; + yield 'βœ… utf-8' => ['ΠΏΡ–Π΄Π½Ρ–ΠΌΠ°ΠΉ']; + yield 'βœ… one kilobyte' => [str_repeat('x', 1024)]; + } + + public function testShouldConcatenateWritesIntoOneDatagram(): void + { + $transport = $this->makeTransport(); + + $transport->write('one '); + $transport->write('two '); + $transport->write('three'); + $transport->flush(); + + self::assertSame('one two three', $this->listener->receive()); + } + + public function testShouldSendNothingWhenTheBufferIsEmpty(): void + { + $transport = $this->makeTransport(); + + $transport->flush(); + + self::assertNull($this->listener->receive(), 'an empty flush must not produce a datagram'); + } + + public function testShouldClearItsBufferAfterFlushing(): void + { + $transport = $this->makeTransport(); + $transport->write('once'); + $transport->flush(); + + $this->listener->receive(); + + $transport->flush(); + + self::assertNull($this->listener->receive(), 'a second flush must not resend the payload'); + } + + /** + * The socket is opened lazily and then reused; PHP 8 returns a Socket object, not a resource. + */ + public function testShouldReuseOneSocketAcrossFlushes(): void + { + $transport = $this->makeTransport(); + $property = new ReflectionProperty(TUDPTransport::class, 'socket'); + + $ids = []; + for ($i = 0; $i < 5; $i++) { + $transport->write('x'); + $transport->flush(); + $this->listener->receive(); + $socket = $property->getValue($transport); + self::assertInstanceOf(Socket::class, $socket); + $ids[] = spl_object_id($socket); + } + + self::assertCount(1, array_unique($ids)); + } + + public function testShouldNotOpenASocketBeforeTheFirstFlush(): void + { + $transport = $this->makeTransport(); + $transport->write('buffered but not sent'); + + self::assertNull(new ReflectionProperty(TUDPTransport::class, 'socket')->getValue($transport)); + } + + public function testShouldDropItsSocketOnClose(): void + { + $transport = $this->makeTransport(); + $transport->write('x'); + $transport->flush(); + + $this->listener->receive(); + + $transport->close(); + + self::assertNull(new ReflectionProperty(TUDPTransport::class, 'socket')->getValue($transport)); + } + + public function testShouldTolerateClosingBeforeAnythingWasSent(): void + { + $transport = $this->makeTransport(); + + $transport->close(); + + self::assertTrue($transport->isOpen()); + } + + public function testShouldStillSendAfterBeingClosed(): void + { + $transport = $this->makeTransport(); + $transport->write('first'); + $transport->flush(); + + $this->listener->receive(); + $transport->close(); + + $transport->write('second'); + $transport->flush(); + + self::assertSame('second', $this->listener->receive()); + } + + public function testShouldRefuseToBeReadFrom(): void + { + $this->expectException(TTransportException::class); + $this->expectExceptionMessageIsOrContains('TUDPTransport is write-only'); + + $this->makeTransport()->read(4); + } + + /** + * readAll() loops on read() until it has enough bytes; read() must throw rather than spin forever. + */ + public function testShouldFailFastInsteadOfLoopingForeverOnReadAll(): void + { + $this->expectException(TTransportException::class); + + $this->makeTransport()->readAll(4); + } + + private function makeTransport(): TUDPTransport + { + return new TUDPTransport('127.0.0.1', $this->listener->port()); + } +}