diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/ContextSnapshot.java b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/ContextSnapshot.java
index 755a2275d8b0b0662ee96592fd381fd8ecbc1c36..9d988e190d381e20ca2ab0b6e6a38e82d3be7b86 100644
--- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/ContextSnapshot.java
+++ b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/ContextSnapshot.java
@@ -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 ContextSnapshot
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 distributedTraceIds;
ContextSnapshot(String traceSegmentId, int spanId,
- List distributedTraceIds) {
+ List 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 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;
}
}
diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/IgnoredTracerContext.java b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/IgnoredTracerContext.java
index 4ad37e361a73b6403b534d0d5acf8cfddcca94c2..6f3e0ce51e01a1c3425227c19c0435c6f31f6eab 100644
--- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/IgnoredTracerContext.java
+++ b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/IgnoredTracerContext.java
@@ -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) {
diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/TracingContext.java b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/TracingContext.java
index 15e41c2a85bac32762880cc396d3414012400153..f74654f4727ea3e8a94173662e4a108c87ee7e1c 100644
--- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/TracingContext.java
+++ b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/TracingContext.java
@@ -132,10 +132,20 @@ public class TracingContext implements AbstractTracerContext {
*/
@Override
public ContextSnapshot capture() {
- return new ContextSnapshot(segment.getTraceSegmentId(),
- activeSpan().getSpanId(),
- segment.getRelatedGlobalTraces()
- );
+ List 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()
+ );
+ }
}
/**
diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/trace/TraceSegmentRef.java b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/trace/TraceSegmentRef.java
index 1e2da121733152da9de828743558926a4909e36a..672d7b35f14dfe28cbc4b675c9ecc5211dbe78a3 100644
--- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/trace/TraceSegmentRef.java
+++ b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/trace/TraceSegmentRef.java
@@ -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() {