提交 f4f0d1cb 编写于 作者: wu-sheng's avatar wu-sheng 提交者: GitHub

Merge branch 'master' into feature/336

...@@ -23,7 +23,9 @@ public class ContextCarrier implements Serializable { ...@@ -23,7 +23,9 @@ public class ContextCarrier implements Serializable {
private int spanId = -1; private int spanId = -1;
private int applicationInstanceId = DictionaryUtil.nullValue(); private int parentApplicationInstanceId = DictionaryUtil.nullValue();
private int entryApplicationInstanceId = DictionaryUtil.nullValue();
private String peerHost; private String peerHost;
...@@ -47,11 +49,12 @@ public class ContextCarrier implements Serializable { ...@@ -47,11 +49,12 @@ public class ContextCarrier implements Serializable {
return StringUtil.join('|', return StringUtil.join('|',
this.getTraceSegmentId().toBase64(), this.getTraceSegmentId().toBase64(),
this.getSpanId() + "", this.getSpanId() + "",
this.getApplicationInstanceId() + "", this.getParentApplicationInstanceId() + "",
this.getEntryApplicationInstanceId() + "",
this.getPeerHost(), this.getPeerHost(),
this.getEntryOperationName(), this.getEntryOperationName(),
this.getParentOperationName(), this.getParentOperationName(),
this.getPrimaryDistributedTraceId()); this.getPrimaryDistributedTraceId().toBase64());
} else { } else {
return ""; return "";
} }
...@@ -64,16 +67,17 @@ public class ContextCarrier implements Serializable { ...@@ -64,16 +67,17 @@ public class ContextCarrier implements Serializable {
*/ */
public ContextCarrier deserialize(String text) { public ContextCarrier deserialize(String text) {
if (text != null) { if (text != null) {
String[] parts = text.split("\\|", 7); String[] parts = text.split("\\|", 8);
if (parts.length == 7) { if (parts.length == 8) {
try { try {
this.traceSegmentId = new ID(parts[0]); this.traceSegmentId = new ID(parts[0]);
this.spanId = Integer.parseInt(parts[1]); this.spanId = Integer.parseInt(parts[1]);
this.applicationInstanceId = Integer.parseInt(parts[2]); this.parentApplicationInstanceId = Integer.parseInt(parts[2]);
this.peerHost = parts[3]; this.entryApplicationInstanceId = Integer.parseInt(parts[3]);
this.entryOperationName = parts[4]; this.peerHost = parts[4];
this.parentOperationName = parts[5]; this.entryOperationName = parts[5];
this.primaryDistributedTraceId = new PropagatedTraceId(parts[6]); this.parentOperationName = parts[6];
this.primaryDistributedTraceId = new PropagatedTraceId(parts[7]);
} catch (NumberFormatException e) { } catch (NumberFormatException e) {
} }
...@@ -90,7 +94,8 @@ public class ContextCarrier implements Serializable { ...@@ -90,7 +94,8 @@ public class ContextCarrier implements Serializable {
public boolean isValid() { public boolean isValid() {
return traceSegmentId != null return traceSegmentId != null
&& getSpanId() > -1 && getSpanId() > -1
&& applicationInstanceId != DictionaryUtil.nullValue() && parentApplicationInstanceId != DictionaryUtil.nullValue()
&& entryApplicationInstanceId != DictionaryUtil.nullValue()
&& !StringUtil.isEmpty(peerHost) && !StringUtil.isEmpty(peerHost)
&& !StringUtil.isEmpty(entryOperationName) && !StringUtil.isEmpty(entryOperationName)
&& !StringUtil.isEmpty(parentOperationName) && !StringUtil.isEmpty(parentOperationName)
...@@ -133,12 +138,12 @@ public class ContextCarrier implements Serializable { ...@@ -133,12 +138,12 @@ public class ContextCarrier implements Serializable {
this.spanId = spanId; this.spanId = spanId;
} }
public int getApplicationInstanceId() { public int getParentApplicationInstanceId() {
return applicationInstanceId; return parentApplicationInstanceId;
} }
void setApplicationInstanceId(int applicationInstanceId) { void setParentApplicationInstanceId(int parentApplicationInstanceId) {
this.applicationInstanceId = applicationInstanceId; this.parentApplicationInstanceId = parentApplicationInstanceId;
} }
public String getPeerHost() { public String getPeerHost() {
...@@ -161,11 +166,20 @@ public class ContextCarrier implements Serializable { ...@@ -161,11 +166,20 @@ public class ContextCarrier implements Serializable {
this.primaryDistributedTraceId = distributedTraceIds.get(0); this.primaryDistributedTraceId = distributedTraceIds.get(0);
} }
private String getPrimaryDistributedTraceId() { private DistributedTraceId getPrimaryDistributedTraceId() {
return primaryDistributedTraceId.toBase64(); return primaryDistributedTraceId;
} }
public String getParentOperationName() { public String getParentOperationName() {
return parentOperationName; return parentOperationName;
} }
public int getEntryApplicationInstanceId() {
return entryApplicationInstanceId;
}
public void setEntryApplicationInstanceId(int entryApplicationInstanceId) {
this.entryApplicationInstanceId = entryApplicationInstanceId;
}
} }
...@@ -3,6 +3,7 @@ package org.skywalking.apm.agent.core.context; ...@@ -3,6 +3,7 @@ package org.skywalking.apm.agent.core.context;
import java.util.List; import java.util.List;
import org.skywalking.apm.agent.core.context.ids.DistributedTraceId; import org.skywalking.apm.agent.core.context.ids.DistributedTraceId;
import org.skywalking.apm.agent.core.context.ids.ID; import org.skywalking.apm.agent.core.context.ids.ID;
import org.skywalking.apm.agent.core.dictionary.DictionaryUtil;
import org.skywalking.apm.util.StringUtil; import org.skywalking.apm.util.StringUtil;
/** /**
...@@ -31,6 +32,8 @@ public class ContextSnapshot { ...@@ -31,6 +32,8 @@ public class ContextSnapshot {
*/ */
private DistributedTraceId primaryDistributedTraceId; private DistributedTraceId primaryDistributedTraceId;
private int entryApplicationInstanceId = DictionaryUtil.nullValue();
ContextSnapshot(ID traceSegmentId, int spanId, ContextSnapshot(ID traceSegmentId, int spanId,
List<DistributedTraceId> distributedTraceIds) { List<DistributedTraceId> distributedTraceIds) {
this.traceSegmentId = traceSegmentId; this.traceSegmentId = traceSegmentId;
...@@ -75,6 +78,7 @@ public class ContextSnapshot { ...@@ -75,6 +78,7 @@ public class ContextSnapshot {
public boolean isValid() { public boolean isValid() {
return traceSegmentId != null return traceSegmentId != null
&& spanId > -1 && spanId > -1
&& entryApplicationInstanceId != DictionaryUtil.nullValue()
&& primaryDistributedTraceId != null && primaryDistributedTraceId != null
&& !StringUtil.isEmpty(entryOperationName) && !StringUtil.isEmpty(entryOperationName)
&& !StringUtil.isEmpty(parentOperationName); && !StringUtil.isEmpty(parentOperationName);
...@@ -83,4 +87,12 @@ public class ContextSnapshot { ...@@ -83,4 +87,12 @@ public class ContextSnapshot {
public String getEntryOperationName() { public String getEntryOperationName() {
return entryOperationName; return entryOperationName;
} }
public void setEntryApplicationInstanceId(int entryApplicationInstanceId) {
this.entryApplicationInstanceId = entryApplicationInstanceId;
}
public int getEntryApplicationInstanceId() {
return entryApplicationInstanceId;
}
} }
...@@ -84,7 +84,7 @@ public class TracingContext implements AbstractTracerContext { ...@@ -84,7 +84,7 @@ public class TracingContext implements AbstractTracerContext {
carrier.setTraceSegmentId(this.segment.getTraceSegmentId()); carrier.setTraceSegmentId(this.segment.getTraceSegmentId());
carrier.setSpanId(span.getSpanId()); carrier.setSpanId(span.getSpanId());
carrier.setApplicationInstanceId(segment.getApplicationId()); carrier.setParentApplicationInstanceId(segment.getApplicationInstanceId());
if (DictionaryUtil.isNull(exitSpan.getPeerId())) { if (DictionaryUtil.isNull(exitSpan.getPeerId())) {
carrier.setPeerHost(exitSpan.getPeer()); carrier.setPeerHost(exitSpan.getPeer());
...@@ -94,15 +94,20 @@ public class TracingContext implements AbstractTracerContext { ...@@ -94,15 +94,20 @@ public class TracingContext implements AbstractTracerContext {
List<TraceSegmentRef> refs = this.segment.getRefs(); List<TraceSegmentRef> refs = this.segment.getRefs();
int operationId; int operationId;
String operationName; String operationName;
int entryApplicationInstanceId;
if (refs != null && refs.size() > 0) { if (refs != null && refs.size() > 0) {
TraceSegmentRef ref = refs.get(0); TraceSegmentRef ref = refs.get(0);
operationId = ref.getEntryOperationId(); operationId = ref.getEntryOperationId();
operationName = ref.getEntryOperationName(); operationName = ref.getEntryOperationName();
entryApplicationInstanceId = ref.getEntryApplicationInstanceId();
} else { } else {
AbstractTracingSpan firstSpan = first(); AbstractTracingSpan firstSpan = first();
operationId = firstSpan.getOperationId(); operationId = firstSpan.getOperationId();
operationName = firstSpan.getOperationName(); operationName = firstSpan.getOperationName();
entryApplicationInstanceId = this.segment.getApplicationInstanceId();
} }
carrier.setEntryApplicationInstanceId(entryApplicationInstanceId);
if (operationId == DictionaryUtil.nullValue()) { if (operationId == DictionaryUtil.nullValue()) {
carrier.setEntryOperationName(operationName); carrier.setEntryOperationName(operationName);
} else { } else {
...@@ -145,15 +150,20 @@ public class TracingContext implements AbstractTracerContext { ...@@ -145,15 +150,20 @@ public class TracingContext implements AbstractTracerContext {
segment.getRelatedGlobalTraces()); segment.getRelatedGlobalTraces());
int entryOperationId; int entryOperationId;
String entryOperationName; String entryOperationName;
int entryApplicationInstanceId;
AbstractTracingSpan firstSpan = first(); AbstractTracingSpan firstSpan = first();
if (refs != null && refs.size() > 0) { if (refs != null && refs.size() > 0) {
TraceSegmentRef ref = refs.get(0); TraceSegmentRef ref = refs.get(0);
entryOperationId = ref.getEntryOperationId(); entryOperationId = ref.getEntryOperationId();
entryOperationName = ref.getEntryOperationName(); entryOperationName = ref.getEntryOperationName();
entryApplicationInstanceId = ref.getEntryApplicationInstanceId();
} else { } else {
entryOperationId = firstSpan.getOperationId(); entryOperationId = firstSpan.getOperationId();
entryOperationName = firstSpan.getOperationName(); entryOperationName = firstSpan.getOperationName();
entryApplicationInstanceId = this.segment.getApplicationInstanceId();
} }
snapshot.setEntryApplicationInstanceId(entryApplicationInstanceId);
if (entryOperationId == DictionaryUtil.nullValue()) { if (entryOperationId == DictionaryUtil.nullValue()) {
snapshot.setEntryOperationName(entryOperationName); snapshot.setEntryOperationName(entryOperationName);
} else { } else {
......
...@@ -191,4 +191,8 @@ public class TraceSegment { ...@@ -191,4 +191,8 @@ public class TraceSegment {
", relatedGlobalTraces=" + relatedGlobalTraces + ", relatedGlobalTraces=" + relatedGlobalTraces +
'}'; '}';
} }
public int getApplicationInstanceId() {
return RemoteDownstreamConfig.Agent.APPLICATION_INSTANCE_ID;
}
} }
package org.skywalking.apm.agent.core.context.trace; package org.skywalking.apm.agent.core.context.trace;
import org.skywalking.apm.agent.core.conf.RemoteDownstreamConfig;
import org.skywalking.apm.agent.core.context.ContextCarrier; import org.skywalking.apm.agent.core.context.ContextCarrier;
import org.skywalking.apm.agent.core.context.ContextSnapshot; import org.skywalking.apm.agent.core.context.ContextSnapshot;
import org.skywalking.apm.agent.core.context.ids.ID; import org.skywalking.apm.agent.core.context.ids.ID;
...@@ -20,11 +21,13 @@ public class TraceSegmentRef { ...@@ -20,11 +21,13 @@ public class TraceSegmentRef {
private int spanId = -1; private int spanId = -1;
private int applicationInstanceId; private int peerId = DictionaryUtil.nullValue();
private String peerHost; private String peerHost;
private int peerId = DictionaryUtil.nullValue(); private int entryApplicationInstanceId = DictionaryUtil.nullValue();
private int parentApplicationInstanceId = DictionaryUtil.nullValue();
private String entryOperationName; private String entryOperationName;
...@@ -43,7 +46,8 @@ public class TraceSegmentRef { ...@@ -43,7 +46,8 @@ public class TraceSegmentRef {
this.type = SegmentRefType.CROSS_PROCESS; this.type = SegmentRefType.CROSS_PROCESS;
this.traceSegmentId = carrier.getTraceSegmentId(); this.traceSegmentId = carrier.getTraceSegmentId();
this.spanId = carrier.getSpanId(); this.spanId = carrier.getSpanId();
this.applicationInstanceId = carrier.getApplicationInstanceId(); this.parentApplicationInstanceId = carrier.getParentApplicationInstanceId();
this.entryApplicationInstanceId = carrier.getEntryApplicationInstanceId();
String host = carrier.getPeerHost(); String host = carrier.getPeerHost();
if (host.charAt(0) == '#') { if (host.charAt(0) == '#') {
this.peerHost = host.substring(1); this.peerHost = host.substring(1);
...@@ -68,6 +72,8 @@ public class TraceSegmentRef { ...@@ -68,6 +72,8 @@ public class TraceSegmentRef {
this.type = SegmentRefType.CROSS_THREAD; this.type = SegmentRefType.CROSS_THREAD;
this.traceSegmentId = snapshot.getTraceSegmentId(); this.traceSegmentId = snapshot.getTraceSegmentId();
this.spanId = snapshot.getSpanId(); this.spanId = snapshot.getSpanId();
this.parentApplicationInstanceId = RemoteDownstreamConfig.Agent.APPLICATION_INSTANCE_ID;
this.entryApplicationInstanceId = snapshot.getEntryApplicationInstanceId();
String entryOperationName = snapshot.getEntryOperationName(); String entryOperationName = snapshot.getEntryOperationName();
if (entryOperationName.charAt(0) == '#') { if (entryOperationName.charAt(0) == '#') {
this.entryOperationName = entryOperationName.substring(1); this.entryOperationName = entryOperationName.substring(1);
...@@ -90,11 +96,15 @@ public class TraceSegmentRef { ...@@ -90,11 +96,15 @@ public class TraceSegmentRef {
return entryOperationId; return entryOperationId;
} }
public int getEntryApplicationInstanceId() {
return entryApplicationInstanceId;
}
public TraceSegmentReference transform() { public TraceSegmentReference transform() {
TraceSegmentReference.Builder refBuilder = TraceSegmentReference.newBuilder(); TraceSegmentReference.Builder refBuilder = TraceSegmentReference.newBuilder();
if (SegmentRefType.CROSS_PROCESS.equals(type)) { if (SegmentRefType.CROSS_PROCESS.equals(type)) {
refBuilder.setRefType(RefType.CrossProcess); refBuilder.setRefType(RefType.CrossProcess);
refBuilder.setParentApplicationInstanceId(applicationInstanceId); refBuilder.setParentApplicationInstanceId(parentApplicationInstanceId);
if (peerId == DictionaryUtil.nullValue()) { if (peerId == DictionaryUtil.nullValue()) {
refBuilder.setNetworkAddress(peerHost); refBuilder.setNetworkAddress(peerHost);
} else { } else {
...@@ -104,6 +114,7 @@ public class TraceSegmentRef { ...@@ -104,6 +114,7 @@ public class TraceSegmentRef {
refBuilder.setRefType(RefType.CrossThread); refBuilder.setRefType(RefType.CrossThread);
} }
refBuilder.setEntryApplicationInstanceId(entryApplicationInstanceId);
refBuilder.setParentTraceSegmentId(traceSegmentId.transform()); refBuilder.setParentTraceSegmentId(traceSegmentId.transform());
refBuilder.setParentSpanId(spanId); refBuilder.setParentSpanId(spanId);
if (entryOperationId == DictionaryUtil.nullValue()) { if (entryOperationId == DictionaryUtil.nullValue()) {
...@@ -139,7 +150,6 @@ public class TraceSegmentRef { ...@@ -139,7 +150,6 @@ public class TraceSegmentRef {
result = 31 * result + spanId; result = 31 * result + spanId;
return result; return result;
} }
public enum SegmentRefType { public enum SegmentRefType {
CROSS_PROCESS, CROSS_PROCESS,
CROSS_THREAD CROSS_THREAD
......
package org.skywalking.apm.agent.core.plugin.match; package org.skywalking.apm.agent.core.plugin.match;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import net.bytebuddy.description.type.TypeDescription; import net.bytebuddy.description.type.TypeDescription;
import net.bytebuddy.description.type.TypeList;
import net.bytebuddy.matcher.ElementMatcher; import net.bytebuddy.matcher.ElementMatcher;
import static net.bytebuddy.matcher.ElementMatchers.hasSuperType; import static net.bytebuddy.matcher.ElementMatchers.hasSuperType;
...@@ -28,24 +32,54 @@ public class HierarchyMatch implements IndirectMatch { ...@@ -28,24 +32,54 @@ public class HierarchyMatch implements IndirectMatch {
ElementMatcher.Junction junction = null; ElementMatcher.Junction junction = null;
for (String superTypeName : parentTypes) { for (String superTypeName : parentTypes) {
if (junction == null) { if (junction == null) {
junction = buildEachAnnotation(superTypeName); junction = buildSuperClassMatcher(superTypeName);
} else { } else {
junction = junction.and(buildEachAnnotation(superTypeName)); junction = junction.and(buildSuperClassMatcher(superTypeName));
} }
} }
junction = junction.and(not(isInterface())); junction = junction.and(not(isInterface()));
return junction; return junction;
} }
private ElementMatcher.Junction buildEachAnnotation(String superTypeName) { private ElementMatcher.Junction buildSuperClassMatcher(String superTypeName) {
return hasSuperType(named(superTypeName)); return hasSuperType(named(superTypeName));
} }
@Override @Override
public boolean isMatch(TypeDescription typeDescription) { public boolean isMatch(TypeDescription typeDescription) {
List<String> parentTypes = new ArrayList<String>(Arrays.asList(this.parentTypes));
TypeList.Generic implInterfaces = typeDescription.getInterfaces();
for (TypeDescription.Generic implInterface : implInterfaces) {
matchHierarchyClass(implInterface, parentTypes);
}
matchHierarchyClass(typeDescription.getSuperClass(), parentTypes);
if (parentTypes.size() == 0) {
return true;
}
return false; return false;
} }
private void matchHierarchyClass(TypeDescription.Generic clazz, List<String> parentTypes) {
parentTypes.remove(clazz.getTypeName());
if (parentTypes.size() == 0) {
return;
}
for (TypeDescription.Generic generic : clazz.getInterfaces()) {
matchHierarchyClass(generic, parentTypes);
}
TypeDescription.Generic superClazz = clazz.getSuperClass();
if (superClazz != null && !clazz.getTypeName().equals("java.lang.Object")) {
matchHierarchyClass(superClazz, parentTypes);
}
}
public static ClassMatch byHierarchyMatch(String[] parentTypes) { public static ClassMatch byHierarchyMatch(String[] parentTypes) {
return new HierarchyMatch(parentTypes); return new HierarchyMatch(parentTypes);
} }
......
...@@ -79,7 +79,7 @@ public class ContextManagerTest { ...@@ -79,7 +79,7 @@ public class ContextManagerTest {
@Test @Test
public void createMultipleEntrySpan() { public void createMultipleEntrySpan() {
ContextCarrier contextCarrier = new ContextCarrier().deserialize("#AQA*#AQA*4WcWe0tQNQA*|1|1|#127.0.0.1:8080|#/portal/|#/testEntrySpan|#AQA*#AQA*Et0We0tQNQA*"); ContextCarrier contextCarrier = new ContextCarrier().deserialize("#AQA*#AQA*4WcWe0tQNQA*|1|1|1|#127.0.0.1:8080|#/portal/|#/testEntrySpan|#AQA*#AQA*Et0We0tQNQA*");
assertTrue(contextCarrier.isValid()); assertTrue(contextCarrier.isValid());
AbstractSpan firstEntrySpan = ContextManager.createEntrySpan("/testFirstEntry", contextCarrier); AbstractSpan firstEntrySpan = ContextManager.createEntrySpan("/testFirstEntry", contextCarrier);
...@@ -202,7 +202,7 @@ public class ContextManagerTest { ...@@ -202,7 +202,7 @@ public class ContextManagerTest {
@Test @Test
public void testTransform() throws InvalidProtocolBufferException { public void testTransform() throws InvalidProtocolBufferException {
ContextCarrier contextCarrier = new ContextCarrier().deserialize("#AQA*#AQA*4WcWe0tQNQA*|3|1|#127.0.0.1:8080|#/portal/|#/testEntrySpan|#AQA*#AQA*Et0We0tQNQA*"); ContextCarrier contextCarrier = new ContextCarrier().deserialize("#AQA*#AQA*4WcWe0tQNQA*|3|1|1|#127.0.0.1:8080|#/portal/|#/testEntrySpan|#AQA*#AQA*Et0We0tQNQA*");
assertTrue(contextCarrier.isValid()); assertTrue(contextCarrier.isValid());
AbstractSpan firstEntrySpan = ContextManager.createEntrySpan("/testFirstEntry", contextCarrier); AbstractSpan firstEntrySpan = ContextManager.createEntrySpan("/testFirstEntry", contextCarrier);
......
...@@ -148,7 +148,7 @@ public class DubboInterceptorTest { ...@@ -148,7 +148,7 @@ public class DubboInterceptorTest {
@Test @Test
public void testProviderWithAttachment() throws Throwable { public void testProviderWithAttachment() throws Throwable {
when(rpcContext.isConsumerSide()).thenReturn(false); when(rpcContext.isConsumerSide()).thenReturn(false);
when(rpcContext.getAttachment(Config.Plugin.Propagation.HEADER_NAME)).thenReturn("#AQA*#AQA*4WcWe0tQNQA*|3|1|#192.168.1.8 :18002|#/portal/|#/testEntrySpan|#AQA*#AQA*Et0We0tQNQA*"); when(rpcContext.getAttachment(Config.Plugin.Propagation.HEADER_NAME)).thenReturn("#AQA*#AQA*4WcWe0tQNQA*|3|1|1|#192.168.1.8 :18002|#/portal/|#/testEntrySpan|#AQA*#AQA*Et0We0tQNQA*");
dubboInterceptor.beforeMethod(enhancedInstance, "invoke", allArguments, argumentTypes, methodInterceptResult); dubboInterceptor.beforeMethod(enhancedInstance, "invoke", allArguments, argumentTypes, methodInterceptResult);
dubboInterceptor.afterMethod(enhancedInstance, "invoke", allArguments, argumentTypes, result); dubboInterceptor.afterMethod(enhancedInstance, "invoke", allArguments, argumentTypes, result);
...@@ -160,7 +160,7 @@ public class DubboInterceptorTest { ...@@ -160,7 +160,7 @@ public class DubboInterceptorTest {
when(rpcContext.isConsumerSide()).thenReturn(false); when(rpcContext.isConsumerSide()).thenReturn(false);
FieldSetter.setStaticValue(BugFixActive.class, "ACTIVE", true); FieldSetter.setStaticValue(BugFixActive.class, "ACTIVE", true);
testParam.setTraceContext("#AQA*#AQA*4WcWe0tQNQA*|3|1|#192.168.1.8 :18002|#/portal/|#/testEntrySpan|#AQA*#AQA*Et0We0tQNQA*"); testParam.setTraceContext("#AQA*#AQA*4WcWe0tQNQA*|3|1|1|#192.168.1.8 :18002|#/portal/|#/testEntrySpan|#AQA*#AQA*Et0We0tQNQA*");
dubboInterceptor.beforeMethod(enhancedInstance, "invoke", allArguments, argumentTypes, methodInterceptResult); dubboInterceptor.beforeMethod(enhancedInstance, "invoke", allArguments, argumentTypes, methodInterceptResult);
dubboInterceptor.afterMethod(enhancedInstance, "invoke", allArguments, argumentTypes, result); dubboInterceptor.afterMethod(enhancedInstance, "invoke", allArguments, argumentTypes, result);
...@@ -194,6 +194,7 @@ public class DubboInterceptorTest { ...@@ -194,6 +194,7 @@ public class DubboInterceptorTest {
private void assertTraceSegmentRef(TraceSegmentRef actual) { private void assertTraceSegmentRef(TraceSegmentRef actual) {
assertThat(SegmentRefHelper.getSpanId(actual), is(3)); assertThat(SegmentRefHelper.getSpanId(actual), is(3));
assertThat(SegmentRefHelper.getEntryApplicationInstanceId(actual), is(1));
assertThat(SegmentRefHelper.getTraceSegmentId(actual).toString(), is("1.1.15006458883500001")); assertThat(SegmentRefHelper.getTraceSegmentId(actual).toString(), is("1.1.15006458883500001"));
} }
......
...@@ -91,7 +91,7 @@ public class MotanProviderInterceptorTest { ...@@ -91,7 +91,7 @@ public class MotanProviderInterceptorTest {
@Test @Test
public void testInvokerWithRefSegment() throws Throwable { public void testInvokerWithRefSegment() throws Throwable {
HashMap attachments = new HashMap(); HashMap attachments = new HashMap();
attachments.put(Config.Plugin.Propagation.HEADER_NAME, "#AQA*#AQA*4WcWe0tQNQA*|3|1|#192.168.1.8:18002|#/portal/|#/testEntrySpan|#AQA*#AQA*Et0We0tQNQA*"); attachments.put(Config.Plugin.Propagation.HEADER_NAME, "#AQA*#AQA*4WcWe0tQNQA*|3|1|1|#192.168.1.8:18002|#/portal/|#/testEntrySpan|#AQA*#AQA*Et0We0tQNQA*");
when(request.getAttachments()).thenReturn(attachments); when(request.getAttachments()).thenReturn(attachments);
invokeInterceptor.beforeMethod(enhancedInstance, "execute", arguments, argumentType, null); invokeInterceptor.beforeMethod(enhancedInstance, "execute", arguments, argumentType, null);
...@@ -137,6 +137,7 @@ public class MotanProviderInterceptorTest { ...@@ -137,6 +137,7 @@ public class MotanProviderInterceptorTest {
private void assertRefSegment(TraceSegmentRef primaryRef) { private void assertRefSegment(TraceSegmentRef primaryRef) {
assertThat(SegmentRefHelper.getTraceSegmentId(primaryRef).toString(), is("1.1.15006458883500001")); assertThat(SegmentRefHelper.getTraceSegmentId(primaryRef).toString(), is("1.1.15006458883500001"));
assertThat(SegmentRefHelper.getSpanId(primaryRef), is(3)); assertThat(SegmentRefHelper.getSpanId(primaryRef), is(3));
assertThat(SegmentRefHelper.getEntryApplicationInstanceId(primaryRef), is(1));
assertThat(SegmentRefHelper.getPeerHost(primaryRef), is("192.168.1.8:18002")); assertThat(SegmentRefHelper.getPeerHost(primaryRef), is("192.168.1.8:18002"));
} }
......
...@@ -90,7 +90,7 @@ public class ResinV3InterceptorTest { ...@@ -90,7 +90,7 @@ public class ResinV3InterceptorTest {
@Test @Test
public void testWithSerializedContextData() throws Throwable { public void testWithSerializedContextData() throws Throwable {
when(request.getHeader(Config.Plugin.Propagation.HEADER_NAME)).thenReturn("#AQA*#AQA*4WcWe0tQNQA*|3|1|#192.168.1.8:18002|#/portal/|#/testEntrySpan|#AQA*#AQA*Et0We0tQNQA*"); when(request.getHeader(Config.Plugin.Propagation.HEADER_NAME)).thenReturn("#AQA*#AQA*4WcWe0tQNQA*|3|1|1|#192.168.1.8:18002|#/portal/|#/testEntrySpan|#AQA*#AQA*Et0We0tQNQA*");
interceptor.beforeMethod(enhancedInstance, "service", arguments, argumentType, methodInterceptResult); interceptor.beforeMethod(enhancedInstance, "service", arguments, argumentType, methodInterceptResult);
interceptor.afterMethod(enhancedInstance, "service", arguments, argumentType, null); interceptor.afterMethod(enhancedInstance, "service", arguments, argumentType, null);
...@@ -121,6 +121,7 @@ public class ResinV3InterceptorTest { ...@@ -121,6 +121,7 @@ public class ResinV3InterceptorTest {
private void assertTraceSegmentRef(TraceSegmentRef ref) { private void assertTraceSegmentRef(TraceSegmentRef ref) {
assertThat(SegmentRefHelper.getSpanId(ref), is(3)); assertThat(SegmentRefHelper.getSpanId(ref), is(3));
assertThat(SegmentRefHelper.getEntryApplicationInstanceId(ref), is(1));
assertThat(SegmentRefHelper.getTraceSegmentId(ref).toString(), is("1.1.15006458883500001")); assertThat(SegmentRefHelper.getTraceSegmentId(ref).toString(), is("1.1.15006458883500001"));
} }
......
...@@ -92,7 +92,7 @@ public class ResinV4InterceptorTest { ...@@ -92,7 +92,7 @@ public class ResinV4InterceptorTest {
@Test @Test
public void testWithSerializedContextData() throws Throwable { public void testWithSerializedContextData() throws Throwable {
when(request.getHeader(Config.Plugin.Propagation.HEADER_NAME)).thenReturn("#AQA*#AQA*4WcWe0tQNQA*|3|1|#192.168.1.8:18002|#/portal/|#/testEntrySpan|#AQA*#AQA*Et0We0tQNQA*"); when(request.getHeader(Config.Plugin.Propagation.HEADER_NAME)).thenReturn("#AQA*#AQA*4WcWe0tQNQA*|3|1|1|#192.168.1.8:18002|#/portal/|#/testEntrySpan|#AQA*#AQA*Et0We0tQNQA*");
interceptor.beforeMethod(enhancedInstance, "service", arguments, argumentType, methodInterceptResult); interceptor.beforeMethod(enhancedInstance, "service", arguments, argumentType, methodInterceptResult);
interceptor.afterMethod(enhancedInstance, "service", arguments, argumentType, null); interceptor.afterMethod(enhancedInstance, "service", arguments, argumentType, null);
...@@ -122,6 +122,7 @@ public class ResinV4InterceptorTest { ...@@ -122,6 +122,7 @@ public class ResinV4InterceptorTest {
} }
private void assertTraceSegmentRef(TraceSegmentRef ref) { private void assertTraceSegmentRef(TraceSegmentRef ref) {
assertThat(SegmentRefHelper.getEntryApplicationInstanceId(ref), is(1));
assertThat(SegmentRefHelper.getSpanId(ref), is(3)); assertThat(SegmentRefHelper.getSpanId(ref), is(3));
assertThat(SegmentRefHelper.getTraceSegmentId(ref).toString(), is("1.1.15006458883500001")); assertThat(SegmentRefHelper.getTraceSegmentId(ref).toString(), is("1.1.15006458883500001"));
} }
......
...@@ -82,7 +82,7 @@ public class TomcatInterceptorTest { ...@@ -82,7 +82,7 @@ public class TomcatInterceptorTest {
@Test @Test
public void testWithSerializedContextData() throws Throwable { public void testWithSerializedContextData() throws Throwable {
when(request.getHeader(Config.Plugin.Propagation.HEADER_NAME)).thenReturn("#AQA*#AQA*4WcWe0tQNQA*|3|1|#192.168.1.8:18002|#/portal/|#/testEntrySpan|#AQA*#AQA*Et0We0tQNQA*"); when(request.getHeader(Config.Plugin.Propagation.HEADER_NAME)).thenReturn("#AQA*#AQA*4WcWe0tQNQA*|3|1|1|#192.168.1.8:18002|#/portal/|#/testEntrySpan|#AQA*#AQA*Et0We0tQNQA*");
tomcatInterceptor.beforeMethod(enhancedInstance, "invoke", arguments, argumentType, methodInterceptResult); tomcatInterceptor.beforeMethod(enhancedInstance, "invoke", arguments, argumentType, methodInterceptResult);
tomcatInterceptor.afterMethod(enhancedInstance, "invoke", arguments, argumentType, null); tomcatInterceptor.afterMethod(enhancedInstance, "invoke", arguments, argumentType, null);
...@@ -112,6 +112,7 @@ public class TomcatInterceptorTest { ...@@ -112,6 +112,7 @@ public class TomcatInterceptorTest {
} }
private void assertTraceSegmentRef(TraceSegmentRef ref) { private void assertTraceSegmentRef(TraceSegmentRef ref) {
assertThat(SegmentRefHelper.getEntryApplicationInstanceId(ref), is(1));
assertThat(SegmentRefHelper.getSpanId(ref), is(3)); assertThat(SegmentRefHelper.getSpanId(ref), is(3));
assertThat(SegmentRefHelper.getTraceSegmentId(ref).toString(), is("1.1.15006458883500001")); assertThat(SegmentRefHelper.getTraceSegmentId(ref).toString(), is("1.1.15006458883500001"));
} }
......
...@@ -30,4 +30,13 @@ public class SegmentRefHelper { ...@@ -30,4 +30,13 @@ public class SegmentRefHelper {
return -1; return -1;
} }
public static int getEntryApplicationInstanceId(TraceSegmentRef ref) {
try {
return FieldGetter.getValue(ref, "entryApplicationInstanceId");
} catch (Exception e) {
}
return -1;
}
} }
...@@ -18,4 +18,9 @@ public class SegmentRefAssert { ...@@ -18,4 +18,9 @@ public class SegmentRefAssert {
public static void assertPeerHost(TraceSegmentRef ref, String peerHost) { public static void assertPeerHost(TraceSegmentRef ref, String peerHost) {
assertThat(SegmentRefHelper.getPeerHost(ref), is(peerHost)); assertThat(SegmentRefHelper.getPeerHost(ref), is(peerHost));
} }
public static void assertEntryApplicationInstanceId(TraceSegmentRef ref, int entryApplicationInstanceID) {
assertThat(SegmentRefHelper.getEntryApplicationInstanceId(ref), is(entryApplicationInstanceID));
}
} }
...@@ -17,6 +17,7 @@ import org.skywalking.apm.agent.core.context.trace.TraceSegment; ...@@ -17,6 +17,7 @@ import org.skywalking.apm.agent.core.context.trace.TraceSegment;
import org.skywalking.apm.agent.core.context.trace.TraceSegmentRef; import org.skywalking.apm.agent.core.context.trace.TraceSegmentRef;
import org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; import org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance;
import org.skywalking.apm.agent.test.helper.SegmentHelper; import org.skywalking.apm.agent.test.helper.SegmentHelper;
import org.skywalking.apm.agent.test.helper.SegmentRefHelper;
import org.skywalking.apm.agent.test.tools.AgentServiceRule; import org.skywalking.apm.agent.test.tools.AgentServiceRule;
import org.skywalking.apm.agent.test.tools.SegmentStorage; import org.skywalking.apm.agent.test.tools.SegmentStorage;
import org.skywalking.apm.agent.test.tools.SegmentStoragePoint; import org.skywalking.apm.agent.test.tools.SegmentStoragePoint;
...@@ -37,6 +38,7 @@ import static org.junit.Assert.assertNull; ...@@ -37,6 +38,7 @@ import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import static org.skywalking.apm.agent.test.tools.SegmentRefAssert.assertPeerHost; import static org.skywalking.apm.agent.test.tools.SegmentRefAssert.assertPeerHost;
import static org.skywalking.apm.agent.test.tools.SegmentRefAssert.assertSegmentId; import static org.skywalking.apm.agent.test.tools.SegmentRefAssert.assertSegmentId;
import static org.skywalking.apm.agent.test.tools.SegmentRefAssert.assertEntryApplicationInstanceId;
import static org.skywalking.apm.agent.test.tools.SegmentRefAssert.assertSpanId; import static org.skywalking.apm.agent.test.tools.SegmentRefAssert.assertSpanId;
import static org.skywalking.apm.agent.test.tools.SpanAssert.assertComponent; import static org.skywalking.apm.agent.test.tools.SpanAssert.assertComponent;
import static org.skywalking.apm.agent.test.tools.SpanAssert.assertLogSize; import static org.skywalking.apm.agent.test.tools.SpanAssert.assertLogSize;
...@@ -181,7 +183,7 @@ public class SkywalkingSpanActivationTest { ...@@ -181,7 +183,7 @@ public class SkywalkingSpanActivationTest {
.withTag(Tags.PEER_HOST_IPV4.getKey(), "127.0.0.1").withTag(Tags.PEER_PORT.getKey(), 8080); .withTag(Tags.PEER_HOST_IPV4.getKey(), "127.0.0.1").withTag(Tags.PEER_PORT.getKey(), 8080);
startSpan(); startSpan();
extractInterceptor.afterMethod(enhancedInstance, "extract", extractInterceptor.afterMethod(enhancedInstance, "extract",
new Object[] {"#AQA*#AQA*4WcWe0tQNQA*|3|1|#127.0.0.1:8080|#/portal/|#/testEntrySpan|#AQA*#AQA*Et0We0tQNQA*"}, new Class[] {String.class}, null); new Object[] {"#AQA*#AQA*4WcWe0tQNQA*|3|1|1|#127.0.0.1:8080|#/portal/|#/testEntrySpan|#AQA*#AQA*Et0We0tQNQA*"}, new Class[] {String.class}, null);
stopSpan(); stopSpan();
TraceSegment tracingSegment = assertTraceSemgnets(); TraceSegment tracingSegment = assertTraceSemgnets();
...@@ -190,11 +192,11 @@ public class SkywalkingSpanActivationTest { ...@@ -190,11 +192,11 @@ public class SkywalkingSpanActivationTest {
TraceSegmentRef ref = tracingSegment.getRefs().get(0); TraceSegmentRef ref = tracingSegment.getRefs().get(0);
assertSegmentId(ref, "1.1.15006458883500001"); assertSegmentId(ref, "1.1.15006458883500001");
assertSpanId(ref, 3); assertSpanId(ref, 3);
assertEntryApplicationInstanceId(ref, 1);
assertPeerHost(ref, "127.0.0.1:8080"); assertPeerHost(ref, "127.0.0.1:8080");
assertThat(spans.size(), is(1)); assertThat(spans.size(), is(1));
assertSpanCommonsAttribute(spans.get(0)); assertSpanCommonsAttribute(spans.get(0));
} }
@Test @Test
public void testExtractWithInValidateContext() throws Throwable { public void testExtractWithInValidateContext() throws Throwable {
spanBuilder.withTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_CLIENT) spanBuilder.withTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_CLIENT)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册