diff --git a/.github/workflows/lint.yaml b/.github/workflows/lint.yaml new file mode 100644 index 0000000..68c79cd --- /dev/null +++ b/.github/workflows/lint.yaml @@ -0,0 +1,44 @@ +name: Lint + +on: [push, pull_request] + +jobs: + lint: + runs-on: ubuntu-latest + strategy: + fail-fast: true + matrix: + php: + - '7.1' + - '7.2' + - '7.3' + - '7.4' + # - '8.0' + dependency-version: [prefer-stable] + name: ${{ matrix.php }} - ${{ matrix.dependency-version }} + + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Cache dependencies + uses: actions/cache@v2 + with: + path: ~/.composer/cache/files + key: dependencies-laravel-php-${{ matrix.php }}-composer-${{ hashFiles('composer.json') }} + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php }} + coverage: none + + - name: Install dependencies + run: | + composer update --${{ matrix.dependency-version }} --prefer-dist --no-interaction + + - name: Execute PHPStan + run: vendor/bin/phpstan analyse src tests + + - name: PHP CS Fixer Check + run: vendor/bin/php-cs-fixer fix --dry-run --diff 1>&2 diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml new file mode 100644 index 0000000..823bc36 --- /dev/null +++ b/.github/workflows/test.yaml @@ -0,0 +1,41 @@ +name: Tests + +on: [push, pull_request] + +jobs: + test: + runs-on: ubuntu-latest + strategy: + fail-fast: true + matrix: + php: + - '7.1' + - '7.2' + - '7.3' + - '7.4' +# - '8.0' + dependency-version: [prefer-stable] + name: ${{ matrix.php }} - ${{ matrix.dependency-version }} + + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Cache dependencies + uses: actions/cache@v2 + with: + path: ~/.composer/cache/files + key: dependencies-laravel-php-${{ matrix.php }}-composer-${{ hashFiles('composer.json') }} + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php }} + coverage: none + + - name: Install dependencies + run: | + composer update --${{ matrix.dependency-version }} --prefer-dist --no-interaction + + - name: Execute tests + run: ./vendor/bin/phpunit diff --git a/.gitignore b/.gitignore index ed8581a..67fe1ad 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ .buildpath .project .idea +.php_cs.cache composer.lock vendor/* build diff --git a/.php_cs b/.php_cs new file mode 100644 index 0000000..f1767d3 --- /dev/null +++ b/.php_cs @@ -0,0 +1,22 @@ +exclude('vendor') + ->exclude('src/Jaeger/Thrift') + ->in(__DIR__); + +return PhpCsFixer\Config::create() + ->setRiskyAllowed(true) + ->setRules([ + '@Symfony' => true, + ]) + ->setFinder($finder); \ No newline at end of file diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index f3562fe..0000000 --- a/.travis.yml +++ /dev/null @@ -1,18 +0,0 @@ -language: php - -php: - - '5.6' - - '7.0' - - '7.1' - - '7.2' - - '7.3' - - -install: - - composer install - -script: - - composer test - -after_success: - - travis_retry php vendor/bin/coveralls -v \ No newline at end of file diff --git a/README.md b/README.md index 03b4421..c110804 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,7 @@ +# jaeger-php + [![Build Status](https://travis-ci.com/jukylin/jaeger-php.svg?branch=master)](https://travis-ci.com/jukylin/jaeger-php) -[![Minimum PHP Version](https://img.shields.io/badge/php-%3E%3D%205.6-8892BF.svg)](https://php.net/) +[![Minimum PHP Version](https://img.shields.io/badge/php-%3E%3D%207.1-8892BF.svg)](https://php.net/) [![License](https://img.shields.io/github/license/jukylin/jaeger-php.svg)](https://github.com/jukylin/jaeger-php/blob/master/LICENSE) [![Coverage Status](https://coveralls.io/repos/github/jukylin/jaeger-php/badge.svg?branch=master)](https://coveralls.io/github/jukylin/jaeger-php?branch=master) @@ -10,7 +12,6 @@ Install via composer. ``` -composer config minimum-stability dev composer require jukylin/jaeger-php ``` @@ -101,3 +102,10 @@ $config->flush(); [OpenTracing](https://opentracing.io/) [Jaeger](https://uber.github.io/jaeger/) + + +## TODO +- [x] Implement the latest opentracing/opentracing +- [ ] Improve documentation +- [x] Refactor thrift +- [ ] Improve unit test coverage diff --git a/composer.json b/composer.json index 0216a99..c4d43a9 100644 --- a/composer.json +++ b/composer.json @@ -5,9 +5,10 @@ "license": "Apache-2.0", "minimum-stability": "stable", "require": { - "php": ">=5.6.0", - "packaged/thrift" : "0.10.0", - "opentracing/opentracing" : "1.0.0-beta5" + "php": ">=7.1", + "ext-json": "*", + "packaged/thrift" : "~0.13.0", + "opentracing/opentracing" : "^1.0.1" }, "authors": [ { @@ -24,10 +25,14 @@ ] }, "scripts": { - "test": "./vendor/bin/phpunit" + "test": "./vendor/bin/phpunit", + "phpcs": "./vendor/bin/php-cs-fixer fix --ansi", + "phpstan": "./vendor/bin/phpstan analyse src tests" }, "require-dev": { "phpunit/phpunit": "^5", - "php-coveralls/php-coveralls": "^1.0" + "php-coveralls/php-coveralls": "^v2.4.3", + "phpstan/phpstan": "^0.12.64", + "friendsofphp/php-cs-fixer": "^2.17" } } diff --git a/example/HTTP.php b/example/HTTP.php index 07c185a..05bdd03 100644 --- a/example/HTTP.php +++ b/example/HTTP.php @@ -13,29 +13,34 @@ * the License. */ -require_once dirname(dirname(dirname(dirname(__FILE__)))).'/autoload.php'; +require_once dirname(__FILE__, 2).'/vendor/autoload.php'; -use Jaeger\Config; use GuzzleHttp\Client; +use Jaeger\Config; use OpenTracing\Formats; use OpenTracing\Reference; unset($_SERVER['argv']); - //init server span start $config = Config::getInstance(); + $config->gen128bit(); $config::$propagator = Jaeger\Constants\PROPAGATOR_ZIPKIN; -$tracer = $config->initTracer('example', '0.0.0.0:6831'); +$tracer = $config->initTracer('example', 'localhost:6831'); $injectTarget = []; $spanContext = $tracer->extract(Formats\TEXT_MAP, $_SERVER); -$serverSpan = $tracer->startSpan('example HTTP', ['child_of' => $spanContext]); -$serverSpan->addBaggageItem("version", "1.8.9"); -print_r($serverSpan->getContext()); + +$options = []; +if (null != $spanContext) { + $options = ['child_of' => $spanContext]; +} + +$serverSpan = $tracer->startSpan('HTTP', $options); +//$serverSpan->addBaggageItem('version', '1.8.9'); $tracer->inject($serverSpan->getContext(), Formats\TEXT_MAP, $_SERVER); //init server span end @@ -50,13 +55,13 @@ $method = 'GET'; $url = 'https://github.com/'; $client = new Client(); -$res = $client->request($method, $url,['headers' => $injectTarget1]); +$res = $client->request($method, $url, ['headers' => $injectTarget1]); $clientSpan1->setTag('http.status_code', 200); $clientSpan1->setTag('http.method', 'GET'); $clientSpan1->setTag('http.url', $url); -$clientSpan1->log(['message' => "HTTP1 ". $method .' '. $url .' end !']); +//$clientSpan1->log(['message' => 'HTTP1 '.$method.' '.$url.' end !']); $clientSpan1->finish(); //client span1 end @@ -65,8 +70,8 @@ $spanContext = $clientTracer->extract(Formats\TEXT_MAP, $_SERVER); $clientSpan2 = $clientTracer->startSpan('HTTP2', ['references' => [ - Reference::create(Reference::FOLLOWS_FROM, $clientSpan1->spanContext), - Reference::create(Reference::CHILD_OF, $spanContext) + //Reference::createForSpan(Reference::FOLLOWS_FROM, $clientSpan1), + Reference::createForSpan(Reference::CHILD_OF, $clientSpan1), ]]); $clientTracer->inject($clientSpan2->spanContext, Formats\TEXT_MAP, $injectTarget2); @@ -80,7 +85,7 @@ $clientSpan2->setTag('http.method', 'GET'); $clientSpan2->setTag('http.url', $url); -$clientSpan2->log(['message' => "HTTP2 ". $method .' '. $url .' end !']); +//$clientSpan2->log(['message' => 'HTTP2 '.$method.' '.$url.' end !']); $clientSpan2->finish(); //client span2 end diff --git a/example/HTTP2.php b/example/HTTP2.php index c217498..0229d84 100644 --- a/example/HTTP2.php +++ b/example/HTTP2.php @@ -1,15 +1,11 @@ startActiveSpan('level third'); $num = 0; -for ($i = 0; $i < 10; $i++){ - $num += 1; +for ($i = 0; $i < 10; ++$i) { + ++$num; } -$third->getSpan()->setTag("num", $num); +$third->getSpan()->setTag('num', $num); sleep(1); $third->close(); $num = 0; -for ($i = 0; $i < 10; $i++){ +for ($i = 0; $i < 10; ++$i) { $num += 2; } -$third->getSpan()->setTag("num", $num); +$third->getSpan()->setTag('num', $num); sleep(1); $second->close(); - $top->close(); //trace flush diff --git a/example/Hprose.php b/example/Hprose.php index e1112af..e10c516 100644 --- a/example/Hprose.php +++ b/example/Hprose.php @@ -13,13 +13,12 @@ * the License. */ -require_once dirname(dirname(dirname(dirname(__FILE__)))).'/autoload.php'; +require_once dirname(__FILE__, 2).'/vendor/autoload.php'; use Hprose\Client; use Jaeger\Config; use OpenTracing\Formats; - unset($_SERVER['argv']); //init server span start @@ -37,33 +36,30 @@ $header = []; $spanContext = $clientTracer->extract(Formats\TEXT_MAP, $_SERVER); $clientSpan = $clientTracer->startSpan('get', ['child_of' => $spanContext]); -$clientSpan->addBaggageItem("version", "2.0.0"); +$clientSpan->addBaggageItem('version', '2.0.0'); $clientTracer->inject($clientSpan->spanContext, Formats\TEXT_MAP, $header); $url = 'http://0.0.0.0:8080/main'; $client = Client::create($url, false); -if($header){ - foreach($header as $key => $val){ +if ($header) { + foreach ($header as $key => $val) { $client->setHeader($key, $val); } } $clientSpan->setTag('http.url', $url); -$clientSpan->setTag('http.method' , 'POST'); +$clientSpan->setTag('http.method', 'POST'); -$result = $client->get("Hprose"); +$result = $client->get('Hprose'); $clientSpan->log(['http.result' => $result]); $clientSpan->finish(); //client span end - //server span end $serverSpan->finish(); //trace flush $config->flush(); echo "success\r\n"; - - diff --git a/example/Istio1.php b/example/Istio1.php index e30196d..8b24de8 100644 --- a/example/Istio1.php +++ b/example/Istio1.php @@ -13,13 +13,13 @@ * the License. */ -require_once dirname(dirname(dirname(dirname(__FILE__)))).'/autoload.php'; +require_once dirname(__FILE__, 2).'/vendor/autoload.php'; +use GuzzleHttp\Client; use Jaeger\Config; use OpenTracing\Formats; -use GuzzleHttp\Client; -$http = new swoole_http_server("0.0.0.0", 8000); +$http = new swoole_http_server('0.0.0.0', 8000); $http->on('request', function ($request, $response) { unset($_SERVER['argv']); $config = Config::getInstance(); @@ -40,9 +40,9 @@ $clientTracer->inject($clientSpan->spanContext, Formats\TEXT_MAP, $injectTarget); $client = new Client(); - $clientSpan->setTag("http.url", "Istio2:8001"); - $res = $client->request('GET', 'Istio2:8001' ,['headers' => $injectTarget]); - $clientSpan->setTag("http.status_code", $res->getStatusCode()); + $clientSpan->setTag('http.url', 'Istio2:8001'); + $res = $client->request('GET', 'Istio2:8001', ['headers' => $injectTarget]); + $clientSpan->setTag('http.status_code', $res->getStatusCode()); //client span1 end //server span end @@ -50,6 +50,6 @@ //trace flush $config->flush(); - $response->end("Hello Istio1"); + $response->end('Hello Istio1'); }); $http->start(); diff --git a/example/Istio2.php b/example/Istio2.php index 3e6a6a6..299c076 100644 --- a/example/Istio2.php +++ b/example/Istio2.php @@ -13,12 +13,12 @@ * the License. */ -require_once dirname(dirname(dirname(dirname(__FILE__)))).'/autoload.php'; +require_once dirname(__FILE__, 2).'/vendor/autoload.php'; use Jaeger\Config; use OpenTracing\Formats; -$http = new swoole_http_server("0.0.0.0", 8001); +$http = new swoole_http_server('0.0.0.0', 8001); $http->on('request', function ($request, $response) { unset($_SERVER['argv']); $config = Config::getInstance(); @@ -38,9 +38,9 @@ $clientTracer->inject($clientSpan->spanContext, Formats\TEXT_MAP, $injectTarget); $client = new \GuzzleHttp\Client(); - $clientSpan->setTag("http.url", "Istio3:8002"); + $clientSpan->setTag('http.url', 'Istio3:8002'); $res = $client->request('GET', 'Istio3:8002', ['headers' => $injectTarget]); - $clientSpan->setTag("http.status_code", $res->getStatusCode()); + $clientSpan->setTag('http.status_code', $res->getStatusCode()); //client span1 end //server span end @@ -48,6 +48,6 @@ //trace flush $config->flush(); - $response->end("Hello Istio2"); + $response->end('Hello Istio2'); }); $http->start(); diff --git a/example/Istio3.php b/example/Istio3.php index 9fdd6b1..6637e2d 100644 --- a/example/Istio3.php +++ b/example/Istio3.php @@ -13,12 +13,12 @@ * the License. */ -require_once dirname(dirname(dirname(dirname(__FILE__)))).'/autoload.php'; +require_once dirname(__FILE__, 2).'/vendor/autoload.php'; use Jaeger\Config; use OpenTracing\Formats; -$http = new swoole_http_server("0.0.0.0", 8002); +$http = new swoole_http_server('0.0.0.0', 8002); $http->on('request', function ($request, $response) { unset($_SERVER['argv']); $config = Config::getInstance(); @@ -38,7 +38,7 @@ $clientSpan = $clientTracer->startSpan('Istio3', ['child_of' => $spanContext]); $sum = 0; - for($i = 0; $i < 10; $i++){ + for ($i = 0; $i < 10; ++$i) { $sum += $i; } $clientSpan->log(['message' => 'result:'.$sum]); @@ -51,6 +51,6 @@ //trace flush $config->flush(); - $response->end("Hello Istio3"); + $response->end('Hello Istio3'); }); $http->start(); diff --git a/phpstan.neon b/phpstan.neon new file mode 100644 index 0000000..6bfb433 --- /dev/null +++ b/phpstan.neon @@ -0,0 +1,7 @@ +parameters: + level: 4 + paths: + - src + - tests + ignoreErrors: + - '#Function thrift_protocol_.* not found#' diff --git a/src/Jaeger/Config.php b/src/Jaeger/Config.php index cba4c79..150b59a 100644 --- a/src/Jaeger/Config.php +++ b/src/Jaeger/Config.php @@ -15,158 +15,169 @@ namespace Jaeger; +use Jaeger\Propagator\JaegerPropagator; +use Jaeger\Propagator\ZipkinPropagator; use Jaeger\Reporter\RemoteReporter; use Jaeger\Reporter\Reporter; +use Jaeger\Sampler\ConstSampler; +use Jaeger\Sampler\Sampler; use Jaeger\Transport\TransportUdp; use OpenTracing\NoopTracer; -use Jaeger\Sampler\Sampler; -use Jaeger\Sampler\ConstSampler; -use Jaeger\Propagator\JaegerPropagator; -use Jaeger\Propagator\ZipkinPropagator; - -class Config { +use OpenTracing\Tracer; +class Config +{ + /** + * @var \Jaeger\Transport\Transport|null + */ private $transport = null; + /** + * @var \Jaeger\Reporter\Reporter|null + */ private $reporter = null; + /** + * @var \Jaeger\Sampler\Sampler|null + */ private $sampler = null; + /** + * @var \OpenTracing\ScopeManager|null + */ private $scopeManager = null; private $gen128bit = false; + /** + * @var array|null + */ public static $tracer = null; + /** + * @var \OpenTracing\Span|null + */ public static $span = null; + /** + * @var self|null + */ public static $instance = null; public static $disabled = false; public static $propagator = \Jaeger\Constants\PROPAGATOR_JAEGER; - - private function __construct(){ - + private function __construct() + { } - - private function __clone(){ - + private function __clone() + { } - public static function getInstance() { - if(! (self::$instance instanceof self) ) - { + if (!(self::$instance instanceof self)) { self::$instance = new self(); } + return self::$instance; } - /** - * init jaeger, return can use flush buffers - * @param $serviceName + * init tracer. + * * @param string $agentHostPort - * @return Jaeger|null - * @throws \Exception + * + * @throws \RuntimeException */ - public function initTracer($serverName, $agentHostPort = ''){ - - if(self::$disabled){ - return NoopTracer::create(); + public function initTracer(string $serviceName, $agentHostPort = ''): Tracer + { + if (self::$disabled) { + return new NoopTracer(); } - if($serverName == ''){ - throw new \Exception("serverName require"); + if ('' == $serviceName) { + throw new \RuntimeException('serviceName require'); } - if(isset(self::$tracer[$serverName]) && !empty(self::$tracer[$serverName])){ - return self::$tracer[$serverName]; + if (isset(self::$tracer[$serviceName]) && !empty(self::$tracer[$serviceName])) { + return self::$tracer[$serviceName]; } - - if($this->transport == null){ + if (null == $this->transport) { $this->transport = new TransportUdp($agentHostPort); } - if($this->reporter == null) { + if (null == $this->reporter) { $this->reporter = new RemoteReporter($this->transport); } - if($this->sampler == null){ + if (null == $this->sampler) { $this->sampler = new ConstSampler(true); } - if($this->scopeManager == null){ + if (null == $this->scopeManager) { $this->scopeManager = new ScopeManager(); } - $tracer = new Jaeger($serverName, $this->reporter, $this->sampler, $this->scopeManager); + $tracer = new Jaeger($serviceName, $this->reporter, $this->sampler, $this->scopeManager); - if($this->gen128bit == true){ + if (true == $this->gen128bit) { $tracer->gen128bit(); } - if(self::$propagator == \Jaeger\Constants\PROPAGATOR_ZIPKIN){ + if (\Jaeger\Constants\PROPAGATOR_ZIPKIN == self::$propagator) { $tracer->setPropagator(new ZipkinPropagator()); - }else{ + } else { $tracer->setPropagator(new JaegerPropagator()); } - - self::$tracer[$serverName] = $tracer; - + self::$tracer[$serviceName] = $tracer; return $tracer; } - - /** - * close tracer - * @param $disabled - */ - public function setDisabled($disabled){ + public function setDisabled(bool $disabled) + { self::$disabled = $disabled; return $this; } - - public function setTransport(Transport\Transport $transport){ + public function setTransport(Transport\Transport $transport) + { $this->transport = $transport; return $this; } - - public function setReporter(Reporter $reporter){ + public function setReporter(Reporter $reporter) + { $this->reporter = $reporter; return $this; } - - public function setSampler(Sampler $sampler){ + public function setSampler(Sampler $sampler) + { $this->sampler = $sampler; return $this; } - - public function gen128bit(){ + public function gen128bit() + { $this->gen128bit = true; return $this; } - - public function flush(){ - if(count(self::$tracer) > 0) { - foreach(self::$tracer as $tracer){ + public function flush() + { + if (count(self::$tracer) > 0) { + foreach (self::$tracer as $tracer) { $tracer->reportSpan(); } $this->reporter->close(); diff --git a/src/Jaeger/Constants.php b/src/Jaeger/Constants.php index d83b4b8..de7a8ba 100644 --- a/src/Jaeger/Constants.php +++ b/src/Jaeger/Constants.php @@ -21,9 +21,9 @@ const Trace_Baggage_Header_Prefix = 'uberctx-'; -const Jaeger_Debug_Header = "jaeger-debug-id"; +const Jaeger_Debug_Header = 'jaeger-debug-id'; -const EMIT_BATCH_OVER_HEAD = 30; +const EMIT_BATCH_OVER_HEAD = 70; const UDP_PACKET_MAX_LENGTH = 65000; @@ -43,28 +43,28 @@ const X_B3_SAMPLED = 'x-b3-sampled'; -const CLIENT_SEND = "cs"; +const CLIENT_SEND = 'cs'; -const CLIENT_RECV = "cr"; +const CLIENT_RECV = 'cr'; -const SERVER_SEND = "ss"; +const SERVER_SEND = 'ss'; -const SERVER_RECV = "sr"; +const SERVER_RECV = 'sr'; -const WIRE_SEND = "ws"; +const WIRE_SEND = 'ws'; -const WIRE_RECV = "wr"; +const WIRE_RECV = 'wr'; -const CLIENT_SEND_FRAGMENT = "csf"; +const CLIENT_SEND_FRAGMENT = 'csf'; -const CLIENT_RECV_FRAGMENT = "crf"; +const CLIENT_RECV_FRAGMENT = 'crf'; -const SERVER_SEND_FRAGMENT = "ssf"; +const SERVER_SEND_FRAGMENT = 'ssf'; -const SERVER_RECV_FRAGMENT = "srf"; +const SERVER_RECV_FRAGMENT = 'srf'; -const LOCAL_COMPONENT = "lc"; +const LOCAL_COMPONENT = 'lc'; -const CLIENT_ADDR = "ca"; +const CLIENT_ADDR = 'ca'; -const SERVER_ADDR = "sa"; \ No newline at end of file +const SERVER_ADDR = 'sa'; diff --git a/src/Jaeger/Jaeger.php b/src/Jaeger/Jaeger.php index f317246..1b43240 100644 --- a/src/Jaeger/Jaeger.php +++ b/src/Jaeger/Jaeger.php @@ -15,42 +15,41 @@ namespace Jaeger; -use Jaeger\Sampler\Sampler; -use OpenTracing\Exceptions\UnsupportedFormat; -use OpenTracing\SpanContext; -use OpenTracing\Formats; -use OpenTracing\Tracer; -use Jaeger\Reporter\Reporter; -use OpenTracing\StartSpanOptions; -use OpenTracing\Reference; use Jaeger\Propagator\Propagator; +use Jaeger\Reporter\Reporter; +use Jaeger\Sampler\Sampler; -class Jaeger implements Tracer{ - +class Jaeger implements \OpenTracing\Tracer +{ + /** + * @var Reporter|null + */ private $reporter = null; + /** + * @var Sampler|null + */ private $sampler = null; private $gen128bit = false; + /** + * @var \Jaeger\ScopeManager + */ private $scopeManager; public $spans = []; public $tags = []; - public $process = null; - - public $serverName = ''; - - public $processThrift = ''; + public $serviceName = ''; /** @var Propagator|null */ public $propagator = null; - public function __construct($serverName = '', Reporter $reporter, Sampler $sampler, - ScopeManager $scopeManager){ - + public function __construct(string $serviceName, Reporter $reporter = null, Sampler $sampler = null, + ScopeManager $scopeManager = null) + { $this->reporter = $reporter; $this->sampler = $sampler; @@ -60,180 +59,190 @@ public function __construct($serverName = '', Reporter $reporter, Sampler $sampl $this->setTags($this->sampler->getTags()); $this->setTags($this->getEnvTags()); - if($serverName == '') { - $this->serverName = isset($_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME'] : 'unknow server'; - }else{ - $this->serverName = $serverName; + if ('' == $serviceName) { + $this->serviceName = $_SERVER['SERVER_NAME'] ?? 'unknow server'; + } else { + $this->serviceName = $serviceName; } } - /** - * @param array $tags key => value + * @param array $tags key => value */ - public function setTags(array $tags = []){ - if(!empty($tags)) { + public function setTags(array $tags = []) + { + if (!empty($tags)) { $this->tags = array_merge($this->tags, $tags); } } - /** - * init span info - * @param string $operationName - * @param array $options + * {@inheritDoc} + * * @return Span */ - public function startSpan($operationName, $options = []){ - - if (!($options instanceof StartSpanOptions)) { - $options = StartSpanOptions::create($options); + public function startSpan(string $operationName, $options = []): \OpenTracing\Span + { + if (!($options instanceof \OpenTracing\StartSpanOptions)) { + $options = \OpenTracing\StartSpanOptions::create($options); } $parentSpan = $this->getParentSpanContext($options); - if($parentSpan == null || !$parentSpan->traceIdLow){ + if (null == $parentSpan || !$parentSpan->traceIdLow) { $low = $this->generateId(); $spanId = $low; $flags = $this->sampler->IsSampled(); $spanContext = new \Jaeger\SpanContext($spanId, 0, $flags, null, 0); $spanContext->traceIdLow = $low; - if($this->gen128bit == true){ + if (true == $this->gen128bit) { $spanContext->traceIdHigh = $this->generateId(); } - }else{ + } else { $spanContext = new \Jaeger\SpanContext($this->generateId(), $parentSpan->spanId, $parentSpan->flags, $parentSpan->baggage, 0); $spanContext->traceIdLow = $parentSpan->traceIdLow; - if($parentSpan->traceIdHigh){ + if ($parentSpan->traceIdHigh) { $spanContext->traceIdHigh = $parentSpan->traceIdHigh; } } $startTime = $options->getStartTime() ? intval($options->getStartTime() * 1000000) : null; $span = new Span($operationName, $spanContext, $options->getReferences(), $startTime); - if(!empty($options->getTags())) { + if (!empty($options->getTags())) { foreach ($options->getTags() as $k => $tag) { $span->setTag($k, $tag); } } - if($spanContext->isSampled() == 1) { + if (1 == $spanContext->isSampled()) { $this->spans[] = $span; } return $span; } - - public function setPropagator(Propagator $propagator){ + public function setPropagator(Propagator $propagator) + { $this->propagator = $propagator; } - /** - * 注入 - * @param SpanContext $spanContext - * @param string $format - * @param $carrier + * {@inheritDoc} */ - public function inject(SpanContext $spanContext, $format, &$carrier){ - if($format == Formats\TEXT_MAP){ + public function inject(\OpenTracing\SpanContext $spanContext, string $format, &$carrier): void + { + if (\OpenTracing\Formats\TEXT_MAP == $format) { $this->propagator->inject($spanContext, $format, $carrier); - }else{ - throw UnsupportedFormat::forFormat($format); + } else { + throw \OpenTracing\UnsupportedFormatException::forFormat($format); } } - /** - * 提取 - * @param string $format - * @param $carrier + * {@inheritDoc} + * + * @return SpanContext */ - public function extract($format, $carrier){ - if($format == Formats\TEXT_MAP){ + public function extract(string $format, $carrier): ?\OpenTracing\SpanContext + { + if (\OpenTracing\Formats\TEXT_MAP == $format) { return $this->propagator->extract($format, $carrier); - }else{ - throw UnsupportedFormat::forFormat($format); + } else { + throw \OpenTracing\UnsupportedFormatException::forFormat($format); } } - - public function getSpans(){ + public function getSpans() + { return $this->spans; } - - public function reportSpan(){ - if($this->spans) { + public function reportSpan() + { + if ($this->spans) { $this->reporter->report($this); $this->spans = []; } } - - public function getScopeManager(){ + /** + * {@inheritDoc} + * + * @return \Jaeger\ScopeManager + */ + public function getScopeManager(): \OpenTracing\ScopeManager + { return $this->scopeManager; } - - public function getActiveSpan(){ + /** + * {@inheritDoc} + */ + public function getActiveSpan(): ?\OpenTracing\Span + { $activeScope = $this->getScopeManager()->getActive(); - if ($activeScope === null) { + if (null === $activeScope) { return null; } return $activeScope->getSpan(); } - - public function startActiveSpan($operationName, $options = []){ - if (!$options instanceof StartSpanOptions) { - $options = StartSpanOptions::create($options); + /** + * {@inheritDoc} + * + * @return Scope + */ + public function startActiveSpan(string $operationName, $options = []): \OpenTracing\Scope + { + if (!$options instanceof \OpenTracing\StartSpanOptions) { + $options = \OpenTracing\StartSpanOptions::create($options); } $parentSpan = $this->getParentSpanContext($options); - if ($parentSpan === null && $this->getActiveSpan() !== null) { + if (null === $parentSpan && null !== $this->getActiveSpan()) { $parentContext = $this->getActiveSpan()->getContext(); $options = $options->withParent($parentContext); } $span = $this->startSpan($operationName, $options); + return $this->getScopeManager()->activate($span, $options->shouldFinishSpanOnClose()); } - - private function getParentSpanContext(StartSpanOptions $options) + private function getParentSpanContext(\OpenTracing\StartSpanOptions $options) { $references = $options->getReferences(); - $parentSpan = null; + $parentSpanContext = null; foreach ($references as $ref) { - $parentSpan = $ref->getContext(); - if ($ref->isType(Reference::CHILD_OF)) { - return $parentSpan; + $parentSpanContext = $ref->getSpanContext(); + if ($ref->isType(\OpenTracing\Reference::CHILD_OF)) { + return $parentSpanContext; } } - if ($parentSpan) { - if (($parentSpan->isValid() - || (!$parentSpan->isTraceIdValid() && $parentSpan->debugId) - || count($parentSpan->baggage) > 0) + if ($parentSpanContext) { + assert($parentSpanContext instanceof \Jaeger\SpanContext); + + if (($parentSpanContext->isValid() + || (!$parentSpanContext->isTraceIdValid() && $parentSpanContext->debugId) + || count($parentSpanContext->baggage) > 0) ) { - return $parentSpan; + return $parentSpanContext; } } return null; } - - public function getEnvTags(){ + public function getEnvTags() + { $tags = []; - if(isset($_SERVER['JAEGER_TAGS']) && $_SERVER['JAEGER_TAGS'] != ''){ + if (isset($_SERVER['JAEGER_TAGS']) && '' != $_SERVER['JAEGER_TAGS']) { $envTags = explode(',', $_SERVER['JAEGER_TAGS']); - foreach ($envTags as $envK => $envTag){ - list($key, $value) = explode('=', $envTag); + foreach ($envTags as $envK => $envTag) { + [$key, $value] = explode('=', $envTag); $tags[$key] = $value; } } @@ -241,22 +250,22 @@ public function getEnvTags(){ return $tags; } - - public function gen128bit(){ + public function gen128bit() + { $this->gen128bit = true; } - /** - * 结束,发送信息到jaeger + * {@inheritDoc} */ - public function flush(){ + public function flush(): void + { $this->reportSpan(); $this->reporter->close(); } - - private function generateId(){ - return microtime(true) * 10000 . rand(10000, 99999); + private function generateId() + { + return microtime(true) * 10000 .random_int(10000, 99999); } } diff --git a/src/Jaeger/JaegerThrift.php b/src/Jaeger/JaegerThrift.php new file mode 100644 index 0000000..2133071 --- /dev/null +++ b/src/Jaeger/JaegerThrift.php @@ -0,0 +1,157 @@ +tags); + + $processThrift = new Process([ + 'serviceName' => $jaeger->serviceName, + 'tags' => $this->buildTags($tags), + ]); + + return $processThrift; + } + + public function buildSpanThrift(jspan $span): Span + { + $spContext = $span->spanContext; + assert($spContext instanceof \Jaeger\SpanContext); + + $thriftSpan = new Span([ + 'traceIdLow' => intval($spContext->traceIdLow), + 'traceIdHigh' => intval($spContext->traceIdHigh), + 'spanId' => intval($spContext->spanId), + 'parentSpanId' => intval($spContext->parentId), + 'operationName' => $span->getOperationName(), + 'flags' => intval($spContext->flags), + 'startTime' => $span->startTime, + 'duration' => $span->duration, + 'tags' => $this->buildTags($span->tags), + 'logs' => $this->buildLogs($span->logs), + 'references' => $this->buildReferences($span->references), + ]); + + return $thriftSpan; + } + + private function buildLogs(array $logs): array + { + $resultLogs = []; + foreach ($logs as $log) { + $resultLogs[] = new Log([ + 'timestamp' => $log['timestamp'], + 'fields' => $this->buildTags($log['fields']), + ]); + } + + return $resultLogs; + } + + /** + * @param array $references + */ + private function buildReferences(array $references): array + { + $spanRef = []; + foreach ($references as $ref) { + if ($ref->isType(Reference::CHILD_OF)) { + $type = SpanRefType::CHILD_OF; + } elseif ($ref->isType(Reference::FOLLOWS_FROM)) { + $type = SpanRefType::FOLLOWS_FROM; + } else { + throw new \LogicException('Unsupported reference type'); + } + + $ctx = $ref->getSpanContext(); + assert($ctx instanceof \Jaeger\SpanContext); + + $spanRef[] = new SpanRef([ + 'refType' => $type, + 'traceIdLow' => intval($ctx->traceIdLow), + 'traceIdHigh' => intval($ctx->traceIdHigh), + 'spanId' => intval($ctx->spanId), + ]); + } + + return $spanRef; + } + + public function buildTags(array $tags): array + { + $jTags = []; + if (empty($tags)) { + return $jTags; + } + + foreach ($tags as $k => $v) { + switch (gettype($v)) { + case 'boolean': + $jTags[] = new Tag([ + 'key' => $k, + 'vType' => TagType::BOOL, + 'vBool' => $v, + ]); + break; + case 'integer': + $jTags[] = new Tag([ + 'key' => $k, + 'vType' => TagType::LONG, + 'vLong' => $v, + ]); + break; + case 'double': + $jTags[] = new Tag([ + 'key' => $k, + 'vType' => TagType::DOUBLE, + 'vDouble' => $v, + ]); + break; + case 'array': + $v = json_encode($v, JSON_UNESCAPED_UNICODE); + // no break + default: + $jTags[] = new Tag([ + 'key' => $k, + 'vType' => TagType::STRING, + 'vStr' => $v, + ]); + } + } + + return $jTags; + } +} diff --git a/src/Jaeger/Propagator/JaegerPropagator.php b/src/Jaeger/Propagator/JaegerPropagator.php index 763435f..e8abe34 100644 --- a/src/Jaeger/Propagator/JaegerPropagator.php +++ b/src/Jaeger/Propagator/JaegerPropagator.php @@ -15,59 +15,66 @@ namespace Jaeger\Propagator; -use Jaeger\SpanContext; use Jaeger\Constants; +use Jaeger\SpanContext; -class JaegerPropagator implements Propagator{ - - public function inject(SpanContext $spanContext, $format, &$carrier){ +class JaegerPropagator implements Propagator +{ + /** + * {@inheritDoc} + * + * @param SpanContext $spanContext + */ + public function inject(\OpenTracing\SpanContext $spanContext, $format, &$carrier) + { $carrier[strtoupper(Constants\Tracer_State_Header_Name)] = $spanContext->buildString(); - if($spanContext->baggage) { + if ($spanContext->baggage) { foreach ($spanContext->baggage as $k => $v) { - $carrier[strtoupper(Constants\Trace_Baggage_Header_Prefix . $k)] = $v; + $carrier[strtoupper(Constants\Trace_Baggage_Header_Prefix.$k)] = $v; } } } - - public function extract($format, $carrier){ + /** + * {@inheritDoc} + */ + public function extract($format, $carrier) + { $spanContext = null; - + $carrier = array_change_key_case($carrier, CASE_LOWER); - foreach ($carrier as $k => $v){ - - if(!in_array($k, [Constants\Tracer_State_Header_Name, - Constants\Jaeger_Debug_Header, Constants\Jaeger_Baggage_Header]) && - stripos($k, Constants\Trace_Baggage_Header_Prefix) === false){ + foreach ($carrier as $k => $v) { + if (!in_array($k, [Constants\Tracer_State_Header_Name, + Constants\Jaeger_Debug_Header, Constants\Jaeger_Baggage_Header, ]) && + false === stripos($k, Constants\Trace_Baggage_Header_Prefix)) { continue; } - if($spanContext === null){ + if (null === $spanContext) { $spanContext = new SpanContext(0, 0, 0, null, 0); } - - if(is_array($v)){ + + if (is_array($v)) { $v = urldecode(current($v)); - }else { + } else { $v = urldecode($v); } - if($k == Constants\Tracer_State_Header_Name){ - list($traceId, $spanId, $parentId,$flags) = explode(':', $v); + if (Constants\Tracer_State_Header_Name == $k) { + [$traceId, $spanId, $parentId, $flags] = explode(':', $v); $spanContext->spanId = $spanContext->hexToSignedInt($spanId); $spanContext->parentId = $spanContext->hexToSignedInt($parentId); $spanContext->flags = $flags; $spanContext->traceIdToString($traceId); - - }elseif(stripos($k, Constants\Trace_Baggage_Header_Prefix) !== false){ - $safeKey = str_replace(Constants\Trace_Baggage_Header_Prefix, "", $k); - if($safeKey != "") { + } elseif (false !== stripos($k, Constants\Trace_Baggage_Header_Prefix)) { + $safeKey = str_replace(Constants\Trace_Baggage_Header_Prefix, '', $k); + if ('' != $safeKey) { $spanContext->withBaggageItem($safeKey, $v); } - }elseif($k == Constants\Jaeger_Debug_Header){ + } elseif (Constants\Jaeger_Debug_Header == $k) { $spanContext->debugId = $v; - }elseif($k == Constants\Jaeger_Baggage_Header){ + } elseif (Constants\Jaeger_Baggage_Header == $k) { // Converts a comma separated key value pair list into a map // e.g. key1=value1, key2=value2, key3 = value3 // is converted to array { "key1" : "value1", @@ -75,19 +82,16 @@ public function extract($format, $carrier){ // "key3" : "value3" } $parseVal = explode(',', $v); foreach ($parseVal as $val) { - if(stripos($v, '=') !== false) { + if (false !== stripos($v, '=')) { $kv = explode('=', trim($val)); - if (count($kv) == 2) { + if (2 == count($kv)) { $spanContext->withBaggageItem($kv[0], $kv[1]); } } } - } } - return $spanContext; } - } diff --git a/src/Jaeger/Propagator/Propagator.php b/src/Jaeger/Propagator/Propagator.php index d094e4d..4ffb0b1 100644 --- a/src/Jaeger/Propagator/Propagator.php +++ b/src/Jaeger/Propagator/Propagator.php @@ -17,23 +17,23 @@ use Jaeger\SpanContext; -interface Propagator{ - +interface Propagator +{ /** - * 注入 - * @param SpanContext $spanContext + * 注入. + * * @param string $format - * @param $carrier + * @param mixed $carrier */ - public function inject(SpanContext $spanContext, $format, &$carrier); - + public function inject(\OpenTracing\SpanContext $spanContext, $format, &$carrier); /** - * 提取 + * 提取. + * * @param string $format - * @param $carrier + * @param mixed $carrier + * * @return SpanContext|null */ public function extract($format, $carrier); - } diff --git a/src/Jaeger/Propagator/ZipkinPropagator.php b/src/Jaeger/Propagator/ZipkinPropagator.php index 7dfcb41..5900cee 100644 --- a/src/Jaeger/Propagator/ZipkinPropagator.php +++ b/src/Jaeger/Propagator/ZipkinPropagator.php @@ -15,50 +15,58 @@ namespace Jaeger\Propagator; -use Jaeger\SpanContext; use Jaeger\Constants; +use Jaeger\SpanContext; -class ZipkinPropagator implements Propagator{ - - public function inject(SpanContext $spanContext, $format, &$carrier){ - $carrier[Constants\X_B3_TRACEID] = $spanContext ->traceIdLowToString(); +class ZipkinPropagator implements Propagator +{ + /** + * {@inheritDoc} + * + * @param SpanContext $spanContext + */ + public function inject(\OpenTracing\SpanContext $spanContext, $format, &$carrier) + { + $carrier[Constants\X_B3_TRACEID] = $spanContext->traceIdLowToString(); $carrier[Constants\X_B3_PARENT_SPANID] = $spanContext->parentIdToString(); $carrier[Constants\X_B3_SPANID] = $spanContext->spanIdToString(); $carrier[Constants\X_B3_SAMPLED] = $spanContext->flagsToString(); } - - public function extract($format, $carrier){ + /** + * {@inheritDoc} + */ + public function extract($format, $carrier) + { $spanContext = null; foreach ($carrier as $k => $val) { if (in_array($k, [Constants\X_B3_TRACEID, - Constants\X_B3_PARENT_SPANID, Constants\X_B3_SPANID, Constants\X_B3_SAMPLED]) + Constants\X_B3_PARENT_SPANID, Constants\X_B3_SPANID, Constants\X_B3_SAMPLED, ]) ) { - if($spanContext === null){ + if (null === $spanContext) { $spanContext = new SpanContext(0, 0, 0, null, 0); } continue; } } - - if(isset($carrier[Constants\X_B3_TRACEID]) && $carrier[Constants\X_B3_TRACEID]){ + + if (isset($carrier[Constants\X_B3_TRACEID]) && $carrier[Constants\X_B3_TRACEID]) { $spanContext->traceIdToString($carrier[Constants\X_B3_TRACEID]); } - if(isset($carrier[Constants\X_B3_PARENT_SPANID]) && $carrier[Constants\X_B3_PARENT_SPANID]){ + if (isset($carrier[Constants\X_B3_PARENT_SPANID]) && $carrier[Constants\X_B3_PARENT_SPANID]) { $spanContext->parentId = $spanContext->hexToSignedInt($carrier[Constants\X_B3_PARENT_SPANID]); } - if(isset($carrier[Constants\X_B3_SPANID]) && $carrier[Constants\X_B3_SPANID]){ + if (isset($carrier[Constants\X_B3_SPANID]) && $carrier[Constants\X_B3_SPANID]) { $spanContext->spanId = $spanContext->hexToSignedInt($carrier[Constants\X_B3_SPANID]); } - if(isset($carrier[Constants\X_B3_SAMPLED]) && $carrier[Constants\X_B3_SAMPLED]){ + if (isset($carrier[Constants\X_B3_SAMPLED]) && $carrier[Constants\X_B3_SAMPLED]) { $spanContext->flags = $carrier[Constants\X_B3_SAMPLED]; } - return $spanContext; } } diff --git a/src/Jaeger/Reporter/NullReporter.php b/src/Jaeger/Reporter/NullReporter.php new file mode 100644 index 0000000..ee50900 --- /dev/null +++ b/src/Jaeger/Reporter/NullReporter.php @@ -0,0 +1,31 @@ +tran->append($jaeger); } - public function close() { - $this->tran->flush(); + $this->tran->close(); } -} \ No newline at end of file +} diff --git a/src/Jaeger/Reporter/Reporter.php b/src/Jaeger/Reporter/Reporter.php index a480b40..4e7f6bd 100644 --- a/src/Jaeger/Reporter/Reporter.php +++ b/src/Jaeger/Reporter/Reporter.php @@ -17,8 +17,8 @@ use Jaeger\Jaeger; -interface Reporter{ - +interface Reporter +{ public function report(Jaeger $jaeger); public function close(); diff --git a/src/Jaeger/Sampler/ConstSampler.php b/src/Jaeger/Sampler/ConstSampler.php index 515c56a..6f0622c 100644 --- a/src/Jaeger/Sampler/ConstSampler.php +++ b/src/Jaeger/Sampler/ConstSampler.php @@ -15,32 +15,33 @@ namespace Jaeger\Sampler; - use Jaeger\Constants; -class ConstSampler implements Sampler{ - +class ConstSampler implements Sampler +{ private $decision = ''; private $tags = []; - public function __construct($decision = true){ + public function __construct($decision = true) + { $this->decision = $decision; $this->tags[Constants\SAMPLER_TYPE_TAG_KEY] = 'const'; $this->tags[Constants\SAMPLER_PARAM_TAG_KEY] = $decision; } - public function IsSampled(){ + public function IsSampled() + { return $this->decision; } - - public function Close(){ + public function Close() + { //nothing to do } - - public function getTags(){ + public function getTags() + { return $this->tags; } -} \ No newline at end of file +} diff --git a/src/Jaeger/Sampler/ProbabilisticSampler.php b/src/Jaeger/Sampler/ProbabilisticSampler.php index 112ece6..5e17f6b 100644 --- a/src/Jaeger/Sampler/ProbabilisticSampler.php +++ b/src/Jaeger/Sampler/ProbabilisticSampler.php @@ -12,40 +12,41 @@ * or implied. See the License for the specific language governing permissions and limitations under * the License. */ + namespace Jaeger\Sampler; use Jaeger\Constants; -class ProbabilisticSampler implements Sampler{ - +class ProbabilisticSampler implements Sampler +{ // min 0, max 1 private $rate = 0; private $tags = []; - - public function __construct($rate = 0.0001){ + public function __construct($rate = 0.0001) + { $this->rate = $rate; $this->tags[Constants\SAMPLER_TYPE_TAG_KEY] = 'probabilistic'; $this->tags[Constants\SAMPLER_PARAM_TAG_KEY] = $rate; } - - public function IsSampled(){ - if(mt_rand(1, 1 / $this->rate) == 1){ + public function IsSampled() + { + if (1 == random_int(1, 1 / $this->rate)) { return true; - }else{ + } else { return false; } } - - public function Close(){ + public function Close() + { //nothing to do } - - public function getTags(){ + public function getTags() + { return $this->tags; } } diff --git a/src/Jaeger/Sampler/Sampler.php b/src/Jaeger/Sampler/Sampler.php index 1a5c3ed..1dd85a8 100644 --- a/src/Jaeger/Sampler/Sampler.php +++ b/src/Jaeger/Sampler/Sampler.php @@ -15,7 +15,6 @@ namespace Jaeger\Sampler; - interface Sampler { public function IsSampled(); @@ -23,4 +22,4 @@ public function IsSampled(); public function Close(); public function getTags(); -} \ No newline at end of file +} diff --git a/src/Jaeger/Scope.php b/src/Jaeger/Scope.php index e885d2d..2d80ed0 100644 --- a/src/Jaeger/Scope.php +++ b/src/Jaeger/Scope.php @@ -2,17 +2,15 @@ namespace Jaeger; - - -class Scope implements \OpenTracing\Scope{ - +class Scope implements \OpenTracing\Scope +{ /** - * @var MockScopeManager + * @var ScopeManager */ private $scopeManager = null; /** - * @var span + * @var Span */ private $span = null; @@ -21,30 +19,35 @@ class Scope implements \OpenTracing\Scope{ */ private $finishSpanOnClose; - /** * Scope constructor. - * @param ScopeManager $scopeManager - * @param \OpenTracing\Span $span + * * @param bool $finishSpanOnClose */ - public function __construct(ScopeManager $scopeManager, \OpenTracing\Span $span, $finishSpanOnClose){ + public function __construct(ScopeManager $scopeManager, Span $span, $finishSpanOnClose) + { $this->scopeManager = $scopeManager; $this->span = $span; $this->finishSpanOnClose = $finishSpanOnClose; } - - public function close(){ + /** + * {@inheritDoc} + */ + public function close(): void + { if ($this->finishSpanOnClose) { $this->span->finish(); } - $this->scopeManager->delActive($this); + $this->scopeManager->deactivate($this); } - - public function getSpan(){ + /** + * {@inheritDoc} + */ + public function getSpan(): \OpenTracing\Span + { return $this->span; } } diff --git a/src/Jaeger/ScopeManager.php b/src/Jaeger/ScopeManager.php index 3d11a06..a4c9e41 100644 --- a/src/Jaeger/ScopeManager.php +++ b/src/Jaeger/ScopeManager.php @@ -2,30 +2,30 @@ namespace Jaeger; - -class ScopeManager implements \OpenTracing\ScopeManager{ - +class ScopeManager implements \OpenTracing\ScopeManager +{ private $scopes = []; - /** - * append scope - * @param \OpenTracing\Span $span - * @param bool $finishSpanOnClose + * {@inheritDoc} + * * @return Scope */ - public function activate(\OpenTracing\Span $span, $finishSpanOnClose){ + public function activate(\OpenTracing\Span $span, bool $finishSpanOnClose = self::DEFAULT_FINISH_SPAN_ON_CLOSE): \OpenTracing\Scope + { $scope = new Scope($this, $span, $finishSpanOnClose); $this->scopes[] = $scope; + return $scope; } - /** - * get last scope - * @return mixed|null + * {@inheritDoc} + * + * @return Scope */ - public function getActive(){ + public function getActive(): ?\OpenTracing\Scope + { if (empty($this->scopes)) { return null; } @@ -33,20 +33,15 @@ public function getActive(){ return $this->scopes[count($this->scopes) - 1]; } - - /** - * del scope - * @param Scope $scope - * @return bool - */ - public function delActive(Scope $scope){ + public function deactivate(Scope $scope) + { $scopeLength = count($this->scopes); - if($scopeLength <= 0){ + if ($scopeLength <= 0) { return false; } - for ($i = 0; $i < $scopeLength; $i++) { + for ($i = 0; $i < $scopeLength; ++$i) { if ($scope === $this->scopes[$i]) { array_splice($this->scopes, $i, 1); } diff --git a/src/Jaeger/Sender/NullSender.php b/src/Jaeger/Sender/NullSender.php new file mode 100644 index 0000000..9e7ff57 --- /dev/null +++ b/src/Jaeger/Sender/NullSender.php @@ -0,0 +1,31 @@ +host, $this->post] = explode(':', $hostPost); + $this->agentClient = $agentClient; + $this->socket = fsockopen("udp://$this->host", $this->post); + $this->tran = $tran; + } + + /** + * @return bool + */ + public function isOpen() + { + return null !== $this->socket; + } + + /** + * send thrift. + * + * @return bool + * + * @throws \Exception + */ + public function emitBatch(\Jaeger\Thrift\Batch $batch) + { + $this->agentClient->emitBatch($batch); + $len = $this->tran->available(); + if ($len > 0 && $this->isOpen()) { + $res = fwrite($this->socket, $this->tran->read($len)); + if (false === $res) { + throw new \Exception('emit failse'); + } + + return true; + } else { + return false; + } + } + + public function close() + { + fclose($this->socket); + $this->socket = null; + } +} diff --git a/src/Jaeger/Span.php b/src/Jaeger/Span.php index 8fee8fd..df34ee6 100644 --- a/src/Jaeger/Span.php +++ b/src/Jaeger/Span.php @@ -15,112 +15,136 @@ namespace Jaeger; - -class Span implements \OpenTracing\Span{ - +class Span implements \OpenTracing\Span +{ + /** + * @var string + */ private $operationName = ''; - public $startTime = ''; + /** + * @var int|null + */ + public $startTime = null; - public $finishTime = ''; + /** + * @var int|null + */ + public $finishTime = null; + /** + * @var string + */ public $spanKind = ''; + /** + * @var \OpenTracing\SpanContext|null + */ public $spanContext = null; + /** + * @var int + */ public $duration = 0; + /** + * @var array + */ public $logs = []; + /** + * @var array + */ public $tags = []; + /** + * @var array + */ public $references = []; - public function __construct($operationName, \OpenTracing\SpanContext $spanContext, $references, $startTime = null){ + public function __construct($operationName, \OpenTracing\SpanContext $spanContext, $references, $startTime = null) + { $this->operationName = $operationName; - $this->startTime = $startTime == null ? $this->microtimeToInt() : $startTime; + $this->startTime = null == $startTime ? $this->microtimeToInt() : $startTime; $this->spanContext = $spanContext; $this->references = $references; } /** - * @return string + * {@inheritDoc} */ - public function getOperationName(){ + public function getOperationName(): string + { return $this->operationName; } /** - * @return SpanContext + * {@inheritDoc} */ - public function getContext(){ + public function getContext(): \OpenTracing\SpanContext + { return $this->spanContext; } /** - * @param float|int|\DateTimeInterface|null $finishTime if passing float or int - * it should represent the timestamp (including as many decimal places as you need) - * @param array $logRecords - * @return mixed + * {@inheritDoc} */ - public function finish($finishTime = null, array $logRecords = []){ - $this->finishTime = $finishTime == null ? $this->microtimeToInt() : $finishTime; + public function finish($finishTime = null): void + { + $this->finishTime = null == $finishTime ? $this->microtimeToInt() : $finishTime; $this->duration = $this->finishTime - $this->startTime; } /** - * @param string $newOperationName + * {@inheritDoc} */ - public function overwriteOperationName($newOperationName){ + public function overwriteOperationName(string $newOperationName): void + { $this->operationName = $newOperationName; } - - public function setTag($key, $value){ + /** + * {@inheritDoc} + */ + public function setTag(string $key, $value): void + { $this->tags[$key] = $value; } - /** - * Adds a log record to the span - * - * @param array $fields [key => val] - * @param int|float|\DateTimeInterface $timestamp - * @throws SpanAlreadyFinished if the span is already finished + * {@inheritDoc} */ - public function log(array $fields = [], $timestamp = null){ + public function log(array $fields = [], $timestamp = null): void + { $log['timestamp'] = $timestamp ? $timestamp : $this->microtimeToInt(); $log['fields'] = $fields; $this->logs[] = $log; } /** - * Adds a baggage item to the SpanContext which is immutable so it is required to use SpanContext::withBaggageItem - * to get a new one. - * - * @param string $key - * @param string $value - * @throws SpanAlreadyFinished if the span is already finished + * {@inheritDoc} */ - public function addBaggageItem($key, $value){ + public function addBaggageItem(string $key, string $value): void + { $this->log([ 'event' => 'baggage', 'key' => $key, 'value' => $value, ]); - return $this->spanContext->withBaggageItem($key, $value); + + $this->spanContext->withBaggageItem($key, $value); } /** - * @param string $key - * @return string|null + * {@inheritDoc} */ - public function getBaggageItem($key){ + public function getBaggageItem(string $key): ?string + { return $this->spanContext->getBaggageItem($key); } - - private function microtimeToInt(){ + private function microtimeToInt() + { return intval(microtime(true) * 1000000); } -} \ No newline at end of file +} diff --git a/src/Jaeger/SpanContext.php b/src/Jaeger/SpanContext.php index 955d023..33850f9 100644 --- a/src/Jaeger/SpanContext.php +++ b/src/Jaeger/SpanContext.php @@ -15,15 +15,14 @@ namespace Jaeger; - -class SpanContext implements \OpenTracing\SpanContext{ +class SpanContext implements \OpenTracing\SpanContext +{ // traceID represents globally unique ID of the trace. // Usually generated as a random number. public $traceIdLow; public $traceIdHigh; - // spanID represents span ID that must be unique within its trace, // but does not have to be globally unique. public $spanId; @@ -43,8 +42,8 @@ class SpanContext implements \OpenTracing\SpanContext{ // extracted from a TextMap carrier. public $debugId; - - public function __construct($spanId, $parentId, $flags, $baggage = null, $debugId = 0){ + public function __construct($spanId, $parentId, $flags, $baggage = null, $debugId = 0) + { $this->spanId = $spanId; $this->parentId = $parentId; $this->flags = $flags; @@ -52,76 +51,86 @@ public function __construct($spanId, $parentId, $flags, $baggage = null, $debugI $this->debugId = $debugId; } - - public function getBaggageItem($key){ - return isset($this->baggage[$key]) ? $this->baggage[$key] : null; + /** + * {@inheritDoc} + */ + public function getBaggageItem(string $key): ?string + { + return $this->baggage[$key] ?? null; } - - public function withBaggageItem($key, $value){ + /** + * {@inheritDoc} + */ + public function withBaggageItem(string $key, string $value): \OpenTracing\SpanContext + { $this->baggage[$key] = $value; - return true; + + return $this; } - public function getIterator() + /** + * {@inheritDoc} + */ + public function getIterator(): \Traversable { - // TODO: Implement getIterator() method. + return new \ArrayIterator($this->baggage); } - - public function buildString(){ - if($this->traceIdHigh){ - return sprintf("%x%016x:%x:%x:%x", $this->traceIdHigh, $this->traceIdLow, + public function buildString() + { + if ($this->traceIdHigh) { + return sprintf('%x%016x:%x:%x:%x', $this->traceIdHigh, $this->traceIdLow, $this->spanId, $this->parentId, $this->flags); } - return sprintf("%x:%x:%x:%x", $this->traceIdLow, $this->spanId, $this->parentId, $this->flags); + return sprintf('%x:%x:%x:%x', $this->traceIdLow, $this->spanId, $this->parentId, $this->flags); } - - public function spanIdToString(){ - return sprintf("%x", $this->spanId); + public function spanIdToString() + { + return sprintf('%x', $this->spanId); } - - public function parentIdToString(){ - return sprintf("%x", $this->parentId); + public function parentIdToString() + { + return sprintf('%x', $this->parentId); } - - public function traceIdLowToString(){ + public function traceIdLowToString() + { if ($this->traceIdHigh) { - return sprintf("%x%016x", $this->traceIdHigh, $this->traceIdLow); + return sprintf('%x%016x', $this->traceIdHigh, $this->traceIdLow); } - return sprintf("%x", $this->traceIdLow); + return sprintf('%x', $this->traceIdLow); } - - public function flagsToString(){ - return sprintf("%x", $this->flags); + public function flagsToString() + { + return sprintf('%x', $this->flags); } - /** - * 是否取样 + * 是否取样. + * * @return mixed */ - public function isSampled(){ + public function isSampled() + { return $this->flags; } - public function hexToSignedInt($hex) { //Avoid pure Arabic numerals eg:1 - if (gettype($hex) != "string") { + if ('string' != gettype($hex)) { $hex .= ''; } $hexStrLen = strlen($hex); $dec = 0; - for ($i = 0; $i < $hexStrLen; $i++) { + for ($i = 0; $i < $hexStrLen; ++$i) { $hexByteStr = $hex[$i]; if (ctype_xdigit($hexByteStr)) { $decByte = hexdec($hex[$i]); @@ -132,7 +141,6 @@ public function hexToSignedInt($hex) return $dec; } - public function traceIdToString($traceId) { $len = strlen($traceId); @@ -144,7 +152,6 @@ public function traceIdToString($traceId) } } - /** * @return bool */ @@ -153,7 +160,6 @@ public function isValid() return $this->isTraceIdValid() && $this->spanId; } - /** * @return bool */ diff --git a/src/Jaeger/Thrift/Agent/AgentClient.php b/src/Jaeger/Thrift/Agent/AgentClient.php new file mode 100644 index 0000000..ff7c4b1 --- /dev/null +++ b/src/Jaeger/Thrift/Agent/AgentClient.php @@ -0,0 +1,86 @@ +input_ = $input; + $this->output_ = $output ? $output : $input; + } + + + public function emitZipkinBatch(array $spans) + { + $this->send_emitZipkinBatch($spans); + } + + public function send_emitZipkinBatch(array $spans) + { + $args = new \Jaeger\Thrift\Agent\Agent_emitZipkinBatch_args(); + $args->spans = $spans; + $bin_accel = ($this->output_ instanceof TBinaryProtocolAccelerated) && function_exists('thrift_protocol_write_binary'); + if ($bin_accel) { + thrift_protocol_write_binary( + $this->output_, + 'emitZipkinBatch', + TMessageType::ONEWAY, + $args, + $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(); + } + } + + public function emitBatch(\Jaeger\Thrift\Batch $batch) + { + $this->send_emitBatch($batch); + } + + public function send_emitBatch(\Jaeger\Thrift\Batch $batch) + { + $args = new \Jaeger\Thrift\Agent\Agent_emitBatch_args(); + $args->batch = $batch; + $bin_accel = ($this->output_ instanceof TBinaryProtocolAccelerated) && function_exists('thrift_protocol_write_binary'); + if ($bin_accel) { + thrift_protocol_write_binary( + $this->output_, + 'emitBatch', + TMessageType::ONEWAY, + $args, + $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(); + } + } +} diff --git a/src/Jaeger/Thrift/Agent/AgentIf.php b/src/Jaeger/Thrift/Agent/AgentIf.php new file mode 100644 index 0000000..b022128 --- /dev/null +++ b/src/Jaeger/Thrift/Agent/AgentIf.php @@ -0,0 +1,29 @@ + array( + 'var' => 'batch', + 'isRequired' => false, + 'type' => TType::STRUCT, + 'class' => '\Jaeger\Thrift\Batch', + ), + ); + + /** + * @var \Jaeger\Thrift\Batch + */ + public $batch = null; + + public function __construct($vals = null) + { + if (is_array($vals)) { + if (isset($vals['batch'])) { + $this->batch = $vals['batch']; + } + } + } + + public function getName() + { + return 'Agent_emitBatch_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->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->readStructEnd(); + return $xfer; + } + + public function write($output) + { + $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); + } + $xfer += $output->writeFieldBegin('batch', TType::STRUCT, 1); + $xfer += $this->batch->write($output); + $xfer += $output->writeFieldEnd(); + } + $xfer += $output->writeFieldStop(); + $xfer += $output->writeStructEnd(); + return $xfer; + } +} diff --git a/src/Jaeger/Thrift/Agent/Agent_emitZipkinBatch_args.php b/src/Jaeger/Thrift/Agent/Agent_emitZipkinBatch_args.php new file mode 100644 index 0000000..b91d2c2 --- /dev/null +++ b/src/Jaeger/Thrift/Agent/Agent_emitZipkinBatch_args.php @@ -0,0 +1,116 @@ + array( + 'var' => 'spans', + 'isRequired' => false, + 'type' => TType::LST, + 'etype' => TType::STRUCT, + 'elem' => array( + 'type' => TType::STRUCT, + 'class' => '\Jaeger\Thrift\Agent\Zipkin\Span', + ), + ), + ); + + /** + * @var \Jaeger\Thrift\Agent\Zipkin\Span[] + */ + public $spans = null; + + public function __construct($vals = null) + { + if (is_array($vals)) { + if (isset($vals['spans'])) { + $this->spans = $vals['spans']; + } + } + } + + public function getName() + { + return 'Agent_emitZipkinBatch_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->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; + } + $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('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(); + } + $xfer += $output->writeFieldStop(); + $xfer += $output->writeStructEnd(); + return $xfer; + } +} diff --git a/src/Jaeger/Thrift/Agent/AggregationValidatorClient.php b/src/Jaeger/Thrift/Agent/AggregationValidatorClient.php new file mode 100644 index 0000000..4b3a1b2 --- /dev/null +++ b/src/Jaeger/Thrift/Agent/AggregationValidatorClient.php @@ -0,0 +1,91 @@ +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/Jaeger/Thrift/Agent/AggregationValidatorIf.php b/src/Jaeger/Thrift/Agent/AggregationValidatorIf.php new file mode 100644 index 0000000..de54419 --- /dev/null +++ b/src/Jaeger/Thrift/Agent/AggregationValidatorIf.php @@ -0,0 +1,26 @@ + 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/Jaeger/Thrift/Agent/AggregationValidator_validateTrace_result.php b/src/Jaeger/Thrift/Agent/AggregationValidator_validateTrace_result.php new file mode 100644 index 0000000..cecf4ff --- /dev/null +++ b/src/Jaeger/Thrift/Agent/AggregationValidator_validateTrace_result.php @@ -0,0 +1,99 @@ + 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/Jaeger/Thrift/Agent/BaggageRestriction.php b/src/Jaeger/Thrift/Agent/BaggageRestriction.php new file mode 100644 index 0000000..1e535b4 --- /dev/null +++ b/src/Jaeger/Thrift/Agent/BaggageRestriction.php @@ -0,0 +1,118 @@ + 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/Jaeger/Thrift/Agent/BaggageRestrictionManagerClient.php b/src/Jaeger/Thrift/Agent/BaggageRestrictionManagerClient.php new file mode 100644 index 0000000..29bf690 --- /dev/null +++ b/src/Jaeger/Thrift/Agent/BaggageRestrictionManagerClient.php @@ -0,0 +1,91 @@ +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/Jaeger/Thrift/Agent/BaggageRestrictionManagerIf.php b/src/Jaeger/Thrift/Agent/BaggageRestrictionManagerIf.php new file mode 100644 index 0000000..66dea4a --- /dev/null +++ b/src/Jaeger/Thrift/Agent/BaggageRestrictionManagerIf.php @@ -0,0 +1,30 @@ + 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/Jaeger/Thrift/Agent/BaggageRestrictionManager_getBaggageRestrictions_result.php b/src/Jaeger/Thrift/Agent/BaggageRestrictionManager_getBaggageRestrictions_result.php new file mode 100644 index 0000000..f7e226a --- /dev/null +++ b/src/Jaeger/Thrift/Agent/BaggageRestrictionManager_getBaggageRestrictions_result.php @@ -0,0 +1,116 @@ + 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/Jaeger/Thrift/Agent/Dependencies.php b/src/Jaeger/Thrift/Agent/Dependencies.php new file mode 100644 index 0000000..739399c --- /dev/null +++ b/src/Jaeger/Thrift/Agent/Dependencies.php @@ -0,0 +1,116 @@ + 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/Jaeger/Thrift/Agent/DependencyClient.php b/src/Jaeger/Thrift/Agent/DependencyClient.php new file mode 100644 index 0000000..a650ec5 --- /dev/null +++ b/src/Jaeger/Thrift/Agent/DependencyClient.php @@ -0,0 +1,118 @@ +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/Jaeger/Thrift/Agent/DependencyIf.php b/src/Jaeger/Thrift/Agent/DependencyIf.php new file mode 100644 index 0000000..118f2ae --- /dev/null +++ b/src/Jaeger/Thrift/Agent/DependencyIf.php @@ -0,0 +1,30 @@ + 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/Jaeger/Thrift/Agent/Dependency_getDependenciesForTrace_args.php b/src/Jaeger/Thrift/Agent/Dependency_getDependenciesForTrace_args.php new file mode 100644 index 0000000..409c56b --- /dev/null +++ b/src/Jaeger/Thrift/Agent/Dependency_getDependenciesForTrace_args.php @@ -0,0 +1,94 @@ + 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/Jaeger/Thrift/Agent/Dependency_getDependenciesForTrace_result.php b/src/Jaeger/Thrift/Agent/Dependency_getDependenciesForTrace_result.php new file mode 100644 index 0000000..229b4d2 --- /dev/null +++ b/src/Jaeger/Thrift/Agent/Dependency_getDependenciesForTrace_result.php @@ -0,0 +1,99 @@ + 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/Jaeger/Thrift/Agent/Dependency_saveDependencies_args.php b/src/Jaeger/Thrift/Agent/Dependency_saveDependencies_args.php new file mode 100644 index 0000000..3c34c5c --- /dev/null +++ b/src/Jaeger/Thrift/Agent/Dependency_saveDependencies_args.php @@ -0,0 +1,99 @@ + 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/Jaeger/Thrift/Agent/OperationSamplingStrategy.php b/src/Jaeger/Thrift/Agent/OperationSamplingStrategy.php new file mode 100644 index 0000000..902fcfc --- /dev/null +++ b/src/Jaeger/Thrift/Agent/OperationSamplingStrategy.php @@ -0,0 +1,123 @@ + array( + 'var' => 'operation', + 'isRequired' => true, + 'type' => TType::STRING, + ), + 2 => array( + '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 function __construct($vals = null) + { + if (is_array($vals)) { + if (isset($vals['operation'])) { + $this->operation = $vals['operation']; + } + if (isset($vals['probabilisticSampling'])) { + $this->probabilisticSampling = $vals['probabilisticSampling']; + } + } + } + + public function getName() + { + return 'OperationSamplingStrategy'; + } + + + 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->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; + } + $xfer += $input->readFieldEnd(); + } + $xfer += $input->readStructEnd(); + return $xfer; + } + + public function write($output) + { + $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); + } + $xfer += $output->writeFieldBegin('probabilisticSampling', TType::STRUCT, 2); + $xfer += $this->probabilisticSampling->write($output); + $xfer += $output->writeFieldEnd(); + } + $xfer += $output->writeFieldStop(); + $xfer += $output->writeStructEnd(); + return $xfer; + } +} diff --git a/src/Jaeger/Thrift/Agent/PerOperationSamplingStrategies.php b/src/Jaeger/Thrift/Agent/PerOperationSamplingStrategies.php new file mode 100644 index 0000000..59f9d9a --- /dev/null +++ b/src/Jaeger/Thrift/Agent/PerOperationSamplingStrategies.php @@ -0,0 +1,188 @@ + array( + 'var' => 'defaultSamplingProbability', + 'isRequired' => true, + 'type' => TType::DOUBLE, + ), + 2 => array( + 'var' => 'defaultLowerBoundTracesPerSecond', + 'isRequired' => true, + 'type' => TType::DOUBLE, + ), + 3 => array( + 'var' => 'perOperationStrategies', + 'isRequired' => true, + 'type' => TType::LST, + 'etype' => TType::STRUCT, + 'elem' => array( + 'type' => TType::STRUCT, + 'class' => '\Jaeger\Thrift\Agent\OperationSamplingStrategy', + ), + ), + 4 => array( + 'var' => 'defaultUpperBoundTracesPerSecond', + 'isRequired' => false, + 'type' => TType::DOUBLE, + ), + ); + + /** + * @var double + */ + public $defaultSamplingProbability = null; + /** + * @var double + */ + public $defaultLowerBoundTracesPerSecond = null; + /** + * @var \Jaeger\Thrift\Agent\OperationSamplingStrategy[] + */ + public $perOperationStrategies = null; + /** + * @var double + */ + public $defaultUpperBoundTracesPerSecond = null; + + public function __construct($vals = null) + { + if (is_array($vals)) { + if (isset($vals['defaultSamplingProbability'])) { + $this->defaultSamplingProbability = $vals['defaultSamplingProbability']; + } + if (isset($vals['defaultLowerBoundTracesPerSecond'])) { + $this->defaultLowerBoundTracesPerSecond = $vals['defaultLowerBoundTracesPerSecond']; + } + if (isset($vals['perOperationStrategies'])) { + $this->perOperationStrategies = $vals['perOperationStrategies']; + } + if (isset($vals['defaultUpperBoundTracesPerSecond'])) { + $this->defaultUpperBoundTracesPerSecond = $vals['defaultUpperBoundTracesPerSecond']; + } + } + } + + public function getName() + { + return 'PerOperationSamplingStrategies'; + } + + + 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::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); + } + 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; + } + $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; + } + $xfer += $input->readFieldEnd(); + } + $xfer += $input->readStructEnd(); + return $xfer; + } + + public function write($output) + { + $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); + } + $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(); + return $xfer; + } +} diff --git a/src/Jaeger/Thrift/Agent/ProbabilisticSamplingStrategy.php b/src/Jaeger/Thrift/Agent/ProbabilisticSamplingStrategy.php new file mode 100644 index 0000000..a7fe556 --- /dev/null +++ b/src/Jaeger/Thrift/Agent/ProbabilisticSamplingStrategy.php @@ -0,0 +1,94 @@ + array( + 'var' => 'samplingRate', + 'isRequired' => true, + 'type' => TType::DOUBLE, + ), + ); + + /** + * @var double + */ + public $samplingRate = null; + + public function __construct($vals = null) + { + if (is_array($vals)) { + if (isset($vals['samplingRate'])) { + $this->samplingRate = $vals['samplingRate']; + } + } + } + + public function getName() + { + return 'ProbabilisticSamplingStrategy'; + } + + + 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::DOUBLE) { + $xfer += $input->readDouble($this->samplingRate); + } 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('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(); + return $xfer; + } +} diff --git a/src/Jaeger/Thrift/Agent/RateLimitingSamplingStrategy.php b/src/Jaeger/Thrift/Agent/RateLimitingSamplingStrategy.php new file mode 100644 index 0000000..7d15c8d --- /dev/null +++ b/src/Jaeger/Thrift/Agent/RateLimitingSamplingStrategy.php @@ -0,0 +1,94 @@ + array( + 'var' => 'maxTracesPerSecond', + 'isRequired' => true, + 'type' => TType::I16, + ), + ); + + /** + * @var int + */ + public $maxTracesPerSecond = null; + + public function __construct($vals = null) + { + if (is_array($vals)) { + if (isset($vals['maxTracesPerSecond'])) { + $this->maxTracesPerSecond = $vals['maxTracesPerSecond']; + } + } + } + + public function getName() + { + return 'RateLimitingSamplingStrategy'; + } + + + 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::I16) { + $xfer += $input->readI16($this->maxTracesPerSecond); + } 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('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(); + return $xfer; + } +} diff --git a/src/Jaeger/Thrift/Agent/SamplingManagerClient.php b/src/Jaeger/Thrift/Agent/SamplingManagerClient.php new file mode 100644 index 0000000..bd5f646 --- /dev/null +++ b/src/Jaeger/Thrift/Agent/SamplingManagerClient.php @@ -0,0 +1,91 @@ +input_ = $input; + $this->output_ = $output ? $output : $input; + } + + + public function getSamplingStrategy($serviceName) + { + $this->send_getSamplingStrategy($serviceName); + return $this->recv_getSamplingStrategy(); + } + + public function send_getSamplingStrategy($serviceName) + { + $args = new \Jaeger\Thrift\Agent\SamplingManager_getSamplingStrategy_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_, + 'getSamplingStrategy', + TMessageType::CALL, + $args, + $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(); + } + } + + public function recv_getSamplingStrategy() + { + $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\SamplingManager_getSamplingStrategy_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\SamplingManager_getSamplingStrategy_result(); + $result->read($this->input_); + $this->input_->readMessageEnd(); + } + if ($result->success !== null) { + return $result->success; + } + throw new \Exception("getSamplingStrategy failed: unknown result"); + } +} diff --git a/src/Jaeger/Thrift/Agent/SamplingManagerIf.php b/src/Jaeger/Thrift/Agent/SamplingManagerIf.php new file mode 100644 index 0000000..9eca93f --- /dev/null +++ b/src/Jaeger/Thrift/Agent/SamplingManagerIf.php @@ -0,0 +1,26 @@ + 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 'SamplingManager_getSamplingStrategy_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('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(); + return $xfer; + } +} diff --git a/src/Jaeger/Thrift/Agent/SamplingManager_getSamplingStrategy_result.php b/src/Jaeger/Thrift/Agent/SamplingManager_getSamplingStrategy_result.php new file mode 100644 index 0000000..7f7aca3 --- /dev/null +++ b/src/Jaeger/Thrift/Agent/SamplingManager_getSamplingStrategy_result.php @@ -0,0 +1,99 @@ + array( + 'var' => 'success', + 'isRequired' => false, + 'type' => TType::STRUCT, + 'class' => '\Jaeger\Thrift\Agent\SamplingStrategyResponse', + ), + ); + + /** + * @var \Jaeger\Thrift\Agent\SamplingStrategyResponse + */ + public $success = null; + + public function __construct($vals = null) + { + if (is_array($vals)) { + if (isset($vals['success'])) { + $this->success = $vals['success']; + } + } + } + + public function getName() + { + return 'SamplingManager_getSamplingStrategy_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\SamplingStrategyResponse(); + $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('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->writeFieldStop(); + $xfer += $output->writeStructEnd(); + return $xfer; + } +} diff --git a/src/Jaeger/Thrift/Agent/SamplingStrategyResponse.php b/src/Jaeger/Thrift/Agent/SamplingStrategyResponse.php new file mode 100644 index 0000000..14f4538 --- /dev/null +++ b/src/Jaeger/Thrift/Agent/SamplingStrategyResponse.php @@ -0,0 +1,181 @@ + array( + 'var' => 'strategyType', + 'isRequired' => true, + 'type' => TType::I32, + ), + 2 => array( + 'var' => 'probabilisticSampling', + 'isRequired' => false, + 'type' => TType::STRUCT, + 'class' => '\Jaeger\Thrift\Agent\ProbabilisticSamplingStrategy', + ), + 3 => array( + 'var' => 'rateLimitingSampling', + 'isRequired' => false, + 'type' => TType::STRUCT, + 'class' => '\Jaeger\Thrift\Agent\RateLimitingSamplingStrategy', + ), + 4 => array( + '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 function __construct($vals = null) + { + if (is_array($vals)) { + if (isset($vals['strategyType'])) { + $this->strategyType = $vals['strategyType']; + } + if (isset($vals['probabilisticSampling'])) { + $this->probabilisticSampling = $vals['probabilisticSampling']; + } + if (isset($vals['rateLimitingSampling'])) { + $this->rateLimitingSampling = $vals['rateLimitingSampling']; + } + if (isset($vals['operationSampling'])) { + $this->operationSampling = $vals['operationSampling']; + } + } + } + + public function getName() + { + return 'SamplingStrategyResponse'; + } + + + 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->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; + } + $xfer += $input->readFieldEnd(); + } + $xfer += $input->readStructEnd(); + return $xfer; + } + + public function write($output) + { + $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); + } + $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); + } + $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); + } + $xfer += $output->writeFieldBegin('operationSampling', TType::STRUCT, 4); + $xfer += $this->operationSampling->write($output); + $xfer += $output->writeFieldEnd(); + } + $xfer += $output->writeFieldStop(); + $xfer += $output->writeStructEnd(); + return $xfer; + } +} diff --git a/src/Jaeger/Thrift/Agent/SamplingStrategyType.php b/src/Jaeger/Thrift/Agent/SamplingStrategyType.php new file mode 100644 index 0000000..0a7fa40 --- /dev/null +++ b/src/Jaeger/Thrift/Agent/SamplingStrategyType.php @@ -0,0 +1,30 @@ + 'PROBABILISTIC', + 1 => 'RATE_LIMITING', + ); +} + diff --git a/src/Jaeger/Thrift/Agent/ValidateTraceResponse.php b/src/Jaeger/Thrift/Agent/ValidateTraceResponse.php new file mode 100644 index 0000000..593bb93 --- /dev/null +++ b/src/Jaeger/Thrift/Agent/ValidateTraceResponse.php @@ -0,0 +1,118 @@ + 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/Jaeger/Thrift/Agent/Zipkin/Annotation.php b/src/Jaeger/Thrift/Agent/Zipkin/Annotation.php new file mode 100644 index 0000000..178c8bb --- /dev/null +++ b/src/Jaeger/Thrift/Agent/Zipkin/Annotation.php @@ -0,0 +1,159 @@ + array( + 'var' => 'timestamp', + 'isRequired' => false, + 'type' => TType::I64, + ), + 2 => array( + 'var' => 'value', + 'isRequired' => false, + 'type' => TType::STRING, + ), + 3 => array( + '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; + /** + * 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 function __construct($vals = null) + { + if (is_array($vals)) { + if (isset($vals['timestamp'])) { + $this->timestamp = $vals['timestamp']; + } + if (isset($vals['value'])) { + $this->value = $vals['value']; + } + if (isset($vals['host'])) { + $this->host = $vals['host']; + } + } + } + + public function getName() + { + return 'Annotation'; + } + + + 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::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; + } + $xfer += $input->readFieldEnd(); + } + $xfer += $input->readStructEnd(); + return $xfer; + } + + public function write($output) + { + $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); + } + $xfer += $output->writeFieldBegin('host', TType::STRUCT, 3); + $xfer += $this->host->write($output); + $xfer += $output->writeFieldEnd(); + } + $xfer += $output->writeFieldStop(); + $xfer += $output->writeStructEnd(); + return $xfer; + } +} diff --git a/src/Jaeger/Thrift/Agent/Zipkin/AnnotationType.php b/src/Jaeger/Thrift/Agent/Zipkin/AnnotationType.php new file mode 100644 index 0000000..39c5a16 --- /dev/null +++ b/src/Jaeger/Thrift/Agent/Zipkin/AnnotationType.php @@ -0,0 +1,45 @@ + 'BOOL', + 1 => 'BYTES', + 2 => 'I16', + 3 => 'I32', + 4 => 'I64', + 5 => 'DOUBLE', + 6 => 'STRING', + ); +} + diff --git a/src/Jaeger/Thrift/Agent/Zipkin/BinaryAnnotation.php b/src/Jaeger/Thrift/Agent/Zipkin/BinaryAnnotation.php new file mode 100644 index 0000000..39884d7 --- /dev/null +++ b/src/Jaeger/Thrift/Agent/Zipkin/BinaryAnnotation.php @@ -0,0 +1,193 @@ + array( + 'var' => 'key', + 'isRequired' => false, + 'type' => TType::STRING, + ), + 2 => array( + 'var' => 'value', + 'isRequired' => false, + 'type' => TType::STRING, + ), + 3 => array( + 'var' => 'annotation_type', + 'isRequired' => false, + 'type' => TType::I32, + ), + 4 => array( + '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; + /** + * 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 function __construct($vals = null) + { + if (is_array($vals)) { + if (isset($vals['key'])) { + $this->key = $vals['key']; + } + if (isset($vals['value'])) { + $this->value = $vals['value']; + } + if (isset($vals['annotation_type'])) { + $this->annotation_type = $vals['annotation_type']; + } + if (isset($vals['host'])) { + $this->host = $vals['host']; + } + } + } + + public function getName() + { + return 'BinaryAnnotation'; + } + + + 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->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; + } + $xfer += $input->readFieldEnd(); + } + $xfer += $input->readStructEnd(); + return $xfer; + } + + public function write($output) + { + $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); + } + $xfer += $output->writeFieldBegin('host', TType::STRUCT, 4); + $xfer += $this->host->write($output); + $xfer += $output->writeFieldEnd(); + } + $xfer += $output->writeFieldStop(); + $xfer += $output->writeStructEnd(); + return $xfer; + } +} diff --git a/src/Jaeger/Thrift/Agent/Zipkin/Constant.php b/src/Jaeger/Thrift/Agent/Zipkin/Constant.php new file mode 100644 index 0000000..ade2f62 --- /dev/null +++ b/src/Jaeger/Thrift/Agent/Zipkin/Constant.php @@ -0,0 +1,261 @@ + array( + 'var' => 'ipv4', + 'isRequired' => false, + 'type' => TType::I32, + ), + 2 => array( + 'var' => 'port', + 'isRequired' => false, + 'type' => TType::I16, + ), + 3 => array( + 'var' => 'service_name', + 'isRequired' => false, + 'type' => TType::STRING, + ), + 4 => array( + '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; + /** + * 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; + /** + * 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; + /** + * IPv6 host address packed into 16 bytes. Ex Inet6Address.getBytes() + * + * @var string + */ + public $ipv6 = null; + + public function __construct($vals = null) + { + if (is_array($vals)) { + if (isset($vals['ipv4'])) { + $this->ipv4 = $vals['ipv4']; + } + if (isset($vals['port'])) { + $this->port = $vals['port']; + } + if (isset($vals['service_name'])) { + $this->service_name = $vals['service_name']; + } + if (isset($vals['ipv6'])) { + $this->ipv6 = $vals['ipv6']; + } + } + } + + public function getName() + { + return 'Endpoint'; + } + + + 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->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; + } + $xfer += $input->readFieldEnd(); + } + $xfer += $input->readStructEnd(); + return $xfer; + } + + public function write($output) + { + $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(); + } + $xfer += $output->writeFieldStop(); + $xfer += $output->writeStructEnd(); + return $xfer; + } +} diff --git a/src/Jaeger/Thrift/Agent/Zipkin/Response.php b/src/Jaeger/Thrift/Agent/Zipkin/Response.php new file mode 100644 index 0000000..22ae6f3 --- /dev/null +++ b/src/Jaeger/Thrift/Agent/Zipkin/Response.php @@ -0,0 +1,94 @@ + array( + 'var' => 'ok', + 'isRequired' => true, + 'type' => TType::BOOL, + ), + ); + + /** + * @var bool + */ + public $ok = null; + + public function __construct($vals = null) + { + if (is_array($vals)) { + if (isset($vals['ok'])) { + $this->ok = $vals['ok']; + } + } + } + + public function getName() + { + return 'Response'; + } + + + 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; + default: + $xfer += $input->skip($ftype); + break; + } + $xfer += $input->readFieldEnd(); + } + $xfer += $input->readStructEnd(); + return $xfer; + } + + public function write($output) + { + $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(); + } + $xfer += $output->writeFieldStop(); + $xfer += $output->writeStructEnd(); + return $xfer; + } +} diff --git a/src/Jaeger/Thrift/Agent/Zipkin/Span.php b/src/Jaeger/Thrift/Agent/Zipkin/Span.php new file mode 100644 index 0000000..5f90335 --- /dev/null +++ b/src/Jaeger/Thrift/Agent/Zipkin/Span.php @@ -0,0 +1,397 @@ + array( + 'var' => 'trace_id', + 'isRequired' => false, + 'type' => TType::I64, + ), + 3 => array( + 'var' => 'name', + 'isRequired' => false, + 'type' => TType::STRING, + ), + 4 => array( + 'var' => 'id', + 'isRequired' => false, + 'type' => TType::I64, + ), + 5 => array( + 'var' => 'parent_id', + 'isRequired' => false, + 'type' => TType::I64, + ), + 6 => array( + 'var' => 'annotations', + 'isRequired' => false, + 'type' => TType::LST, + 'etype' => TType::STRUCT, + 'elem' => array( + 'type' => TType::STRUCT, + 'class' => '\Jaeger\Thrift\Agent\Zipkin\Annotation', + ), + ), + 8 => array( + 'var' => 'binary_annotations', + 'isRequired' => false, + 'type' => TType::LST, + 'etype' => TType::STRUCT, + 'elem' => array( + 'type' => TType::STRUCT, + 'class' => '\Jaeger\Thrift\Agent\Zipkin\BinaryAnnotation', + ), + ), + 9 => array( + 'var' => 'debug', + 'isRequired' => false, + 'type' => TType::BOOL, + ), + 10 => array( + 'var' => 'timestamp', + 'isRequired' => false, + 'type' => TType::I64, + ), + 11 => array( + 'var' => 'duration', + 'isRequired' => false, + 'type' => TType::I64, + ), + 12 => array( + 'var' => 'trace_id_high', + 'isRequired' => false, + 'type' => TType::I64, + ), + ); + + /** + * @var int + */ + public $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; + /** + * @var \Jaeger\Thrift\Agent\Zipkin\Annotation[] + */ + public $annotations = null; + /** + * @var \Jaeger\Thrift\Agent\Zipkin\BinaryAnnotation[] + */ + public $binary_annotations = null; + /** + * @var bool + */ + public $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; + /** + * 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; + /** + * 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 function __construct($vals = null) + { + if (is_array($vals)) { + if (isset($vals['trace_id'])) { + $this->trace_id = $vals['trace_id']; + } + if (isset($vals['name'])) { + $this->name = $vals['name']; + } + if (isset($vals['id'])) { + $this->id = $vals['id']; + } + if (isset($vals['parent_id'])) { + $this->parent_id = $vals['parent_id']; + } + if (isset($vals['annotations'])) { + $this->annotations = $vals['annotations']; + } + if (isset($vals['binary_annotations'])) { + $this->binary_annotations = $vals['binary_annotations']; + } + if (isset($vals['debug'])) { + $this->debug = $vals['debug']; + } + if (isset($vals['timestamp'])) { + $this->timestamp = $vals['timestamp']; + } + if (isset($vals['duration'])) { + $this->duration = $vals['duration']; + } + if (isset($vals['trace_id_high'])) { + $this->trace_id_high = $vals['trace_id_high']; + } + } + } + + public function getName() + { + return 'Span'; + } + + + 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::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); + } + 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; + } + $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; + } + $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; + } + $xfer += $input->readFieldEnd(); + } + $xfer += $input->readStructEnd(); + return $xfer; + } + + public function write($output) + { + $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); + } + $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(); + return $xfer; + } +} diff --git a/src/Jaeger/Thrift/Agent/Zipkin/ZipkinCollectorClient.php b/src/Jaeger/Thrift/Agent/Zipkin/ZipkinCollectorClient.php new file mode 100644 index 0000000..ee0bea1 --- /dev/null +++ b/src/Jaeger/Thrift/Agent/Zipkin/ZipkinCollectorClient.php @@ -0,0 +1,91 @@ +input_ = $input; + $this->output_ = $output ? $output : $input; + } + + + public function submitZipkinBatch(array $spans) + { + $this->send_submitZipkinBatch($spans); + return $this->recv_submitZipkinBatch(); + } + + public function send_submitZipkinBatch(array $spans) + { + $args = new \Jaeger\Thrift\Agent\Zipkin\ZipkinCollector_submitZipkinBatch_args(); + $args->spans = $spans; + $bin_accel = ($this->output_ instanceof TBinaryProtocolAccelerated) && function_exists('thrift_protocol_write_binary'); + if ($bin_accel) { + thrift_protocol_write_binary( + $this->output_, + 'submitZipkinBatch', + TMessageType::CALL, + $args, + $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(); + } + } + + public function recv_submitZipkinBatch() + { + $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\Zipkin\ZipkinCollector_submitZipkinBatch_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\Zipkin\ZipkinCollector_submitZipkinBatch_result(); + $result->read($this->input_); + $this->input_->readMessageEnd(); + } + if ($result->success !== null) { + return $result->success; + } + throw new \Exception("submitZipkinBatch failed: unknown result"); + } +} diff --git a/src/Jaeger/Thrift/Agent/Zipkin/ZipkinCollectorIf.php b/src/Jaeger/Thrift/Agent/Zipkin/ZipkinCollectorIf.php new file mode 100644 index 0000000..ad07496 --- /dev/null +++ b/src/Jaeger/Thrift/Agent/Zipkin/ZipkinCollectorIf.php @@ -0,0 +1,26 @@ + array( + 'var' => 'spans', + 'isRequired' => false, + 'type' => TType::LST, + 'etype' => TType::STRUCT, + 'elem' => array( + 'type' => TType::STRUCT, + 'class' => '\Jaeger\Thrift\Agent\Zipkin\Span', + ), + ), + ); + + /** + * @var \Jaeger\Thrift\Agent\Zipkin\Span[] + */ + public $spans = null; + + public function __construct($vals = null) + { + if (is_array($vals)) { + if (isset($vals['spans'])) { + $this->spans = $vals['spans']; + } + } + } + + public function getName() + { + return 'ZipkinCollector_submitZipkinBatch_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->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; + } + $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('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(); + } + $xfer += $output->writeFieldStop(); + $xfer += $output->writeStructEnd(); + return $xfer; + } +} diff --git a/src/Jaeger/Thrift/Agent/Zipkin/ZipkinCollector_submitZipkinBatch_result.php b/src/Jaeger/Thrift/Agent/Zipkin/ZipkinCollector_submitZipkinBatch_result.php new file mode 100644 index 0000000..c04a8a1 --- /dev/null +++ b/src/Jaeger/Thrift/Agent/Zipkin/ZipkinCollector_submitZipkinBatch_result.php @@ -0,0 +1,116 @@ + array( + 'var' => 'success', + 'isRequired' => false, + 'type' => TType::LST, + 'etype' => TType::STRUCT, + 'elem' => array( + 'type' => TType::STRUCT, + 'class' => '\Jaeger\Thrift\Agent\Zipkin\Response', + ), + ), + ); + + /** + * @var \Jaeger\Thrift\Agent\Zipkin\Response[] + */ + public $success = null; + + public function __construct($vals = null) + { + if (is_array($vals)) { + if (isset($vals['success'])) { + $this->success = $vals['success']; + } + } + } + + public function getName() + { + return 'ZipkinCollector_submitZipkinBatch_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(); + $_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); + } + break; + default: + $xfer += $input->skip($ftype); + break; + } + $xfer += $input->readFieldEnd(); + } + $xfer += $input->readStructEnd(); + return $xfer; + } + + public function write($output) + { + $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->writeListEnd(); + $xfer += $output->writeFieldEnd(); + } + $xfer += $output->writeFieldStop(); + $xfer += $output->writeStructEnd(); + return $xfer; + } +} diff --git a/src/Jaeger/Thrift/AgentClient.php b/src/Jaeger/Thrift/AgentClient.php deleted file mode 100644 index 25b0e07..0000000 --- a/src/Jaeger/Thrift/AgentClient.php +++ /dev/null @@ -1,88 +0,0 @@ -writeMessageBegin('emitBatch', TMessageType::ONEWAY, 1); - self::$tptl->writeStructBegin('emitBatch_args'); - - $this->handleBatch($batch); - self::$tptl->writeFieldStop(); - - self::$tptl->writeStructEnd(); - self::$tptl->writeMessageEnd(); - - $batchLen = $tran->available(); - $batchThriftStr = $tran->read(Constants\UDP_PACKET_MAX_LENGTH); - - return ['len' => $batchLen, 'thriftStr' => $batchThriftStr]; - } - - - private function handleBatch($batch) - { - self::$tptl->writeFieldBegin("batch", TType::STRUCT, 1); - - self::$tptl->writeStructBegin("Batch"); - $this->handleThriftProcess($batch['thriftProcess']); - $this->handleThriftSpans($batch['thriftSpans']); - - self::$tptl->writeFieldStop(); - self::$tptl->writeStructEnd(); - - self::$tptl->writeFieldEnd(); - } - - - private function handleThriftSpans($thriftSpans) - { - self::$tptl->writeFieldBegin("spans", TType::LST, 2); - self::$tptl->writeListBegin(TType::STRUCT, count($thriftSpans)); - - $agentSpan = Span::getInstance(); - foreach ($thriftSpans as $thriftSpan){ - $agentSpan->setThriftSpan($thriftSpan); - $agentSpan->write(self::$tptl); - } - - self::$tptl->writeListEnd(); - self::$tptl->writeFieldEnd(); - } - - - private function handleThriftProcess($thriftProcess) - { - self::$tptl->writeFieldBegin("process", TType::STRUCT, 1); - (new Process($thriftProcess))->write(self::$tptl); - self::$tptl->writeFieldEnd(); - } - - -} diff --git a/src/Jaeger/Thrift/Batch.php b/src/Jaeger/Thrift/Batch.php new file mode 100644 index 0000000..311c656 --- /dev/null +++ b/src/Jaeger/Thrift/Batch.php @@ -0,0 +1,198 @@ + array( + 'var' => 'process', + 'isRequired' => true, + 'type' => TType::STRUCT, + 'class' => '\Jaeger\Thrift\Process', + ), + 2 => array( + 'var' => 'spans', + 'isRequired' => true, + 'type' => TType::LST, + 'etype' => TType::STRUCT, + 'elem' => array( + 'type' => TType::STRUCT, + 'class' => '\Jaeger\Thrift\Span', + ), + ), + 3 => array( + 'var' => 'seqNo', + 'isRequired' => false, + 'type' => TType::I64, + ), + 4 => array( + 'var' => 'stats', + 'isRequired' => false, + 'type' => TType::STRUCT, + 'class' => '\Jaeger\Thrift\ClientStats', + ), + ); + + /** + * @var \Jaeger\Thrift\Process + */ + public $process = null; + /** + * @var \Jaeger\Thrift\Span[] + */ + public $spans = null; + /** + * @var int + */ + public $seqNo = null; + /** + * @var \Jaeger\Thrift\ClientStats + */ + public $stats = null; + + public function __construct($vals = null) + { + if (is_array($vals)) { + if (isset($vals['process'])) { + $this->process = $vals['process']; + } + if (isset($vals['spans'])) { + $this->spans = $vals['spans']; + } + if (isset($vals['seqNo'])) { + $this->seqNo = $vals['seqNo']; + } + if (isset($vals['stats'])) { + $this->stats = $vals['stats']; + } + } + } + + public function getName() + { + return 'Batch'; + } + + + 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->process = new \Jaeger\Thrift\Process(); + $xfer += $this->process->read($input); + } else { + $xfer += $input->skip($ftype); + } + 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; + } + $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; + } + $xfer += $input->readFieldEnd(); + } + $xfer += $input->readStructEnd(); + return $xfer; + } + + public function write($output) + { + $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); + } + $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); + } + $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(); + } + 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); + } + $xfer += $output->writeFieldBegin('stats', TType::STRUCT, 4); + $xfer += $this->stats->write($output); + $xfer += $output->writeFieldEnd(); + } + $xfer += $output->writeFieldStop(); + $xfer += $output->writeStructEnd(); + return $xfer; + } +} diff --git a/src/Jaeger/Thrift/BatchSubmitResponse.php b/src/Jaeger/Thrift/BatchSubmitResponse.php new file mode 100644 index 0000000..492e293 --- /dev/null +++ b/src/Jaeger/Thrift/BatchSubmitResponse.php @@ -0,0 +1,94 @@ + array( + 'var' => 'ok', + 'isRequired' => true, + 'type' => TType::BOOL, + ), + ); + + /** + * @var bool + */ + public $ok = null; + + public function __construct($vals = null) + { + if (is_array($vals)) { + if (isset($vals['ok'])) { + $this->ok = $vals['ok']; + } + } + } + + public function getName() + { + return 'BatchSubmitResponse'; + } + + + 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; + default: + $xfer += $input->skip($ftype); + break; + } + $xfer += $input->readFieldEnd(); + } + $xfer += $input->readStructEnd(); + return $xfer; + } + + public function write($output) + { + $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(); + } + $xfer += $output->writeFieldStop(); + $xfer += $output->writeStructEnd(); + return $xfer; + } +} diff --git a/src/Jaeger/Thrift/ClientStats.php b/src/Jaeger/Thrift/ClientStats.php new file mode 100644 index 0000000..e554c20 --- /dev/null +++ b/src/Jaeger/Thrift/ClientStats.php @@ -0,0 +1,142 @@ + array( + 'var' => 'fullQueueDroppedSpans', + 'isRequired' => true, + 'type' => TType::I64, + ), + 2 => array( + 'var' => 'tooLargeDroppedSpans', + 'isRequired' => true, + 'type' => TType::I64, + ), + 3 => array( + 'var' => 'failedToEmitSpans', + 'isRequired' => true, + 'type' => TType::I64, + ), + ); + + /** + * @var int + */ + public $fullQueueDroppedSpans = null; + /** + * @var int + */ + public $tooLargeDroppedSpans = null; + /** + * @var int + */ + public $failedToEmitSpans = null; + + public function __construct($vals = null) + { + if (is_array($vals)) { + if (isset($vals['fullQueueDroppedSpans'])) { + $this->fullQueueDroppedSpans = $vals['fullQueueDroppedSpans']; + } + if (isset($vals['tooLargeDroppedSpans'])) { + $this->tooLargeDroppedSpans = $vals['tooLargeDroppedSpans']; + } + if (isset($vals['failedToEmitSpans'])) { + $this->failedToEmitSpans = $vals['failedToEmitSpans']; + } + } + } + + public function getName() + { + return 'ClientStats'; + } + + + 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::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; + } + $xfer += $input->readFieldEnd(); + } + $xfer += $input->readStructEnd(); + return $xfer; + } + + public function write($output) + { + $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(); + } + $xfer += $output->writeFieldStop(); + $xfer += $output->writeStructEnd(); + return $xfer; + } +} diff --git a/src/Jaeger/Thrift/CollectorClient.php b/src/Jaeger/Thrift/CollectorClient.php new file mode 100644 index 0000000..b8d385c --- /dev/null +++ b/src/Jaeger/Thrift/CollectorClient.php @@ -0,0 +1,91 @@ +input_ = $input; + $this->output_ = $output ? $output : $input; + } + + + public function submitBatches(array $batches) + { + $this->send_submitBatches($batches); + return $this->recv_submitBatches(); + } + + public function send_submitBatches(array $batches) + { + $args = new \Jaeger\Thrift\Collector_submitBatches_args(); + $args->batches = $batches; + $bin_accel = ($this->output_ instanceof TBinaryProtocolAccelerated) && function_exists('thrift_protocol_write_binary'); + if ($bin_accel) { + thrift_protocol_write_binary( + $this->output_, + 'submitBatches', + TMessageType::CALL, + $args, + $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(); + } + } + + public function recv_submitBatches() + { + $bin_accel = ($this->input_ instanceof TBinaryProtocolAccelerated) && function_exists('thrift_protocol_read_binary'); + if ($bin_accel) { + $result = thrift_protocol_read_binary( + $this->input_, + '\Jaeger\Thrift\Collector_submitBatches_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\Collector_submitBatches_result(); + $result->read($this->input_); + $this->input_->readMessageEnd(); + } + if ($result->success !== null) { + return $result->success; + } + throw new \Exception("submitBatches failed: unknown result"); + } +} diff --git a/src/Jaeger/Thrift/CollectorIf.php b/src/Jaeger/Thrift/CollectorIf.php new file mode 100644 index 0000000..66d35f2 --- /dev/null +++ b/src/Jaeger/Thrift/CollectorIf.php @@ -0,0 +1,26 @@ + array( + 'var' => 'batches', + 'isRequired' => false, + 'type' => TType::LST, + 'etype' => TType::STRUCT, + 'elem' => array( + 'type' => TType::STRUCT, + 'class' => '\Jaeger\Thrift\Batch', + ), + ), + ); + + /** + * @var \Jaeger\Thrift\Batch[] + */ + public $batches = null; + + public function __construct($vals = null) + { + if (is_array($vals)) { + if (isset($vals['batches'])) { + $this->batches = $vals['batches']; + } + } + } + + public function getName() + { + return 'Collector_submitBatches_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->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; + } + $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('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(); + } + $xfer += $output->writeFieldStop(); + $xfer += $output->writeStructEnd(); + return $xfer; + } +} diff --git a/src/Jaeger/Thrift/Collector_submitBatches_result.php b/src/Jaeger/Thrift/Collector_submitBatches_result.php new file mode 100644 index 0000000..1b179b7 --- /dev/null +++ b/src/Jaeger/Thrift/Collector_submitBatches_result.php @@ -0,0 +1,116 @@ + array( + 'var' => 'success', + 'isRequired' => false, + 'type' => TType::LST, + 'etype' => TType::STRUCT, + 'elem' => array( + 'type' => TType::STRUCT, + 'class' => '\Jaeger\Thrift\BatchSubmitResponse', + ), + ), + ); + + /** + * @var \Jaeger\Thrift\BatchSubmitResponse[] + */ + public $success = null; + + public function __construct($vals = null) + { + if (is_array($vals)) { + if (isset($vals['success'])) { + $this->success = $vals['success']; + } + } + } + + public function getName() + { + return 'Collector_submitBatches_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(); + $_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); + } + break; + default: + $xfer += $input->skip($ftype); + break; + } + $xfer += $input->readFieldEnd(); + } + $xfer += $input->readStructEnd(); + return $xfer; + } + + public function write($output) + { + $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->writeListEnd(); + $xfer += $output->writeFieldEnd(); + } + $xfer += $output->writeFieldStop(); + $xfer += $output->writeStructEnd(); + return $xfer; + } +} diff --git a/src/Jaeger/Thrift/Crossdock/Downstream.php b/src/Jaeger/Thrift/Crossdock/Downstream.php new file mode 100644 index 0000000..d8d03f5 --- /dev/null +++ b/src/Jaeger/Thrift/Crossdock/Downstream.php @@ -0,0 +1,219 @@ + array( + 'var' => 'serviceName', + 'isRequired' => true, + 'type' => TType::STRING, + ), + 2 => array( + 'var' => 'serverRole', + 'isRequired' => true, + 'type' => TType::STRING, + ), + 3 => array( + 'var' => 'host', + 'isRequired' => true, + 'type' => TType::STRING, + ), + 4 => array( + 'var' => 'port', + 'isRequired' => true, + 'type' => TType::STRING, + ), + 5 => array( + 'var' => 'transport', + 'isRequired' => true, + 'type' => TType::I32, + ), + 6 => array( + 'var' => 'downstream', + 'isRequired' => false, + 'type' => TType::STRUCT, + 'class' => '\Jaeger\Thrift\Crossdock\Downstream', + ), + ); + + /** + * @var string + */ + public $serviceName = null; + /** + * @var string + */ + public $serverRole = null; + /** + * @var string + */ + public $host = null; + /** + * @var string + */ + public $port = null; + /** + * @var int + */ + public $transport = null; + /** + * @var \Jaeger\Thrift\Crossdock\Downstream + */ + public $downstream = null; + + public function __construct($vals = null) + { + if (is_array($vals)) { + if (isset($vals['serviceName'])) { + $this->serviceName = $vals['serviceName']; + } + if (isset($vals['serverRole'])) { + $this->serverRole = $vals['serverRole']; + } + if (isset($vals['host'])) { + $this->host = $vals['host']; + } + if (isset($vals['port'])) { + $this->port = $vals['port']; + } + if (isset($vals['transport'])) { + $this->transport = $vals['transport']; + } + if (isset($vals['downstream'])) { + $this->downstream = $vals['downstream']; + } + } + } + + public function getName() + { + return 'Downstream'; + } + + + 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::STRING) { + $xfer += $input->readString($this->serverRole); + } else { + $xfer += $input->skip($ftype); + } + break; + case 3: + if ($ftype == TType::STRING) { + $xfer += $input->readString($this->host); + } else { + $xfer += $input->skip($ftype); + } + break; + case 4: + if ($ftype == TType::STRING) { + $xfer += $input->readString($this->port); + } else { + $xfer += $input->skip($ftype); + } + break; + case 5: + if ($ftype == TType::I32) { + $xfer += $input->readI32($this->transport); + } else { + $xfer += $input->skip($ftype); + } + break; + case 6: + if ($ftype == TType::STRUCT) { + $this->downstream = new \Jaeger\Thrift\Crossdock\Downstream(); + $xfer += $this->downstream->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('Downstream'); + if ($this->serviceName !== null) { + $xfer += $output->writeFieldBegin('serviceName', TType::STRING, 1); + $xfer += $output->writeString($this->serviceName); + $xfer += $output->writeFieldEnd(); + } + if ($this->serverRole !== null) { + $xfer += $output->writeFieldBegin('serverRole', TType::STRING, 2); + $xfer += $output->writeString($this->serverRole); + $xfer += $output->writeFieldEnd(); + } + if ($this->host !== null) { + $xfer += $output->writeFieldBegin('host', TType::STRING, 3); + $xfer += $output->writeString($this->host); + $xfer += $output->writeFieldEnd(); + } + if ($this->port !== null) { + $xfer += $output->writeFieldBegin('port', TType::STRING, 4); + $xfer += $output->writeString($this->port); + $xfer += $output->writeFieldEnd(); + } + if ($this->transport !== null) { + $xfer += $output->writeFieldBegin('transport', TType::I32, 5); + $xfer += $output->writeI32($this->transport); + $xfer += $output->writeFieldEnd(); + } + if ($this->downstream !== null) { + if (!is_object($this->downstream)) { + throw new TProtocolException('Bad type in structure.', TProtocolException::INVALID_DATA); + } + $xfer += $output->writeFieldBegin('downstream', TType::STRUCT, 6); + $xfer += $this->downstream->write($output); + $xfer += $output->writeFieldEnd(); + } + $xfer += $output->writeFieldStop(); + $xfer += $output->writeStructEnd(); + return $xfer; + } +} diff --git a/src/Jaeger/Thrift/Crossdock/JoinTraceRequest.php b/src/Jaeger/Thrift/Crossdock/JoinTraceRequest.php new file mode 100644 index 0000000..c80fec8 --- /dev/null +++ b/src/Jaeger/Thrift/Crossdock/JoinTraceRequest.php @@ -0,0 +1,123 @@ + array( + 'var' => 'serverRole', + 'isRequired' => true, + 'type' => TType::STRING, + ), + 2 => array( + 'var' => 'downstream', + 'isRequired' => false, + 'type' => TType::STRUCT, + 'class' => '\Jaeger\Thrift\Crossdock\Downstream', + ), + ); + + /** + * @var string + */ + public $serverRole = null; + /** + * @var \Jaeger\Thrift\Crossdock\Downstream + */ + public $downstream = null; + + public function __construct($vals = null) + { + if (is_array($vals)) { + if (isset($vals['serverRole'])) { + $this->serverRole = $vals['serverRole']; + } + if (isset($vals['downstream'])) { + $this->downstream = $vals['downstream']; + } + } + } + + public function getName() + { + return 'JoinTraceRequest'; + } + + + 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->serverRole); + } else { + $xfer += $input->skip($ftype); + } + break; + case 2: + if ($ftype == TType::STRUCT) { + $this->downstream = new \Jaeger\Thrift\Crossdock\Downstream(); + $xfer += $this->downstream->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('JoinTraceRequest'); + if ($this->serverRole !== null) { + $xfer += $output->writeFieldBegin('serverRole', TType::STRING, 1); + $xfer += $output->writeString($this->serverRole); + $xfer += $output->writeFieldEnd(); + } + if ($this->downstream !== null) { + if (!is_object($this->downstream)) { + throw new TProtocolException('Bad type in structure.', TProtocolException::INVALID_DATA); + } + $xfer += $output->writeFieldBegin('downstream', TType::STRUCT, 2); + $xfer += $this->downstream->write($output); + $xfer += $output->writeFieldEnd(); + } + $xfer += $output->writeFieldStop(); + $xfer += $output->writeStructEnd(); + return $xfer; + } +} diff --git a/src/Jaeger/Thrift/Crossdock/ObservedSpan.php b/src/Jaeger/Thrift/Crossdock/ObservedSpan.php new file mode 100644 index 0000000..20fcfd2 --- /dev/null +++ b/src/Jaeger/Thrift/Crossdock/ObservedSpan.php @@ -0,0 +1,142 @@ + array( + 'var' => 'traceId', + 'isRequired' => true, + 'type' => TType::STRING, + ), + 2 => array( + 'var' => 'sampled', + 'isRequired' => true, + 'type' => TType::BOOL, + ), + 3 => array( + 'var' => 'baggage', + 'isRequired' => true, + 'type' => TType::STRING, + ), + ); + + /** + * @var string + */ + public $traceId = null; + /** + * @var bool + */ + public $sampled = null; + /** + * @var string + */ + public $baggage = null; + + public function __construct($vals = null) + { + if (is_array($vals)) { + if (isset($vals['traceId'])) { + $this->traceId = $vals['traceId']; + } + if (isset($vals['sampled'])) { + $this->sampled = $vals['sampled']; + } + if (isset($vals['baggage'])) { + $this->baggage = $vals['baggage']; + } + } + } + + public function getName() + { + return 'ObservedSpan'; + } + + + 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; + case 2: + if ($ftype == TType::BOOL) { + $xfer += $input->readBool($this->sampled); + } else { + $xfer += $input->skip($ftype); + } + break; + case 3: + if ($ftype == TType::STRING) { + $xfer += $input->readString($this->baggage); + } 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('ObservedSpan'); + if ($this->traceId !== null) { + $xfer += $output->writeFieldBegin('traceId', TType::STRING, 1); + $xfer += $output->writeString($this->traceId); + $xfer += $output->writeFieldEnd(); + } + if ($this->sampled !== null) { + $xfer += $output->writeFieldBegin('sampled', TType::BOOL, 2); + $xfer += $output->writeBool($this->sampled); + $xfer += $output->writeFieldEnd(); + } + if ($this->baggage !== null) { + $xfer += $output->writeFieldBegin('baggage', TType::STRING, 3); + $xfer += $output->writeString($this->baggage); + $xfer += $output->writeFieldEnd(); + } + $xfer += $output->writeFieldStop(); + $xfer += $output->writeStructEnd(); + return $xfer; + } +} diff --git a/src/Jaeger/Thrift/Crossdock/StartTraceRequest.php b/src/Jaeger/Thrift/Crossdock/StartTraceRequest.php new file mode 100644 index 0000000..2170171 --- /dev/null +++ b/src/Jaeger/Thrift/Crossdock/StartTraceRequest.php @@ -0,0 +1,171 @@ + array( + 'var' => 'serverRole', + 'isRequired' => true, + 'type' => TType::STRING, + ), + 2 => array( + 'var' => 'sampled', + 'isRequired' => true, + 'type' => TType::BOOL, + ), + 3 => array( + 'var' => 'baggage', + 'isRequired' => true, + 'type' => TType::STRING, + ), + 4 => array( + 'var' => 'downstream', + 'isRequired' => true, + 'type' => TType::STRUCT, + 'class' => '\Jaeger\Thrift\Crossdock\Downstream', + ), + ); + + /** + * @var string + */ + public $serverRole = null; + /** + * @var bool + */ + public $sampled = null; + /** + * @var string + */ + public $baggage = null; + /** + * @var \Jaeger\Thrift\Crossdock\Downstream + */ + public $downstream = null; + + public function __construct($vals = null) + { + if (is_array($vals)) { + if (isset($vals['serverRole'])) { + $this->serverRole = $vals['serverRole']; + } + if (isset($vals['sampled'])) { + $this->sampled = $vals['sampled']; + } + if (isset($vals['baggage'])) { + $this->baggage = $vals['baggage']; + } + if (isset($vals['downstream'])) { + $this->downstream = $vals['downstream']; + } + } + } + + public function getName() + { + return 'StartTraceRequest'; + } + + + 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->serverRole); + } else { + $xfer += $input->skip($ftype); + } + break; + case 2: + if ($ftype == TType::BOOL) { + $xfer += $input->readBool($this->sampled); + } else { + $xfer += $input->skip($ftype); + } + break; + case 3: + if ($ftype == TType::STRING) { + $xfer += $input->readString($this->baggage); + } else { + $xfer += $input->skip($ftype); + } + break; + case 4: + if ($ftype == TType::STRUCT) { + $this->downstream = new \Jaeger\Thrift\Crossdock\Downstream(); + $xfer += $this->downstream->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('StartTraceRequest'); + if ($this->serverRole !== null) { + $xfer += $output->writeFieldBegin('serverRole', TType::STRING, 1); + $xfer += $output->writeString($this->serverRole); + $xfer += $output->writeFieldEnd(); + } + if ($this->sampled !== null) { + $xfer += $output->writeFieldBegin('sampled', TType::BOOL, 2); + $xfer += $output->writeBool($this->sampled); + $xfer += $output->writeFieldEnd(); + } + if ($this->baggage !== null) { + $xfer += $output->writeFieldBegin('baggage', TType::STRING, 3); + $xfer += $output->writeString($this->baggage); + $xfer += $output->writeFieldEnd(); + } + if ($this->downstream !== null) { + if (!is_object($this->downstream)) { + throw new TProtocolException('Bad type in structure.', TProtocolException::INVALID_DATA); + } + $xfer += $output->writeFieldBegin('downstream', TType::STRUCT, 4); + $xfer += $this->downstream->write($output); + $xfer += $output->writeFieldEnd(); + } + $xfer += $output->writeFieldStop(); + $xfer += $output->writeStructEnd(); + return $xfer; + } +} diff --git a/src/Jaeger/Thrift/Crossdock/TraceResponse.php b/src/Jaeger/Thrift/Crossdock/TraceResponse.php new file mode 100644 index 0000000..898ddd6 --- /dev/null +++ b/src/Jaeger/Thrift/Crossdock/TraceResponse.php @@ -0,0 +1,158 @@ + array( + 'var' => 'span', + 'isRequired' => false, + 'type' => TType::STRUCT, + 'class' => '\Jaeger\Thrift\Crossdock\ObservedSpan', + ), + 2 => array( + 'var' => 'downstream', + 'isRequired' => false, + 'type' => TType::STRUCT, + 'class' => '\Jaeger\Thrift\Crossdock\TraceResponse', + ), + 3 => array( + 'var' => 'notImplementedError', + 'isRequired' => true, + 'type' => TType::STRING, + ), + ); + + /** + * @var \Jaeger\Thrift\Crossdock\ObservedSpan + */ + public $span = null; + /** + * @var \Jaeger\Thrift\Crossdock\TraceResponse + */ + public $downstream = null; + /** + * @var string + */ + public $notImplementedError = null; + + public function __construct($vals = null) + { + if (is_array($vals)) { + if (isset($vals['span'])) { + $this->span = $vals['span']; + } + if (isset($vals['downstream'])) { + $this->downstream = $vals['downstream']; + } + if (isset($vals['notImplementedError'])) { + $this->notImplementedError = $vals['notImplementedError']; + } + } + } + + public function getName() + { + return 'TraceResponse'; + } + + + 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->span = new \Jaeger\Thrift\Crossdock\ObservedSpan(); + $xfer += $this->span->read($input); + } else { + $xfer += $input->skip($ftype); + } + break; + case 2: + if ($ftype == TType::STRUCT) { + $this->downstream = new \Jaeger\Thrift\Crossdock\TraceResponse(); + $xfer += $this->downstream->read($input); + } else { + $xfer += $input->skip($ftype); + } + break; + case 3: + if ($ftype == TType::STRING) { + $xfer += $input->readString($this->notImplementedError); + } 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('TraceResponse'); + if ($this->span !== null) { + if (!is_object($this->span)) { + throw new TProtocolException('Bad type in structure.', TProtocolException::INVALID_DATA); + } + $xfer += $output->writeFieldBegin('span', TType::STRUCT, 1); + $xfer += $this->span->write($output); + $xfer += $output->writeFieldEnd(); + } + if ($this->downstream !== null) { + if (!is_object($this->downstream)) { + throw new TProtocolException('Bad type in structure.', TProtocolException::INVALID_DATA); + } + $xfer += $output->writeFieldBegin('downstream', TType::STRUCT, 2); + $xfer += $this->downstream->write($output); + $xfer += $output->writeFieldEnd(); + } + if ($this->notImplementedError !== null) { + $xfer += $output->writeFieldBegin('notImplementedError', TType::STRING, 3); + $xfer += $output->writeString($this->notImplementedError); + $xfer += $output->writeFieldEnd(); + } + $xfer += $output->writeFieldStop(); + $xfer += $output->writeStructEnd(); + return $xfer; + } +} diff --git a/src/Jaeger/Thrift/Crossdock/TracedServiceClient.php b/src/Jaeger/Thrift/Crossdock/TracedServiceClient.php new file mode 100644 index 0000000..e44c66d --- /dev/null +++ b/src/Jaeger/Thrift/Crossdock/TracedServiceClient.php @@ -0,0 +1,150 @@ +input_ = $input; + $this->output_ = $output ? $output : $input; + } + + + public function startTrace(\Jaeger\Thrift\Crossdock\StartTraceRequest $request) + { + $this->send_startTrace($request); + return $this->recv_startTrace(); + } + + public function send_startTrace(\Jaeger\Thrift\Crossdock\StartTraceRequest $request) + { + $args = new \Jaeger\Thrift\Crossdock\TracedService_startTrace_args(); + $args->request = $request; + $bin_accel = ($this->output_ instanceof TBinaryProtocolAccelerated) && function_exists('thrift_protocol_write_binary'); + if ($bin_accel) { + thrift_protocol_write_binary( + $this->output_, + 'startTrace', + TMessageType::CALL, + $args, + $this->seqid_, + $this->output_->isStrictWrite() + ); + } else { + $this->output_->writeMessageBegin('startTrace', TMessageType::CALL, $this->seqid_); + $args->write($this->output_); + $this->output_->writeMessageEnd(); + $this->output_->getTransport()->flush(); + } + } + + public function recv_startTrace() + { + $bin_accel = ($this->input_ instanceof TBinaryProtocolAccelerated) && function_exists('thrift_protocol_read_binary'); + if ($bin_accel) { + $result = thrift_protocol_read_binary( + $this->input_, + '\Jaeger\Thrift\Crossdock\TracedService_startTrace_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\Crossdock\TracedService_startTrace_result(); + $result->read($this->input_); + $this->input_->readMessageEnd(); + } + if ($result->success !== null) { + return $result->success; + } + throw new \Exception("startTrace failed: unknown result"); + } + + public function joinTrace(\Jaeger\Thrift\Crossdock\JoinTraceRequest $request) + { + $this->send_joinTrace($request); + return $this->recv_joinTrace(); + } + + public function send_joinTrace(\Jaeger\Thrift\Crossdock\JoinTraceRequest $request) + { + $args = new \Jaeger\Thrift\Crossdock\TracedService_joinTrace_args(); + $args->request = $request; + $bin_accel = ($this->output_ instanceof TBinaryProtocolAccelerated) && function_exists('thrift_protocol_write_binary'); + if ($bin_accel) { + thrift_protocol_write_binary( + $this->output_, + 'joinTrace', + TMessageType::CALL, + $args, + $this->seqid_, + $this->output_->isStrictWrite() + ); + } else { + $this->output_->writeMessageBegin('joinTrace', TMessageType::CALL, $this->seqid_); + $args->write($this->output_); + $this->output_->writeMessageEnd(); + $this->output_->getTransport()->flush(); + } + } + + public function recv_joinTrace() + { + $bin_accel = ($this->input_ instanceof TBinaryProtocolAccelerated) && function_exists('thrift_protocol_read_binary'); + if ($bin_accel) { + $result = thrift_protocol_read_binary( + $this->input_, + '\Jaeger\Thrift\Crossdock\TracedService_joinTrace_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\Crossdock\TracedService_joinTrace_result(); + $result->read($this->input_); + $this->input_->readMessageEnd(); + } + if ($result->success !== null) { + return $result->success; + } + throw new \Exception("joinTrace failed: unknown result"); + } +} diff --git a/src/Jaeger/Thrift/Crossdock/TracedServiceIf.php b/src/Jaeger/Thrift/Crossdock/TracedServiceIf.php new file mode 100644 index 0000000..35b942b --- /dev/null +++ b/src/Jaeger/Thrift/Crossdock/TracedServiceIf.php @@ -0,0 +1,39 @@ + array( + 'var' => 'request', + 'isRequired' => false, + 'type' => TType::STRUCT, + 'class' => '\Jaeger\Thrift\Crossdock\JoinTraceRequest', + ), + ); + + /** + * @var \Jaeger\Thrift\Crossdock\JoinTraceRequest + */ + public $request = null; + + public function __construct($vals = null) + { + if (is_array($vals)) { + if (isset($vals['request'])) { + $this->request = $vals['request']; + } + } + } + + public function getName() + { + return 'TracedService_joinTrace_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->request = new \Jaeger\Thrift\Crossdock\JoinTraceRequest(); + $xfer += $this->request->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('TracedService_joinTrace_args'); + if ($this->request !== null) { + if (!is_object($this->request)) { + throw new TProtocolException('Bad type in structure.', TProtocolException::INVALID_DATA); + } + $xfer += $output->writeFieldBegin('request', TType::STRUCT, 1); + $xfer += $this->request->write($output); + $xfer += $output->writeFieldEnd(); + } + $xfer += $output->writeFieldStop(); + $xfer += $output->writeStructEnd(); + return $xfer; + } +} diff --git a/src/Jaeger/Thrift/Crossdock/TracedService_joinTrace_result.php b/src/Jaeger/Thrift/Crossdock/TracedService_joinTrace_result.php new file mode 100644 index 0000000..1adb3c9 --- /dev/null +++ b/src/Jaeger/Thrift/Crossdock/TracedService_joinTrace_result.php @@ -0,0 +1,99 @@ + array( + 'var' => 'success', + 'isRequired' => false, + 'type' => TType::STRUCT, + 'class' => '\Jaeger\Thrift\Crossdock\TraceResponse', + ), + ); + + /** + * @var \Jaeger\Thrift\Crossdock\TraceResponse + */ + public $success = null; + + public function __construct($vals = null) + { + if (is_array($vals)) { + if (isset($vals['success'])) { + $this->success = $vals['success']; + } + } + } + + public function getName() + { + return 'TracedService_joinTrace_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\Crossdock\TraceResponse(); + $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('TracedService_joinTrace_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/Jaeger/Thrift/Crossdock/TracedService_startTrace_args.php b/src/Jaeger/Thrift/Crossdock/TracedService_startTrace_args.php new file mode 100644 index 0000000..2c812a0 --- /dev/null +++ b/src/Jaeger/Thrift/Crossdock/TracedService_startTrace_args.php @@ -0,0 +1,99 @@ + array( + 'var' => 'request', + 'isRequired' => false, + 'type' => TType::STRUCT, + 'class' => '\Jaeger\Thrift\Crossdock\StartTraceRequest', + ), + ); + + /** + * @var \Jaeger\Thrift\Crossdock\StartTraceRequest + */ + public $request = null; + + public function __construct($vals = null) + { + if (is_array($vals)) { + if (isset($vals['request'])) { + $this->request = $vals['request']; + } + } + } + + public function getName() + { + return 'TracedService_startTrace_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->request = new \Jaeger\Thrift\Crossdock\StartTraceRequest(); + $xfer += $this->request->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('TracedService_startTrace_args'); + if ($this->request !== null) { + if (!is_object($this->request)) { + throw new TProtocolException('Bad type in structure.', TProtocolException::INVALID_DATA); + } + $xfer += $output->writeFieldBegin('request', TType::STRUCT, 1); + $xfer += $this->request->write($output); + $xfer += $output->writeFieldEnd(); + } + $xfer += $output->writeFieldStop(); + $xfer += $output->writeStructEnd(); + return $xfer; + } +} diff --git a/src/Jaeger/Thrift/Crossdock/TracedService_startTrace_result.php b/src/Jaeger/Thrift/Crossdock/TracedService_startTrace_result.php new file mode 100644 index 0000000..3e8d307 --- /dev/null +++ b/src/Jaeger/Thrift/Crossdock/TracedService_startTrace_result.php @@ -0,0 +1,99 @@ + array( + 'var' => 'success', + 'isRequired' => false, + 'type' => TType::STRUCT, + 'class' => '\Jaeger\Thrift\Crossdock\TraceResponse', + ), + ); + + /** + * @var \Jaeger\Thrift\Crossdock\TraceResponse + */ + public $success = null; + + public function __construct($vals = null) + { + if (is_array($vals)) { + if (isset($vals['success'])) { + $this->success = $vals['success']; + } + } + } + + public function getName() + { + return 'TracedService_startTrace_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\Crossdock\TraceResponse(); + $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('TracedService_startTrace_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/Jaeger/Thrift/Crossdock/Transport.php b/src/Jaeger/Thrift/Crossdock/Transport.php new file mode 100644 index 0000000..5cb5ba5 --- /dev/null +++ b/src/Jaeger/Thrift/Crossdock/Transport.php @@ -0,0 +1,33 @@ + 'HTTP', + 1 => 'TCHANNEL', + 2 => 'DUMMY', + ); +} + diff --git a/src/Jaeger/Thrift/JaegerThriftSpan.php b/src/Jaeger/Thrift/JaegerThriftSpan.php deleted file mode 100644 index 446fdd4..0000000 --- a/src/Jaeger/Thrift/JaegerThriftSpan.php +++ /dev/null @@ -1,113 +0,0 @@ -tags); - $tagsObj = Tags::getInstance(); - $tagsObj->setTags($tags); - $thriftTags = $tagsObj->buildTags(); - - $processThrift = [ - 'serverName' => $jaeger->serverName, - 'tags' => $thriftTags, - ]; - - - return $processThrift; - } - - public function buildJaegerSpanThrift(Span $span){ - - $spContext = $span->spanContext; - $thriftSpan = [ - 'traceIdLow' => $spContext->traceIdLow, - 'traceIdHigh' => $spContext->traceIdHigh, - 'spanId' => $spContext->spanId, - 'parentSpanId' => $spContext->parentId, - 'operationName' => $span->getOperationName(), - 'flags' => intval($spContext->flags), - 'startTime' => $span->startTime, - 'duration' => $span->duration, - 'tags' => $this->buildTags($span->tags), - 'logs' => $this->buildLogs($span->logs), - 'references' => $this->buildReferences($span->references) - ]; - - return $thriftSpan; - } - - - - private function buildTags($tags){ - $tagsObj = Tags::getInstance(); - $tagsObj->setTags($tags); - $resultTags = $tagsObj->buildTags(); - - return $resultTags; - } - - - private function buildLogs($logs){ - $resultLogs = []; - $tagsObj = Tags::getInstance(); - foreach($logs as $log){ - $tagsObj->setTags($log['fields']); - $fields = $tagsObj->buildTags(); - $resultLogs[] = [ - "timestamp" => $log['timestamp'], - "fields" => $fields, - ]; - } - - return $resultLogs; - } - - - private function buildReferences($references){ - $spanRef = []; - foreach ($references as $ref){ - if($ref->isType(Reference::CHILD_OF)){ - $type = SpanRefType::CHILD_OF; - }else if($ref->isType(Reference::FOLLOWS_FROM)){ - $type = SpanRefType::FOLLOWS_FROM; - } - $ctx = $ref->getContext(); - $spanRef[] = [ - 'refType' => $type, - 'traceIdLow' => $ctx->traceIdLow, - 'traceIdHigh' => $ctx->traceIdHigh, - 'spanId' => $ctx->spanId, - ]; - } - - return $spanRef; - } -} \ No newline at end of file diff --git a/src/Jaeger/Thrift/Log.php b/src/Jaeger/Thrift/Log.php new file mode 100644 index 0000000..416bbb7 --- /dev/null +++ b/src/Jaeger/Thrift/Log.php @@ -0,0 +1,140 @@ + array( + 'var' => 'timestamp', + 'isRequired' => true, + 'type' => TType::I64, + ), + 2 => array( + 'var' => 'fields', + 'isRequired' => true, + 'type' => TType::LST, + 'etype' => TType::STRUCT, + 'elem' => array( + 'type' => TType::STRUCT, + 'class' => '\Jaeger\Thrift\Tag', + ), + ), + ); + + /** + * @var int + */ + public $timestamp = null; + /** + * @var \Jaeger\Thrift\Tag[] + */ + public $fields = null; + + public function __construct($vals = null) + { + if (is_array($vals)) { + if (isset($vals['timestamp'])) { + $this->timestamp = $vals['timestamp']; + } + if (isset($vals['fields'])) { + $this->fields = $vals['fields']; + } + } + } + + public function getName() + { + return 'Log'; + } + + + 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::I64) { + $xfer += $input->readI64($this->timestamp); + } else { + $xfer += $input->skip($ftype); + } + 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; + } + $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('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); + } + $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(); + } + $xfer += $output->writeFieldStop(); + $xfer += $output->writeStructEnd(); + return $xfer; + } +} diff --git a/src/Jaeger/Thrift/Process.php b/src/Jaeger/Thrift/Process.php index 4aaa24e..8c6befb 100644 --- a/src/Jaeger/Thrift/Process.php +++ b/src/Jaeger/Thrift/Process.php @@ -1,87 +1,140 @@ array( + 'var' => 'serviceName', + 'isRequired' => true, + 'type' => TType::STRING, + ), + 2 => array( + 'var' => 'tags', + 'isRequired' => false, + 'type' => TType::LST, + 'etype' => TType::STRUCT, + 'elem' => array( + 'type' => TType::STRUCT, + 'class' => '\Jaeger\Thrift\Tag', + ), + ), + ); + + /** + * @var string + */ + public $serviceName = null; + /** + * @var \Jaeger\Thrift\Tag[] + */ + public $tags = null; + + public function __construct($vals = null) { - self::$serverName = isset($processThrift['serverName']) ? $processThrift['serverName'] : ''; - self::$thriftTags = isset($processThrift['tags']) ? $processThrift['tags'] : ''; - self::$wrote = isset($processThrift['wrote']) ? $processThrift['wrote'] : ''; - } - - - public function write(TProtocol $t){ - self::$tptl = $t; - - if(self::$wrote){ - $tran = self::$tptl->getTransport(); - $tran->write(self::$wrote); - } else { - - self::$tptl->writeStructBegin("Process"); - - $this->handleProcessSName(); - $this->handleProcessTags(); - - self::$tptl->writeFieldStop(); - self::$tptl->writeStructEnd(); + if (is_array($vals)) { + if (isset($vals['serviceName'])) { + $this->serviceName = $vals['serviceName']; + } + if (isset($vals['tags'])) { + $this->tags = $vals['tags']; + } } - - } - - private function handleProcessSName() + public function getName() { - self::$tptl->writeFieldBegin("serverName", TType::STRING, 1); - - self::$tptl->writeString(self::$serverName); - - self::$tptl->writeFieldEnd(); + return 'Process'; } - private function handleProcessTags() + public function read($input) { - if(count(self::$thriftTags) > 0) { - self::$tptl->writeFieldBegin("tags", TType::LST, 2); - self::$tptl->writeListBegin(TType::STRUCT, count(self::$thriftTags)); - - $tagsObj = Tags::getInstance(); - $tagsObj->setThriftTags(self::$thriftTags); - $tagsObj->write(self::$tptl); - - self::$tptl->writeListEnd(); - self::$tptl->writeFieldEnd(); + $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::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; + } + $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 read(TProtocol $t){} -} \ No newline at end of file + public function write($output) + { + $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); + } + $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(); + } + $xfer += $output->writeFieldStop(); + $xfer += $output->writeStructEnd(); + return $xfer; + } +} diff --git a/src/Jaeger/Thrift/Span.php b/src/Jaeger/Thrift/Span.php index 93f00ec..f04e952 100644 --- a/src/Jaeger/Thrift/Span.php +++ b/src/Jaeger/Thrift/Span.php @@ -1,223 +1,400 @@ array( + 'var' => 'traceIdLow', + 'isRequired' => true, + 'type' => TType::I64, + ), + 2 => array( + 'var' => 'traceIdHigh', + 'isRequired' => true, + 'type' => TType::I64, + ), + 3 => array( + 'var' => 'spanId', + 'isRequired' => true, + 'type' => TType::I64, + ), + 4 => array( + 'var' => 'parentSpanId', + 'isRequired' => true, + 'type' => TType::I64, + ), + 5 => array( + 'var' => 'operationName', + 'isRequired' => true, + 'type' => TType::STRING, + ), + 6 => array( + 'var' => 'references', + 'isRequired' => false, + 'type' => TType::LST, + 'etype' => TType::STRUCT, + 'elem' => array( + 'type' => TType::STRUCT, + 'class' => '\Jaeger\Thrift\SpanRef', + ), + ), + 7 => array( + 'var' => 'flags', + 'isRequired' => true, + 'type' => TType::I32, + ), + 8 => array( + 'var' => 'startTime', + 'isRequired' => true, + 'type' => TType::I64, + ), + 9 => array( + 'var' => 'duration', + 'isRequired' => true, + 'type' => TType::I64, + ), + 10 => array( + 'var' => 'tags', + 'isRequired' => false, + 'type' => TType::LST, + 'etype' => TType::STRUCT, + 'elem' => array( + 'type' => TType::STRUCT, + 'class' => '\Jaeger\Thrift\Tag', + ), + ), + 11 => array( + 'var' => 'logs', + 'isRequired' => false, + 'type' => TType::LST, + 'etype' => TType::STRUCT, + 'elem' => array( + '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; + /** + * @var \Jaeger\Thrift\SpanRef[] + */ + public $references = null; + /** + * @var int + */ + public $flags = null; + /** + * @var int + */ + public $startTime = null; + /** + * @var int + */ + public $duration = null; + /** + * @var \Jaeger\Thrift\Tag[] + */ + public $tags = null; + /** + * @var \Jaeger\Thrift\Log[] + */ + public $logs = null; + + public function __construct($vals = null) { - } - - - public static function getInstance(){ - if(! (self::$instance instanceof self) ) - { - self::$instance = new self(); + if (is_array($vals)) { + if (isset($vals['traceIdLow'])) { + $this->traceIdLow = $vals['traceIdLow']; + } + if (isset($vals['traceIdHigh'])) { + $this->traceIdHigh = $vals['traceIdHigh']; + } + if (isset($vals['spanId'])) { + $this->spanId = $vals['spanId']; + } + if (isset($vals['parentSpanId'])) { + $this->parentSpanId = $vals['parentSpanId']; + } + if (isset($vals['operationName'])) { + $this->operationName = $vals['operationName']; + } + if (isset($vals['references'])) { + $this->references = $vals['references']; + } + if (isset($vals['flags'])) { + $this->flags = $vals['flags']; + } + if (isset($vals['startTime'])) { + $this->startTime = $vals['startTime']; + } + if (isset($vals['duration'])) { + $this->duration = $vals['duration']; + } + if (isset($vals['tags'])) { + $this->tags = $vals['tags']; + } + if (isset($vals['logs'])) { + $this->logs = $vals['logs']; + } } - return self::$instance; } - - public function setThriftSpan($thriftSpan = []){ - self::$thriftSpan = $thriftSpan; - } - - - public function getThriftSpan(){ - return self::$thriftSpan; - } - - - public function write(TProtocol $t) + public function getName() { - self::$tptl = $t; - if(isset(self::$thriftSpan['wrote']) && self::$thriftSpan['wrote']){ - $tran = self::$tptl->getTransport(); - $tran->write(self::$thriftSpan['wrote']); - } else { - $this->handleSpan(self::$thriftSpan); - } + return 'Span'; } - public function read(TProtocol $t) + public function read($input) { - // TODO: Implement read() method. + $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); + } + 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; + } + $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; + } + $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; + } + $xfer += $input->readListEnd(); + } else { + $xfer += $input->skip($ftype); + } + break; + default: + $xfer += $input->skip($ftype); + break; + } + $xfer += $input->readFieldEnd(); + } + $xfer += $input->readStructEnd(); + return $xfer; } - - private function handleSpan($span) + public function write($output) { - self::$tptl->writeStructBegin("Span"); - - self::$tptl->writeFieldBegin('traceIdLow', TType::I64, 1); - self::$tptl->writeI64($span['traceIdLow']); - self::$tptl->writeFieldEnd(); - - self::$tptl->writeFieldBegin('traceIdHigh', TType::I64, 2); - self::$tptl->writeI64($span['traceIdHigh']); - self::$tptl->writeFieldEnd(); - - self::$tptl->writeFieldBegin('spanId', TType::I64, 3); - self::$tptl->writeI64($span['spanId']); - self::$tptl->writeFieldEnd(); - - self::$tptl->writeFieldBegin('parentSpanId', TType::I64, 4); - self::$tptl->writeI64($span['parentSpanId']); - self::$tptl->writeFieldEnd(); - - self::$tptl->writeFieldBegin('operationName', TType::STRING, 5); - self::$tptl->writeString($span['operationName']); - self::$tptl->writeFieldEnd(); - - if (isset($span['references'])) { - $this->handleSpanRefes($span['references']); + $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(); } - - self::$tptl->writeFieldBegin('flags', TType::I32, 7); - self::$tptl->writeI32($span['flags']); - self::$tptl->writeFieldEnd(); - - self::$tptl->writeFieldBegin('startTime', TType::I64, 8); - self::$tptl->writeI64($span['startTime']); - self::$tptl->writeFieldEnd(); - - self::$tptl->writeFieldBegin('duration', TType::I64, 9); - self::$tptl->writeI64($span['duration']); - self::$tptl->writeFieldEnd(); - - if (isset($span['tags'])) { - $this->handleSpanTags($span['tags']); + if ($this->traceIdHigh !== null) { + $xfer += $output->writeFieldBegin('traceIdHigh', TType::I64, 2); + $xfer += $output->writeI64($this->traceIdHigh); + $xfer += $output->writeFieldEnd(); } - - if (isset($span['logs'])) { - $this->handleSpanLogs($span['logs']); + if ($this->spanId !== null) { + $xfer += $output->writeFieldBegin('spanId', TType::I64, 3); + $xfer += $output->writeI64($this->spanId); + $xfer += $output->writeFieldEnd(); } - - self::$tptl->writeFieldStop(); - self::$tptl->writeStructEnd(); - } - - - private function handleSpanLogs($logs) - { - self::$tptl->writeFieldBegin('logs', TType::LST, 11); - self::$tptl->writeListBegin(TType::STRUCT, count($logs)); - - foreach ($logs as $log) { - $this->handleLog($log); + if ($this->parentSpanId !== null) { + $xfer += $output->writeFieldBegin('parentSpanId', TType::I64, 4); + $xfer += $output->writeI64($this->parentSpanId); + $xfer += $output->writeFieldEnd(); } - - self::$tptl->writeListEnd(); - self::$tptl->writeFieldEnd(); - } - - - private function handleLog($log) - { - self::$tptl->writeStructBegin("Log"); - - self::$tptl->writeFieldBegin('timestamp', TType::I64, 1); - self::$tptl->writeI64($log['timestamp']); - self::$tptl->writeFieldEnd(); - - $this->handleLogFields($log['fields']); - - self::$tptl->writeFieldStop(); - self::$tptl->writeStructEnd(); - } - - - private function handleLogFields($fields) - { - self::$tptl->writeFieldBegin('fields', TType::LST, 2); - self::$tptl->writeListBegin(TType::STRUCT, count($fields)); - - $tagsObj = Tags::getInstance(); - $tagsObj->setThriftTags($fields); - $tagsObj->write(self::$tptl); - - self::$tptl->writeListEnd(); - self::$tptl->writeFieldEnd(); - } - - - private function handleSpanTags($tags) - { - self::$tptl->writeFieldBegin('tags', TType::LST, 10); - self::$tptl->writeListBegin(TType::STRUCT, count($tags)); - - $tagsObj = Tags::getInstance(); - $tagsObj->setThriftTags($tags); - $tagsObj->write(self::$tptl); - - self::$tptl->writeListEnd(); - self::$tptl->writeFieldEnd(); - } - - - private function handleSpanRefes($references) - { - self::$tptl->writeFieldBegin('references', TType::LST, 6); - self::$tptl->writeListBegin(TType::STRUCT, count($references)); - - foreach ($references as $refe) { - $this->handleSpanRefe($refe); + if ($this->operationName !== null) { + $xfer += $output->writeFieldBegin('operationName', TType::STRING, 5); + $xfer += $output->writeString($this->operationName); + $xfer += $output->writeFieldEnd(); } - - self::$tptl->writeListEnd(); - self::$tptl->writeFieldEnd(); - } - - - private function handleSpanRefe($refe) - { - self::$tptl->writeStructBegin("SpanRef"); - - self::$tptl->writeFieldBegin("refType", TType::I32, 1); - self::$tptl->writeI32($refe['refType']); - self::$tptl->writeFieldEnd(); - - self::$tptl->writeFieldBegin("traceIdLow", TType::I64, 2); - self::$tptl->writeI64($refe['traceIdLow']); - self::$tptl->writeFieldEnd(); - - self::$tptl->writeFieldBegin("traceIdHigh", TType::I64, 3); - self::$tptl->writeI64($refe['traceIdHigh']); - self::$tptl->writeFieldEnd(); - - self::$tptl->writeFieldBegin("spanId", TType::I64, 4); - self::$tptl->writeI64($refe['spanId']); - self::$tptl->writeFieldEnd(); - - self::$tptl->writeFieldStop(); - self::$tptl->writeStructEnd(); + 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(); + } + 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); + } + $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(); + return $xfer; } -} \ No newline at end of file +} diff --git a/src/Jaeger/Thrift/SpanRef.php b/src/Jaeger/Thrift/SpanRef.php new file mode 100644 index 0000000..407bf4d --- /dev/null +++ b/src/Jaeger/Thrift/SpanRef.php @@ -0,0 +1,166 @@ + array( + 'var' => 'refType', + 'isRequired' => true, + 'type' => TType::I32, + ), + 2 => array( + 'var' => 'traceIdLow', + 'isRequired' => true, + 'type' => TType::I64, + ), + 3 => array( + 'var' => 'traceIdHigh', + 'isRequired' => true, + 'type' => TType::I64, + ), + 4 => array( + '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 function __construct($vals = null) + { + if (is_array($vals)) { + if (isset($vals['refType'])) { + $this->refType = $vals['refType']; + } + if (isset($vals['traceIdLow'])) { + $this->traceIdLow = $vals['traceIdLow']; + } + if (isset($vals['traceIdHigh'])) { + $this->traceIdHigh = $vals['traceIdHigh']; + } + if (isset($vals['spanId'])) { + $this->spanId = $vals['spanId']; + } + } + } + + public function getName() + { + return 'SpanRef'; + } + + + 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->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; + } + $xfer += $input->readFieldEnd(); + } + $xfer += $input->readStructEnd(); + return $xfer; + } + + public function write($output) + { + $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(); + } + $xfer += $output->writeFieldStop(); + $xfer += $output->writeStructEnd(); + return $xfer; + } +} diff --git a/src/Jaeger/Thrift/SpanRefType.php b/src/Jaeger/Thrift/SpanRefType.php index 6b48f6a..d657a92 100644 --- a/src/Jaeger/Thrift/SpanRefType.php +++ b/src/Jaeger/Thrift/SpanRefType.php @@ -1,24 +1,30 @@ 'CHILD_OF', + 1 => 'FOLLOWS_FROM', + ); } + diff --git a/src/Jaeger/Thrift/Tag.php b/src/Jaeger/Thrift/Tag.php new file mode 100644 index 0000000..1a3c003 --- /dev/null +++ b/src/Jaeger/Thrift/Tag.php @@ -0,0 +1,238 @@ + array( + 'var' => 'key', + 'isRequired' => true, + 'type' => TType::STRING, + ), + 2 => array( + 'var' => 'vType', + 'isRequired' => true, + 'type' => TType::I32, + ), + 3 => array( + 'var' => 'vStr', + 'isRequired' => false, + 'type' => TType::STRING, + ), + 4 => array( + 'var' => 'vDouble', + 'isRequired' => false, + 'type' => TType::DOUBLE, + ), + 5 => array( + 'var' => 'vBool', + 'isRequired' => false, + 'type' => TType::BOOL, + ), + 6 => array( + 'var' => 'vLong', + 'isRequired' => false, + 'type' => TType::I64, + ), + 7 => array( + '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 function __construct($vals = null) + { + if (is_array($vals)) { + if (isset($vals['key'])) { + $this->key = $vals['key']; + } + if (isset($vals['vType'])) { + $this->vType = $vals['vType']; + } + if (isset($vals['vStr'])) { + $this->vStr = $vals['vStr']; + } + if (isset($vals['vDouble'])) { + $this->vDouble = $vals['vDouble']; + } + if (isset($vals['vBool'])) { + $this->vBool = $vals['vBool']; + } + if (isset($vals['vLong'])) { + $this->vLong = $vals['vLong']; + } + if (isset($vals['vBinary'])) { + $this->vBinary = $vals['vBinary']; + } + } + } + + public function getName() + { + return 'Tag'; + } + + + 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->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; + } + $xfer += $input->readFieldEnd(); + } + $xfer += $input->readStructEnd(); + return $xfer; + } + + public function write($output) + { + $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(); + } + $xfer += $output->writeFieldStop(); + $xfer += $output->writeStructEnd(); + return $xfer; + } +} diff --git a/src/Jaeger/Thrift/TagType.php b/src/Jaeger/Thrift/TagType.php new file mode 100644 index 0000000..c526ada --- /dev/null +++ b/src/Jaeger/Thrift/TagType.php @@ -0,0 +1,39 @@ + 'STRING', + 1 => 'DOUBLE', + 2 => 'BOOL', + 3 => 'LONG', + 4 => 'BINARY', + ); +} + diff --git a/src/Jaeger/Thrift/Tags.php b/src/Jaeger/Thrift/Tags.php deleted file mode 100644 index 86c7520..0000000 --- a/src/Jaeger/Thrift/Tags.php +++ /dev/null @@ -1,185 +0,0 @@ -thriftTags)){ - return false; - } - - foreach($this->thriftTags as $tag) { - - self::$tptl->writeStructBegin("Tag"); - - if (isset($tag['key'])) { - self::$tptl->writeFieldBegin("key", TType::STRING, 1); - self::$tptl->writeString(strval($tag['key'])); - self::$tptl->writeFieldEnd(); - } - - if (isset($tag['vType'])) { - self::$tptl->writeFieldBegin('vType', TType::I32, 2); - self::$tptl->writeI32(Types::stringToTagType($tag['vType'])); - self::$tptl->writeFieldEnd(); - } - - if (isset($tag['vStr'])) { - self::$tptl->writeFieldBegin('vStr', TType::STRING, 3); - self::$tptl->writeString($tag['vStr']); - self::$tptl->writeFieldEnd(); - } - - if (isset($tag['vDouble'])) { - self::$tptl->writeFieldBegin('vDouble', TType::DOUBLE, 4); - self::$tptl->writeDouble($tag['vDouble']); - self::$tptl->writeFieldEnd(); - } - - if (isset($tag['vBool'])) { - self::$tptl->writeFieldBegin('vBool', TType::BOOL, 5); - self::$tptl->writeBool($tag['vBool']); - self::$tptl->writeFieldEnd(); - } - - if (isset($tag['vLong'])) { - self::$tptl->writeFieldBegin('vLong', TType::I64, 6); - self::$tptl->writeI64($tag['vLong']); - self::$tptl->writeFieldEnd(); - } - - if (isset($tag['vBinary'])) { - self::$tptl->writeFieldBegin('vBinary', TType::STRING, 7); - self::$tptl->writeByte($tag['vBinary']); - self::$tptl->writeFieldEnd(); - } - - self::$tptl->writeFieldStop(); - self::$tptl->writeStructEnd(); - } - - - return true; - } - - - public function read(TProtocol $t){ - - } - - - public function setThriftTags($thriftTags){ - $this->thriftTags = $thriftTags; - } - - - public function setTags($tags){ - $this->tags = $tags; - } - - - public function buildTags(){ - - $thriftTags = []; - if(empty($this->tags)){ - return $thriftTags; - } - - foreach ($this->tags as $k => $v){ - switch(gettype($v)){ - case "string": - $thriftTags[] = [ - 'key' => $k, - 'vType' => 'STRING', - 'vStr' => $v, - ]; - break; - case "boolean": - $thriftTags[] = [ - 'key' => $k, - 'vType' => 'BOOL', - 'vBool' => $v, - ]; - break; - case "double": - $thriftTags[] = [ - 'key' => $k, - 'vType' => 'DOUBLE', - 'vDouble' => $v, - ]; - break; - case "integer": - $thriftTags[] = [ - 'key' => $k, - 'vType' => 'DOUBLE', - 'vDouble' => $v, - ]; - break; - case "array": - $thriftTags[] = [ - 'key' => $k, - 'vType' => 'STRING', - 'vStr' => json_encode($v, JSON_UNESCAPED_UNICODE), - ]; - break; - default: - $thriftTags[] = [ - 'key' => $k, - 'vType' => 'STRING', - 'vStr' => is_string($v), - ]; - } - } - - - return $thriftTags; - } -} \ No newline at end of file diff --git a/src/Jaeger/Thrift/Types.php b/src/Jaeger/Thrift/Types.php deleted file mode 100644 index 38e97de..0000000 --- a/src/Jaeger/Thrift/Types.php +++ /dev/null @@ -1,59 +0,0 @@ -agentServerHostPort; - } - self::$hostPort = $hostport; + $this->agentHostPort = $hostport; - if ($maxPacketSize == 0) { + if (0 === $maxPacketSize) { $maxPacketSize = stristr(PHP_OS, 'DAR') ? self::MAC_UDP_MAX_SIZE : Constants\UDP_PACKET_MAX_LENGTH; } self::$maxSpanBytes = $maxPacketSize - Constants\EMIT_BATCH_OVER_HEAD; $this->tran = new TMemoryBuffer(); - $this->thriftProtocol = new TCompactProtocol($this->tran); - } + $this->protocol = new TCompactProtocol($this->tran); - public function buildAndCalcSizeOfProcessThrift(Jaeger $jaeger) - { - $jaeger->processThrift = (new JaegerThriftSpan())->buildJaegerProcessThrift($jaeger); - $jaeger->process = (new Process($jaeger->processThrift)); - $this->procesSize = $this->getAndCalcSizeOfSerializedThrift($jaeger->process, $jaeger->processThrift); - $this->bufferSize += $this->procesSize; - } + $this->agentClient = new AgentClient($this->protocol, null); + + $this->sender = $udpSender; + if (null == $this->sender) { + $this->sender = new UdpSender($this->agentHostPort, $this->agentClient, $this->tran); + } + $this->jaegerThrift = new JaegerThrift(); + } /** - * 收集将要发送的追踪信息 - * @param Jaeger $jaeger + * 收集将要发送的追踪信息. + * * @return bool */ public function append(Jaeger $jaeger) { - - if ($jaeger->process == null) { + if (null == $this->process) { $this->buildAndCalcSizeOfProcessThrift($jaeger); } $thriftSpansBuffer = []; // Uncommitted span used to temporarily store shards foreach ($jaeger->spans as $span) { - - $spanThrift = (new JaegerThriftSpan())->buildJaegerSpanThrift($span); - - $agentSpan = Span::getInstance(); - $agentSpan->setThriftSpan($spanThrift); - $spanSize = $this->getAndCalcSizeOfSerializedThrift($agentSpan, $spanThrift); - + $spanThrift = $this->jaegerThrift->buildSpanThrift($span); + $spanSize = $this->getAndCalcSizeOfSerializedThrift($spanThrift); if ($spanSize > self::$maxSpanBytes) { //throw new \Exception("Span is too large"); continue; } - if ($this->bufferSize + $spanSize >= self::$maxSpanBytes) { - self::$batchs[] = [ - 'thriftProcess' => $jaeger->processThrift, - 'thriftSpans' => $thriftSpansBuffer, - ]; + $thriftSpansBuffer[] = $spanThrift; + $this->bufferSize += $spanSize; + + if ($this->bufferSize >= self::$maxSpanBytes) { + self::$batch = new Batch([ + 'process' => $this->process, + 'spans' => $thriftSpansBuffer, + ]); $this->flush(); $thriftSpansBuffer = []; // Empty the temp buffer } - - $thriftSpansBuffer[] = $spanThrift; - $this->bufferSize += $spanSize; } - if ($thriftSpansBuffer) { - self::$batchs[] = [ - 'thriftProcess' => $jaeger->processThrift, - 'thriftSpans' => $thriftSpansBuffer, - ]; + if (count($thriftSpansBuffer) > 0) { + self::$batch = new Batch([ + 'process' => $this->process, + 'spans' => $thriftSpansBuffer, + ]); $this->flush(); } + $this->process = null; + return true; } - - public function resetBuffer() + public function buildAndCalcSizeOfProcessThrift(Jaeger $jaeger) { - $this->bufferSize = $this->procesSize; - self::$batchs = []; + $this->process = $this->jaegerThrift->buildProcessThrift($jaeger); + $this->procesSize = $this->getAndCalcSizeOfSerializedThrift($this->process); + $this->bufferSize += $this->procesSize; } - /** - * 获取序列化后的thrift和计算序列化后的thrift字符长度 - * @param TStruct $ts - * @param $serializedThrift + * 计算序列化后的thrift字符长度. + * + * @param mixed $thrift + * * @return mixed */ - private function getAndCalcSizeOfSerializedThrift(TStruct $ts, &$serializedThrift) + private function getAndCalcSizeOfSerializedThrift($thrift) { + $thrift->write($this->protocol); + $len = $this->tran->available(); + // 清空buf, 避免重复序列化 + $this->tran->read($len); - $ts->write($this->thriftProtocol); - $serThriftStrlen = $this->tran->available(); - //获取后buf清空 - $serializedThrift['wrote'] = $this->tran->read(Constants\UDP_PACKET_MAX_LENGTH); - - return $serThriftStrlen; + return $len; } - /** * @return int */ public function flush() { - $batchNum = count(self::$batchs); - if ($batchNum <= 0) { + if (null == self::$batch) { return 0; } - $spanNum = 0; - $udp = new UdpClient(self::$hostPort, new AgentClient()); - - foreach (self::$batchs as $batch) { - $spanNum += count($batch['thriftSpans']); - $udp->emitBatch($batch); - } + $spanNum = count(self::$batch->spans); + $this->sender->emitBatch(self::$batch); - $udp->close(); $this->resetBuffer(); return $spanNum; } + public function resetBuffer() + { + $this->bufferSize = $this->procesSize; + self::$batch = null; + } - public function getBatchs() + public function close() { - return self::$batchs; + $this->sender->close(); } -} \ No newline at end of file +} diff --git a/src/Jaeger/UdpClient.php b/src/Jaeger/UdpClient.php deleted file mode 100644 index 8e47dfe..0000000 --- a/src/Jaeger/UdpClient.php +++ /dev/null @@ -1,77 +0,0 @@ -host, $this->post) = explode(":", $hostPost); - $this->agentClient = $agentClient; - $this->socket = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP); - } - - - /** - * @return bool - */ - public function isOpen(){ - return $this->socket !== null; - } - - - /** - * send thrift - * @param $batch - * @return bool - */ - public function emitBatch($batch){ - $buildThrift = $this->agentClient->buildThrift($batch); - if(isset($buildThrift['len']) && $buildThrift['len'] && $this->isOpen()) { - $len = $buildThrift['len']; - $enitThrift = $buildThrift['thriftStr']; - $res = socket_sendto($this->socket, $enitThrift, $len, 0, $this->host, $this->post); - if($res === false) { - throw new \Exception("emit failse"); - } - - return true; - }else{ - return false; - } - } - - - public function close(){ - socket_close($this->socket); - $this->socket = null; - } -} \ No newline at end of file diff --git a/tests/ConfigTest.php b/tests/ConfigTest.php index 2dc39e1..cdeaa53 100644 --- a/tests/ConfigTest.php +++ b/tests/ConfigTest.php @@ -12,25 +12,27 @@ * or implied. See the License for the specific language governing permissions and limitations under * the License. */ + namespace tests; -use PHPUnit\Framework\TestCase; use Jaeger\Config; +use Jaeger\Reporter\NullReporter; use OpenTracing\NoopTracer; +use OpenTracing\Tracer; +use PHPUnit\Framework\TestCase; class ConfigTest extends TestCase { - - public function testSetDisabled(){ + public function testSetDisabled() + { $config = Config::getInstance(); $config->setDisabled(true); - $this->assertTrue($config::$disabled == true); + $this->assertTrue(true == $config::$disabled); } - - public function testNoopTracer(){ - + public function testNoopTracer() + { $config = Config::getInstance(); $config->setDisabled(true); $trace = $config->initTracer('test'); @@ -38,6 +40,28 @@ public function testNoopTracer(){ $this->assertTrue($trace instanceof NoopTracer); } + public function testflushMulTracer() + { + $report = new NullReporter(); + $config = Config::getInstance(); + $config->setDisabled(false); + $config->setReporter($report); + $tracer1 = $config->initTracer('tracer1'); + $this->assertTrue($tracer1 instanceof Tracer); + $tracer2 = $config->initTracer('tracer2'); + $this->assertTrue($tracer2 instanceof Tracer); + $this->assertTrue($config->flush()); + } - -} \ No newline at end of file + /** + * @expectedException \RuntimeException + */ + public function testEmptyServiceName() + { + $report = new NullReporter(); + $config = Config::getInstance(); + $config->setDisabled(false); + $config->setReporter($report); + $config->initTracer(''); + } +} diff --git a/tests/JaegerTest.php b/tests/JaegerTest.php index 7f2eaa0..a0906d6 100644 --- a/tests/JaegerTest.php +++ b/tests/JaegerTest.php @@ -15,215 +15,196 @@ namespace tests; +use Jaeger\Constants; use Jaeger\Jaeger; -use Jaeger\Reporter\RemoteReporter; +use Jaeger\Propagator\JaegerPropagator; +use Jaeger\Reporter\NullReporter; use Jaeger\Sampler\ConstSampler; use Jaeger\ScopeManager; use Jaeger\Span; -use Jaeger\Transport\TransportUdp; +use Jaeger\SpanContext; +use OpenTracing\Formats; use OpenTracing\Reference; use PHPUnit\Framework\TestCase; -use OpenTracing\Formats; -use Jaeger\SpanContext; -use Jaeger\Constants; -use Jaeger\Propagator\JaegerPropagator; class JaegerTest extends TestCase { + /** + * @var Jaeger|null + */ + public $tracer = null; - - public function getJaeger(){ - - $tranSport = new TransportUdp(); - $reporter = new RemoteReporter($tranSport); + public function setUp() + { + $reporter = new NullReporter(); $sampler = new ConstSampler(); $scopeManager = new ScopeManager(); - - return new Jaeger('jaeger', $reporter, $sampler, $scopeManager); + $this->tracer = new Jaeger('jaeger', $reporter, $sampler, $scopeManager); } - - public function testNew(){ - $Jaeger = $this->getJaeger(); - $this->assertInstanceOf(Jaeger::class, $Jaeger); + public function testNew() + { + $this->assertInstanceOf(Jaeger::class, $this->tracer); } - public function testGetEnvTags(){ - + public function testGetEnvTags() + { $_SERVER['JAEGER_TAGS'] = 'a=b,c=d'; - $Jaeger = $this->getJaeger(); - $tags = $Jaeger->getEnvTags(); - + $tags = $this->tracer->getEnvTags(); $this->assertTrue(count($tags) > 0); } - - public function testSetTags(){ - $Jaeger = $this->getJaeger(); - - $Jaeger->setTags(['version' => '2.0.0']); - $this->assertTrue($Jaeger->tags['version'] == '2.0.0'); + public function testSetTags() + { + $this->tracer->setTags(['version' => '2.0.0']); + $this->assertTrue('2.0.0' == $this->tracer->tags['version']); } - - public function testInject(){ - $Jaeger = $this->getJaeger(); - $Jaeger->setPropagator(new JaegerPropagator()); + public function testInject() + { + $this->tracer->setPropagator(new JaegerPropagator()); $context = new SpanContext(1, 1, 1, null, 1); - $Jaeger->inject($context, Formats\TEXT_MAP, $_SERVER); + $this->tracer->inject($context, Formats\TEXT_MAP, $_SERVER); $this->assertTrue('0:1:1:1' == $_SERVER[strtoupper(Constants\Tracer_State_Header_Name)]); } - - public function testInjectUnSupportFormat(){ - $Jaeger = $this->getJaeger(); - $Jaeger->setPropagator(new JaegerPropagator()); + /** + * @expectedException \OpenTracing\UnsupportedFormatException + */ + public function testInjectUnSupportFormat() + { + $this->tracer->setPropagator(new JaegerPropagator()); $context = new SpanContext(1, 1, 1, null, 1); - $this->expectExceptionMessage('The format \'http_headers\' is not supported.'); + $this->expectExceptionMessage('The format "http_headers" is not supported.'); - $Jaeger->inject($context, Formats\HTTP_HEADERS, $_SERVER); + $this->tracer->inject($context, Formats\HTTP_HEADERS, $_SERVER); } - - public function testExtract(){ - $Jaeger = $this->getJaeger(); - $Jaeger->setPropagator(new JaegerPropagator()); + public function testExtract() + { + $this->tracer->setPropagator(new JaegerPropagator()); $carrier[strtoupper(Constants\Tracer_State_Header_Name)] = '1:1:1:1'; - $spanContext = $Jaeger->extract(Formats\TEXT_MAP, $carrier); - $this->assertTrue($spanContext->parentId == 1); - $this->assertTrue($spanContext->traceIdLow == 1); - $this->assertTrue($spanContext->flags == 1); - $this->assertTrue($spanContext->spanId == 1); + $spanContext = $this->tracer->extract(Formats\TEXT_MAP, $carrier); + $this->assertTrue(1 == $spanContext->parentId); + $this->assertTrue(1 == $spanContext->traceIdLow); + $this->assertTrue(1 == $spanContext->flags); + $this->assertTrue(1 == $spanContext->spanId); } - - public function testExtractUnSupportFormat(){ - $Jaeger = $this->getJaeger(); - $Jaeger->setPropagator(new JaegerPropagator()); + /** + * @expectedException \OpenTracing\UnsupportedFormatException + */ + public function testExtractUnSupportFormat() + { + $this->tracer->setPropagator(new JaegerPropagator()); $_SERVER[strtoupper(Constants\Tracer_State_Header_Name)] = '1:1:1:1'; - $this->expectExceptionMessage('The format \'http_headers\' is not supported.'); + $this->expectExceptionMessage('The format "http_headers" is not supported.'); - $Jaeger->extract(Formats\HTTP_HEADERS, $_SERVER); + $this->tracer->extract(Formats\HTTP_HEADERS, $_SERVER); } - - public function testStartSpan(){ - $Jaeger = $this->getJaeger(); - $span = $Jaeger->startSpan('test'); - $this->assertNotEmpty($span->startTime); - $this->assertNotEmpty($Jaeger->getSpans()); + public function testStartSpan() + { + $span = $this->tracer->startSpan('test'); + $this->assertNotNull($span->startTime); + $this->assertNotEmpty($this->tracer->getSpans()); } - public function testStartSpanWithFollowsFromTypeRef() { - $jaeger = $this->getJaeger(); - $rootSpan = $jaeger->startSpan('root-a'); - $childSpan = $jaeger->startSpan('span-a', [ - 'references' => Reference::create(Reference::FOLLOWS_FROM, $rootSpan), + $rootSpan = $this->tracer->startSpan('root-a'); + $childSpan = $this->tracer->startSpan('span-a', [ + 'references' => Reference::createForSpan(Reference::FOLLOWS_FROM, $rootSpan), ]); $this->assertSame($childSpan->spanContext->traceIdLow, $rootSpan->spanContext->traceIdLow); - $this->assertSame(current($childSpan->references)->getContext(), $rootSpan->spanContext); + $this->assertSame(current($childSpan->references)->getSpanContext(), $rootSpan->spanContext); - $otherRootSpan = $jaeger->startSpan('root-a'); - $childSpan = $jaeger->startSpan('span-b', [ + $otherRootSpan = $this->tracer->startSpan('root-a'); + $childSpan = $this->tracer->startSpan('span-b', [ 'references' => [ - Reference::create(Reference::FOLLOWS_FROM, $rootSpan), - Reference::create(Reference::FOLLOWS_FROM, $otherRootSpan), + Reference::createForSpan(Reference::FOLLOWS_FROM, $rootSpan), + Reference::createForSpan(Reference::FOLLOWS_FROM, $otherRootSpan), ], ]); $this->assertSame($childSpan->spanContext->traceIdLow, $otherRootSpan->spanContext->traceIdLow); } - public function testStartSpanWithChildOfTypeRef() { - $jaeger = $this->getJaeger(); - $rootSpan = $jaeger->startSpan('root-a'); - $otherRootSpan = $jaeger->startSpan('root-b'); - $childSpan = $jaeger->startSpan('span-a', [ + $rootSpan = $this->tracer->startSpan('root-a'); + $otherRootSpan = $this->tracer->startSpan('root-b'); + $childSpan = $this->tracer->startSpan('span-a', [ 'references' => [ - Reference::create(Reference::CHILD_OF, $rootSpan), - Reference::create(Reference::CHILD_OF, $otherRootSpan), + Reference::createForSpan(Reference::CHILD_OF, $rootSpan), + Reference::createForSpan(Reference::CHILD_OF, $otherRootSpan), ], ]); $this->assertSame($childSpan->spanContext->traceIdLow, $rootSpan->spanContext->traceIdLow); } - public function testStartSpanWithCustomStartTime() { - $jaeger = $this->getJaeger(); - $span = $jaeger->startSpan('test', ['start_time' => 1499355363.123456]); + $span = $this->tracer->startSpan('test', ['start_time' => 1499355363.123456]); $this->assertSame(1499355363123456, $span->startTime); } - public function testStartSpanWithAllRefType() { - $jaeger = $this->getJaeger(); - $rootSpan = $jaeger->startSpan('root-a'); - $otherRootSpan = $jaeger->startSpan('root-b'); - $childSpan = $jaeger->startSpan('span-a', [ + $rootSpan = $this->tracer->startSpan('root-a'); + $otherRootSpan = $this->tracer->startSpan('root-b'); + $childSpan = $this->tracer->startSpan('span-a', [ 'references' => [ - Reference::create(Reference::FOLLOWS_FROM, $rootSpan), - Reference::create(Reference::CHILD_OF, $otherRootSpan), + Reference::createForSpan(Reference::FOLLOWS_FROM, $rootSpan), + Reference::createForSpan(Reference::CHILD_OF, $otherRootSpan), ], ]); $this->assertSame($childSpan->spanContext->traceIdLow, $otherRootSpan->spanContext->traceIdLow); } - - public function testReportSpan(){ - $Jaeger = $this->getJaeger(); - $Jaeger->startSpan('test'); - $Jaeger->reportSpan(); - $this->assertEmpty($Jaeger->getSpans()); + public function testReportSpan() + { + $this->tracer->startSpan('test'); + $this->tracer->reportSpan(); + $this->assertEmpty($this->tracer->getSpans()); } - public function testStartActiveSpan(){ - $Jaeger = $this->getJaeger(); - $Jaeger->startActiveSpan('test'); - - $this->assertNotEmpty($Jaeger->getSpans()); + public function testStartActiveSpan() + { + $this->tracer->startActiveSpan('test'); + $this->assertNotEmpty($this->tracer->getSpans()); } + public function testGetActiveSpan() + { + $this->tracer->startActiveSpan('test'); - public function testGetActiveSpan(){ - $Jaeger = $this->getJaeger(); - $Jaeger->startActiveSpan('test'); - - $span = $Jaeger->getActiveSpan(); - + $span = $this->tracer->getActiveSpan(); $this->assertInstanceOf(Span::class, $span); } - - public function testFlush(){ - $Jaeger = $this->getJaeger(); - $Jaeger->startSpan('test'); - $Jaeger->flush(); - $this->assertEmpty($Jaeger->getSpans()); + public function testFlush() + { + $this->tracer->startSpan('test'); + $this->tracer->flush(); + $this->assertEmpty($this->tracer->getSpans()); } - - public function testNestedSpanBaggage(){ - $tracer = $this->getJaeger(); - - $parent = $tracer->startSpan('parent'); + public function testNestedSpanBaggage() + { + $parent = $this->tracer->startSpan('parent'); $parent->addBaggageItem('key', 'value'); - $child = $tracer->startSpan('child', [Reference::CHILD_OF => $parent]); + $child = $this->tracer->startSpan('child', [Reference::CHILD_OF => $parent]); $this->assertEquals($parent->getBaggageItem('key'), $child->getBaggageItem('key')); } diff --git a/tests/JaegerThriftTest.php b/tests/JaegerThriftTest.php new file mode 100644 index 0000000..8a1bc1e --- /dev/null +++ b/tests/JaegerThriftTest.php @@ -0,0 +1,88 @@ +tracer = new Jaeger('jaeger', $reporter, $sampler, $scopeManager); + + $this->jaegerThrift = new JaegerThrift(); + } + + public function testBuildProcessThrift() + { + $process = $this->jaegerThrift->buildProcessThrift($this->tracer); + $this->assertEquals('jaeger', $process->serviceName); + } + + public function testBuildTags() + { + $tags = ['event' => 'test']; + $jtags = $this->jaegerThrift->buildTags($tags); + $this->assertEquals('event', $jtags[0]->key); + $this->assertEquals(TagType::STRING, $jtags[0]->vType); + $this->assertEquals('test', $jtags[0]->vStr); + + $tags = ['success' => true]; + $jtags = $this->jaegerThrift->buildTags($tags); + $this->assertEquals('success', $jtags[0]->key); + $this->assertEquals(TagType::BOOL, $jtags[0]->vType); + $this->assertTrue($jtags[0]->vBool); + + $tags = ['data' => [1, 2]]; + $jtags = $this->jaegerThrift->buildTags($tags); + $this->assertEquals('data', $jtags[0]->key); + $this->assertEquals(TagType::STRING, $jtags[0]->vType); + + $tags = ['num' => 1]; + $jtags = $this->jaegerThrift->buildTags($tags); + $this->assertEquals('num', $jtags[0]->key); + $this->assertEquals(TagType::LONG, $jtags[0]->vType); + $this->assertEquals(1, $jtags[0]->vDouble); + } + + public function testBuildSpanThrift() + { + $span = $this->tracer->startSpan('BuildSpanThrift'); + $jspan = $this->jaegerThrift->buildSpanThrift($span); + $this->assertEquals('BuildSpanThrift', $jspan->operationName); + } +} diff --git a/tests/Propagator/JaegerPropagatorTest.php b/tests/Propagator/JaegerPropagatorTest.php index 937a4e7..b1475b3 100644 --- a/tests/Propagator/JaegerPropagatorTest.php +++ b/tests/Propagator/JaegerPropagatorTest.php @@ -15,100 +15,102 @@ namespace tests; -use PHPUnit\Framework\TestCase; -use OpenTracing\Formats; use Jaeger\Constants; -use Jaeger\SpanContext; use Jaeger\Propagator\JaegerPropagator; +use Jaeger\SpanContext; +use OpenTracing\Formats; +use PHPUnit\Framework\TestCase; -class JaegerPropagatorTest extends TestCase{ +class JaegerPropagatorTest extends TestCase +{ + /** + * @var SpanContext|null + */ + public $spanContext = null; - public function getSpanContext(){ - return new SpanContext(1562237095801441413, 0, 1, null, 1); + public function setUp() + { + $this->spanContext = new SpanContext(1, 1, 1, null, 1); } - - public function testInject(){ - $context = $this->getSpanContext(); - $context->traceIdLow = 1562237095801441413; + public function testInject() + { + $this->spanContext->traceIdLow = 1562237095801441413; $jaeger = new JaegerPropagator(); $carrier = []; - $jaeger->inject($context, Formats\TEXT_MAP, $carrier); - $this->assertTrue($carrier[strtoupper(Constants\Tracer_State_Header_Name)] == '15ae2e5c8e2ecc85:15ae2e5c8e2ecc85:0:1'); + $jaeger->inject($this->spanContext, Formats\TEXT_MAP, $carrier); + $this->assertTrue('15ae2e5c8e2ecc85:1:1:1' == $carrier[strtoupper(Constants\Tracer_State_Header_Name)]); } - - public function testInject128Bit(){ - $context = $this->getSpanContext(); - $context->traceIdLow = 1562289663898779811; - $context->traceIdHigh = 1562289663898881723; + public function testInject128Bit() + { + $this->spanContext->traceIdLow = 1562289663898779811; + $this->spanContext->traceIdHigh = 1562289663898881723; $jaeger = new JaegerPropagator(); $carrier = []; - $jaeger->inject($context, Formats\TEXT_MAP, $carrier); - $this->assertTrue($carrier[strtoupper(Constants\Tracer_State_Header_Name)] - == '15ae5e2c04f50ebb15ae5e2c04f380a3:15ae2e5c8e2ecc85:0:1'); + $jaeger->inject($this->spanContext, Formats\TEXT_MAP, $carrier); + $this->assertTrue('15ae5e2c04f50ebb15ae5e2c04f380a3:1:1:1' + == $carrier[strtoupper(Constants\Tracer_State_Header_Name)]); } - - public function testExtract(){ - + public function testExtract() + { $jaeger = new JaegerPropagator(); $carrier = []; $carrier[strtoupper(Constants\Tracer_State_Header_Name)] = '15ae2e5c8e2ecc85:15ae2e5c8e2ecc85:0:1'; $context = $jaeger->extract(Formats\TEXT_MAP, $carrier); - $this->assertTrue($context->traceIdLow == 1562237095801441413); - $this->assertTrue($context->parentId == 0); - $this->assertTrue($context->spanId == 1562237095801441413); - $this->assertTrue($context->flags == 1); + $this->assertTrue(1562237095801441413 == $context->traceIdLow); + $this->assertTrue(0 == $context->parentId); + $this->assertTrue(1562237095801441413 == $context->spanId); + $this->assertTrue(1 == $context->flags); } - - public function testExtractDebugId(){ - + public function testExtractDebugId() + { $jaeger = new JaegerPropagator(); - $carrier[Constants\Trace_Baggage_Header_Prefix . 'baggage'] = 2; + $carrier[Constants\Trace_Baggage_Header_Prefix.'baggage'] = 2; $context = $jaeger->extract(Formats\TEXT_MAP, $carrier); - $this->assertTrue($context->debugId == 0); + $this->assertTrue(0 == $context->debugId); $carrier[Constants\Jaeger_Debug_Header] = 1; $context = $jaeger->extract(Formats\TEXT_MAP, $carrier); - $this->assertTrue($context->debugId == 1); + $this->assertTrue(1 == $context->debugId); } - - public function testExtractUberctx(){ + public function testExtractUberctx() + { $jaeger = new JaegerPropagator(); $carrier[Constants\Trace_Baggage_Header_Prefix] = '2.0.0'; $carrier[Constants\Jaeger_Debug_Header] = true; $context = $jaeger->extract(Formats\TEXT_MAP, $carrier); - $this->assertTrue($context->baggage == null); + $this->assertTrue(null == $context->baggage); $carrier = []; $carrier[Constants\Trace_Baggage_Header_Prefix.'version'] = '2.0.0'; $context = $jaeger->extract(Formats\TEXT_MAP, $carrier); - $this->assertTrue($context->getBaggageItem('version') == '2.0.0'); + $this->assertTrue('2.0.0' == $context->getBaggageItem('version')); } - - public function testExtractBaggageHeader(){ + public function testExtractBaggageHeader() + { $jaeger = new JaegerPropagator(); $carrier = []; $carrier[Constants\Jaeger_Baggage_Header] = 'version=2.0.0,os=1'; $context = $jaeger->extract(Formats\TEXT_MAP, $carrier); - $this->assertTrue($context->getBaggageItem('version') == '2.0.0'); - $this->assertTrue($context->getBaggageItem('os') == '1'); + $this->assertTrue('2.0.0' == $context->getBaggageItem('version')); + $this->assertTrue('1' == $context->getBaggageItem('os')); } - - public function testExtractBadBaggageHeader(){ + public function testExtractBadBaggageHeader() + { $jaeger = new JaegerPropagator(); $carrier = []; @@ -116,41 +118,39 @@ public function testExtractBadBaggageHeader(){ $carrier[Constants\Jaeger_Baggage_Header] = 'version'; $carrier[Constants\Jaeger_Debug_Header] = true; $context = $jaeger->extract(Formats\TEXT_MAP, $carrier); - $this->assertTrue($context->baggage == null); + $this->assertTrue(null == $context->baggage); } - - public function testExtract128Bit(){ - + public function testExtract128Bit() + { $jaeger = new JaegerPropagator(); $carrier = []; $carrier[strtoupper(Constants\Tracer_State_Header_Name)] = '15ae5e2c04f50ebb15ae5e2c04f380a3:15ae2e5c8e2ecc85:0:1'; $context = $jaeger->extract(Formats\TEXT_MAP, $carrier); - $this->assertTrue($context->traceIdLow == 1562289663898779811); - $this->assertTrue($context->traceIdHigh == 1562289663898881723); - $this->assertTrue($context->parentId == 0); - $this->assertTrue($context->spanId == 1562237095801441413); - $this->assertTrue($context->flags == 1); + $this->assertTrue(1562289663898779811 == $context->traceIdLow); + $this->assertTrue(1562289663898881723 == $context->traceIdHigh); + $this->assertTrue(0 == $context->parentId); + $this->assertTrue(1562237095801441413 == $context->spanId); + $this->assertTrue(1 == $context->flags); } - - public function testExtractPsr7(){ - + public function testExtractPsr7() + { $jaeger = new JaegerPropagator(); $carrier = []; $carrier[] = [strtoupper(Constants\Tracer_State_Header_Name) => '15ae2e5c8e2ecc85:15ae2e5c8e2ecc85:0:1']; $context = $jaeger->extract(Formats\TEXT_MAP, $carrier); - $this->assertTrue($context->traceIdLow == 1562237095801441413); - $this->assertTrue($context->parentId == 0); - $this->assertTrue($context->spanId == 1562237095801441413); - $this->assertTrue($context->flags == 1); + $this->assertTrue(1562237095801441413 == $context->traceIdLow); + $this->assertTrue(0 == $context->parentId); + $this->assertTrue(1562237095801441413 == $context->spanId); + $this->assertTrue(1 == $context->flags); } - - public function testExtractReturnsNull(){ + public function testExtractReturnsNull() + { $jaeger = new JaegerPropagator(); $carrier = []; diff --git a/tests/Propagator/ZipkinPropagatorTest.php b/tests/Propagator/ZipkinPropagatorTest.php index 94a3c28..bafe717 100644 --- a/tests/Propagator/ZipkinPropagatorTest.php +++ b/tests/Propagator/ZipkinPropagatorTest.php @@ -15,52 +15,56 @@ namespace tests; -use PHPUnit\Framework\TestCase; -use OpenTracing\Formats; use Jaeger\Constants; -use Jaeger\SpanContext; use Jaeger\Propagator\ZipkinPropagator; +use Jaeger\SpanContext; +use OpenTracing\Formats; +use PHPUnit\Framework\TestCase; -class ZipkinPropagatorTest extends TestCase{ +class ZipkinPropagatorTest extends TestCase +{ + /** + * @var SpanContext|null + */ + public $spanContext = null; - public function getSpanContext(){ - return new SpanContext(1562237095801441413, 0, 1, null, 1); + public function setUp() + { + $this->spanContext = new SpanContext(1, 1, 1, null, 1); } - - public function testInject(){ - $context = $this->getSpanContext(); - $context->traceIdLow = 1562237095801441413; + public function testInject() + { + $this->spanContext->traceIdLow = 1562237095801441413; $zipkin = new ZipkinPropagator(); $carrier = []; - $zipkin->inject($context, Formats\TEXT_MAP, $carrier); + $zipkin->inject($this->spanContext, Formats\TEXT_MAP, $carrier); - $this->assertTrue($carrier[Constants\X_B3_TRACEID] == '15ae2e5c8e2ecc85'); - $this->assertTrue($carrier[Constants\X_B3_PARENT_SPANID] == 0); - $this->assertTrue($carrier[Constants\X_B3_SPANID] == '15ae2e5c8e2ecc85'); - $this->assertTrue($carrier[Constants\X_B3_SAMPLED] == 1); + $this->assertTrue('15ae2e5c8e2ecc85' == $carrier[Constants\X_B3_TRACEID]); + $this->assertTrue(1 == $carrier[Constants\X_B3_PARENT_SPANID]); + $this->assertTrue(1 == $carrier[Constants\X_B3_SPANID]); + $this->assertTrue(1 == $carrier[Constants\X_B3_SAMPLED]); } - - public function testInject128Bit(){ - $context = $this->getSpanContext(); - $context->traceIdLow = 1562289663898779811; - $context->traceIdHigh = 1562289663898881723; + public function testInject128Bit() + { + $this->spanContext->traceIdLow = 1562289663898779811; + $this->spanContext->traceIdHigh = 1562289663898881723; $zipkin = new ZipkinPropagator(); $carrier = []; - $zipkin->inject($context, Formats\TEXT_MAP, $carrier); + $zipkin->inject($this->spanContext, Formats\TEXT_MAP, $carrier); - $this->assertTrue($carrier[Constants\X_B3_TRACEID] == '15ae5e2c04f50ebb15ae5e2c04f380a3'); - $this->assertTrue($carrier[Constants\X_B3_PARENT_SPANID] == 0); - $this->assertTrue($carrier[Constants\X_B3_SPANID] == '15ae2e5c8e2ecc85'); - $this->assertTrue($carrier[Constants\X_B3_SAMPLED] == 1); + $this->assertTrue('15ae5e2c04f50ebb15ae5e2c04f380a3' == $carrier[Constants\X_B3_TRACEID]); + $this->assertTrue(1 == $carrier[Constants\X_B3_PARENT_SPANID]); + $this->assertTrue(1 == $carrier[Constants\X_B3_SPANID]); + $this->assertTrue(1 == $carrier[Constants\X_B3_SAMPLED]); } - public function testExtract(){ - + public function testExtract() + { $zipkin = new ZipkinPropagator(); $carrier = []; $carrier[Constants\X_B3_TRACEID] = '15ae2e5c8e2ecc85'; @@ -69,15 +73,14 @@ public function testExtract(){ $carrier[Constants\X_B3_SAMPLED] = 1; $context = $zipkin->extract(Formats\TEXT_MAP, $carrier); - $this->assertTrue($context->traceIdLow == '1562237095801441413'); - $this->assertTrue($context->parentId == 1); - $this->assertTrue($context->spanId == '1562237095801441413'); - $this->assertTrue($context->flags == 1); + $this->assertTrue('1562237095801441413' == $context->traceIdLow); + $this->assertTrue(1 == $context->parentId); + $this->assertTrue('1562237095801441413' == $context->spanId); + $this->assertTrue(1 == $context->flags); } - - public function testExtract128Bit(){ - + public function testExtract128Bit() + { $zipkin = new ZipkinPropagator(); $carrier = []; $carrier[Constants\X_B3_TRACEID] = '15ae5e2c04f50ebb15ae5e2c04f380a3'; @@ -86,15 +89,15 @@ public function testExtract128Bit(){ $carrier[Constants\X_B3_SAMPLED] = 1; $context = $zipkin->extract(Formats\TEXT_MAP, $carrier); - $this->assertTrue($context->traceIdLow == 1562289663898779811); - $this->assertTrue($context->traceIdHigh == 1562289663898881723); - $this->assertTrue($context->parentId == 0); - $this->assertTrue($context->spanId == 1562289663898779811); - $this->assertTrue($context->flags == 1); + $this->assertTrue(1562289663898779811 == $context->traceIdLow); + $this->assertTrue(1562289663898881723 == $context->traceIdHigh); + $this->assertTrue(0 == $context->parentId); + $this->assertTrue(1562289663898779811 == $context->spanId); + $this->assertTrue(1 == $context->flags); } - - public function testExtractReturnsNull(){ + public function testExtractReturnsNull() + { $jaeger = new ZipkinPropagator(); $carrier = []; diff --git a/tests/Reporter/RemoteReporterTest.php b/tests/Reporter/RemoteReporterTest.php index 4b841fa..9d96877 100644 --- a/tests/Reporter/RemoteReporterTest.php +++ b/tests/Reporter/RemoteReporterTest.php @@ -15,18 +15,18 @@ namespace tests; -use PHPUnit\Framework\TestCase; use Jaeger\SpanContext; +use PHPUnit\Framework\TestCase; -class RemoteReporterTest extends TestCase{ - - public function getSpanContext(){ +class RemoteReporterTest extends TestCase +{ + public function getSpanContext() + { return new SpanContext(1562237095801441413, 0, 1, null, 1); } - - public function testClose(){ + public function testClose() + { $this->assertTrue(true); } - -} \ No newline at end of file +} diff --git a/tests/Sampler/ConstSamplerTest.php b/tests/Sampler/ConstSamplerTest.php index d4f5487..d90e3b4 100644 --- a/tests/Sampler/ConstSamplerTest.php +++ b/tests/Sampler/ConstSamplerTest.php @@ -15,21 +15,22 @@ namespace tests; +use Jaeger\Constants; use Jaeger\Sampler\ConstSampler; use PHPUnit\Framework\TestCase; -use Jaeger\Constants; class ConstSamplerTest extends TestCase { - - public function testConstSampler(){ + public function testConstSampler() + { $sample = new ConstSampler(true); - $this->assertTrue($sample->IsSampled() == true); + $this->assertTrue(true == $sample->IsSampled()); } - public function testConstSamplerGetTag(){ + public function testConstSamplerGetTag() + { $sample = new ConstSampler(true); $tags = $sample->getTags(); - $this->assertTrue($tags[Constants\SAMPLER_TYPE_TAG_KEY] == 'const'); + $this->assertTrue('const' == $tags[Constants\SAMPLER_TYPE_TAG_KEY]); } -} \ No newline at end of file +} diff --git a/tests/Sampler/ProbabilisticSamplerTest.php b/tests/Sampler/ProbabilisticSamplerTest.php index 48646db..68d4b1f 100644 --- a/tests/Sampler/ProbabilisticSamplerTest.php +++ b/tests/Sampler/ProbabilisticSamplerTest.php @@ -15,21 +15,22 @@ namespace tests; +use Jaeger\Constants; use Jaeger\Sampler\ProbabilisticSampler; use PHPUnit\Framework\TestCase; -use Jaeger\Constants; class ProbabilisticSamplerTest extends TestCase { - - public function testProbabilisticSampler(){ + public function testProbabilisticSampler() + { $sample = new ProbabilisticSampler(0.0001); - $this->assertTrue($sample->IsSampled() !== null); + $this->assertTrue(null !== $sample->IsSampled()); } - public function testConstSamplerGetTag(){ + public function testConstSamplerGetTag() + { $sample = new ProbabilisticSampler(0.0001); $tags = $sample->getTags(); - $this->assertTrue($tags[Constants\SAMPLER_TYPE_TAG_KEY] == 'probabilistic'); + $this->assertTrue('probabilistic' == $tags[Constants\SAMPLER_TYPE_TAG_KEY]); } -} \ No newline at end of file +} diff --git a/tests/ScopeMangerTest.php b/tests/ScopeMangerTest.php index b1d515e..331aaaa 100644 --- a/tests/ScopeMangerTest.php +++ b/tests/ScopeMangerTest.php @@ -15,15 +15,15 @@ namespace tests; -use OpenTracing\NoopSpanContext; +use Jaeger\ScopeManager; use Jaeger\Span; +use OpenTracing\NoopSpanContext; use PHPUnit\Framework\TestCase; -use Jaeger\ScopeManager; class ScopeMangerTest extends TestCase { - - public function testActivate(){ + public function testActivate() + { $span1 = new Span('test', new NoopSpanContext(), []); $scopeManager = new ScopeManager(); @@ -33,8 +33,8 @@ public function testActivate(){ $this->assertTrue($span1 === $span2); } - public function testGetActive(){ - + public function testGetActive() + { $span = new Span('test', new NoopSpanContext(), []); $scopeManager = new ScopeManager(); @@ -44,22 +44,22 @@ public function testGetActive(){ $this->assertTrue($scope1 === $scope2); } - - public function testDelActive(){ - + public function testDelActive() + { $span = new Span('test', new NoopSpanContext(), []); $scopeManager = new ScopeManager(); $scope = $scopeManager->activate($span, true); - $res = $scopeManager->delActive($scope); - $this->assertTrue($res == true); + $res = $scopeManager->deactivate($scope); + $this->assertTrue(true == $res); $getRes = $scopeManager->getActive(); - $this->assertTrue($getRes === null); + $this->assertTrue(null === $getRes); } - public function testDelActiveNestedScopes() { + public function testDelActiveNestedScopes() + { $scopeManager = new ScopeManager(); $span1 = new Span('Z', new NoopSpanContext(), []); $scope1 = $scopeManager->activate($span1, true); @@ -71,23 +71,24 @@ public function testDelActiveNestedScopes() { $active = $scopeManager->getActive(); $this->assertTrue($active === $scope3); - $res = $scopeManager->delActive($scope3); - $this->assertTrue($res == true); + $res = $scopeManager->deactivate($scope3); + $this->assertTrue(true == $res); $active = $scopeManager->getActive(); $this->assertTrue($active === $scope2); - $res = $scopeManager->delActive($scope2); - $this->assertTrue($res == true); + $res = $scopeManager->deactivate($scope2); + $this->assertTrue(true == $res); $active = $scopeManager->getActive(); $this->assertTrue($active === $scope1); - $res = $scopeManager->delActive($scope1); - $this->assertTrue($res == true); + $res = $scopeManager->deactivate($scope1); + $this->assertTrue(true == $res); $active = $scopeManager->getActive(); - $this->assertTrue($active === null); + $this->assertTrue(null === $active); } - public function testDelActiveReNestScopes() { + public function testDelActiveReNestScopes() + { $scopeManager = new ScopeManager(); $span1 = new Span('A', new NoopSpanContext(), []); $scope1 = $scopeManager->activate($span1, true); @@ -98,7 +99,7 @@ public function testDelActiveReNestScopes() { $this->assertTrue($active === $scope2); // Remove scope2 so that scope1 is active - $scopeManager->delActive($scope2); + $scopeManager->deactivate($scope2); $active = $scopeManager->getActive(); $this->assertTrue($active === $scope1); @@ -109,12 +110,12 @@ public function testDelActiveReNestScopes() { $this->assertTrue($active === $scope3); // Delete active scope3 - $scopeManager->delActive($scope3); + $scopeManager->deactivate($scope3); $active = $scopeManager->getActive(); $this->assertTrue($active === $scope1); - $scopeManager->delActive($scope1); + $scopeManager->deactivate($scope1); $active = $scopeManager->getActive(); - $this->assertTrue($active === null); + $this->assertTrue(null === $active); } -} \ No newline at end of file +} diff --git a/tests/ScopeTest.php b/tests/ScopeTest.php index 1e182b2..03a3131 100644 --- a/tests/ScopeTest.php +++ b/tests/ScopeTest.php @@ -15,31 +15,31 @@ namespace tests; -use OpenTracing\NoopSpanContext; +use Jaeger\ScopeManager; use Jaeger\Span; +use OpenTracing\NoopSpanContext; use PHPUnit\Framework\TestCase; -use Jaeger\ScopeManager; class ScopeTest extends TestCase { - - public function testClose(){ + public function testClose() + { $span1 = new Span('test', new NoopSpanContext(), []); $scopeManager = new ScopeManager(); $scope = $scopeManager->activate($span1, true); $scope->close(); - $this->assertTrue($scopeManager->getActive() === null); + $this->assertTrue(null === $scopeManager->getActive()); } - - public function testGetSpan(){ + public function testGetSpan() + { $span1 = new Span('test', new NoopSpanContext(), []); $scopeManager = new ScopeManager(); $scope = $scopeManager->activate($span1, true); - $this->assertTrue($scope->getSpan() !== null); + $this->assertTrue(null !== $scope->getSpan()); } -} \ No newline at end of file +} diff --git a/tests/Sender/UdpSenderTest.php b/tests/Sender/UdpSenderTest.php new file mode 100644 index 0000000..ce172e9 --- /dev/null +++ b/tests/Sender/UdpSenderTest.php @@ -0,0 +1,114 @@ +tran = new TMemoryBuffer(); + $this->protocol = new TCompactProtocol($this->tran); + $this->agentClient = (new AgentClient($this->protocol, null)); + $this->udpSender = new UdpSender('localhost:6831', $this->agentClient, $this->tran); + } + + public function testIsOpen() + { + $this->assertTrue($this->udpSender->isOpen()); + } + + public function testClose() + { + $this->udpSender->close(); + $this->assertFalse($this->udpSender->isOpen()); + } + + public function testEmitBatch() + { + $span = new \Jaeger\Thrift\Span( + [ + 'traceIdLow' => 1609214197859399756, + 'traceIdHigh' => 1609214197860113544, + 'spanId' => 1609214197859399756, + 'parentSpanId' => 0, + 'operationName' => 'test', + 'flags' => 1, + 'startTime' => 1609214197860775, + 'duration' => 3216877, + 'tags' => [], + 'logs' => [], + ] + ); + + $batch = new \Jaeger\Thrift\Batch( + [ + 'process' => new \Jaeger\Thrift\Process([ + 'serviceName' => 'EmitBatch', + 'tags' => [ + (new \Jaeger\Thrift\Tag([ + 'key' => 'peer.ipv4', + 'vType' => 0, + 'vStr' => '0.0.0.0', + ])), + (new \Jaeger\Thrift\Tag([ + 'key' => 'peer.port', + 'vType' => 0, + 'vStr' => '80', + ])), + (new \Jaeger\Thrift\Tag([ + 'key' => 'sampler.type', + 'vType' => 0, + 'vStr' => 'const', + ])), + (new \Jaeger\Thrift\Tag([ + 'key' => 'sampler.param', + 'vType' => 2, + 'vBool' => true, + ])), + ], + ]), + 'spans' => [$span], + ] + ); + $this->assertTrue($this->udpSender->emitBatch($batch)); + } +} diff --git a/tests/SpanContextTest.php b/tests/SpanContextTest.php index 8f7dae2..632efe0 100644 --- a/tests/SpanContextTest.php +++ b/tests/SpanContextTest.php @@ -15,85 +15,81 @@ namespace tests; -use PHPUnit\Framework\TestCase; use Jaeger\SpanContext; +use PHPUnit\Framework\TestCase; class SpanContextTest extends TestCase { - - - public function getSpanContext(){ - return new SpanContext(1, 1, 1, null, 1); + /** + * @var SpanContext|null + */ + public $spanContext = null; + + public function setUp() + { + $this->spanContext = new SpanContext(1, 1, 1, null, 1); } - - public function testNew(){ - $spanContext = $this->getSpanContext(); - $this->assertInstanceOf(SpanContext::class, $spanContext); + public function testNew() + { + $this->assertInstanceOf(SpanContext::class, $this->spanContext); } - - public function testWithBaggageItem(){ - $spanContext = $this->getSpanContext(); - $res = $spanContext->withBaggageItem('version', '2.0.0'); - $this->assertTrue($res); + public function testWithBaggageItem() + { + $res = $this->spanContext->withBaggageItem('version', '2.0.0'); + // TODO + // $this->assertTrue($res); } + public function testGetBaggageItem() + { + $this->spanContext->withBaggageItem('version', '2.0.0'); - public function testGetBaggageItem(){ - $spanContext = $this->getSpanContext(); - $res = $spanContext->withBaggageItem('version', '2.0.0'); + $version = $this->spanContext->getBaggageItem('version'); - $version = $spanContext->getBaggageItem('version'); - $this->assertTrue($res == $version); + $this->assertTrue('2.0.0' === $version); - $service = $spanContext->getBaggageItem('service'); + $service = $this->spanContext->getBaggageItem('service'); $this->assertNull($service); } + public function testBuildString() + { + $this->spanContext->traceIdLow = 1; + $this->assertTrue('1:1:1:1' == $this->spanContext->buildString()); - public function testBuildString(){ - $spanContext = $this->getSpanContext(); - $spanContext->traceIdLow = 1; - $this->assertTrue($spanContext->buildString() == '1:1:1:1'); - - $spanContext->traceIdHigh = 1; - $this->assertTrue($spanContext->buildString() == '10000000000000001:1:1:1'); + $this->spanContext->traceIdHigh = 1; + $this->assertTrue('10000000000000001:1:1:1' == $this->spanContext->buildString()); } + public function testSpanIdToString() + { + $this->assertTrue('1' == $this->spanContext->spanIdToString()); - public function testSpanIdToString(){ - $spanContext = $this->getSpanContext(); - $this->assertTrue($spanContext->spanIdToString() == '1'); - - $spanContext->spanId = "111111"; - $this->assertTrue($spanContext->spanIdToString() == '1b207'); + $this->spanContext->spanId = '111111'; + $this->assertTrue('1b207' == $this->spanContext->spanIdToString()); } + public function testTraceIdLowToString() + { + $this->spanContext->traceIdLow = '111111'; + $this->assertTrue('1b207' == $this->spanContext->traceIdLowToString()); - public function testTraceIdLowToString(){ - $spanContext = $this->getSpanContext(); - $spanContext->traceIdLow = "111111"; - $this->assertTrue($spanContext->traceIdLowToString() == '1b207'); - - $spanContext->traceIdHigh = "111111"; - $this->assertTrue($spanContext->traceIdLowToString() == '1b207000000000001b207'); + $this->spanContext->traceIdHigh = '111111'; + $this->assertTrue('1b207000000000001b207' == $this->spanContext->traceIdLowToString()); } - - public function testTraceIdToString(){ - $spanContext = $this->getSpanContext(); - $spanContext->traceIdToString('1b207000000000001b207'); - $this->assertTrue($spanContext->traceIdLow == '111111'); - $this->assertTrue($spanContext->traceIdHigh == '1954685383581106176'); - - $spanContext->traceIdLow = null; - $spanContext->traceIdHigh = null; - $spanContext->traceIdToString('1b207'); - $this->assertTrue($spanContext->traceIdLow == '111111'); - $this->assertTrue(!$spanContext->traceIdHigh); + public function testTraceIdToString() + { + $this->spanContext->traceIdToString('1b207000000000001b207'); + $this->assertTrue('111111' == $this->spanContext->traceIdLow); + $this->assertTrue('1954685383581106176' == $this->spanContext->traceIdHigh); + + $this->spanContext->traceIdLow = null; + $this->spanContext->traceIdHigh = null; + $this->spanContext->traceIdToString('1b207'); + $this->assertTrue('111111' == $this->spanContext->traceIdLow); + $this->assertTrue(null === $this->spanContext->traceIdHigh); } - - - -} \ No newline at end of file +} diff --git a/tests/SpanTest.php b/tests/SpanTest.php index d3fd48a..9a86d9a 100644 --- a/tests/SpanTest.php +++ b/tests/SpanTest.php @@ -15,63 +15,62 @@ namespace tests; +use Jaeger\Span; use Jaeger\SpanContext; use OpenTracing\NoopSpanContext; -use Jaeger\Span; use PHPUnit\Framework\TestCase; class SpanTest extends TestCase { - - public function testOverwriteOperationName(){ + public function testOverwriteOperationName() + { $span = new Span('test', new NoopSpanContext(), []); $span->overwriteOperationName('test2'); - $this->assertTrue($span->getOperationName() == 'test2'); + $this->assertTrue('test2' == $span->getOperationName()); } - - public function testAddTags(){ + public function testAddTags() + { $span = new Span('test', new NoopSpanContext(), []); $span->setTag('test', 'test'); - $this->assertTrue((isset($span->tags['test']) && $span->tags['test'] == 'test')); + $this->assertTrue((isset($span->tags['test']) && 'test' == $span->tags['test'])); } - - public function testFinish(){ + public function testFinish() + { $span = new Span('test', new NoopSpanContext(), []); $span->setTag('test', 'test'); $span->finish(); - $this->assertTrue(!empty($span->finishTime) && !empty($span->duration)); + $this->assertTrue(null !== $span->finishTime && null !== $span->duration); } - - public function testGetContext(){ + public function testGetContext() + { $span = new Span('test', new NoopSpanContext(), []); $spanContext = $span->getContext(); $this->assertInstanceOf(NoopSpanContext::class, $spanContext); } - - - public function testLog(){ + public function testLog() + { $span = new Span('test', new NoopSpanContext(), []); $logs = [ 'msg' => 'is test', - 'msg2' => 'is msg 2' + 'msg2' => 'is msg 2', ]; $span->log($logs); - $this->assertTrue(count($span->logs) == 1); + $this->assertTrue(1 == count($span->logs)); } - - public function testGetBaggageItem(){ + public function testGetBaggageItem() + { $span = new Span('test', new SpanContext(0, 0, 0), []); $span->addBaggageItem('version', '2.0.0'); - $version = $span->getBaggageItem('version'); + $version = $span->getBaggageItem('version'); $this->assertEquals('2.0.0', $version); $service = $span->getBaggageItem('service'); $this->assertNull($service); } -} \ No newline at end of file +} diff --git a/tests/Transport/TransportUdpTest.php b/tests/Transport/TransportUdpTest.php index ece8d08..e216e0f 100644 --- a/tests/Transport/TransportUdpTest.php +++ b/tests/Transport/TransportUdpTest.php @@ -15,28 +15,72 @@ namespace tests; -use PHPUnit\Framework\TestCase; +use Jaeger\Jaeger; +use Jaeger\Reporter\RemoteReporter; +use Jaeger\Sampler\ConstSampler; +use Jaeger\ScopeManager; +use Jaeger\Sender\Sender; use Jaeger\Transport\TransportUdp; +use PHPUnit\Framework\TestCase; class TransportUdpTest extends TestCase { - + /** + * @var TransportUdp|null + */ public $tran = null; - public function setUp(){ - $this->tran = new TransportUdp('localhost:6831'); + /** + * @var Jaeger|null + */ + public $tracer = null; + + public function setUp() + { + $senderMock = $this->createMock(Sender::class); + $senderMock->method('emitBatch')->willReturn(true); + + $this->tran = new TransportUdp('localhost:6831', 0, $senderMock); + + $reporter = new RemoteReporter($this->tran); + $sampler = new ConstSampler(); + $scopeManager = new ScopeManager(); + + $this->tracer = new Jaeger('jaeger', $reporter, $sampler, $scopeManager); } + public function testBuildAndCalcSizeOfProcessThrift() + { + $span = $this->tracer->startSpan('BuildAndCalcSizeOfProcessThrift'); + $span->finish(); + $this->tran->buildAndCalcSizeOfProcessThrift($this->tracer); + $this->assertEquals(95, $this->tran->procesSize); + } -// public function testFlush(){ -// $this->tran->append(); +// public function testSpanIsTooLarge() +// { +// $this->tran::$maxSpanBytes = 50; +// $span = $this->tracer->startSpan('SpanIsTooLarge'); +// $span->finish(); +// $this->tran->append($this->tracer); // } + public function testSplitEmit() + { + $i = 0; + $this->tran::$maxSpanBytes = 150; + $span = $this->tracer->startSpan('SplitEmit1'); + ++$i; + $span->finish(); - public function testResetBuffer(){ - $this->tran->resetBuffer(); - $this->assertCount(0, $this->tran->getBatchs()); + $span = $this->tracer->startSpan('SplitEmit2'); + ++$i; + $span->finish(); - } + $span = $this->tracer->startSpan('SplitEmit3'); + ++$i; + $span->finish(); -} \ No newline at end of file + $this->tran->append($this->tracer); + } +} diff --git a/tests/UdpClientTest.php b/tests/UdpClientTest.php deleted file mode 100644 index 20db1f7..0000000 --- a/tests/UdpClientTest.php +++ /dev/null @@ -1,71 +0,0 @@ -agentClient = $this->createMock(AgentClient::class); - $this->udpClient = new UdpClient('localhost:6831', $this->agentClient); - } - - - public function testIsOpen(){ - $this->assertTrue($this->udpClient->isOpen()); - } - - - public function testEmitBatch(){ - - $this->agentClient->expects($this->once())->method('buildThrift') - ->willReturn(['len'=> 3 , 'thriftStr' => 123]); - $batch = ['thriftProcess' => '' - , 'thriftSpans' => '']; - - $this->assertTrue($this->udpClient->emitBatch($batch)); - } - - - public function testEmitBatchFalse(){ - $batch = ['thriftProcess' => '' - , 'thriftSpans' => '']; - - $this->agentClient->expects($this->any())->method('buildThrift') - ->willReturn(['thriftStr' => 123]); - - $this->assertFalse($this->udpClient->emitBatch($batch)); - - $this->udpClient->close(); - $this->agentClient->expects($this->any())->method('buildThrift') - ->willReturn(['len'=> 3 , 'thriftStr' => 123]); - - - $this->assertFalse($this->udpClient->emitBatch($batch)); - } - - public function testClose(){ - $this->udpClient->close(); - $this->assertFalse($this->udpClient->isOpen()); - } -} \ No newline at end of file