提交 5bcc6fbf 编写于 作者: wu-sheng's avatar wu-sheng

Refactor ContextCarrier.

上级 c7c0256c
......@@ -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 + "";
}
......
......@@ -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();
}
}
......@@ -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;
......
......@@ -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();
}
......
......@@ -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)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册