Add host:port/peers to ContextCarrier.

This commit is contained in:
wusheng 2017-03-22 14:19:21 +08:00
parent d6696ad285
commit 680c2c2337
2 changed files with 11 additions and 3 deletions

View File

@ -125,9 +125,16 @@ public final class TracerContext {
*/
public void inject(ContextCarrier carrier) {
carrier.setTraceSegmentId(this.segment.getTraceSegmentId());
carrier.setSpanId(this.activeSpan().getSpanId());
Span span = this.activeSpan();
carrier.setSpanId(span.getSpanId());
carrier.setApplicationCode(Config.Agent.APPLICATION_CODE);
carrier.setPeerHost(Tags.PEER_HOST.get(activeSpan()));
String host = Tags.PEER_HOST.get(span);
if(host != null) {
Integer port = Tags.PEER_PORT.get(span);
carrier.setPeerHost(host + ":" + port);
}else{
carrier.setPeerHost(Tags.PEERS.get(span));
}
carrier.setDistributedTraceIds(this.segment.getRelatedGlobalTraces());
carrier.setSampled(this.segment.isSampled());
}

View File

@ -61,7 +61,8 @@ public class TracerContextTestCase {
TracerContext context = new TracerContext();
Span serviceSpan = context.createSpan("/serviceA");
Span dbSpan = context.createSpan("db/preparedStatement/execute");
Tags.PEER_HOST.set(dbSpan, "127.0.0.1:8080");
Tags.PEER_HOST.set(dbSpan, "127.0.0.1");
Tags.PEER_PORT.set(dbSpan, 8080);
ContextCarrier carrier = new ContextCarrier();
context.inject(carrier);