Refactor ContextCarrier.

This commit is contained in:
wusheng 2017-07-02 22:47:16 +08:00
parent c7c0256ce7
commit 5bcc6fbf5c
5 changed files with 46 additions and 8 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.DictionaryManager;
import org.skywalking.apm.agent.core.dictionary.DictionaryUtil;
import org.skywalking.apm.util.StringUtil;
@ -96,11 +97,11 @@ public class ContextCarrier implements Serializable {
return entryOperationName;
}
public void setEntryOperationName(String entryOperationName) {
void setEntryOperationName(String entryOperationName) {
this.entryOperationName = '#' + entryOperationName;
}
public void setEntryOperationId(int entryOperationId) {
void setEntryOperationId(int entryOperationId) {
this.entryOperationName = entryOperationId + "";
}
@ -112,11 +113,11 @@ public class ContextCarrier implements Serializable {
return spanId;
}
public void setTraceSegmentId(String traceSegmentId) {
void setTraceSegmentId(String traceSegmentId) {
this.traceSegmentId = traceSegmentId;
}
public void setSpanId(int spanId) {
void setSpanId(int spanId) {
this.spanId = spanId;
}
@ -124,7 +125,7 @@ public class ContextCarrier implements Serializable {
return applicationId;
}
public void setApplicationId(int applicationId) {
void setApplicationId(int applicationId) {
this.applicationId = applicationId;
}
@ -132,11 +133,11 @@ public class ContextCarrier implements Serializable {
return peerHost;
}
public void setPeerHost(String peerHost) {
void setPeerHost(String peerHost) {
this.peerHost = '#' + peerHost;
}
public void setPeerId(int peerId) {
void setPeerId(int peerId) {
this.peerHost = peerId + "";
}

View File

@ -60,6 +60,23 @@ public class TracingContext implements AbstractTracerContext {
} else {
carrier.setPeerId(exitSpan.getPeerId());
}
List<TraceSegmentRef> refs = this.segment.getRefs();
int operationId;
String operationName;
if (refs != null && refs.size() > 0) {
TraceSegmentRef ref = refs.get(0);
operationId = ref.getOperationId();
operationName = ref.getOperationName();
} else {
AbstractTracingSpan firstSpan = first();
operationId = firstSpan.getOperationId();
operationName = firstSpan.getOperationName();
}
if (operationId == DictionaryUtil.nullValue()) {
carrier.setEntryOperationName(operationName);
} else {
carrier.setEntryOperationId(operationId);
}
carrier.setDistributedTraceIds(this.segment.getRelatedGlobalTraces());
}
@ -274,4 +291,8 @@ public class TracingContext implements AbstractTracerContext {
}
return activeSpanStack.getLast();
}
private AbstractTracingSpan first() {
return activeSpanStack.getFirst();
}
}

View File

@ -121,6 +121,10 @@ public abstract class AbstractTracingSpan implements AbstractSpan {
return operationId;
}
public String getOperationName() {
return operationName;
}
@Override
public AbstractSpan setLayer(SpanLayer layer) {
this.layer = layer;

View File

@ -178,6 +178,10 @@ public class TraceSegment {
return !(refs == null || refs.size() == 0);
}
public List<TraceSegmentRef> getRefs() {
return refs;
}
public List<DistributedTraceId> getRelatedGlobalTraces() {
return relatedGlobalTraces.getRelatedGlobalTraces();
}

View File

@ -24,7 +24,7 @@ public class TraceSegmentRef {
private String operationName;
private int operationId;
private int operationId = DictionaryUtil.nullValue();
/**
* {@link DistributedTraceId}
@ -56,6 +56,14 @@ public class TraceSegmentRef {
this.distributedTraceIds = carrier.getDistributedTraceIds();
}
public String getOperationName() {
return operationName;
}
public int getOperationId() {
return operationId;
}
@Override
public boolean equals(Object o) {
if (this == o)