提交 809158b2 编写于 作者: A ascrutae

fix miss entryServiceId and entryServiceName in ContextSnapshot issue

上级 79a45823
......@@ -2,6 +2,8 @@ package org.skywalking.apm.agent.core.context;
import java.util.List;
import org.skywalking.apm.agent.core.context.ids.DistributedTraceId;
import org.skywalking.apm.agent.core.dictionary.DictionaryUtil;
import org.skywalking.apm.util.StringUtil;
/**
* The <code>ContextSnapshot</code> is a snapshot for current context. The snapshot carries the info for building
......@@ -20,16 +22,24 @@ public class ContextSnapshot {
*/
private int spanId = -1;
private String entryOperationName;
/**
* {@link DistributedTraceId}
*/
private List<DistributedTraceId> distributedTraceIds;
ContextSnapshot(String traceSegmentId, int spanId,
List<DistributedTraceId> distributedTraceIds) {
List<DistributedTraceId> distributedTraceIds, int entryServiceId, String entryOperationName) {
this.traceSegmentId = traceSegmentId;
this.spanId = spanId;
this.distributedTraceIds = distributedTraceIds;
if (entryServiceId == DictionaryUtil.nullValue()) {
this.entryOperationName = "#" + entryOperationName;
} else {
this.entryOperationName = String.valueOf(entryServiceId);
}
}
public List<DistributedTraceId> getDistributedTraceIds() {
......@@ -48,6 +58,11 @@ public class ContextSnapshot {
return traceSegmentId != null
&& spanId > -1
&& distributedTraceIds != null
&& distributedTraceIds.size() > 0;
&& distributedTraceIds.size() > 0
&& !StringUtil.isEmpty(entryOperationName);
}
public String getEntryOperationName() {
return entryOperationName;
}
}
......@@ -33,7 +33,7 @@ public class IgnoredTracerContext implements AbstractTracerContext {
}
@Override public ContextSnapshot capture() {
return new ContextSnapshot(null, -1, null);
return new ContextSnapshot(null, -1, null, 0, null);
}
@Override public void continued(ContextSnapshot snapshot) {
......
......@@ -132,10 +132,20 @@ public class TracingContext implements AbstractTracerContext {
*/
@Override
public ContextSnapshot capture() {
return new ContextSnapshot(segment.getTraceSegmentId(),
activeSpan().getSpanId(),
segment.getRelatedGlobalTraces()
);
List<TraceSegmentRef> refs = this.segment.getRefs();
if (refs != null && refs.size() > 0) {
TraceSegmentRef ref = refs.get(0);
return new ContextSnapshot(segment.getTraceSegmentId(),
activeSpan().getSpanId(),
segment.getRelatedGlobalTraces(), ref.getOperationId(), ref.getOperationName()
);
} else {
AbstractTracingSpan firstSpan = first();
return new ContextSnapshot(segment.getTraceSegmentId(),
activeSpan().getSpanId(),
segment.getRelatedGlobalTraces(), firstSpan.getOperationId(), firstSpan.getOperationName()
);
}
}
/**
......
......@@ -57,6 +57,12 @@ public class TraceSegmentRef {
this.type = SegmentRefType.CROSS_THREAD;
this.traceSegmentId = snapshot.getTraceSegmentId();
this.spanId = snapshot.getSpanId();
String entryOperationName = snapshot.getEntryOperationName();
if (entryOperationName.charAt(0) == '#') {
this.operationName = entryOperationName.substring(1);
} else {
this.operationId = Integer.parseInt(entryOperationName);
}
}
public String getOperationName() {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册