Merge branch 'master' into feature/jvm-shutdown-hook

This commit is contained in:
吴晟 Wu Sheng 2017-07-19 14:19:02 +08:00 committed by GitHub
commit 686a802097
4 changed files with 38 additions and 7 deletions

View File

@ -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;
}
}

View File

@ -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) {

View File

@ -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()
);
}
}
/**

View File

@ -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() {