java追踪弹_jaegeropentracing的Java-client完整分布式追踪链

public static void main(String[] args) throwsInterruptedException {

Configuration conf= new Configuration("EK Demo Jaeger."); //配置全局configuration//发送sender configuration

Configuration.SenderConfiguration senderConf = newConfiguration.SenderConfiguration();

senderConf.withAgentHost("192.168.1.111");

senderConf.withAgentPort(5775);

Sender sender=senderConf.getSender();

log.info("[ sender ] : "+sender);

conf.withReporter(newConfiguration.ReporterConfiguration()

.withSender(senderConf)

.withFlushInterval(100)

.withLogSpans(false)

);

conf.withSampler(newConfiguration.SamplerConfiguration()

.withType("const")

.withParam(1)

);

Tracer tracer=conf.getTracer();

log.info(tracer.toString());

GlobalTracer.register(tracer);

Tracer.SpanBuilder spanBuilder= GlobalTracer.get().buildSpan("EK Demo P");

Span parent=spanBuilder.start();

parent.log(100, "before Controller Method is running......");

log.info("before Controller Method is running......");

Tracer.SpanBuilder childB= GlobalTracer.get().buildSpan("EK Demo child").asChildOf(parent);

Span child=childB.start();

JaegerSpanContext context=(JaegerSpanContext) child.context();

child.log("......"+context.contextAsString());

String url= "http://localhost:8080/jeeek/services/phopuService/getUserPost";

HttpClient httpClient=HttpClients.createSystem();final HttpPost httpPost = newHttpPost(url);

httpPost.addHeader("Content-Type", "text/plain");

StringEntity se= null;

String weatherInfo= null;try{//透传context到服务端

tracer.inject(parent.context(), Format.Builtin.TEXT_MAP, newTextMap() {

@Overridepublic Iterator>iterator() {throw new UnsupportedOperationException("TextMapInjectAdapter should only be used with Tracer.inject()");

}

@Overridepublic voidput(String key, String value) {

log.info(key+",----------------------- "+value);

httpPost.setHeader(key, value);

}

});

se= new StringEntity("101010500");

se.setContentType("text/plain");

httpPost.setEntity(se);

HttpResponse response= null;

response=httpClient.execute(httpPost);int status =response.getStatusLine().getStatusCode();

log.info("[接口返回状态吗] : " +status);

weatherInfo=getReturnStr(response);

}catch(UnsupportedEncodingException e) {

e.printStackTrace();

}catch(IOException e) {

e.printStackTrace();

}

log.info("[接口返回信息] : " +weatherInfo);

Thread.sleep(5000);

child.finish();

Thread.sleep(5000);

parent.finish();

log.info("after Controller Method is running.......");

Thread.sleep(10000);

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值