diff --git a/README.md b/README.md index 8bdda24..47137ff 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,8 @@ [![Minimum PHP Version](https://img.shields.io/badge/php-%3E%3D%205.6-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) +[![Latest Stable Version](https://img.shields.io/packagist/v/jukylin/jaeger-php.svg)](https://packagist.org/packages/jukylin/jaeger-php) + # jaeger-php ## principle of Distributed Tracing @@ -68,7 +70,7 @@ $clientTrace->inject($clientSapn1->spanContext, Formats\TEXT_MAP, $_SERVER); ``` //can search in Jaeger UI -$span->addTags(['http.status' => "200"]); +$span->setTag('http.status', "200"); //log record $span->log(['error' => "HTTP request timeout"]); diff --git a/example/HTTP.php b/example/HTTP.php index ba3fa96..191af52 100644 --- a/example/HTTP.php +++ b/example/HTTP.php @@ -37,7 +37,7 @@ $serverSpan->addBaggageItem("version", "1.8.9"); print_r($serverSpan->getContext()); $tracer->inject($serverSpan->getContext(), Formats\TEXT_MAP, $_SERVER); -print_r($_SERVER);exit; + //init server span end $clientTracer = $config->initTracer('HTTP'); @@ -52,8 +52,10 @@ $client = new Client(); $res = $client->request($method, $url,['headers' => $injectTarget1]); -$clientSapn1->setTags(['http.status_code' => 200 - , 'http.method' => 'GET', 'http.url' => $url]); +$clientSapn1->setTag('http.status_code', 200); +$clientSapn1->setTag('http.method', 'GET'); +$clientSapn1->setTag('http.url', $url); + $clientSapn1->log(['message' => "HTTP1 ". $method .' '. $url .' end !']); $clientSapn1->finish(); //client span1 end @@ -74,8 +76,10 @@ $client = new Client(); $res = $client->request($method, $url, ['headers' => $injectTarget2]); -$clientSpan2->setTags(['http.status_code' => 200 - , 'http.method' => 'GET', 'http.url' => $url]); +$clientSpan2->setTag('http.status_code', 200); +$clientSpan2->setTag('http.method', 'GET'); +$clientSpan2->setTag('http.url', $url); + $clientSpan2->log(['message' => "HTTP2 ". $method .' '. $url .' end !']); $clientSpan2->finish(); //client span2 end diff --git a/example/HTTP2.php b/example/HTTP2.php index 3d263a6..c217498 100644 --- a/example/HTTP2.php +++ b/example/HTTP2.php @@ -13,7 +13,7 @@ //init server span start $config = Config::getInstance(); -$tracer = $config->initTrace('example', '0.0.0.0:6831'); +$tracer = $config->initTracer('example', '0.0.0.0:6831'); $top = $tracer->startActiveSpan('level top'); $second = $tracer->startActiveSpan('level second'); diff --git a/example/Hprose.php b/example/Hprose.php index 900263b..a9921db 100644 --- a/example/Hprose.php +++ b/example/Hprose.php @@ -49,8 +49,8 @@ $client->setHeader($key, $val); } } -$clientSapn->setTags(['http.url' => $url]); -$clientSapn->setTags(['http.method' => 'POST']); +$clientSapn->setTag('http.url', $url); +$clientSapn->setTag('http.method' , 'POST'); $result = $client->get("Hprose"); diff --git a/example/Istio1.php b/example/Istio1.php index 07abe80..f305de3 100644 --- a/example/Istio1.php +++ b/example/Istio1.php @@ -40,9 +40,9 @@ $clientTracer->inject($clientSapn->spanContext, Formats\TEXT_MAP, $injectTarget); $client = new Client(); - $clientSapn->setTags(["http.url" => "Istio2:8001"]); + $clientSapn->setTag("http.url", "Istio2:8001"); $res = $client->request('GET', 'Istio2:8001' ,['headers' => $injectTarget]); - $clientSapn->setTags(["http.status_code" => $res->getStatusCode()]); + $clientSapn->setTag("http.status_code", $res->getStatusCode()); //client span1 end //server span end diff --git a/example/Istio2.php b/example/Istio2.php index 452daa0..f543c88 100644 --- a/example/Istio2.php +++ b/example/Istio2.php @@ -38,9 +38,9 @@ $clientTracer->inject($clientSapn->spanContext, Formats\TEXT_MAP, $injectTarget); $client = new \GuzzleHttp\Client(); - $clientSapn->setTags(["http.url" => "Istio3:8002"]); + $clientSapn->setTag("http.url", "Istio3:8002"); $res = $client->request('GET', 'Istio3:8002', ['headers' => $injectTarget]); - $clientSapn->setTags(["http.status_code" => $res->getStatusCode()]); + $clientSapn->setTag("http.status_code", $res->getStatusCode()); //client span1 end //server span end diff --git a/src/Jaeger/Jaeger.php b/src/Jaeger/Jaeger.php index 2b75c09..ea5cffd 100644 --- a/src/Jaeger/Jaeger.php +++ b/src/Jaeger/Jaeger.php @@ -116,8 +116,11 @@ public function startSpan($operationName, $options = []){ } $span = new Span($operationName, $newSpan, $options->getReferences()); - $span->setTags($options->getTags()); - + if(!empty($options->getTags())) { + foreach ($options->getTags() as $k => $tag) { + $span->setTag($k, $tag); + } + } if($newSpan->isSampled() == 1) { $this->spans[] = $span; } diff --git a/src/Jaeger/Span.php b/src/Jaeger/Span.php index e693376..4c32601 100644 --- a/src/Jaeger/Span.php +++ b/src/Jaeger/Span.php @@ -75,19 +75,6 @@ public function overwriteOperationName($newOperationName){ $this->operationName = $newOperationName; } - /** - * Adds tags to the Span in key:value format, key must be a string and tag must be either - * a string, a boolean value, or a numeric type. - * - * As an implementor, consider using "standard tags" listed in {@see \OpenTracing\Ext\Tags} - * - * @param array $tags - * @throws SpanAlreadyFinished if the span is already finished - */ - public function setTags(array $tags){ - $this->tags = array_merge($this->tags, $tags); - } - public function setTag($key, $value){ $this->tags[$key] = $value; diff --git a/tests/SpanTest.php b/tests/SpanTest.php index 04bc4fc..7a09e08 100644 --- a/tests/SpanTest.php +++ b/tests/SpanTest.php @@ -31,14 +31,14 @@ public function testOverwriteOperationName(){ public function testAddTags(){ $span = new Span('test', new NoopSpanContext(), []); - $span->setTags(['test' => 'test']); + $span->setTag('test', 'test'); $this->assertTrue((isset($span->tags['test']) && $span->tags['test'] == 'test')); } public function testFinish(){ $span = new Span('test', new NoopSpanContext(), []); - $span->setTags(['test' => 'test']); + $span->setTag('test', 'test'); $span->finish(); $this->assertTrue(!empty($span->finishTime) && !empty($span->duration)); }