From d774dde4cfd97e47ab2429d042bc1818999011c5 Mon Sep 17 00:00:00 2001 From: dozer Date: Wed, 16 Sep 2026 16:18:25 +0300 Subject: [PATCH 01/12] :lock: Require apache/thrift ^0.24.0 and PHP ^8.4 (CVE-2026-43871) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit apache/thrift < 0.24.0 is affected by GHSA-8wv5-x4w7-5gww / CVE-2026-43871 — an infinite loop in the PHP, Python, Go and Java bindings, severity high — so the whole previous '>=0.11, <0.17' range is unusable and 0.24.0 is the only release that is not. 0.24.0 itself requires PHP ^8.1; this major goes to ^8.4 so the toolchain can land on current stable releases. Co-Authored-By: Claude Opus 5 (1M context) --- composer.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 4a1851d..5bf3ba5 100644 --- a/composer.json +++ b/composer.json @@ -7,9 +7,9 @@ } }, "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" From 1dd9ab09ff73c27daa67cd63522492984814aa13 Mon Sep 17 00:00:00 2001 From: dozer Date: Wed, 16 Sep 2026 16:18:37 +0300 Subject: [PATCH 02/12] :recycle: Modernise TUDPTransport for PHP 8.4 and thrift 0.24 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Three fixes, all enabled by the new baseline: * socket_create() returns a Socket object since PHP 8.0, so the is_resource($this->socket) guard in connect() was always false and a fresh socket was created on every flush(). Descriptors did not leak — the old socket was collected immediately — but each flush paid for a needless socket_create() plus socket_connect(), and close() was a no-op in practice. * Match the parameter types of the now strictly typed TTransport in 0.24: read(int $len): string and write(string $buf): void. * read() returned '' unconditionally, so the inherited readAll() spun forever in while (strlen($data) < $len). Unreachable for the emit-only agent client, but it is the same infinite-loop shape as CVE-2026-43871. It throws TTransportException now. Co-Authored-By: Claude Opus 5 (1M context) --- src/Transport/TUDPTransport.php | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/src/Transport/TUDPTransport.php b/src/Transport/TUDPTransport.php index 2c4b34c..add96a8 100644 --- a/src/Transport/TUDPTransport.php +++ b/src/Transport/TUDPTransport.php @@ -3,20 +3,18 @@ namespace Jaeger\Transport; +use Thrift\Exception\TTransportException; use Thrift\Transport\TTransport; class TUDPTransport extends TTransport { - private $host; + private string $host; - private $port; + private int $port; - /** - * @var resource - */ - private $socket; + private ?\Socket $socket = null; - private $buffer = ''; + private string $buffer = ''; public function __construct(string $host, int $port) { @@ -42,12 +40,12 @@ public function close(): void $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; } @@ -62,7 +60,7 @@ public function flush(): void $this->buffer = ''; } - private function doWrite($buf): void + private function doWrite(string $buf): void { if (null === ($socket = $this->connect())) { return; @@ -80,10 +78,10 @@ private function doWrite($buf): void } } - private function connect() + private function connect(): ?\Socket { $count = 0; - while (false === \is_resource($this->socket) && $count < 5) { + while (null === $this->socket && $count < 5) { if (false !== ($socket = \socket_create(AF_INET, SOCK_DGRAM, SOL_UDP))) { @\socket_connect($socket, $this->host, $this->port); $this->socket = $socket; @@ -93,6 +91,6 @@ private function connect() usleep(10); } - return $this->socket ?: null; + return $this->socket; } } From fee9b611eafb267695705921ab54afb69157b487 Mon Sep 17 00:00:00 2001 From: dozer Date: Wed, 16 Sep 2026 16:18:37 +0300 Subject: [PATCH 03/12] :arrow_up: Regenerate src/Thrift with thrift 0.24 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The tree was generated by compiler 0.15 while the runtime is now 0.24. Regenerating against jaeger-idl v0.12.0 aligns the two: * declare(strict_types=1) in every file (THRIFT-5986) * native property and constructor types (THRIFT-5991), so 'public $key' becomes 'public ?string $key' — which is what the IDL actually says * native return types on struct methods (THRIFT-5990) * PSR-12 layout (THRIFT-5959) bin/thrift-gen.sh cloned jaeger-idl from a moving 'main', so two runs a month apart could differ with no record of what changed. It now pins jaeger-idl v0.12.0, refuses to run unless the compiler is 0.24.x, generates into a mktemp directory cleaned up by a trap instead of leaving a clone in the working tree, and drops a dead 'rm -rf ../src/Jaeger/Thrift/' from an older layout. Running it twice is now a no-op. BREAKING: 24 classes are gone — AggregationValidator, BaggageRestrictionManager, Dependency and ThrottlingService with their DTOs. They came from IDL definitions Jaeger removed upstream long ago (already absent in jaeger-idl v0.11.4); they are server-side APIs this client never used. Co-Authored-By: Claude Opus 5 (1M context) --- bin/thrift-gen.sh | 47 +- src/Thrift/Agent/AgentClient.php | 63 ++- src/Thrift/Agent/AgentIf.php | 13 +- src/Thrift/Agent/Agent_emitBatch_args.php | 103 ++-- .../Agent/Agent_emitZipkinBatch_args.php | 128 +++-- .../Agent/AggregationValidatorClient.php | 91 --- src/Thrift/Agent/AggregationValidatorIf.php | 26 - ...ggregationValidator_validateTrace_args.php | 94 ---- ...regationValidator_validateTrace_result.php | 99 ---- src/Thrift/Agent/BaggageRestriction.php | 118 ---- .../Agent/BaggageRestrictionManagerClient.php | 91 --- .../Agent/BaggageRestrictionManagerIf.php | 30 - ...ionManager_getBaggageRestrictions_args.php | 94 ---- ...nManager_getBaggageRestrictions_result.php | 116 ---- src/Thrift/Agent/Dependencies.php | 116 ---- src/Thrift/Agent/DependencyClient.php | 118 ---- src/Thrift/Agent/DependencyIf.php | 30 - src/Thrift/Agent/DependencyLink.php | 142 ----- ...ependency_getDependenciesForTrace_args.php | 94 ---- ...endency_getDependenciesForTrace_result.php | 99 ---- .../Dependency_saveDependencies_args.php | 99 ---- .../Agent/OperationSamplingStrategy.php | 134 ++--- .../Agent/PerOperationSamplingStrategies.php | 227 ++++---- .../Agent/ProbabilisticSamplingStrategy.php | 97 ++-- .../Agent/RateLimitingSamplingStrategy.php | 97 ++-- src/Thrift/Agent/SamplingManagerClient.php | 61 +- src/Thrift/Agent/SamplingManagerIf.php | 11 +- ...mplingManager_getSamplingStrategy_args.php | 99 ++-- ...lingManager_getSamplingStrategy_result.php | 103 ++-- src/Thrift/Agent/SamplingStrategyResponse.php | 212 +++---- src/Thrift/Agent/SamplingStrategyType.php | 18 +- src/Thrift/Agent/ServiceThrottlingConfig.php | 123 ---- src/Thrift/Agent/ThrottlingConfig.php | 142 ----- src/Thrift/Agent/ThrottlingResponse.php | 145 ----- src/Thrift/Agent/ThrottlingServiceClient.php | 91 --- src/Thrift/Agent/ThrottlingServiceIf.php | 26 - ...tlingService_getThrottlingConfigs_args.php | 114 ---- ...ingService_getThrottlingConfigs_result.php | 99 ---- src/Thrift/Agent/ValidateTraceResponse.php | 118 ---- src/Thrift/Agent/Zipkin/Annotation.php | 171 +++--- src/Thrift/Agent/Zipkin/AnnotationType.php | 28 +- src/Thrift/Agent/Zipkin/BinaryAnnotation.php | 210 +++---- src/Thrift/Agent/Zipkin/Constant.php | 81 +-- src/Thrift/Agent/Zipkin/Endpoint.php | 210 +++---- src/Thrift/Agent/Zipkin/Response.php | 97 ++-- src/Thrift/Agent/Zipkin/Span.php | 482 ++++++++-------- .../Agent/Zipkin/ZipkinCollectorClient.php | 61 +- src/Thrift/Agent/Zipkin/ZipkinCollectorIf.php | 11 +- ...ZipkinCollector_submitZipkinBatch_args.php | 128 +++-- ...pkinCollector_submitZipkinBatch_result.php | 128 +++-- src/Thrift/Batch.php | 235 ++++---- src/Thrift/BatchSubmitResponse.php | 97 ++-- src/Thrift/ClientStats.php | 165 +++--- src/Thrift/CollectorClient.php | 61 +- src/Thrift/CollectorIf.php | 11 +- src/Thrift/Collector_submitBatches_args.php | 128 +++-- src/Thrift/Collector_submitBatches_result.php | 128 +++-- src/Thrift/Log.php | 157 +++--- src/Thrift/Process.php | 157 +++--- src/Thrift/Span.php | 526 +++++++++--------- src/Thrift/SpanRef.php | 200 +++---- src/Thrift/SpanRefType.php | 18 +- src/Thrift/Tag.php | 305 +++++----- src/Thrift/TagType.php | 24 +- 64 files changed, 2797 insertions(+), 4750 deletions(-) delete mode 100644 src/Thrift/Agent/AggregationValidatorClient.php delete mode 100644 src/Thrift/Agent/AggregationValidatorIf.php delete mode 100644 src/Thrift/Agent/AggregationValidator_validateTrace_args.php delete mode 100644 src/Thrift/Agent/AggregationValidator_validateTrace_result.php delete mode 100644 src/Thrift/Agent/BaggageRestriction.php delete mode 100644 src/Thrift/Agent/BaggageRestrictionManagerClient.php delete mode 100644 src/Thrift/Agent/BaggageRestrictionManagerIf.php delete mode 100644 src/Thrift/Agent/BaggageRestrictionManager_getBaggageRestrictions_args.php delete mode 100644 src/Thrift/Agent/BaggageRestrictionManager_getBaggageRestrictions_result.php delete mode 100644 src/Thrift/Agent/Dependencies.php delete mode 100644 src/Thrift/Agent/DependencyClient.php delete mode 100644 src/Thrift/Agent/DependencyIf.php delete mode 100644 src/Thrift/Agent/DependencyLink.php delete mode 100644 src/Thrift/Agent/Dependency_getDependenciesForTrace_args.php delete mode 100644 src/Thrift/Agent/Dependency_getDependenciesForTrace_result.php delete mode 100644 src/Thrift/Agent/Dependency_saveDependencies_args.php delete mode 100644 src/Thrift/Agent/ServiceThrottlingConfig.php delete mode 100644 src/Thrift/Agent/ThrottlingConfig.php delete mode 100644 src/Thrift/Agent/ThrottlingResponse.php delete mode 100644 src/Thrift/Agent/ThrottlingServiceClient.php delete mode 100644 src/Thrift/Agent/ThrottlingServiceIf.php delete mode 100644 src/Thrift/Agent/ThrottlingService_getThrottlingConfigs_args.php delete mode 100644 src/Thrift/Agent/ThrottlingService_getThrottlingConfigs_result.php delete mode 100644 src/Thrift/Agent/ValidateTraceResponse.php 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/src/Thrift/Agent/AgentClient.php b/src/Thrift/Agent/AgentClient.php index f33c072..ced860b 100644 --- a/src/Thrift/Agent/AgentClient.php +++ b/src/Thrift/Agent/AgentClient.php @@ -1,86 +1,93 @@ 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', - ); + ]; } - From 181cb8b2ccd1589b71d6b89dc2865ffb0323735f Mon Sep 17 00:00:00 2001 From: dozer Date: Wed, 16 Sep 2026 16:19:55 +0300 Subject: [PATCH 04/12] :broom: linter dependencies and configs php-cs-fixer and rector, both configured to skip src/Thrift: that tree is generated by bin/thrift-gen.sh and has to stay byte-for-byte reproducible from the IDL, so reformatting it would be undone by the next regeneration. Co-Authored-By: Claude Opus 5 (1M context) --- .gitignore | 1 + .php-cs-fixer.dist.php | 49 ++++++++++++++++++++++++++++++++++++++++++ composer.json | 4 +++- rector.php | 27 +++++++++++++++++++++++ 4 files changed, 80 insertions(+), 1 deletion(-) create mode 100644 .php-cs-fixer.dist.php create mode 100644 rector.php diff --git a/.gitignore b/.gitignore index 19c201d..dc6afcf 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ /vendor/ composer.lock composer.phar +.php-cs-fixer.cache diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php new file mode 100644 index 0000000..876ea47 --- /dev/null +++ b/.php-cs-fixer.dist.php @@ -0,0 +1,49 @@ +in([__DIR__ . '/src']) + // 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/composer.json b/composer.json index 5bf3ba5..8eddc2b 100644 --- a/composer.json +++ b/composer.json @@ -12,7 +12,9 @@ "apache/thrift": "^0.24.0" }, "require-dev": { - "phpunit/phpunit": "@stable" + "phpunit/phpunit": "@stable", + "friendsofphp/php-cs-fixer": "^3.95", + "rector/rector": "^2.6" }, "minimum-stability": "dev", "prefer-stable": true diff --git a/rector.php b/rector.php new file mode 100644 index 0000000..0bdaecb --- /dev/null +++ b/rector.php @@ -0,0 +1,27 @@ +withPaths([ + __DIR__ . '/src', + __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); From e4475058124917293db6cc45b7ae78cbb60d1a63 Mon Sep 17 00:00:00 2001 From: dozer Date: Wed, 16 Sep 2026 16:20:08 +0300 Subject: [PATCH 05/12] :broom: phpCsFixer Co-Authored-By: Claude Opus 5 (1M context) --- src/Client/ClientInterface.php | 1 + src/Client/ThriftClient.php | 3 +- src/Codec/CodecInterface.php | 1 + src/Codec/CodecRegistry.php | 21 ++++++------ src/Codec/TextCodec.php | 13 ++++---- src/General/JaegerHostnameTag.php | 1 + src/General/JaegerVersionTag.php | 1 + src/General/PhpBinaryTag.php | 1 + src/General/PhpVersionTag.php | 1 + src/Http/HttpCodeTag.php | 1 + src/Http/HttpMethodTag.php | 1 + src/Http/HttpUriTag.php | 1 + src/Id/IdGeneratorInterface.php | 1 + src/Id/RandomIntGenerator.php | 5 ++- src/Log/AbstractLog.php | 3 +- src/Log/ErrorKindTag.php | 1 + src/Log/ErrorLog.php | 5 +-- src/Log/ErrorObjectTag.php | 4 ++- src/Log/EventTag.php | 1 + src/Log/LevelTag.php | 1 + src/Log/MessageTag.php | 1 + src/Log/StackTag.php | 1 + src/Log/UserLog.php | 3 +- src/Process/AbstractProcess.php | 5 +-- src/Process/CliProcess.php | 2 +- src/Process/FpmProcess.php | 1 + src/Process/InternalServerProcess.php | 5 ++- src/Process/ProcessGidTag.php | 1 + src/Process/ProcessIpTag.php | 8 ++--- src/Process/ProcessPidTag.php | 1 + src/Process/ProcessSapiTag.php | 1 + src/Process/ProcessUidTag.php | 1 + src/Sampler/AbstractSampler.php | 5 +-- src/Sampler/AdaptiveSampler.php | 7 ++-- src/Sampler/ConstGenerator.php | 1 + src/Sampler/ConstSampler.php | 7 ++-- src/Sampler/GeneratorInterface.php | 3 +- src/Sampler/OperationGenerator.php | 1 + src/Sampler/ProbabilisticSampler.php | 9 +++--- src/Sampler/RateLimitingSampler.php | 37 ++++++++++++---------- src/Sampler/SamplerDecisionTag.php | 1 + src/Sampler/SamplerFlagsTag.php | 1 + src/Sampler/SamplerInterface.php | 1 + src/Sampler/SamplerParamTag.php | 1 + src/Sampler/SamplerResult.php | 1 + src/Sampler/SamplerTypeTag.php | 1 + src/Sampler/SamplingPriorityTag.php | 1 + src/Span/Batch/SpanBatch.php | 1 + src/Span/Context/ContextAwareInterface.php | 1 + src/Span/Context/SpanContext.php | 32 +++++++++++-------- src/Span/Factory/SpanFactory.php | 29 +++++++++-------- src/Span/Factory/SpanFactoryInterface.php | 5 +-- src/Span/Options.php | 6 ++-- src/Span/Span.php | 11 ++++--- src/Span/SpanAwareInterface.php | 1 + src/Span/SpanInterface.php | 1 + src/Span/SpanManagerInterface.php | 7 ++-- src/Span/StackSpanManager.php | 10 +++--- src/Tag/AbstractSpanKindTag.php | 1 + src/Tag/AbstractTag.php | 3 +- src/Tag/BinaryTag.php | 1 + src/Tag/BoolTag.php | 1 + src/Tag/ComponentTag.php | 1 + src/Tag/DbInstanceTag.php | 1 + src/Tag/DbStatementTag.php | 1 + src/Tag/DbType.php | 1 + src/Tag/DbUser.php | 1 + src/Tag/DebugRequestTag.php | 1 + src/Tag/DoubleTag.php | 1 + src/Tag/ErrorTag.php | 1 + src/Tag/LongTag.php | 1 + src/Tag/MessageBusDestinationTag.php | 1 + src/Tag/OutOfScopeTag.php | 1 + src/Tag/PeerAddressTag.php | 1 + src/Tag/PeerHostnameTag.php | 1 + src/Tag/PeerIpv4Tag.php | 1 + src/Tag/PeerPortTag.php | 1 + src/Tag/PeerServiceTag.php | 1 + src/Tag/SpanKindClientTag.php | 1 + src/Tag/SpanKindConsumerTag.php | 1 + src/Tag/SpanKindProducerTag.php | 1 + src/Tag/SpanKindServerTag.php | 1 + src/Tag/StringTag.php | 1 + src/Tag/TagInterface.php | 6 ++-- src/Tracer/DebuggableInterface.php | 1 + src/Tracer/FinishableInterface.php | 3 +- src/Tracer/FlushableInterface.php | 1 + src/Tracer/InjectableInterface.php | 3 +- src/Tracer/ResettableInterface.php | 1 + src/Tracer/Tracer.php | 1 + src/Tracer/TracerInterface.php | 1 + src/Transport/TUDPTransport.php | 20 ++++++------ 92 files changed, 217 insertions(+), 125 deletions(-) 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 @@ serviceName = $serviceName; $this->agent = $agent; - $this->batch = (int)$batch; + $this->batch = (int) $batch; } public function add(SpanInterface $span): ClientInterface diff --git a/src/Codec/CodecInterface.php b/src/Codec/CodecInterface.php index ab7447d..016793d 100644 --- a/src/Codec/CodecInterface.php +++ b/src/Codec/CodecInterface.php @@ -1,4 +1,5 @@ codecs); + return \array_key_exists($offset, $this->codecs); } /** - * @return mixed */ - #[\ReturnTypeWillChange] + #[ReturnTypeWillChange] public function offsetGet($offset) { - if (false === array_key_exists($offset, $this->codecs)) { + if (false === \array_key_exists($offset, $this->codecs)) { return null; } @@ -32,7 +35,7 @@ public function offsetGet($offset) /** * @return $this */ - #[\ReturnTypeWillChange] + #[ReturnTypeWillChange] public function offsetSet($offset, $value) { $this->codecs[$offset] = $value; @@ -43,10 +46,10 @@ public function offsetSet($offset, $value) /** * @return $this */ - #[\ReturnTypeWillChange] + #[ReturnTypeWillChange] public function offsetUnset($offset) { - if (false === array_key_exists($offset, $this->codecs)) { + if (false === \array_key_exists($offset, $this->codecs)) { return $this; } unset($this->codecs[$offset]); diff --git a/src/Codec/TextCodec.php b/src/Codec/TextCodec.php index f9b6b1d..06ae0e2 100644 --- a/src/Codec/TextCodec.php +++ b/src/Codec/TextCodec.php @@ -1,4 +1,5 @@ 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); - return \unpack('Jint64', pack('H*', $hex8byte))['int64']; + return unpack('Jint64', pack('H*', $hex8byte))['int64']; } 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 +53,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..713077e 100644 --- a/src/General/JaegerHostnameTag.php +++ b/src/General/JaegerHostnameTag.php @@ -1,4 +1,5 @@ timestamp = 0 !== $timestamp ? $timestamp : (int)round(microtime(true) * 1000000); + $this->timestamp = 0 !== $timestamp ? $timestamp : (int) round(microtime(true) * 1000000); $this->fields = $tags; parent::__construct(); } diff --git a/src/Log/ErrorKindTag.php b/src/Log/ErrorKindTag.php index c346e14..abd5a5d 100644 --- a/src/Log/ErrorKindTag.php +++ b/src/Log/ErrorKindTag.php @@ -1,4 +1,5 @@ getFlags(), - array_merge([new SamplerTypeTag('adaptive'),], $rateLimitResult->getTags()) + array_merge([new SamplerTypeTag('adaptive'),], $rateLimitResult->getTags()), ); } @@ -31,7 +32,7 @@ public function decide(int $tracerId, string $operationName, string $debugId): S return new SamplerResult( true, $rateLimitResult->getFlags(), - array_merge([new SamplerTypeTag('adaptive'),], $rateLimitResult->getTags()) + array_merge([new SamplerTypeTag('adaptive'),], $rateLimitResult->getTags()), ); } @@ -42,7 +43,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; + $this->debugEnabled = (bool) $debugEnabled; } public function doDecide(int $tracerId, string $operationName): SamplerResult @@ -23,7 +24,7 @@ public function doDecide(int $tracerId, string $operationName): SamplerResult new SamplerParamTag('False'), new SamplerDecisionTag(false), new SamplerFlagsTag(0x00), - ] + ], ); } @@ -35,7 +36,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), + new SamplerParamTag((string) $this->rate), new SamplerDecisionTag(false), new SamplerFlagsTag(0x00), - ] + ], ); } @@ -37,8 +38,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..23fe995 100644 --- a/src/Sampler/RateLimitingSampler.php +++ b/src/Sampler/RateLimitingSampler.php @@ -1,4 +1,5 @@ generator->generate($tracerId, $operationName); - $ttl = max((int)(1 / $this->rate + 1), 1); + $ttl = max((int) (1 / $this->rate + 1), 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), + ], ); } @@ -45,25 +48,27 @@ public function doDecide(int $tracerId, string $operationName): SamplerResult if (false === ($current = apcu_fetch($key))) { return $this->doDecide($tracerId, $operationName); } - list ($timestamp, $count) = $this->spec((int)$current); + [$timestamp, $count] = $this->spec((int) $current); $now = time(); $diff = ($now === $timestamp) ? 1 : $now - $timestamp; if ($this->rate * $diff <= $count) { return new SamplerResult(false, 0); } - if (false === apcu_cas($key, (int)$current, $this->value($timestamp, $count + 1))) { + if (false === apcu_cas($key, (int) $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..33ceaad 100644 --- a/src/Sampler/SamplerDecisionTag.php +++ b/src/Sampler/SamplerDecisionTag.php @@ -1,4 +1,5 @@ traceIdHigh = $traceIdHigh; $this->traceIdLow = $traceIdLow; @@ -60,12 +66,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 @@ -79,12 +85,12 @@ public function getBaggage(): array } /** - * @return \Traversable + * @return Traversable */ - #[\ReturnTypeWillChange] + #[ReturnTypeWillChange] public function getIterator() { - return new \ArrayIterator($this->baggage); + return new ArrayIterator($this->baggage); } public function withItem(string $key, $item) @@ -97,7 +103,7 @@ public function withItem(string $key, $item) public function getItem(string $key, $default = null) { - if (false === array_key_exists($key, $this->baggage)) { + if (false === \array_key_exists($key, $this->baggage)) { return $default; } diff --git a/src/Span/Factory/SpanFactory.php b/src/Span/Factory/SpanFactory.php index 97e79f7..2054e99 100644 --- a/src/Span/Factory/SpanFactory.php +++ b/src/Span/Factory/SpanFactory.php @@ -1,4 +1,5 @@ idGenerator->next(); $traceId = $spanId; @@ -43,21 +44,21 @@ public function parent( $this->idGenerator->next(), $this->idGenerator->next(), 0, - (int)$samplerResult->getFlags() + (int) $samplerResult->getFlags(), ), $operationName, - (int)(microtime(true) * 1000000), + (int) (microtime(true) * 1000000), array_merge($tags, $samplerResult->getTags()), - $logs + $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 +68,12 @@ public function child( $this->idGenerator->next(), $parentContext->getSpanId(), $parentContext->getFlags(), - $parentContext->getBaggage() + $parentContext->getBaggage(), ), $operationName, - (int)(microtime(true) * 1000000), + (int) (microtime(true) * 1000000), $tags, - $logs + $logs, ); } } diff --git a/src/Span/Factory/SpanFactoryInterface.php b/src/Span/Factory/SpanFactoryInterface.php index 0ee7564..f541c86 100644 --- a/src/Span/Factory/SpanFactoryInterface.php +++ b/src/Span/Factory/SpanFactoryInterface.php @@ -1,4 +1,5 @@ tracer = $tracer; $this->context = $context; 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 @@ stack = new \SplStack(); + $this->stack = new SplStack(); } /** @@ -24,27 +26,25 @@ public function __construct() */ public function reset(): ResettableInterface { - $this->stack = new \SplStack(); + $this->stack = new SplStack(); $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 = new SplStack(); return $this; } /** - * @param SpanContext $context * * @return self */ diff --git a/src/Tag/AbstractSpanKindTag.php b/src/Tag/AbstractSpanKindTag.php index ad1c54a..0fa5105 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..7a10790 100644 --- a/src/Tag/BinaryTag.php +++ b/src/Tag/BinaryTag.php @@ -1,4 +1,5 @@ socket) { return; } - \socket_close($this->socket); + socket_close($this->socket); $this->socket = null; } @@ -67,23 +67,23 @@ private function doWrite(string $buf): void } $length = \strlen($buf); while (true) { - if (false === ($result = @\socket_write($socket, $buf))) { + if (false === ($result = @socket_write($socket, $buf))) { break; } if ($result >= $length) { break; } - $buf = \substr($buf, $result); + $buf = substr($buf, $result); $length -= $result; } } - private function connect(): ?\Socket + private function connect(): ?Socket { $count = 0; while (null === $this->socket && $count < 5) { - if (false !== ($socket = \socket_create(AF_INET, SOCK_DGRAM, SOL_UDP))) { - @\socket_connect($socket, $this->host, $this->port); + if (false !== ($socket = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP))) { + @socket_connect($socket, $this->host, $this->port); $this->socket = $socket; break; } From 3b9389420272288e4b7d7df196809895922a526d Mon Sep 17 00:00:00 2001 From: dozer Date: Wed, 16 Sep 2026 16:20:31 +0300 Subject: [PATCH 06/12] :broom: rector Constructor property promotion, readonly properties, inferred return types and early returns across src/, at the PHP 8.4 level. src/Thrift stays untouched. Co-Authored-By: Claude Opus 5 (1M context) --- src/Client/ThriftClient.php | 29 ++++++++----------------- src/Codec/CodecRegistry.php | 1 + src/Codec/TextCodec.php | 2 ++ src/Id/RandomIntGenerator.php | 4 ++-- src/Log/AbstractLog.php | 4 +++- src/Process/ProcessSapiTag.php | 2 +- src/Sampler/AdaptiveSampler.php | 10 +-------- src/Sampler/ConstSampler.php | 2 +- src/Sampler/ProbabilisticSampler.php | 9 +++----- src/Sampler/RateLimitingSampler.php | 16 +++++--------- src/Sampler/SamplerResult.php | 13 +---------- src/Span/Context/SpanContext.php | 32 +++------------------------- src/Span/Factory/SpanFactory.php | 15 ++----------- src/Span/Span.php | 21 +++++++----------- src/Span/StackSpanManager.php | 8 +++---- src/Tag/BoolTag.php | 2 +- src/Tag/DoubleTag.php | 2 +- src/Tag/LongTag.php | 2 +- src/Tag/StringTag.php | 2 +- src/Tracer/FinishableInterface.php | 4 ---- src/Tracer/Tracer.php | 20 ++++++----------- src/Transport/TUDPTransport.php | 22 +++++++++---------- 22 files changed, 66 insertions(+), 156 deletions(-) diff --git a/src/Client/ThriftClient.php b/src/Client/ThriftClient.php index dcc7729..04fd7d3 100644 --- a/src/Client/ThriftClient.php +++ b/src/Client/ThriftClient.php @@ -15,18 +15,12 @@ class ThriftClient implements ClientInterface { public const MAX_BATCH_SIZE = 32; - private $serviceName; + private readonly int $batch; - private $agent; + private array $spans = []; - private $batch; - - private $spans = []; - - public function __construct(string $serviceName, AgentInterface $agent, $batch = self::MAX_BATCH_SIZE) + public function __construct(private readonly string $serviceName, private readonly AgentInterface $agent, $batch = self::MAX_BATCH_SIZE) { - $this->serviceName = $serviceName; - $this->agent = $agent; $this->batch = (int) $batch; } @@ -44,20 +38,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/CodecRegistry.php b/src/Codec/CodecRegistry.php index 1bc2630..15a35bb 100644 --- a/src/Codec/CodecRegistry.php +++ b/src/Codec/CodecRegistry.php @@ -52,6 +52,7 @@ public function offsetUnset($offset) 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 06ae0e2..9aa1555 100644 --- a/src/Codec/TextCodec.php +++ b/src/Codec/TextCodec.php @@ -13,10 +13,12 @@ public function decode($data): ?SpanContext if (false === \is_string($data)) { return null; } + $elements = explode(':', $data); if (4 !== \count($elements)) { return null; } + [$traceIdHigh, $traceIdLow] = $this->convertInt128($elements[0]); return new SpanContext( diff --git a/src/Id/RandomIntGenerator.php b/src/Id/RandomIntGenerator.php index 54f57d7..c0b881c 100644 --- a/src/Id/RandomIntGenerator.php +++ b/src/Id/RandomIntGenerator.php @@ -12,9 +12,9 @@ public function next(): int { try { return random_int(PHP_INT_MIN, PHP_INT_MAX); - } catch (Exception $e) { + } catch (Exception) { } finally { - return rand(PHP_INT_MIN, PHP_INT_MAX); + return random_int(PHP_INT_MIN, PHP_INT_MAX); } } } diff --git a/src/Log/AbstractLog.php b/src/Log/AbstractLog.php index a827e1e..1ae539e 100644 --- a/src/Log/AbstractLog.php +++ b/src/Log/AbstractLog.php @@ -4,7 +4,9 @@ namespace Jaeger\Log; -abstract class AbstractLog extends \Jaeger\Thrift\Log +use Jaeger\Thrift\Log; + +abstract class AbstractLog extends Log { public function __construct(array $tags = [], int $timestamp = 0) { diff --git a/src/Process/ProcessSapiTag.php b/src/Process/ProcessSapiTag.php index e286d63..aeed584 100644 --- a/src/Process/ProcessSapiTag.php +++ b/src/Process/ProcessSapiTag.php @@ -10,6 +10,6 @@ class ProcessSapiTag extends StringTag { public function __construct() { - parent::__construct('process.sapi', php_sapi_name()); + parent::__construct('process.sapi', PHP_SAPI); } } diff --git a/src/Sampler/AdaptiveSampler.php b/src/Sampler/AdaptiveSampler.php index 25f4fd3..0a5eb42 100644 --- a/src/Sampler/AdaptiveSampler.php +++ b/src/Sampler/AdaptiveSampler.php @@ -6,15 +6,7 @@ class AdaptiveSampler implements SamplerInterface { - private $rateLimit; - - private $probabilistic; - - public function __construct(SamplerInterface $rateLimit, SamplerInterface $probabilistic) - { - $this->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 { diff --git a/src/Sampler/ConstSampler.php b/src/Sampler/ConstSampler.php index c2951bb..7d2c0ee 100644 --- a/src/Sampler/ConstSampler.php +++ b/src/Sampler/ConstSampler.php @@ -6,7 +6,7 @@ class ConstSampler extends AbstractSampler { - private $debugEnabled; + private readonly bool $debugEnabled; public function __construct($debugEnabled) { diff --git a/src/Sampler/ProbabilisticSampler.php b/src/Sampler/ProbabilisticSampler.php index ecc7b14..2338886 100644 --- a/src/Sampler/ProbabilisticSampler.php +++ b/src/Sampler/ProbabilisticSampler.php @@ -6,14 +6,11 @@ class ProbabilisticSampler extends AbstractSampler { - private $rate; + private readonly float $threshold; - private $threshold; - - public function __construct(float $rate) + public function __construct(private readonly float $rate) { - $this->rate = $rate; - $this->threshold = 0.5 * $rate * PHP_INT_MAX; + $this->threshold = 0.5 * $this->rate * PHP_INT_MAX; } public function doDecide(int $tracerId, string $operationName): SamplerResult diff --git a/src/Sampler/RateLimitingSampler.php b/src/Sampler/RateLimitingSampler.php index 23fe995..1af4b12 100644 --- a/src/Sampler/RateLimitingSampler.php +++ b/src/Sampler/RateLimitingSampler.php @@ -6,22 +6,14 @@ class RateLimitingSampler extends AbstractSampler { - private $rate; + public function __construct(private readonly float $rate, private readonly GeneratorInterface $generator) {} - private $generator; - - public function __construct(float $rate, GeneratorInterface $generator) - { - $this->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) + public function spec(int $value): array { return [$value >> 16, $value & 0xffff]; } @@ -48,12 +40,14 @@ public function doDecide(int $tracerId, string $operationName): SamplerResult if (false === ($current = apcu_fetch($key))) { return $this->doDecide($tracerId, $operationName); } + [$timestamp, $count] = $this->spec((int) $current); $now = time(); $diff = ($now === $timestamp) ? 1 : $now - $timestamp; if ($this->rate * $diff <= $count) { return new SamplerResult(false, 0); } + if (false === apcu_cas($key, (int) $current, $this->value($timestamp, $count + 1))) { $retries++; continue; diff --git a/src/Sampler/SamplerResult.php b/src/Sampler/SamplerResult.php index ada30ae..87a764c 100644 --- a/src/Sampler/SamplerResult.php +++ b/src/Sampler/SamplerResult.php @@ -6,18 +6,7 @@ class SamplerResult { - private $sampled; - - private $flags; - - private $tags; - - public function __construct(bool $sampled, int $flags, array $tags = []) - { - $this->sampled = $sampled; - $this->flags = $flags; - $this->tags = $tags; - } + public function __construct(private readonly bool $sampled, private readonly int $flags, private readonly array $tags = []) {} public function getFlags(): int { diff --git a/src/Span/Context/SpanContext.php b/src/Span/Context/SpanContext.php index 9d80d1e..551e69c 100644 --- a/src/Span/Context/SpanContext.php +++ b/src/Span/Context/SpanContext.php @@ -11,33 +11,7 @@ class SpanContext implements IteratorAggregate { - private int $traceIdHigh; - - private int $traceIdLow; - - private int $spanId; - - private int $parentId; - - private int $flags; - - private 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; - } + public function __construct(private int $traceIdHigh, private int $traceIdLow, private int $spanId, private int $parentId, private int $flags = 0, private array $baggage = []) {} public function getTraceId(): int { @@ -93,7 +67,7 @@ public function getIterator() return new ArrayIterator($this->baggage); } - public function withItem(string $key, $item) + public function withItem(string $key, $item): static { $copy = clone $this; $copy->baggage[$key] = $item; @@ -110,7 +84,7 @@ public function getItem(string $key, $default = null) 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 2054e99..cf2ba2c 100644 --- a/src/Span/Factory/SpanFactory.php +++ b/src/Span/Factory/SpanFactory.php @@ -13,18 +13,7 @@ class SpanFactory implements SpanFactoryInterface { - private IdGeneratorInterface $idGenerator; - - private SamplerInterface $sampler; - - private bool $trace128; - - public function __construct(IdGeneratorInterface $idGenerator, SamplerInterface $sampler, bool $trace128 = false) - { - $this->idGenerator = $idGenerator; - $this->sampler = $sampler; - $this->trace128 = $trace128; - } + public function __construct(private readonly IdGeneratorInterface $idGenerator, private readonly SamplerInterface $sampler, private readonly bool $trace128 = false) {} public function parent( TracerInterface $tracer, @@ -44,7 +33,7 @@ public function parent( $this->idGenerator->next(), $this->idGenerator->next(), 0, - (int) $samplerResult->getFlags(), + $samplerResult->getFlags(), ), $operationName, (int) (microtime(true) * 1000000), diff --git a/src/Span/Span.php b/src/Span/Span.php index 7efbc6f..a0a72ac 100644 --- a/src/Span/Span.php +++ b/src/Span/Span.php @@ -13,25 +13,19 @@ class Span extends \Jaeger\Thrift\Span implements SpanInterface { - private FinishableInterface $tracer; - - private SpanContext $context; - public function __construct( - FinishableInterface $tracer, - SpanContext $context, + 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; @@ -44,6 +38,7 @@ public function __destruct() if (null !== $this->duration) { return; } + $this->tags[] = new ErrorTag(); $this->tags[] = new OutOfScopeTag(); $this->tracer->finish($this); diff --git a/src/Span/StackSpanManager.php b/src/Span/StackSpanManager.php index 2440100..270e9cb 100644 --- a/src/Span/StackSpanManager.php +++ b/src/Span/StackSpanManager.php @@ -11,10 +11,9 @@ class StackSpanManager implements SpanManagerInterface { - private $stack; + private SplStack $stack; - /** @var SpanContext|null */ - private $context; + private ?SpanContext $context = null; public function __construct() { @@ -55,6 +54,7 @@ public function remove(SpanContext $context): InjectableInterface $this->stack->pop(); continue; } + break; } @@ -78,6 +78,6 @@ 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; } } diff --git a/src/Tag/BoolTag.php b/src/Tag/BoolTag.php index feac902..87fb5b7 100644 --- a/src/Tag/BoolTag.php +++ b/src/Tag/BoolTag.php @@ -10,6 +10,6 @@ class BoolTag extends AbstractTag { public function __construct(string $key, bool $value) { - parent::__construct($key, TagType::BOOL, null, null, $value, null, null); + parent::__construct($key, TagType::BOOL, null, null, $value); } } diff --git a/src/Tag/DoubleTag.php b/src/Tag/DoubleTag.php index ca1b24e..0cf849e 100644 --- a/src/Tag/DoubleTag.php +++ b/src/Tag/DoubleTag.php @@ -10,6 +10,6 @@ class DoubleTag extends AbstractTag { public function __construct(string $key, float $value) { - parent::__construct($key, TagType::DOUBLE, null, $value, null, null, null); + parent::__construct($key, TagType::DOUBLE, null, $value); } } diff --git a/src/Tag/LongTag.php b/src/Tag/LongTag.php index 19260ef..aa7f9cf 100644 --- a/src/Tag/LongTag.php +++ b/src/Tag/LongTag.php @@ -10,6 +10,6 @@ class LongTag extends AbstractTag { public function __construct(string $key, int $value) { - parent::__construct($key, TagType::LONG, null, null, null, $value, null); + parent::__construct($key, TagType::LONG, null, null, null, $value); } } diff --git a/src/Tag/StringTag.php b/src/Tag/StringTag.php index 9b72a23..f22dbd3 100644 --- a/src/Tag/StringTag.php +++ b/src/Tag/StringTag.php @@ -10,6 +10,6 @@ class StringTag extends AbstractTag { public function __construct(string $key, string $value) { - parent::__construct($key, TagType::STRING, $value, null, null, null, null); + parent::__construct($key, TagType::STRING, $value); } } diff --git a/src/Tracer/FinishableInterface.php b/src/Tracer/FinishableInterface.php index 839f387..3efa320 100644 --- a/src/Tracer/FinishableInterface.php +++ b/src/Tracer/FinishableInterface.php @@ -12,9 +12,5 @@ */ interface FinishableInterface { - /** - * - * @return mixed - */ public function finish(SpanInterface $span, int $duration = 0): void; } diff --git a/src/Tracer/Tracer.php b/src/Tracer/Tracer.php index 51ac3ce..b8895d1 100644 --- a/src/Tracer/Tracer.php +++ b/src/Tracer/Tracer.php @@ -19,20 +19,9 @@ class Tracer implements ResettableInterface, DebuggableInterface { - private $manager; + private string $debugId = ''; - private $debugId = ''; - - private $factory; - - private $client; - - public function __construct(SpanManagerInterface $manager, SpanFactoryInterface $factory, ClientInterface $client) - { - $this->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 { @@ -92,11 +81,12 @@ public function debug(string $operationName, array $tags = []): SpanInterface public function start(string $operationName, array $tags = [], ?SpanContext $userContext = null): SpanInterface { - if (null === ($context = $userContext ?: $this->manager->getContext())) { + if (!($context = $userContext ?: $this->manager->getContext()) instanceof SpanContext) { $span = $this->factory->parent($this, $operationName, $this->debugId, $tags); } else { $span = $this->factory->child($this, $operationName, $context, $tags); } + $this->manager->new($span); return $span; @@ -114,10 +104,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/Transport/TUDPTransport.php b/src/Transport/TUDPTransport.php index f786c69..6d674f9 100644 --- a/src/Transport/TUDPTransport.php +++ b/src/Transport/TUDPTransport.php @@ -10,19 +10,11 @@ class TUDPTransport extends TTransport { - private string $host; - - private int $port; - private ?Socket $socket = null; private string $buffer = ''; - public function __construct(string $host, int $port) - { - $this->host = $host; - $this->port = $port; - } + public function __construct(private readonly string $host, private readonly int $port) {} public function isOpen(): bool { @@ -33,9 +25,10 @@ public function open(): void {} public function close(): void { - if (null === $this->socket) { + if (!$this->socket instanceof Socket) { return; } + socket_close($this->socket); $this->socket = null; } @@ -56,23 +49,27 @@ public function flush(): void if ('' === $this->buffer) { return; } + $this->doWrite($this->buffer); $this->buffer = ''; } 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))) { break; } + if ($result >= $length) { break; } + $buf = substr($buf, $result); $length -= $result; } @@ -81,12 +78,13 @@ private function doWrite(string $buf): void private function connect(): ?Socket { $count = 0; - while (null === $this->socket && $count < 5) { + 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); } From 163dfade092648a96742ecb7563d71879fcc07dd Mon Sep 17 00:00:00 2001 From: dozer Date: Wed, 16 Sep 2026 16:20:45 +0300 Subject: [PATCH 07/12] :broom: code readability Break multi-argument constructors across lines and normalise the spacing between promoted parameter types and their names. Co-Authored-By: Claude Opus 5 (1M context) --- src/Client/ThriftClient.php | 7 +++++-- src/General/JaegerHostnameTag.php | 5 ++++- src/General/JaegerVersionTag.php | 5 ++++- src/General/PhpBinaryTag.php | 5 ++++- src/General/PhpVersionTag.php | 5 ++++- src/Http/HttpCodeTag.php | 5 ++++- src/Http/HttpMethodTag.php | 5 ++++- src/Http/HttpUriTag.php | 5 ++++- src/Log/AbstractLog.php | 6 ++++-- src/Log/ErrorKindTag.php | 5 ++++- src/Log/ErrorLog.php | 7 +++++-- src/Log/ErrorObjectTag.php | 5 ++++- src/Log/EventTag.php | 5 ++++- src/Log/LevelTag.php | 5 ++++- src/Log/MessageTag.php | 5 ++++- src/Log/StackTag.php | 5 ++++- src/Log/UserLog.php | 8 ++++++-- src/Process/AbstractProcess.php | 6 ++++-- src/Process/CliProcess.php | 5 ++++- src/Process/FpmProcess.php | 5 ++++- src/Process/ProcessGidTag.php | 5 ++++- src/Process/ProcessIpTag.php | 5 ++++- src/Process/ProcessPidTag.php | 5 ++++- src/Process/ProcessSapiTag.php | 5 ++++- src/Process/ProcessUidTag.php | 5 ++++- src/Sampler/AdaptiveSampler.php | 5 ++++- src/Sampler/RateLimitingSampler.php | 5 ++++- src/Sampler/SamplerDecisionTag.php | 5 ++++- src/Sampler/SamplerFlagsTag.php | 5 ++++- src/Sampler/SamplerParamTag.php | 5 ++++- src/Sampler/SamplerResult.php | 6 +++++- src/Sampler/SamplerTypeTag.php | 5 ++++- src/Sampler/SamplingPriorityTag.php | 5 ++++- src/Span/Batch/SpanBatch.php | 6 ++++-- src/Span/Context/SpanContext.php | 9 ++++++++- src/Span/Factory/SpanFactory.php | 6 +++++- src/Tag/AbstractSpanKindTag.php | 5 ++++- src/Tag/BinaryTag.php | 16 +++++++++++++--- src/Tag/BoolTag.php | 14 +++++++++++--- src/Tag/ComponentTag.php | 5 ++++- src/Tag/DbInstanceTag.php | 5 ++++- src/Tag/DbStatementTag.php | 5 ++++- src/Tag/DbType.php | 5 ++++- src/Tag/DbUser.php | 5 ++++- src/Tag/DebugRequestTag.php | 5 ++++- src/Tag/DoubleTag.php | 13 ++++++++++--- src/Tag/ErrorTag.php | 5 ++++- src/Tag/LongTag.php | 15 ++++++++++++--- src/Tag/MessageBusDestinationTag.php | 5 ++++- src/Tag/OutOfScopeTag.php | 5 ++++- src/Tag/PeerAddressTag.php | 5 ++++- src/Tag/PeerHostnameTag.php | 5 ++++- src/Tag/PeerIpv4Tag.php | 5 ++++- src/Tag/PeerPortTag.php | 5 ++++- src/Tag/PeerServiceTag.php | 5 ++++- src/Tag/StringTag.php | 12 +++++++++--- src/Tracer/Tracer.php | 6 +++++- src/Transport/TUDPTransport.php | 5 ++++- 58 files changed, 278 insertions(+), 74 deletions(-) diff --git a/src/Client/ThriftClient.php b/src/Client/ThriftClient.php index 04fd7d3..3bb584f 100644 --- a/src/Client/ThriftClient.php +++ b/src/Client/ThriftClient.php @@ -19,8 +19,11 @@ class ThriftClient implements ClientInterface private array $spans = []; - public function __construct(private readonly string $serviceName, private readonly AgentInterface $agent, $batch = self::MAX_BATCH_SIZE) - { + public function __construct( + private readonly string $serviceName, + private readonly AgentInterface $agent, + $batch = self::MAX_BATCH_SIZE, + ) { $this->batch = (int) $batch; } diff --git a/src/General/JaegerHostnameTag.php b/src/General/JaegerHostnameTag.php index 713077e..55a7ab3 100644 --- a/src/General/JaegerHostnameTag.php +++ b/src/General/JaegerHostnameTag.php @@ -10,6 +10,9 @@ class JaegerHostnameTag extends StringTag { public function __construct() { - parent::__construct('jaeger.hostname', gethostname()); + parent::__construct( + 'jaeger.hostname', + gethostname(), + ); } } diff --git a/src/General/JaegerVersionTag.php b/src/General/JaegerVersionTag.php index f1f55f4..ff5ca54 100644 --- a/src/General/JaegerVersionTag.php +++ b/src/General/JaegerVersionTag.php @@ -10,6 +10,9 @@ class JaegerVersionTag extends StringTag { public function __construct() { - parent::__construct('jaeger.version', 'PHP'); + parent::__construct( + 'jaeger.version', + 'PHP', + ); } } diff --git a/src/General/PhpBinaryTag.php b/src/General/PhpBinaryTag.php index bd574c0..0f46fcc 100644 --- a/src/General/PhpBinaryTag.php +++ b/src/General/PhpBinaryTag.php @@ -10,6 +10,9 @@ class PhpBinaryTag extends StringTag { public function __construct() { - parent::__construct('php.bin', PHP_BINARY); + parent::__construct( + 'php.bin', + PHP_BINARY, + ); } } diff --git a/src/General/PhpVersionTag.php b/src/General/PhpVersionTag.php index e71a6a4..0b21f40 100644 --- a/src/General/PhpVersionTag.php +++ b/src/General/PhpVersionTag.php @@ -10,6 +10,9 @@ class PhpVersionTag extends StringTag { public function __construct() { - parent::__construct('php.version', PHP_VERSION); + parent::__construct( + 'php.version', + PHP_VERSION, + ); } } diff --git a/src/Http/HttpCodeTag.php b/src/Http/HttpCodeTag.php index d09ce95..a34b172 100644 --- a/src/Http/HttpCodeTag.php +++ b/src/Http/HttpCodeTag.php @@ -10,6 +10,9 @@ class HttpCodeTag extends LongTag { public function __construct(int $code) { - parent::__construct('http.status_code', $code); + parent::__construct( + 'http.status_code', + $code, + ); } } diff --git a/src/Http/HttpMethodTag.php b/src/Http/HttpMethodTag.php index 984eb87..d60407b 100644 --- a/src/Http/HttpMethodTag.php +++ b/src/Http/HttpMethodTag.php @@ -10,6 +10,9 @@ class HttpMethodTag extends StringTag { public function __construct(string $method) { - parent::__construct('http.method', $method); + parent::__construct( + 'http.method', + $method, + ); } } diff --git a/src/Http/HttpUriTag.php b/src/Http/HttpUriTag.php index c5461a5..7971028 100644 --- a/src/Http/HttpUriTag.php +++ b/src/Http/HttpUriTag.php @@ -10,6 +10,9 @@ class HttpUriTag extends StringTag { public function __construct(string $uri) { - parent::__construct('http.url', $uri); + parent::__construct( + 'http.url', + $uri, + ); } } diff --git a/src/Log/AbstractLog.php b/src/Log/AbstractLog.php index 1ae539e..1a4cb90 100644 --- a/src/Log/AbstractLog.php +++ b/src/Log/AbstractLog.php @@ -8,8 +8,10 @@ abstract class AbstractLog extends Log { - public function __construct(array $tags = [], int $timestamp = 0) - { + public function __construct( + array $tags = [], + int $timestamp = 0, + ) { $this->timestamp = 0 !== $timestamp ? $timestamp : (int) round(microtime(true) * 1000000); $this->fields = $tags; parent::__construct(); diff --git a/src/Log/ErrorKindTag.php b/src/Log/ErrorKindTag.php index abd5a5d..0502cef 100644 --- a/src/Log/ErrorKindTag.php +++ b/src/Log/ErrorKindTag.php @@ -10,6 +10,9 @@ class ErrorKindTag extends StringTag { public function __construct(string $value) { - parent::__construct('error.kind', $value); + parent::__construct( + 'error.kind', + $value, + ); } } diff --git a/src/Log/ErrorLog.php b/src/Log/ErrorLog.php index 597274a..4be4f6c 100644 --- a/src/Log/ErrorLog.php +++ b/src/Log/ErrorLog.php @@ -6,8 +6,11 @@ class ErrorLog extends AbstractLog { - public function __construct(string $message, string $stack, int $timestamp = 0) - { + public function __construct( + string $message, + string $stack, + int $timestamp = 0, + ) { parent::__construct( [ new EventTag('error'), diff --git a/src/Log/ErrorObjectTag.php b/src/Log/ErrorObjectTag.php index e1c9bd9..9872901 100644 --- a/src/Log/ErrorObjectTag.php +++ b/src/Log/ErrorObjectTag.php @@ -11,6 +11,9 @@ class ErrorObjectTag extends StringTag { public function __construct(JsonSerializable $value) { - parent::__construct('error.object', json_encode($value)); + parent::__construct( + 'error.object', + json_encode($value), + ); } } diff --git a/src/Log/EventTag.php b/src/Log/EventTag.php index 3db53ab..c7a25ee 100644 --- a/src/Log/EventTag.php +++ b/src/Log/EventTag.php @@ -10,6 +10,9 @@ class EventTag extends StringTag { public function __construct(string $value) { - parent::__construct('event', $value); + parent::__construct( + 'event', + $value, + ); } } diff --git a/src/Log/LevelTag.php b/src/Log/LevelTag.php index 4ed2c11..688a75a 100644 --- a/src/Log/LevelTag.php +++ b/src/Log/LevelTag.php @@ -10,6 +10,9 @@ class LevelTag extends StringTag { public function __construct(string $value) { - parent::__construct('level', $value); + parent::__construct( + 'level', + $value, + ); } } diff --git a/src/Log/MessageTag.php b/src/Log/MessageTag.php index 9cdcfdf..7937f56 100644 --- a/src/Log/MessageTag.php +++ b/src/Log/MessageTag.php @@ -10,6 +10,9 @@ class MessageTag extends StringTag { public function __construct(string $value) { - parent::__construct('message', $value); + parent::__construct( + 'message', + $value, + ); } } diff --git a/src/Log/StackTag.php b/src/Log/StackTag.php index b2c3863..6361eaf 100644 --- a/src/Log/StackTag.php +++ b/src/Log/StackTag.php @@ -10,6 +10,9 @@ class StackTag extends StringTag { public function __construct(string $value) { - parent::__construct('stack', $value); + parent::__construct( + 'stack', + $value, + ); } } diff --git a/src/Log/UserLog.php b/src/Log/UserLog.php index 40f62ff..5e1f744 100644 --- a/src/Log/UserLog.php +++ b/src/Log/UserLog.php @@ -6,8 +6,12 @@ class UserLog extends AbstractLog { - public function __construct(string $name, string $level, string $message, int $timestamp = 0) - { + public function __construct( + string $name, + string $level, + string $message, + int $timestamp = 0, + ) { parent::__construct( [ new EventTag($name), diff --git a/src/Process/AbstractProcess.php b/src/Process/AbstractProcess.php index f18998c..2bafb83 100644 --- a/src/Process/AbstractProcess.php +++ b/src/Process/AbstractProcess.php @@ -12,8 +12,10 @@ abstract class AbstractProcess extends Process { - public function __construct(string $serviceName, array $tags = []) - { + public function __construct( + string $serviceName, + array $tags = [], + ) { $this->serviceName = $serviceName; $this->tags = array_merge( $tags, diff --git a/src/Process/CliProcess.php b/src/Process/CliProcess.php index 823e1e5..6e33a10 100644 --- a/src/Process/CliProcess.php +++ b/src/Process/CliProcess.php @@ -8,6 +8,9 @@ class CliProcess extends AbstractProcess { public function __construct(string $serviceName) { - parent::__construct($serviceName, [new ProcessIpTag()]); + parent::__construct( + $serviceName, + [new ProcessIpTag()], + ); } } diff --git a/src/Process/FpmProcess.php b/src/Process/FpmProcess.php index 7570876..930aca2 100644 --- a/src/Process/FpmProcess.php +++ b/src/Process/FpmProcess.php @@ -8,6 +8,9 @@ class FpmProcess extends AbstractProcess { public function __construct(string $serviceName) { - parent::__construct($serviceName, [new ProcessIpTag()]); + parent::__construct( + $serviceName, + [new ProcessIpTag()], + ); } } diff --git a/src/Process/ProcessGidTag.php b/src/Process/ProcessGidTag.php index b12d22c..310eaf3 100644 --- a/src/Process/ProcessGidTag.php +++ b/src/Process/ProcessGidTag.php @@ -10,6 +10,9 @@ class ProcessGidTag extends LongTag { public function __construct() { - parent::__construct('process.gid', getmygid()); + parent::__construct( + 'process.gid', + getmygid(), + ); } } diff --git a/src/Process/ProcessIpTag.php b/src/Process/ProcessIpTag.php index b6b9170..824156e 100644 --- a/src/Process/ProcessIpTag.php +++ b/src/Process/ProcessIpTag.php @@ -23,6 +23,9 @@ private function getIp(): string public function __construct() { - parent::__construct('ip', $this->getIp()); + parent::__construct( + 'ip', + $this->getIp(), + ); } } diff --git a/src/Process/ProcessPidTag.php b/src/Process/ProcessPidTag.php index 2ea8a02..11a31e2 100644 --- a/src/Process/ProcessPidTag.php +++ b/src/Process/ProcessPidTag.php @@ -10,6 +10,9 @@ class ProcessPidTag extends LongTag { public function __construct() { - parent::__construct('process.pid', getmypid()); + parent::__construct( + 'process.pid', + getmypid(), + ); } } diff --git a/src/Process/ProcessSapiTag.php b/src/Process/ProcessSapiTag.php index aeed584..d3cf46a 100644 --- a/src/Process/ProcessSapiTag.php +++ b/src/Process/ProcessSapiTag.php @@ -10,6 +10,9 @@ class ProcessSapiTag extends StringTag { public function __construct() { - parent::__construct('process.sapi', PHP_SAPI); + parent::__construct( + 'process.sapi', + PHP_SAPI, + ); } } diff --git a/src/Process/ProcessUidTag.php b/src/Process/ProcessUidTag.php index a26e884..b695137 100644 --- a/src/Process/ProcessUidTag.php +++ b/src/Process/ProcessUidTag.php @@ -10,6 +10,9 @@ class ProcessUidTag extends LongTag { public function __construct() { - parent::__construct('process.uid', getmyuid()); + parent::__construct( + 'process.uid', + getmyuid(), + ); } } diff --git a/src/Sampler/AdaptiveSampler.php b/src/Sampler/AdaptiveSampler.php index 0a5eb42..846796e 100644 --- a/src/Sampler/AdaptiveSampler.php +++ b/src/Sampler/AdaptiveSampler.php @@ -6,7 +6,10 @@ class AdaptiveSampler implements SamplerInterface { - public function __construct(private readonly SamplerInterface $rateLimit, private readonly SamplerInterface $probabilistic) {} + public function __construct( + private readonly SamplerInterface $rateLimit, + private readonly SamplerInterface $probabilistic, + ) {} public function decide(int $tracerId, string $operationName, string $debugId): SamplerResult { diff --git a/src/Sampler/RateLimitingSampler.php b/src/Sampler/RateLimitingSampler.php index 1af4b12..8e31bb6 100644 --- a/src/Sampler/RateLimitingSampler.php +++ b/src/Sampler/RateLimitingSampler.php @@ -6,7 +6,10 @@ class RateLimitingSampler extends AbstractSampler { - public function __construct(private readonly float $rate, private readonly GeneratorInterface $generator) {} + public function __construct( + private readonly float $rate, + private readonly GeneratorInterface $generator, + ) {} public function value(int $sec, int $count): int { diff --git a/src/Sampler/SamplerDecisionTag.php b/src/Sampler/SamplerDecisionTag.php index 33ceaad..fb27158 100644 --- a/src/Sampler/SamplerDecisionTag.php +++ b/src/Sampler/SamplerDecisionTag.php @@ -10,6 +10,9 @@ class SamplerDecisionTag extends BoolTag { public function __construct(bool $decision) { - parent::__construct('sampler.decision', $decision); + parent::__construct( + 'sampler.decision', + $decision, + ); } } diff --git a/src/Sampler/SamplerFlagsTag.php b/src/Sampler/SamplerFlagsTag.php index 250171a..3c808f3 100644 --- a/src/Sampler/SamplerFlagsTag.php +++ b/src/Sampler/SamplerFlagsTag.php @@ -10,6 +10,9 @@ class SamplerFlagsTag extends LongTag { public function __construct(int $flags) { - parent::__construct('sampler.flags', $flags); + parent::__construct( + 'sampler.flags', + $flags, + ); } } diff --git a/src/Sampler/SamplerParamTag.php b/src/Sampler/SamplerParamTag.php index 8c8dcdf..5b3a007 100644 --- a/src/Sampler/SamplerParamTag.php +++ b/src/Sampler/SamplerParamTag.php @@ -10,6 +10,9 @@ class SamplerParamTag extends StringTag { public function __construct(string $param) { - parent::__construct('sampler.param', $param); + parent::__construct( + 'sampler.param', + $param, + ); } } diff --git a/src/Sampler/SamplerResult.php b/src/Sampler/SamplerResult.php index 87a764c..2177d1a 100644 --- a/src/Sampler/SamplerResult.php +++ b/src/Sampler/SamplerResult.php @@ -6,7 +6,11 @@ class SamplerResult { - public function __construct(private readonly bool $sampled, private readonly int $flags, private readonly array $tags = []) {} + public function __construct( + private readonly bool $sampled, + private readonly int $flags, + private readonly array $tags = [], + ) {} public function getFlags(): int { diff --git a/src/Sampler/SamplerTypeTag.php b/src/Sampler/SamplerTypeTag.php index 1d9c855..f20ce3e 100644 --- a/src/Sampler/SamplerTypeTag.php +++ b/src/Sampler/SamplerTypeTag.php @@ -10,6 +10,9 @@ class SamplerTypeTag extends StringTag { public function __construct(string $type) { - parent::__construct('sampler.type', $type); + parent::__construct( + 'sampler.type', + $type, + ); } } diff --git a/src/Sampler/SamplingPriorityTag.php b/src/Sampler/SamplingPriorityTag.php index 360dc4e..c1693d3 100644 --- a/src/Sampler/SamplingPriorityTag.php +++ b/src/Sampler/SamplingPriorityTag.php @@ -10,6 +10,9 @@ class SamplingPriorityTag extends LongTag { public function __construct(int $value) { - parent::__construct('sampling.priority', $value); + parent::__construct( + 'sampling.priority', + $value, + ); } } diff --git a/src/Span/Batch/SpanBatch.php b/src/Span/Batch/SpanBatch.php index 73b5414..d5ae927 100644 --- a/src/Span/Batch/SpanBatch.php +++ b/src/Span/Batch/SpanBatch.php @@ -9,8 +9,10 @@ class SpanBatch extends Batch { - public function __construct(AbstractProcess $process, array $spans = []) - { + public function __construct( + AbstractProcess $process, + array $spans = [], + ) { $this->process = $process; $this->spans = $spans; parent::__construct(); diff --git a/src/Span/Context/SpanContext.php b/src/Span/Context/SpanContext.php index 551e69c..fd91007 100644 --- a/src/Span/Context/SpanContext.php +++ b/src/Span/Context/SpanContext.php @@ -11,7 +11,14 @@ class SpanContext implements IteratorAggregate { - public function __construct(private int $traceIdHigh, private int $traceIdLow, private int $spanId, private int $parentId, private int $flags = 0, private array $baggage = []) {} + public function __construct( + private int $traceIdHigh, + private int $traceIdLow, + private int $spanId, + private int $parentId, + private int $flags = 0, + private array $baggage = [], + ) {} public function getTraceId(): int { diff --git a/src/Span/Factory/SpanFactory.php b/src/Span/Factory/SpanFactory.php index cf2ba2c..1596a4d 100644 --- a/src/Span/Factory/SpanFactory.php +++ b/src/Span/Factory/SpanFactory.php @@ -13,7 +13,11 @@ class SpanFactory implements SpanFactoryInterface { - public function __construct(private readonly IdGeneratorInterface $idGenerator, private readonly SamplerInterface $sampler, private readonly bool $trace128 = false) {} + public function __construct( + private readonly IdGeneratorInterface $idGenerator, + private readonly SamplerInterface $sampler, + private readonly bool $trace128 = false, + ) {} public function parent( TracerInterface $tracer, diff --git a/src/Tag/AbstractSpanKindTag.php b/src/Tag/AbstractSpanKindTag.php index 0fa5105..d81d08d 100644 --- a/src/Tag/AbstractSpanKindTag.php +++ b/src/Tag/AbstractSpanKindTag.php @@ -8,6 +8,9 @@ abstract class AbstractSpanKindTag extends StringTag { public function __construct(string $value) { - parent::__construct('span.kind', $value); + parent::__construct( + 'span.kind', + $value, + ); } } diff --git a/src/Tag/BinaryTag.php b/src/Tag/BinaryTag.php index 7a10790..71ad6c1 100644 --- a/src/Tag/BinaryTag.php +++ b/src/Tag/BinaryTag.php @@ -8,8 +8,18 @@ class BinaryTag extends AbstractTag { - public function __construct(string $key, string $value) - { - parent::__construct($key, TagType::BINARY, null, null, null, null, $value); + public function __construct( + string $key, + string $value, + ) { + parent::__construct( + $key, + TagType::BINARY, + null, + null, + null, + null, + $value, + ); } } diff --git a/src/Tag/BoolTag.php b/src/Tag/BoolTag.php index 87fb5b7..093bce5 100644 --- a/src/Tag/BoolTag.php +++ b/src/Tag/BoolTag.php @@ -8,8 +8,16 @@ class BoolTag extends AbstractTag { - public function __construct(string $key, bool $value) - { - parent::__construct($key, TagType::BOOL, null, null, $value); + public function __construct( + string $key, + bool $value, + ) { + parent::__construct( + $key, + TagType::BOOL, + null, + null, + $value, + ); } } diff --git a/src/Tag/ComponentTag.php b/src/Tag/ComponentTag.php index 711b848..7a44941 100644 --- a/src/Tag/ComponentTag.php +++ b/src/Tag/ComponentTag.php @@ -8,6 +8,9 @@ class ComponentTag extends StringTag { public function __construct(string $value) { - parent::__construct('component', $value); + parent::__construct( + 'component', + $value, + ); } } diff --git a/src/Tag/DbInstanceTag.php b/src/Tag/DbInstanceTag.php index 3dbecf3..76c3f5f 100644 --- a/src/Tag/DbInstanceTag.php +++ b/src/Tag/DbInstanceTag.php @@ -8,6 +8,9 @@ class DbInstanceTag extends StringTag { public function __construct(string $value) { - parent::__construct('db.instance', $value); + parent::__construct( + 'db.instance', + $value, + ); } } diff --git a/src/Tag/DbStatementTag.php b/src/Tag/DbStatementTag.php index 82ef2a7..0ee3518 100644 --- a/src/Tag/DbStatementTag.php +++ b/src/Tag/DbStatementTag.php @@ -8,6 +8,9 @@ class DbStatementTag extends StringTag { public function __construct(string $value) { - parent::__construct('db.statement', $value); + parent::__construct( + 'db.statement', + $value, + ); } } diff --git a/src/Tag/DbType.php b/src/Tag/DbType.php index 2b39cf9..4c1a2ef 100644 --- a/src/Tag/DbType.php +++ b/src/Tag/DbType.php @@ -8,6 +8,9 @@ class DbType extends StringTag { public function __construct(string $value) { - parent::__construct('db.type', $value); + parent::__construct( + 'db.type', + $value, + ); } } diff --git a/src/Tag/DbUser.php b/src/Tag/DbUser.php index 233aab8..83d82fe 100644 --- a/src/Tag/DbUser.php +++ b/src/Tag/DbUser.php @@ -8,6 +8,9 @@ class DbUser extends StringTag { public function __construct(string $value) { - parent::__construct('db.user', $value); + parent::__construct( + 'db.user', + $value, + ); } } diff --git a/src/Tag/DebugRequestTag.php b/src/Tag/DebugRequestTag.php index e4bc133..f666990 100644 --- a/src/Tag/DebugRequestTag.php +++ b/src/Tag/DebugRequestTag.php @@ -8,6 +8,9 @@ class DebugRequestTag extends StringTag { public function __construct(string $value) { - parent::__construct('debug', $value); + parent::__construct( + 'debug', + $value, + ); } } diff --git a/src/Tag/DoubleTag.php b/src/Tag/DoubleTag.php index 0cf849e..094d6c1 100644 --- a/src/Tag/DoubleTag.php +++ b/src/Tag/DoubleTag.php @@ -8,8 +8,15 @@ class DoubleTag extends AbstractTag { - public function __construct(string $key, float $value) - { - parent::__construct($key, TagType::DOUBLE, null, $value); + public function __construct( + string $key, + float $value, + ) { + parent::__construct( + $key, + TagType::DOUBLE, + null, + $value, + ); } } diff --git a/src/Tag/ErrorTag.php b/src/Tag/ErrorTag.php index ad74bc3..5d57e95 100644 --- a/src/Tag/ErrorTag.php +++ b/src/Tag/ErrorTag.php @@ -8,6 +8,9 @@ class ErrorTag extends BoolTag { public function __construct() { - parent::__construct('error', true); + parent::__construct( + 'error', + true, + ); } } diff --git a/src/Tag/LongTag.php b/src/Tag/LongTag.php index aa7f9cf..9ffd520 100644 --- a/src/Tag/LongTag.php +++ b/src/Tag/LongTag.php @@ -8,8 +8,17 @@ class LongTag extends AbstractTag { - public function __construct(string $key, int $value) - { - parent::__construct($key, TagType::LONG, null, null, null, $value); + public function __construct( + string $key, + int $value, + ) { + parent::__construct( + $key, + TagType::LONG, + null, + null, + null, + $value, + ); } } diff --git a/src/Tag/MessageBusDestinationTag.php b/src/Tag/MessageBusDestinationTag.php index 5a3b701..ff11b9d 100644 --- a/src/Tag/MessageBusDestinationTag.php +++ b/src/Tag/MessageBusDestinationTag.php @@ -8,6 +8,9 @@ class MessageBusDestinationTag extends StringTag { public function __construct(string $value) { - parent::__construct('message_bus.destination', $value); + parent::__construct( + 'message_bus.destination', + $value, + ); } } diff --git a/src/Tag/OutOfScopeTag.php b/src/Tag/OutOfScopeTag.php index 287c8d8..f7d4c60 100644 --- a/src/Tag/OutOfScopeTag.php +++ b/src/Tag/OutOfScopeTag.php @@ -8,6 +8,9 @@ class OutOfScopeTag extends BoolTag { public function __construct() { - parent::__construct('scope.missing', true); + parent::__construct( + 'scope.missing', + true, + ); } } diff --git a/src/Tag/PeerAddressTag.php b/src/Tag/PeerAddressTag.php index 26daf1e..5133398 100644 --- a/src/Tag/PeerAddressTag.php +++ b/src/Tag/PeerAddressTag.php @@ -8,6 +8,9 @@ class PeerAddressTag extends StringTag { public function __construct(string $value) { - parent::__construct('peer.adress', $value); + parent::__construct( + 'peer.adress', + $value, + ); } } diff --git a/src/Tag/PeerHostnameTag.php b/src/Tag/PeerHostnameTag.php index b50ed85..f7a6032 100644 --- a/src/Tag/PeerHostnameTag.php +++ b/src/Tag/PeerHostnameTag.php @@ -8,6 +8,9 @@ class PeerHostnameTag extends StringTag { public function __construct(string $value) { - parent::__construct('peer.hostname', $value); + parent::__construct( + 'peer.hostname', + $value, + ); } } diff --git a/src/Tag/PeerIpv4Tag.php b/src/Tag/PeerIpv4Tag.php index efb4af1..cd77d98 100644 --- a/src/Tag/PeerIpv4Tag.php +++ b/src/Tag/PeerIpv4Tag.php @@ -8,6 +8,9 @@ class PeerIpv4Tag extends StringTag { public function __construct(string $value) { - parent::__construct('peer.ip', $value); + parent::__construct( + 'peer.ip', + $value, + ); } } diff --git a/src/Tag/PeerPortTag.php b/src/Tag/PeerPortTag.php index 6937f41..71fce73 100644 --- a/src/Tag/PeerPortTag.php +++ b/src/Tag/PeerPortTag.php @@ -8,6 +8,9 @@ class PeerPortTag extends LongTag { public function __construct(int $value) { - parent::__construct('peer.port', $value); + parent::__construct( + 'peer.port', + $value, + ); } } diff --git a/src/Tag/PeerServiceTag.php b/src/Tag/PeerServiceTag.php index ab7f754..ce606b3 100644 --- a/src/Tag/PeerServiceTag.php +++ b/src/Tag/PeerServiceTag.php @@ -8,6 +8,9 @@ class PeerServiceTag extends StringTag { public function __construct(string $value) { - parent::__construct('peer.service', $value); + parent::__construct( + 'peer.service', + $value, + ); } } diff --git a/src/Tag/StringTag.php b/src/Tag/StringTag.php index f22dbd3..43c0015 100644 --- a/src/Tag/StringTag.php +++ b/src/Tag/StringTag.php @@ -8,8 +8,14 @@ class StringTag extends AbstractTag { - public function __construct(string $key, string $value) - { - parent::__construct($key, TagType::STRING, $value); + public function __construct( + string $key, + string $value, + ) { + parent::__construct( + $key, + TagType::STRING, + $value, + ); } } diff --git a/src/Tracer/Tracer.php b/src/Tracer/Tracer.php index b8895d1..4476c4c 100644 --- a/src/Tracer/Tracer.php +++ b/src/Tracer/Tracer.php @@ -21,7 +21,11 @@ class Tracer implements { private string $debugId = ''; - public function __construct(private readonly SpanManagerInterface $manager, private readonly SpanFactoryInterface $factory, private readonly ClientInterface $client) {} + public function __construct( + private readonly SpanManagerInterface $manager, + private readonly SpanFactoryInterface $factory, + private readonly ClientInterface $client, + ) {} public function enable(string $debugId): DebuggableInterface { diff --git a/src/Transport/TUDPTransport.php b/src/Transport/TUDPTransport.php index 6d674f9..23e3b8e 100644 --- a/src/Transport/TUDPTransport.php +++ b/src/Transport/TUDPTransport.php @@ -14,7 +14,10 @@ class TUDPTransport extends TTransport private string $buffer = ''; - public function __construct(private readonly string $host, private readonly int $port) {} + public function __construct( + private readonly string $host, + private readonly int $port, + ) {} public function isOpen(): bool { From ade32d7cb4eae48c1074187e189465d6843f40d4 Mon Sep 17 00:00:00 2001 From: dozer Date: Wed, 16 Sep 2026 16:23:00 +0300 Subject: [PATCH 08/12] :broom: psalm setup MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Level 1 — the strictest — over src/, with src/Thrift excluded: its shape is the thrift compiler's contract and it calls thrift_protocol_* from the optional C extension. ClassMustBeFinal is suppressed because this is a library and consumers legitimately extend these classes. Co-Authored-By: Claude Opus 5 (1M context) --- composer.json | 3 ++- psalm.xml | 27 +++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 psalm.xml diff --git a/composer.json b/composer.json index 8eddc2b..d3461d0 100644 --- a/composer.json +++ b/composer.json @@ -14,7 +14,8 @@ "require-dev": { "phpunit/phpunit": "@stable", "friendsofphp/php-cs-fixer": "^3.95", - "rector/rector": "^2.6" + "rector/rector": "^2.6", + "vimeo/psalm": "^6" }, "minimum-stability": "dev", "prefer-stable": true diff --git a/psalm.xml b/psalm.xml new file mode 100644 index 0000000..0d7ad65 --- /dev/null +++ b/psalm.xml @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + + + + From 13a3b6ffd18958b13c616f57fe5486bd0757ed38 Mon Sep 17 00:00:00 2001 From: dozer Date: Wed, 16 Sep 2026 16:23:00 +0300 Subject: [PATCH 09/12] :broom: psalm Resolve every issue psalm reports at level 1: * type the arrays that cross a public boundary (tags, logs, spans, baggage) so coercions are checked instead of inferred as mixed * handle the false branch of gethostname/getmypid/getmyuid/getmygid/json_encode instead of passing it straight into a string parameter * cast mixed/int and float operands explicitly * give the ArrayAccess and IteratorAggregate implementations their template parameters and real native signatures, dropping #[ReturnTypeWillChange] * align parameter names with the interfaces that declare them, so named arguments work One suppression remains, in Span\Batch\SpanBatch: SpanInterface cannot declare that it extends the generated Thrift\Span even though its only implementation does. Co-Authored-By: Claude Opus 5 (1M context) --- src/Client/ThriftClient.php | 13 +++--- src/Codec/CodecInterface.php | 4 +- src/Codec/CodecRegistry.php | 55 +++++++++-------------- src/Codec/TextCodec.php | 16 +++++-- src/General/JaegerHostnameTag.php | 2 +- src/Log/AbstractLog.php | 6 ++- src/Log/ErrorObjectTag.php | 2 +- src/Process/AbstractProcess.php | 4 ++ src/Process/ProcessGidTag.php | 2 +- src/Process/ProcessPidTag.php | 2 +- src/Process/ProcessUidTag.php | 2 +- src/Sampler/AdaptiveSampler.php | 6 +-- src/Sampler/ConstSampler.php | 7 +-- src/Sampler/ProbabilisticSampler.php | 2 +- src/Sampler/RateLimitingSampler.php | 15 ++++--- src/Sampler/SamplerResult.php | 8 ++++ src/Span/Batch/SpanBatch.php | 9 ++++ src/Span/Context/SpanContext.php | 19 +++++--- src/Span/Factory/SpanFactory.php | 14 +++++- src/Span/Factory/SpanFactoryInterface.php | 10 +++++ src/Span/Span.php | 12 +++-- src/Span/SpanInterface.php | 4 +- src/Span/SpanManagerInterface.php | 2 +- src/Span/StackSpanManager.php | 20 +++++++-- src/Tracer/DebuggableInterface.php | 6 ++- src/Tracer/Tracer.php | 14 ++++-- src/Tracer/TracerInterface.php | 4 ++ src/Transport/TUDPTransport.php | 3 +- 28 files changed, 175 insertions(+), 88 deletions(-) diff --git a/src/Client/ThriftClient.php b/src/Client/ThriftClient.php index 3bb584f..1973bae 100644 --- a/src/Client/ThriftClient.php +++ b/src/Client/ThriftClient.php @@ -13,19 +13,18 @@ class ThriftClient implements ClientInterface { - public const MAX_BATCH_SIZE = 32; - - private readonly int $batch; + public const int MAX_BATCH_SIZE = 32; + /** + * @var list + */ private array $spans = []; public function __construct( private readonly string $serviceName, private readonly AgentInterface $agent, - $batch = self::MAX_BATCH_SIZE, - ) { - $this->batch = (int) $batch; - } + private readonly int $batch = self::MAX_BATCH_SIZE, + ) {} public function add(SpanInterface $span): ClientInterface { diff --git a/src/Codec/CodecInterface.php b/src/Codec/CodecInterface.php index 016793d..4855d8b 100644 --- a/src/Codec/CodecInterface.php +++ b/src/Codec/CodecInterface.php @@ -8,7 +8,7 @@ interface CodecInterface { - public function decode($data): ?SpanContext; + public function decode(mixed $data): ?SpanContext; - public function encode(SpanContext $context); + public function encode(SpanContext $context): string; } diff --git a/src/Codec/CodecRegistry.php b/src/Codec/CodecRegistry.php index 15a35bb..c24e4ac 100644 --- a/src/Codec/CodecRegistry.php +++ b/src/Codec/CodecRegistry.php @@ -5,56 +5,45 @@ namespace Jaeger\Codec; use ArrayAccess; -use ReturnTypeWillChange; +use InvalidArgumentException; +/** + * @implements ArrayAccess + */ class CodecRegistry implements ArrayAccess { - private $codecs = []; - /** - * @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); } - /** - */ - #[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'); + } + + if (!$value instanceof CodecInterface) { + throw new InvalidArgumentException( + \sprintf('Codec must implement %s, %s given', CodecInterface::class, get_debug_type($value)), + ); + } - return $this; + $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 9aa1555..730d248 100644 --- a/src/Codec/TextCodec.php +++ b/src/Codec/TextCodec.php @@ -4,13 +4,14 @@ namespace Jaeger\Codec; +use InvalidArgumentException; use Jaeger\Span\Context\SpanContext; class TextCodec implements CodecInterface { - public function decode($data): ?SpanContext + public function decode(mixed $data): ?SpanContext { - if (false === \is_string($data)) { + if (!\is_string($data)) { return null; } @@ -33,10 +34,19 @@ public function decode($data): ?SpanContext public function convertInt64(string $hex): int { $hex8byte = str_pad($hex, 16, '0', STR_PAD_LEFT); + $binary = pack('H*', $hex8byte); + $unpacked = unpack('Jint64', $binary); - return unpack('Jint64', pack('H*', $hex8byte))['int64']; + if (false === $unpacked) { + throw new InvalidArgumentException(\sprintf('Cannot unpack "%s" as a 64-bit integer', $hex)); + } + + return (int) $unpacked['int64']; } + /** + * @return array{int, int} + */ public function convertInt128(string $hex): array { $hex16byte = str_pad($hex, 32, '0', STR_PAD_LEFT); diff --git a/src/General/JaegerHostnameTag.php b/src/General/JaegerHostnameTag.php index 55a7ab3..1d40f02 100644 --- a/src/General/JaegerHostnameTag.php +++ b/src/General/JaegerHostnameTag.php @@ -12,7 +12,7 @@ public function __construct() { parent::__construct( 'jaeger.hostname', - gethostname(), + false === ($hostname = gethostname()) ? 'unknown' : $hostname, ); } } diff --git a/src/Log/AbstractLog.php b/src/Log/AbstractLog.php index 1a4cb90..4a10217 100644 --- a/src/Log/AbstractLog.php +++ b/src/Log/AbstractLog.php @@ -5,14 +5,18 @@ namespace Jaeger\Log; use Jaeger\Thrift\Log; +use Jaeger\Thrift\Tag; abstract class AbstractLog extends Log { + /** + * @param list $tags + */ public function __construct( array $tags = [], int $timestamp = 0, ) { - $this->timestamp = 0 !== $timestamp ? $timestamp : (int) round(microtime(true) * 1000000); + $this->timestamp = 0 !== $timestamp ? $timestamp : (int) round(microtime(true) * 1000000.0); $this->fields = $tags; parent::__construct(); } diff --git a/src/Log/ErrorObjectTag.php b/src/Log/ErrorObjectTag.php index 9872901..1a12bda 100644 --- a/src/Log/ErrorObjectTag.php +++ b/src/Log/ErrorObjectTag.php @@ -13,7 +13,7 @@ public function __construct(JsonSerializable $value) { parent::__construct( 'error.object', - json_encode($value), + false === ($json = json_encode($value)) ? '' : $json, ); } } diff --git a/src/Process/AbstractProcess.php b/src/Process/AbstractProcess.php index 2bafb83..aad09bd 100644 --- a/src/Process/AbstractProcess.php +++ b/src/Process/AbstractProcess.php @@ -9,9 +9,13 @@ use Jaeger\General\PhpBinaryTag; use Jaeger\General\PhpVersionTag; use Jaeger\Thrift\Process; +use Jaeger\Thrift\Tag; abstract class AbstractProcess extends Process { + /** + * @param array $tags + */ public function __construct( string $serviceName, array $tags = [], diff --git a/src/Process/ProcessGidTag.php b/src/Process/ProcessGidTag.php index 310eaf3..0e542e8 100644 --- a/src/Process/ProcessGidTag.php +++ b/src/Process/ProcessGidTag.php @@ -12,7 +12,7 @@ public function __construct() { parent::__construct( 'process.gid', - getmygid(), + false === ($id = getmygid()) ? 0 : $id, ); } } diff --git a/src/Process/ProcessPidTag.php b/src/Process/ProcessPidTag.php index 11a31e2..6491f7b 100644 --- a/src/Process/ProcessPidTag.php +++ b/src/Process/ProcessPidTag.php @@ -12,7 +12,7 @@ public function __construct() { parent::__construct( 'process.pid', - getmypid(), + false === ($id = getmypid()) ? 0 : $id, ); } } diff --git a/src/Process/ProcessUidTag.php b/src/Process/ProcessUidTag.php index b695137..adeb665 100644 --- a/src/Process/ProcessUidTag.php +++ b/src/Process/ProcessUidTag.php @@ -12,7 +12,7 @@ public function __construct() { parent::__construct( 'process.uid', - getmyuid(), + false === ($id = getmyuid()) ? 0 : $id, ); } } diff --git a/src/Sampler/AdaptiveSampler.php b/src/Sampler/AdaptiveSampler.php index 846796e..a6c8f60 100644 --- a/src/Sampler/AdaptiveSampler.php +++ b/src/Sampler/AdaptiveSampler.php @@ -11,9 +11,9 @@ public function __construct( 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, @@ -22,7 +22,7 @@ public function decide(int $tracerId, string $operationName, string $debugId): S ); } - $probabilisticResult = $this->probabilistic->decide($tracerId, $operationName, $debugId); + $probabilisticResult = $this->probabilistic->decide($traceId, $operationName, $debugId); if ($probabilisticResult->isSampled()) { return new SamplerResult( true, diff --git a/src/Sampler/ConstSampler.php b/src/Sampler/ConstSampler.php index 7d2c0ee..86c232b 100644 --- a/src/Sampler/ConstSampler.php +++ b/src/Sampler/ConstSampler.php @@ -6,12 +6,7 @@ class ConstSampler extends AbstractSampler { - private readonly bool $debugEnabled; - - public function __construct($debugEnabled) - { - $this->debugEnabled = (bool) $debugEnabled; - } + public function __construct(private readonly bool $debugEnabled) {} public function doDecide(int $tracerId, string $operationName): SamplerResult { diff --git a/src/Sampler/ProbabilisticSampler.php b/src/Sampler/ProbabilisticSampler.php index 2338886..14e07e5 100644 --- a/src/Sampler/ProbabilisticSampler.php +++ b/src/Sampler/ProbabilisticSampler.php @@ -10,7 +10,7 @@ class ProbabilisticSampler extends AbstractSampler public function __construct(private readonly float $rate) { - $this->threshold = 0.5 * $this->rate * PHP_INT_MAX; + $this->threshold = 0.5 * $this->rate * (float) PHP_INT_MAX; } public function doDecide(int $tracerId, string $operationName): SamplerResult diff --git a/src/Sampler/RateLimitingSampler.php b/src/Sampler/RateLimitingSampler.php index 8e31bb6..8bdf138 100644 --- a/src/Sampler/RateLimitingSampler.php +++ b/src/Sampler/RateLimitingSampler.php @@ -16,6 +16,9 @@ public function value(int $sec, int $count): int return (($sec & 0xffffffff) << 16) + ($count & 0xffff); } + /** + * @return array{int, int} + */ public function spec(int $value): array { return [$value >> 16, $value & 0xffff]; @@ -24,7 +27,7 @@ public function spec(int $value): array 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, @@ -40,18 +43,20 @@ public function doDecide(int $tracerId, string $operationName): SamplerResult $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); } - [$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; } diff --git a/src/Sampler/SamplerResult.php b/src/Sampler/SamplerResult.php index 2177d1a..6a342f4 100644 --- a/src/Sampler/SamplerResult.php +++ b/src/Sampler/SamplerResult.php @@ -4,8 +4,13 @@ namespace Jaeger\Sampler; +use Jaeger\Thrift\Tag; + class SamplerResult { + /** + * @param array $tags + */ public function __construct( private readonly bool $sampled, private readonly int $flags, @@ -22,6 +27,9 @@ public function isSampled(): bool return $this->sampled; } + /** + * @return array + */ public function getTags(): array { return $this->tags; diff --git a/src/Span/Batch/SpanBatch.php b/src/Span/Batch/SpanBatch.php index d5ae927..be2bf55 100644 --- a/src/Span/Batch/SpanBatch.php +++ b/src/Span/Batch/SpanBatch.php @@ -5,10 +5,19 @@ namespace Jaeger\Span\Batch; use Jaeger\Process\AbstractProcess; +use Jaeger\Span\SpanInterface; use Jaeger\Thrift\Batch; class SpanBatch extends Batch { + /** + * @param array $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 = [], diff --git a/src/Span/Context/SpanContext.php b/src/Span/Context/SpanContext.php index fd91007..050276d 100644 --- a/src/Span/Context/SpanContext.php +++ b/src/Span/Context/SpanContext.php @@ -6,11 +6,16 @@ use ArrayIterator; use IteratorAggregate; -use ReturnTypeWillChange; use Traversable; +/** + * @implements IteratorAggregate + */ class SpanContext implements IteratorAggregate { + /** + * @param array $baggage + */ public function __construct( private int $traceIdHigh, private int $traceIdLow, @@ -60,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); } - public function withItem(string $key, $item): static + public function withItem(string $key, mixed $item): static { $copy = clone $this; $copy->baggage[$key] = $item; @@ -82,7 +89,7 @@ public function withItem(string $key, $item): static 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)) { return $default; diff --git a/src/Span/Factory/SpanFactory.php b/src/Span/Factory/SpanFactory.php index 1596a4d..cafad3a 100644 --- a/src/Span/Factory/SpanFactory.php +++ b/src/Span/Factory/SpanFactory.php @@ -9,6 +9,8 @@ use Jaeger\Span\Context\SpanContext; use Jaeger\Span\Span; use Jaeger\Span\SpanInterface; +use Jaeger\Thrift\Log; +use Jaeger\Thrift\Tag; use Jaeger\Tracer\TracerInterface; class SpanFactory implements SpanFactoryInterface @@ -19,6 +21,10 @@ public function __construct( private readonly bool $trace128 = false, ) {} + /** + * @param array $tags + * @param array $logs + */ public function parent( TracerInterface $tracer, string $operationName, @@ -40,12 +46,16 @@ public function parent( $samplerResult->getFlags(), ), $operationName, - (int) (microtime(true) * 1000000), + (int) (microtime(true) * 1000000.0), array_merge($tags, $samplerResult->getTags()), $logs, ); } + /** + * @param array $tags + * @param array $logs + */ public function child( TracerInterface $tracer, string $operationName, @@ -64,7 +74,7 @@ public function child( $parentContext->getBaggage(), ), $operationName, - (int) (microtime(true) * 1000000), + (int) (microtime(true) * 1000000.0), $tags, $logs, ); diff --git a/src/Span/Factory/SpanFactoryInterface.php b/src/Span/Factory/SpanFactoryInterface.php index f541c86..0a1d36d 100644 --- a/src/Span/Factory/SpanFactoryInterface.php +++ b/src/Span/Factory/SpanFactoryInterface.php @@ -6,10 +6,16 @@ use Jaeger\Span\Context\SpanContext; use Jaeger\Span\SpanInterface; +use Jaeger\Thrift\Log; +use Jaeger\Thrift\Tag; use Jaeger\Tracer\TracerInterface; interface SpanFactoryInterface { + /** + * @param array $tags + * @param array $logs + */ public function parent( TracerInterface $tracer, string $operationName, @@ -18,6 +24,10 @@ public function parent( array $logs = [], ): SpanInterface; + /** + * @param array $tags + * @param array $logs + */ public function child( TracerInterface $tracer, string $operationName, diff --git a/src/Span/Span.php b/src/Span/Span.php index a0a72ac..0b2c0a5 100644 --- a/src/Span/Span.php +++ b/src/Span/Span.php @@ -13,6 +13,10 @@ class Span extends \Jaeger\Thrift\Span implements SpanInterface { + /** + * @param array $tags + * @param array $logs + */ public function __construct( private readonly FinishableInterface $tracer, private SpanContext $context, @@ -63,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; @@ -83,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/SpanInterface.php b/src/Span/SpanInterface.php index 4e0944e..6b660cd 100644 --- a/src/Span/SpanInterface.php +++ b/src/Span/SpanInterface.php @@ -18,9 +18,9 @@ public function addTag(Tag $tag): SpanInterface; public function addLog(Log $log): SpanInterface; - public function withItem(string $key, $item): SpanInterface; + public function withItem(string $key, mixed $item): SpanInterface; - public function getItem(string $key, $default = null); + public function getItem(string $key, mixed $default = null): mixed; public function withoutItem(string $key): SpanInterface; diff --git a/src/Span/SpanManagerInterface.php b/src/Span/SpanManagerInterface.php index 0333214..f30923c 100644 --- a/src/Span/SpanManagerInterface.php +++ b/src/Span/SpanManagerInterface.php @@ -13,7 +13,7 @@ interface SpanManagerInterface extends ContextAwareInterface, ResettableInterface, SpanAwareInterface { - public function new(SpanInterface $span); + public function new(SpanInterface $span): void; public function finish(SpanInterface $span): ?SpanInterface; } diff --git a/src/Span/StackSpanManager.php b/src/Span/StackSpanManager.php index 270e9cb..9f9d6a9 100644 --- a/src/Span/StackSpanManager.php +++ b/src/Span/StackSpanManager.php @@ -11,13 +11,16 @@ class StackSpanManager implements SpanManagerInterface { + /** + * @var SplStack + */ private SplStack $stack; private ?SpanContext $context = null; public function __construct() { - $this->stack = new SplStack(); + $this->stack = $this->createStack(); } /** @@ -25,7 +28,7 @@ public function __construct() */ public function reset(): ResettableInterface { - $this->stack = new SplStack(); + $this->stack = $this->createStack(); $this->context = null; return $this; @@ -38,7 +41,7 @@ public function reset(): ResettableInterface public function assign(SpanContext $context): InjectableInterface { $this->context = $context; - $this->stack = new SplStack(); + $this->stack = $this->createStack(); return $this; } @@ -80,4 +83,15 @@ public function getContext(): ?SpanContext { 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/Tracer/DebuggableInterface.php b/src/Tracer/DebuggableInterface.php index cd0ebb5..633c4d0 100644 --- a/src/Tracer/DebuggableInterface.php +++ b/src/Tracer/DebuggableInterface.php @@ -5,12 +5,16 @@ namespace Jaeger\Tracer; use Jaeger\Span\SpanInterface; +use Jaeger\Thrift\Tag; interface DebuggableInterface { - public function enable(string $requestId): DebuggableInterface; + public function enable(string $debugId): DebuggableInterface; public function disable(): DebuggableInterface; + /** + * @param array $tags + */ public function debug(string $operationName, array $tags = []): SpanInterface; } diff --git a/src/Tracer/Tracer.php b/src/Tracer/Tracer.php index 4476c4c..9f0a06e 100644 --- a/src/Tracer/Tracer.php +++ b/src/Tracer/Tracer.php @@ -10,6 +10,7 @@ use Jaeger\Span\Factory\SpanFactoryInterface; use Jaeger\Span\SpanInterface; use Jaeger\Span\SpanManagerInterface; +use Jaeger\Thrift\Tag; class Tracer implements TracerInterface, @@ -75,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); @@ -83,12 +87,16 @@ 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 (!($context = $userContext ?: $this->manager->getContext()) instanceof SpanContext) { + $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); diff --git a/src/Tracer/TracerInterface.php b/src/Tracer/TracerInterface.php index c0686da..e5c6ed6 100644 --- a/src/Tracer/TracerInterface.php +++ b/src/Tracer/TracerInterface.php @@ -6,8 +6,12 @@ use Jaeger\Span\Context\SpanContext; use Jaeger\Span\SpanInterface; +use Jaeger\Thrift\Tag; interface TracerInterface extends FinishableInterface { + /** + * @param array $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 23e3b8e..9fd3cf0 100644 --- a/src/Transport/TUDPTransport.php +++ b/src/Transport/TUDPTransport.php @@ -65,7 +65,8 @@ private function doWrite(string $buf): void $length = \strlen($buf); while (true) { - if (false === ($result = @socket_write($socket, $buf))) { + $result = @socket_write($socket, $buf); + if (false === $result) { break; } From 004041cffba812f4a341d338315e4a68e304c773 Mon Sep 17 00:00:00 2001 From: dozer Date: Wed, 16 Sep 2026 16:24:31 +0300 Subject: [PATCH 10/12] :white_check_mark: PHPUnit 13 test harness MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adds phpunit/phpunit ^13, a phpunit.xml.dist that keeps the generated src/Thrift tree out of coverage, and a Jaeger\Tests\ autoload-dev namespace. composer.json also loses "minimum-stability": "dev" — every dependency now resolves to a stable release — and gains the description, type and keywords that 'composer validate --strict' requires. ext-apcu is declared as a suggestion since only RateLimitingSampler needs it. The three linter configs are widened to cover tests/ as well. Co-Authored-By: Claude Opus 5 (1M context) --- .gitignore | 2 ++ .php-cs-fixer.dist.php | 2 +- composer.json | 30 ++++++++++++++++++++++-------- phpunit.xml.dist | 32 ++++++++++++++++++++++++++++++++ psalm.xml | 18 ++++++++++++++++++ rector.php | 1 + 6 files changed, 76 insertions(+), 9 deletions(-) create mode 100644 phpunit.xml.dist diff --git a/.gitignore b/.gitignore index dc6afcf..e19c971 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,5 @@ 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 index 876ea47..525c7ae 100644 --- a/.php-cs-fixer.dist.php +++ b/.php-cs-fixer.dist.php @@ -7,7 +7,7 @@ use PhpCsFixer\Runner\Parallel\ParallelConfigFactory; $finder = Finder::create() - ->in([__DIR__ . '/src']) + ->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']) diff --git a/composer.json b/composer.json index d3461d0..cfa801c 100644 --- a/composer.json +++ b/composer.json @@ -1,22 +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": "^8.4", "ext-sockets": "*", "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" }, - "minimum-stability": "dev", - "prefer-stable": true + "suggest": { + "ext-apcu": "Required by RateLimitingSampler to share its rate counters between requests" + }, + "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 index 0d7ad65..2d2ef17 100644 --- a/psalm.xml +++ b/psalm.xml @@ -10,6 +10,7 @@ > + + + + + + + + + + + + + + + + diff --git a/rector.php b/rector.php index 0bdaecb..b3ef4b3 100644 --- a/rector.php +++ b/rector.php @@ -7,6 +7,7 @@ return RectorConfig::configure() ->withPaths([ __DIR__ . '/src', + __DIR__ . '/tests', __DIR__ . '/.php-cs-fixer.dist.php', __FILE__, ]) From 6f5b305aa16a0f2d23a148abada39f3782e234ad Mon Sep 17 00:00:00 2001 From: dozer Date: Wed, 16 Sep 2026 16:24:31 +0300 Subject: [PATCH 11/12] :white_check_mark: Cover the library with tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 317 tests, 96.86% line coverage over src/ excluding the generated Thrift code. Table-driven throughout: each case yields a class name plus constructor arguments rather than a ready-made object, because code executed inside a data provider is not attributed to coverage. No mocks or stubs — tests/Fixture holds real implementations: a recording tracer, client and agent, a deterministic id generator and a bound UDP listener. tests/Thrift/SerializationTest.php exercises the generated structs against the apache/thrift runtime over both the binary and compact protocols and emits a real batch over UDP. Since the generated fields are honestly nullable, it narrows them explicitly — which makes the tests stricter, as a round trip must return every 'required' field non-null. Four existing defects are pinned by tests that document them rather than quietly encoding them as intended behaviour: * PeerAddressTag writes the key 'peer.adress' (typo) and PeerIpv4Tag writes 'peer.ip' where OpenTracing specifies 'peer.ipv4' * AdaptiveSampler copies flags and tags from the rate limiter that rejected the trace when the probabilistic sampler is the one that accepted it * StackSpanManager::remove() never removes anything: SplStack::valid() is false until rewind(), and it compares a Span's object hash against a SpanContext's * TextCodec::encode() writes the trace id as '%x%x' without padding, so a traceIdLow shorter than 16 hex digits cannot be split back out on decode Co-Authored-By: Claude Opus 5 (1M context) --- tests/Client/ThriftClientTest.php | 151 ++++++++++++ tests/Codec/CodecRegistryTest.php | 87 +++++++ tests/Codec/TextCodecTest.php | 111 +++++++++ tests/Fixture/RecordingAgent.php | 42 ++++ tests/Fixture/RecordingClient.php | 49 ++++ tests/Fixture/RecordingTracer.php | 57 +++++ tests/Fixture/SequenceIdGenerator.php | 35 +++ tests/Fixture/UdpListener.php | 59 +++++ tests/Id/RandomIntGeneratorTest.php | 54 ++++ tests/Log/LogTest.php | 129 ++++++++++ tests/Process/ProcessTest.php | 176 +++++++++++++ tests/Sampler/AdaptiveSamplerTest.php | 102 ++++++++ tests/Sampler/ConstSamplerTest.php | 94 +++++++ tests/Sampler/GeneratorTest.php | 51 ++++ tests/Sampler/ProbabilisticSamplerTest.php | 80 ++++++ tests/Sampler/RateLimitingSamplerTest.php | 132 ++++++++++ tests/Sampler/SamplerResultTest.php | 48 ++++ tests/Span/Batch/SpanBatchTest.php | 42 ++++ tests/Span/Context/SpanContextTest.php | 152 ++++++++++++ tests/Span/Factory/SpanFactoryTest.php | 160 ++++++++++++ tests/Span/SpanTest.php | 208 ++++++++++++++++ tests/Span/StackSpanManagerTest.php | 158 ++++++++++++ tests/Tag/TagTest.php | 207 ++++++++++++++++ tests/Thrift/SerializationTest.php | 273 +++++++++++++++++++++ tests/Tracer/TracerTest.php | 212 ++++++++++++++++ tests/Transport/TUDPTransportTest.php | 189 ++++++++++++++ 26 files changed, 3058 insertions(+) create mode 100644 tests/Client/ThriftClientTest.php create mode 100644 tests/Codec/CodecRegistryTest.php create mode 100644 tests/Codec/TextCodecTest.php create mode 100644 tests/Fixture/RecordingAgent.php create mode 100644 tests/Fixture/RecordingClient.php create mode 100644 tests/Fixture/RecordingTracer.php create mode 100644 tests/Fixture/SequenceIdGenerator.php create mode 100644 tests/Fixture/UdpListener.php create mode 100644 tests/Id/RandomIntGeneratorTest.php create mode 100644 tests/Log/LogTest.php create mode 100644 tests/Process/ProcessTest.php create mode 100644 tests/Sampler/AdaptiveSamplerTest.php create mode 100644 tests/Sampler/ConstSamplerTest.php create mode 100644 tests/Sampler/GeneratorTest.php create mode 100644 tests/Sampler/ProbabilisticSamplerTest.php create mode 100644 tests/Sampler/RateLimitingSamplerTest.php create mode 100644 tests/Sampler/SamplerResultTest.php create mode 100644 tests/Span/Batch/SpanBatchTest.php create mode 100644 tests/Span/Context/SpanContextTest.php create mode 100644 tests/Span/Factory/SpanFactoryTest.php create mode 100644 tests/Span/SpanTest.php create mode 100644 tests/Span/StackSpanManagerTest.php create mode 100644 tests/Tag/TagTest.php create mode 100644 tests/Thrift/SerializationTest.php create mode 100644 tests/Tracer/TracerTest.php create mode 100644 tests/Transport/TUDPTransportTest.php 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()); + } +} From 495ae8e0eddc0be1db52dcc94f697af8bf106d0f Mon Sep 17 00:00:00 2001 From: dozer Date: Wed, 16 Sep 2026 16:24:31 +0300 Subject: [PATCH 12/12] :construction_worker: Run tests, psalm and the linters on CI Three jobs: PHPUnit on PHP 8.4 and 8.5, psalm, and a coding-standards job that checks php-cs-fixer and rector in dry-run mode plus 'composer validate --strict'. APCu is enabled on the CLI so the RateLimitingSampler tests run instead of skipping. Co-Authored-By: Claude Opus 5 (1M context) --- .github/workflows/ci.yml | 81 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 .github/workflows/ci.yml 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