测试代码
$config = new Config(
[
'sampler' => [
'type' => Jaeger\SAMPLER_TYPE_CONST,
'param' => true,
],
'logging' => true,
"tags" => [
'http.url' => 'http.url',
'http.method' => 'http.method',
'http.status_code' => 'http.status_code',
'db.query' => 'db.query',
'db.statement' => 'db.statement',
'db.query_time' => 'db.query_time',
'path' => 'request.path',
'method' => 'request.method',
'header' => 'request.header',
'status_code' => 'response.status_code',
],
"local_agent" => [
"reporting_host" => "web-jaeger.your-domain.com",
"reporting_port" => 5775
],
'dispatch_mode' => Config::ZIPKIN_OVER_COMPACT_UDP,
],
'order-center'
);
$config->initializeTracer();
$tracer = GlobalTracer::get();
$scope = $tracer->startActiveSpan('request', []);
$scope->getSpan()->setTag("tag1", "value1");
$scope->getSpan()->setTag("tag2", "value2");
$scope->getSpan()->setTag("tag3", "value2");
$scope->getSpan()->log([
"key1" => "value1",
"key2" => 2,
"key3" => true
]);
$nestedSpanScope1= $tracer->startActiveSpan("db.query");
$nestedSpanScope1->getSpan()->setTag("tag1", "value1");
$nestedSpanScope1->getSpan()->setTag("tag2", "value2");
$nestedSpanScope1->getSpan()->setTag("tag3", "value2");
$nestedSpanScope1->getSpan()->log([
"key1" => "value1",
"key2" => 2,
"key3" => true
]);
$nestedSpanScope11 = $tracer->startActiveSpan("redis.get");
$nestedSpanScope11->getSpan()->setTag("tag1", "value1");
$nestedSpanScope11->getSpan()->setTag("tag2", "value2");
$nestedSpanScope11->getSpan()->setTag("tag3", "value2");
$nestedSpanScope11->getSpan()->log([
"key1" => "value1",
"key2" => 2,
"key3" => true
]);
$nestedSpanScope11->close();
$nestedSpanScope12= $tracer->startActiveSpan("oa");
$oaResponseData = [];
$nestedSpanScope12->getSpan()->setTag("http.url", "xxx.oa.com");
$nestedSpanScope12->getSpan()->setTag("http.method", "POST");
$nestedSpanScope12->getSpan()->setTag("http.status_code", 200);
$nestedSpanScope12->getSpan()->log($oaResponseData);
$nestedSpanScope12->close();
$nestedSpanScope1->close();
$nestedSpanScope2 = $tracer->startActiveSpan("db.insert");
$nestedSpanScope2->getSpan()->setTag("tag1", "value1");
$nestedSpanScope2->getSpan()->setTag("tag2", "value2");
$nestedSpanScope2->getSpan()->setTag("tag3", "value2");
$nestedSpanScope2->getSpan()->log([
"key1" => "value1",
"key2" => 2,
"key3" => true
]);
$nestedSpanScope21 = $tracer->startActiveSpan("redis.hget");
$nestedSpanScope21->getSpan()->setTag("tag1", "value1");
$nestedSpanScope21->getSpan()->setTag("tag2", "value2");
$nestedSpanScope21->getSpan()->setTag("tag3", "value2");
$nestedSpanScope21->getSpan()->log([
"key1" => "value1",
"key2" => 2,
"key3" => true
]);
$nestedSpanScope21->close();
$nestedSpanScope2->close();
$scope->close();
$tracer->flush();