Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

del setTags #51

Merged
merged 2 commits into from
Jul 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"]);
Expand Down
14 changes: 9 additions & 5 deletions example/HTTP.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand All @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion example/HTTP2.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
4 changes: 2 additions & 2 deletions example/Hprose.php
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand Down
4 changes: 2 additions & 2 deletions example/Istio1.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions example/Istio2.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 5 additions & 2 deletions src/Jaeger/Jaeger.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
13 changes: 0 additions & 13 deletions src/Jaeger/Span.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions tests/SpanTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down