New propagation format.

This commit is contained in:
wusheng 2017-07-02 21:57:24 +08:00
parent 945f68b9b1
commit 9d100902de
2 changed files with 53 additions and 20 deletions

View File

@ -6,6 +6,7 @@ import java.util.List;
import org.skywalking.apm.agent.core.context.ids.DistributedTraceId;
import org.skywalking.apm.agent.core.context.ids.PropagatedTraceId;
import org.skywalking.apm.agent.core.context.trace.TraceSegment;
import org.skywalking.apm.agent.core.dictionary.DictionaryUtil;
import org.skywalking.apm.util.StringUtil;
/**
@ -22,10 +23,12 @@ public class ContextCarrier implements Serializable {
private int spanId = -1;
private String applicationCode;
private int applicationId = DictionaryUtil.nullValue();
private String peerHost;
private String entryOperationName;
/**
* {@link DistributedTraceId}
*/
@ -42,8 +45,9 @@ public class ContextCarrier implements Serializable {
return StringUtil.join('|',
this.getTraceSegmentId(),
this.getSpanId() + "",
this.getApplicationCode(),
this.getApplicationId() + "",
this.getPeerHost(),
this.getEntryOperationName(),
this.serializeDistributedTraceIds());
} else {
return "";
@ -58,13 +62,14 @@ public class ContextCarrier implements Serializable {
public ContextCarrier deserialize(String text) {
if (text != null) {
String[] parts = text.split("\\|", 6);
if (parts.length == 5) {
if (parts.length == 6) {
try {
setSpanId(Integer.parseInt(parts[1]));
setTraceSegmentId(parts[0]);
setApplicationCode(parts[2]);
setPeerHost(parts[3]);
setDistributedTraceIds(deserializeDistributedTraceIds(parts[4]));
this.traceSegmentId = parts[0];
this.spanId = Integer.parseInt(parts[1]);
this.applicationId = Integer.parseInt(parts[2]);
this.peerHost = parts[3];
this.entryOperationName = parts[4];
this.distributedTraceIds = deserializeDistributedTraceIds(parts[5]);
} catch (NumberFormatException e) {
}
@ -81,11 +86,24 @@ public class ContextCarrier implements Serializable {
public boolean isValid() {
return !StringUtil.isEmpty(traceSegmentId)
&& getSpanId() > -1
&& !StringUtil.isEmpty(applicationCode)
&& applicationId != DictionaryUtil.nullValue()
&& !StringUtil.isEmpty(peerHost)
&& !StringUtil.isEmpty(entryOperationName)
&& distributedTraceIds != null;
}
public String getEntryOperationName() {
return entryOperationName;
}
public void setEntryOperationName(String entryOperationName) {
this.entryOperationName = '#' + entryOperationName;
}
public void setEntryOperationId(int entryOperationId) {
this.entryOperationName = entryOperationId + "";
}
public String getTraceSegmentId() {
return traceSegmentId;
}
@ -102,16 +120,12 @@ public class ContextCarrier implements Serializable {
this.spanId = spanId;
}
public String getApplicationCode() {
return applicationCode;
}
public void setApplicationCode(String applicationCode) {
this.applicationCode = applicationCode;
public int getApplicationId() {
return applicationId;
}
public void setApplicationId(int applicationId) {
this.applicationCode = applicationId + "";
this.applicationId = applicationId;
}
public String getPeerHost() {
@ -119,7 +133,7 @@ public class ContextCarrier implements Serializable {
}
public void setPeerHost(String peerHost) {
this.peerHost = peerHost;
this.peerHost = '#' + peerHost;
}
public void setPeerId(int peerId) {

View File

@ -3,6 +3,7 @@ package org.skywalking.apm.agent.core.context.trace;
import java.util.List;
import org.skywalking.apm.agent.core.context.ContextCarrier;
import org.skywalking.apm.agent.core.context.ids.DistributedTraceId;
import org.skywalking.apm.agent.core.dictionary.DictionaryUtil;
/**
* {@link TraceSegmentRef} is like a pointer, which ref to another {@link TraceSegment},
@ -15,10 +16,16 @@ public class TraceSegmentRef {
private int spanId = -1;
private String applicationCode;
private int applicationId;
private String peerHost;
private int peerId = DictionaryUtil.nullValue();
private String operationName;
private int operationId;
/**
* {@link DistributedTraceId}
*/
@ -27,8 +34,20 @@ public class TraceSegmentRef {
public TraceSegmentRef(ContextCarrier carrier) {
this.traceSegmentId = carrier.getTraceSegmentId();
this.spanId = carrier.getSpanId();
this.applicationCode = carrier.getApplicationCode();
this.peerHost = carrier.getPeerHost();
this.applicationId = carrier.getApplicationId();
String host = carrier.getPeerHost();
if (host.charAt(0) == '#') {
this.peerHost = host.substring(1);
} else {
this.peerId = Integer.parseInt(host);
}
String entryOperationName = carrier.getEntryOperationName();
if (entryOperationName.charAt(0) == '#') {
this.operationName = host.substring(1);
} else {
this.operationId = Integer.parseInt(entryOperationName);
}
this.distributedTraceIds = carrier.getDistributedTraceIds();
}