- * Created by wusheng on 2016/12/20.
- */
-public class SkyWalkingSpanBuilder implements Tracer.SpanBuilder {
- private String operationName;
-
- private long startTime = 0L;
-
- private final Map tags;
-
- private SpanContext parentContext;
-
- SkyWalkingSpanBuilder(String operationName) {
- this.operationName = operationName;
- this.tags = new HashMap();
- }
-
- /**
- * In SkyWalkingTracer, SpanContext will not be used. Tracer will build reference by itself.
- *
- * @param spanContext
- * @return
- */
- @Override
- public Tracer.SpanBuilder asChildOf(SpanContext spanContext) {
- this.parentContext = spanContext;
- return this;
- }
-
- /**
- * In SkyWalkingTracer, Parent Span will not be used. Tracer will build reference by itself.
- *
- * @param span
- * @return
- */
- @Override
- public Tracer.SpanBuilder asChildOf(Span span) {
- asChildOf(span.context());
- return this;
- }
-
- @Override
- public Tracer.SpanBuilder addReference(String referenceType, SpanContext referencedContext) {
- if (referenceType.equals(References.CHILD_OF)) {
- return asChildOf(referencedContext);
- } else {
- return this;
- }
- }
-
- @Override
- public Tracer.SpanBuilder withTag(String key, String value) {
- if (key != null && value != null) {
- tags.put(key, value);
- }
- return this;
- }
-
- @Override
- public Tracer.SpanBuilder withTag(String key, boolean value) {
- if (key != null) {
- tags.put(key, Boolean.toString(value));
- }
- return this;
- }
-
- @Override
- public Tracer.SpanBuilder withTag(String key, Number value) {
- if (key != null && value != null) {
- tags.put(key, value.toString());
- }
- return this;
- }
-
- @Override
- public Tracer.SpanBuilder withStartTimestamp(long startTime) {
- this.startTime = startTime;
- return this;
- }
-
- @Override
- public Span start() {
- if (startTime == 0) {
- startTime = System.currentTimeMillis();
- }
- return new SkyWalkingSpan(this.operationName, this.startTime, this.tags);
- }
-
- @Override
- public Iterable> baggageItems() {
- return parentContext == null
- ? Collections.emptyMap().entrySet()
- : parentContext.baggageItems();
- }
-}
diff --git a/apm-application-toolkit/apm-toolkit-opentracing/src/main/java/org/skywalking/apm/toolkit/opentracing/SkywalkingActiveSpan.java b/apm-application-toolkit/apm-toolkit-opentracing/src/main/java/org/skywalking/apm/toolkit/opentracing/SkywalkingActiveSpan.java
new file mode 100644
index 0000000000000000000000000000000000000000..802504f4772be937176da9a35ee0aa656edb6abf
--- /dev/null
+++ b/apm-application-toolkit/apm-toolkit-opentracing/src/main/java/org/skywalking/apm/toolkit/opentracing/SkywalkingActiveSpan.java
@@ -0,0 +1,123 @@
+package org.skywalking.apm.toolkit.opentracing;
+
+import io.opentracing.ActiveSpan;
+import io.opentracing.SpanContext;
+import java.util.Map;
+
+/**
+ * The SkywalkingActiveSpan is an extension of {@link SkywalkingSpan},
+ * but because of Java inheritance restrict, only can do with a facade mode.
+ *
+ * @author wusheng
+ */
+public class SkywalkingActiveSpan implements ActiveSpan {
+ private SkywalkingSpan span;
+
+ public SkywalkingActiveSpan(SkywalkingSpan span) {
+ this.span = span;
+ }
+
+ @Override
+ public void deactivate() {
+ span.finish();
+ }
+
+ @Override
+ public void close() {
+ this.deactivate();
+ }
+
+ @Override
+ public Continuation capture() {
+ return new SkywalkingContinuation();
+ }
+
+ @Override
+ public SpanContext context() {
+ return span.context();
+ }
+
+ @Override
+ public ActiveSpan setTag(String key, String value) {
+ span.setTag(key, value);
+ return this;
+ }
+
+ @Override
+ public ActiveSpan setTag(String key, boolean value) {
+ span.setTag(key, value);
+ return this;
+ }
+
+ @Override
+ public ActiveSpan setTag(String key, Number value) {
+ span.setTag(key, value);
+ return this;
+ }
+
+ @Override
+ public ActiveSpan log(Map fields) {
+ span.log(fields);
+ return this;
+ }
+
+ @Override
+ public ActiveSpan log(long timestampMicroseconds, Map fields) {
+ span.log(timestampMicroseconds, fields);
+ return this;
+ }
+
+ @Override
+ public ActiveSpan log(String event) {
+ span.log(event);
+ return this;
+ }
+
+ @Override
+ public ActiveSpan log(long timestampMicroseconds, String event) {
+ span.log(timestampMicroseconds, event);
+ return this;
+ }
+
+ /**
+ * Don't support baggage item.
+ */
+ @Override
+ public ActiveSpan setBaggageItem(String key, String value) {
+ return this;
+ }
+
+ /**
+ * Don't support baggage item.
+ *
+ * @return null, always.
+ */
+ @Override
+ public String getBaggageItem(String key) {
+ return null;
+ }
+
+ @Override
+ public ActiveSpan setOperationName(String operationName) {
+ span.setOperationName(operationName);
+ return this;
+ }
+
+ /**
+ * Don't support logging with payload.
+ */
+ @Deprecated
+ @Override
+ public ActiveSpan log(String eventName, Object payload) {
+ return this;
+ }
+
+ /**
+ * Don't support logging with payload.
+ */
+ @Deprecated
+ @Override
+ public ActiveSpan log(long timestampMicroseconds, String eventName, Object payload) {
+ return this;
+ }
+}
diff --git a/apm-application-toolkit/apm-toolkit-opentracing/src/main/java/org/skywalking/apm/toolkit/opentracing/SkywalkingContext.java b/apm-application-toolkit/apm-toolkit-opentracing/src/main/java/org/skywalking/apm/toolkit/opentracing/SkywalkingContext.java
new file mode 100644
index 0000000000000000000000000000000000000000..2ef6f68dcf8e843a2c72c71f4801d49815e97f0f
--- /dev/null
+++ b/apm-application-toolkit/apm-toolkit-opentracing/src/main/java/org/skywalking/apm/toolkit/opentracing/SkywalkingContext.java
@@ -0,0 +1,21 @@
+package org.skywalking.apm.toolkit.opentracing;
+
+import io.opentracing.SpanContext;
+import java.util.Map;
+
+/**
+ * Skywalking tracer context based on {@link ThreadLocal} auto mechanism.
+ *
+ * @author wusheng
+ */
+public class SkywalkingContext implements SpanContext {
+ public static final SkywalkingContext INSTANCE = new SkywalkingContext();
+
+ private SkywalkingContext() {
+ }
+
+ @Override
+ public Iterable> baggageItems() {
+ return null;
+ }
+}
diff --git a/apm-application-toolkit/apm-toolkit-opentracing/src/main/java/org/skywalking/apm/toolkit/opentracing/SkywalkingContinuation.java b/apm-application-toolkit/apm-toolkit-opentracing/src/main/java/org/skywalking/apm/toolkit/opentracing/SkywalkingContinuation.java
new file mode 100644
index 0000000000000000000000000000000000000000..87c4fafa603964048ae87d0c0457ac1244175c4a
--- /dev/null
+++ b/apm-application-toolkit/apm-toolkit-opentracing/src/main/java/org/skywalking/apm/toolkit/opentracing/SkywalkingContinuation.java
@@ -0,0 +1,21 @@
+package org.skywalking.apm.toolkit.opentracing;
+
+import io.opentracing.ActiveSpan;
+
+/**
+ * @author wusheng
+ */
+public class SkywalkingContinuation implements ActiveSpan.Continuation {
+ @NeedSnifferActivation("1. ContextManager#capture" +
+ "2. set ContextSnapshot to the dynamic field")
+ public SkywalkingContinuation() {
+ }
+
+ @NeedSnifferActivation("1. get ContextSnapshot from the dynamic field" +
+ "2. ContextManager#continued")
+ @Override
+ public ActiveSpan activate() {
+ SkywalkingSpanBuilder builder = new SkywalkingSpanBuilder("Thread/" + Thread.currentThread().getName());
+ return builder.startActive();
+ }
+}
diff --git a/apm-application-toolkit/apm-toolkit-opentracing/src/main/java/org/skywalking/apm/toolkit/opentracing/SkywalkingSpan.java b/apm-application-toolkit/apm-toolkit-opentracing/src/main/java/org/skywalking/apm/toolkit/opentracing/SkywalkingSpan.java
new file mode 100644
index 0000000000000000000000000000000000000000..430fa46e6d4c53c00d7eaa41b6703867a40054a5
--- /dev/null
+++ b/apm-application-toolkit/apm-toolkit-opentracing/src/main/java/org/skywalking/apm/toolkit/opentracing/SkywalkingSpan.java
@@ -0,0 +1,128 @@
+package org.skywalking.apm.toolkit.opentracing;
+
+import io.opentracing.Span;
+import io.opentracing.SpanContext;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * @author wusheng
+ */
+public class SkywalkingSpan implements Span {
+ @NeedSnifferActivation(
+ "1.ContextManager#createSpan (Entry,Exit,Local based on builder)." +
+ "2.set the span reference to the dynamic field of enhanced SkywalkingSpan")
+ SkywalkingSpan(SkywalkingSpanBuilder builder) {
+ }
+
+ /**
+ * Create a shell span for {@link SkywalkingTracer#activeSpan()}
+ *
+ * @param tracer
+ */
+ @NeedSnifferActivation(
+ "1. set the span reference to the dynamic field of enhanced SkywalkingSpan")
+ public SkywalkingSpan(SkywalkingTracer tracer) {
+
+ }
+
+ @NeedSnifferActivation("Override span's operationName, which has been given at ")
+ @Override
+ public Span setOperationName(String operationName) {
+ return this;
+ }
+
+ @NeedSnifferActivation("AbstractTracingSpan#log(long timestampMicroseconds, Map fields)")
+ @Override
+ public Span log(long timestampMicroseconds, Map fields) {
+ return this;
+ }
+
+ /**
+ * Stop the active span
+ *
+ * @param finishMicros
+ */
+ @NeedSnifferActivation(
+ "1.ContextManager#stopSpan(AbstractSpan span)" +
+ "2. The parameter of stop methed is from the dynamic field of enhanced SkywalkingSpan")
+ @Override
+ public void finish(long finishMicros) {
+
+ }
+
+ @Override
+ public Span log(long timestampMicroseconds, String event) {
+ Map eventMap = new HashMap(1);
+ eventMap.put("event", event);
+ return log(timestampMicroseconds, eventMap);
+ }
+
+ @Override
+ public void finish() {
+ this.finish(System.currentTimeMillis());
+ }
+
+ @Override
+ public SpanContext context() {
+ return SkywalkingContext.INSTANCE;
+ }
+
+ @Override public Span setTag(String key, String value) {
+ return null;
+ }
+
+ @Override public Span setTag(String key, boolean value) {
+ return null;
+ }
+
+ @Override public Span setTag(String key, Number value) {
+ return null;
+ }
+
+ @Override
+ public Span log(Map fields) {
+ return log(System.currentTimeMillis(), fields);
+ }
+
+ @Override
+ public Span log(String event) {
+ return log(System.currentTimeMillis(), event);
+ }
+
+ /**
+ * Don't support baggage item.
+ */
+ @Override
+ public Span setBaggageItem(String key, String value) {
+ return this;
+ }
+
+ /**
+ * Don't support baggage item.
+ *
+ * @return null, always.
+ */
+ @Override
+ public String getBaggageItem(String key) {
+ return null;
+ }
+
+ /**
+ * Don't support logging with payload.
+ */
+ @Deprecated
+ @Override
+ public Span log(String eventName, Object payload) {
+ return this;
+ }
+
+ /**
+ * Don't support logging with payload.
+ */
+ @Deprecated
+ @Override
+ public Span log(long timestampMicroseconds, String eventName, Object payload) {
+ return this;
+ }
+}
diff --git a/apm-application-toolkit/apm-toolkit-opentracing/src/main/java/org/skywalking/apm/toolkit/opentracing/SkywalkingSpanBuilder.java b/apm-application-toolkit/apm-toolkit-opentracing/src/main/java/org/skywalking/apm/toolkit/opentracing/SkywalkingSpanBuilder.java
new file mode 100644
index 0000000000000000000000000000000000000000..ca2335a90126f9d1e5c735c1d1bfade27648a6c2
--- /dev/null
+++ b/apm-application-toolkit/apm-toolkit-opentracing/src/main/java/org/skywalking/apm/toolkit/opentracing/SkywalkingSpanBuilder.java
@@ -0,0 +1,177 @@
+package org.skywalking.apm.toolkit.opentracing;
+
+import io.opentracing.ActiveSpan;
+import io.opentracing.BaseSpan;
+import io.opentracing.References;
+import io.opentracing.Span;
+import io.opentracing.SpanContext;
+import io.opentracing.Tracer;
+import io.opentracing.tag.Tags;
+import java.util.LinkedList;
+import java.util.List;
+
+/**
+ * @author wusheng
+ */
+public class SkywalkingSpanBuilder implements Tracer.SpanBuilder {
+ private List tags = new LinkedList();
+ private String operationName;
+ private boolean isEntry = false;
+ private boolean isExit = false;
+ private int port;
+ private String peer;
+ private String componentName;
+ private boolean isError = false;
+ private long startTime;
+
+ public SkywalkingSpanBuilder(String operationName) {
+ this.operationName = operationName;
+ }
+
+ @Override
+ public Tracer.SpanBuilder asChildOf(SpanContext parent) {
+ if (parent instanceof SkywalkingContext) {
+ return this;
+ }
+ throw new IllegalArgumentException("parent must be type of SpanContext");
+ }
+
+ @Override
+ public Tracer.SpanBuilder asChildOf(BaseSpan> parent) {
+ if (parent instanceof SkywalkingSpan || parent instanceof SkywalkingActiveSpan) {
+ return this;
+ }
+ throw new IllegalArgumentException("parent must be type of SkywalkingSpan");
+ }
+
+ /**
+ * Ignore the reference type. the span always the entry or has a parent span.
+ *
+ * @param referenceType
+ * @param referencedContext
+ * @return
+ */
+ @Override
+ public Tracer.SpanBuilder addReference(String referenceType, SpanContext referencedContext) {
+ if (References.FOLLOWS_FROM.equals(referenceType)) {
+ throw new IllegalArgumentException("only support CHILD_OF reference");
+ }
+ return asChildOf(referencedContext);
+ }
+
+ @Override
+ public Tracer.SpanBuilder withTag(String key, String value) {
+ if (Tags.COMPONENT.getKey().equals(key)) {
+ componentName = value;
+ } else if (Tags.SPAN_KIND.getKey().equals(key)) {
+ if (Tags.SPAN_KIND_CLIENT.equals(value) || Tags.SPAN_KIND_PRODUCER.equals(value)) {
+ isEntry = false;
+ isExit = true;
+ } else if (Tags.SPAN_KIND_SERVER.equals(value) || Tags.SPAN_KIND_CONSUMER.equals(value)) {
+ isEntry = true;
+ isExit = false;
+ } else {
+ isEntry = false;
+ isExit = false;
+ }
+ } else if (Tags.PEER_HOST_IPV4.getKey().equals(key) || Tags.PEER_HOST_IPV6.getKey().equals(key)
+ || Tags.PEER_HOSTNAME.getKey().equals(key)) {
+ peer = value;
+ } else if (Tags.PEER_SERVICE.getKey().equals(key)) {
+ operationName = value;
+ } else {
+ tags.add(new Tag(key, value));
+ }
+ return this;
+ }
+
+ @Override
+ public Tracer.SpanBuilder withTag(String key, boolean value) {
+ if (Tags.ERROR.equals(key)) {
+ isError = value;
+ } else {
+ tags.add(new Tag(key, value ? "true" : "false"));
+ }
+ return this;
+ }
+
+ @Override
+ public Tracer.SpanBuilder withTag(String key, Number value) {
+ if (Tags.PEER_PORT.getKey().equals(key)) {
+ port = value.intValue();
+ } else {
+ tags.add(new Tag(key, value.toString()));
+ }
+ return this;
+ }
+
+ @Override
+ public Tracer.SpanBuilder withStartTimestamp(long microseconds) {
+ startTime = microseconds;
+ return this;
+ }
+
+ @Override
+ public ActiveSpan startActive() {
+ return new SkywalkingActiveSpan(new SkywalkingSpan(this));
+ }
+
+ @Override
+ public Span startManual() {
+ return new SkywalkingSpan(this);
+ }
+
+ @Override
+ @Deprecated
+ public Span start() {
+ return startManual();
+ }
+
+ /**
+ * All the get methods are for accessing data from activation
+ */
+ public List getTags() {
+ return tags;
+ }
+
+ public String getOperationName() {
+ return operationName;
+ }
+
+ public boolean isEntry() {
+ return isEntry;
+ }
+
+ public boolean isExit() {
+ return isExit;
+ }
+
+ public int getPort() {
+ return port;
+ }
+
+ public String getPeer() {
+ return peer;
+ }
+
+ public String getComponentName() {
+ return componentName;
+ }
+
+ public boolean isError() {
+ return isError;
+ }
+
+ public long getStartTime() {
+ return startTime;
+ }
+
+ /**
+ * All the following methods are needed for activation.
+ */
+ @Override
+ @NeedSnifferActivation("Stop the active span.")
+ public Tracer.SpanBuilder ignoreActiveSpan() {
+ return this;
+ }
+}
diff --git a/apm-application-toolkit/apm-toolkit-opentracing/src/main/java/org/skywalking/apm/toolkit/opentracing/SkyWalkingTracer.java b/apm-application-toolkit/apm-toolkit-opentracing/src/main/java/org/skywalking/apm/toolkit/opentracing/SkywalkingTracer.java
similarity index 61%
rename from apm-application-toolkit/apm-toolkit-opentracing/src/main/java/org/skywalking/apm/toolkit/opentracing/SkyWalkingTracer.java
rename to apm-application-toolkit/apm-toolkit-opentracing/src/main/java/org/skywalking/apm/toolkit/opentracing/SkywalkingTracer.java
index 0b6a957c0f42c4220c3a15b04863983a3bc5d0eb..0ae5db2da319ff6b59a2c7e7986719e1a064fdf1 100644
--- a/apm-application-toolkit/apm-toolkit-opentracing/src/main/java/org/skywalking/apm/toolkit/opentracing/SkyWalkingTracer.java
+++ b/apm-application-toolkit/apm-toolkit-opentracing/src/main/java/org/skywalking/apm/toolkit/opentracing/SkywalkingTracer.java
@@ -1,74 +1,82 @@
package org.skywalking.apm.toolkit.opentracing;
+import io.opentracing.ActiveSpan;
+import io.opentracing.Span;
import io.opentracing.SpanContext;
import io.opentracing.Tracer;
import io.opentracing.propagation.Format;
import io.opentracing.propagation.TextMap;
-
import java.nio.ByteBuffer;
import java.nio.charset.Charset;
import java.util.Iterator;
import java.util.Map;
/**
- * All source code in SkyWalkingTracer acts like an NoopTracer.
- * Actually, it is NOT.
- * The whole logic will be added after toolkit-activation.
- *
- * Created by wusheng on 2016/12/20.
+ * @author wusheng
*/
-public class SkyWalkingTracer implements Tracer {
+public class SkywalkingTracer implements Tracer {
private static String TRACE_HEAD_NAME = "sw3";
- public static Tracer INSTANCE = new SkyWalkingTracer();
+ @NeedSnifferActivation("1. ContextManager#inject" +
+ "2. ContextCarrier#serialize")
+ private String inject() {
+ return null;
+ }
+
+ @NeedSnifferActivation("1. ContextCarrier#deserialize" +
+ "2. ContextManager#extract")
+ private void extract(String carrier) {
+ }
@Override
public SpanBuilder buildSpan(String operationName) {
- return new SkyWalkingSpanBuilder(operationName);
+ return new SkywalkingSpanBuilder(operationName);
}
@Override
public void inject(SpanContext spanContext, Format format, C carrier) {
if (Format.Builtin.TEXT_MAP.equals(format) || Format.Builtin.HTTP_HEADERS.equals(format)) {
- ((TextMap) carrier).put(TRACE_HEAD_NAME, formatInjectCrossProcessPropagationContextData());
+ ((TextMap)carrier).put(TRACE_HEAD_NAME, inject());
} else if (Format.Builtin.BINARY.equals(format)) {
byte[] key = TRACE_HEAD_NAME.getBytes(ByteBufferContext.CHARSET);
- byte[] value = formatInjectCrossProcessPropagationContextData().getBytes(ByteBufferContext.CHARSET);
- ((ByteBuffer) carrier).put(key);
- ((ByteBuffer) carrier).putInt(value.length);
- ((ByteBuffer) carrier).put(value);
+ byte[] value = inject().getBytes(ByteBufferContext.CHARSET);
+ ((ByteBuffer)carrier).put(key);
+ ((ByteBuffer)carrier).putInt(value.length);
+ ((ByteBuffer)carrier).put(value);
} else {
throw new IllegalArgumentException("Unsupported format: " + format);
}
+
}
@Override
public SpanContext extract(Format format, C carrier) {
if (Format.Builtin.TEXT_MAP.equals(format) || Format.Builtin.HTTP_HEADERS.equals(format)) {
- TextMap textMapCarrier = (TextMap) carrier;
- formatExtractCrossProcessPropagationContextData(fetchContextData(textMapCarrier));
+ TextMap textMapCarrier = (TextMap)carrier;
+ extract(fetchContextData(textMapCarrier));
return new TextMapContext(textMapCarrier);
} else if (Format.Builtin.BINARY.equals(format)) {
- ByteBuffer byteBufferCarrier = (ByteBuffer) carrier;
- formatExtractCrossProcessPropagationContextData(fetchContextData(byteBufferCarrier));
- return new ByteBufferContext((ByteBuffer) carrier);
+ ByteBuffer byteBufferCarrier = (ByteBuffer)carrier;
+ extract(fetchContextData(byteBufferCarrier));
+ return new ByteBufferContext((ByteBuffer)carrier);
} else {
throw new IllegalArgumentException("Unsupported format: " + format);
}
}
- /**
- * set context data in toolkit-opentracing-activation
- */
- private String formatInjectCrossProcessPropagationContextData() {
- return "";
+ @Override
+ public ActiveSpan activeSpan() {
+ return new SkywalkingActiveSpan(new SkywalkingSpan(this));
}
- /**
- * read context data in toolkit-opentracing-activation
- */
- private void formatExtractCrossProcessPropagationContextData(String contextData) {
+ @Override
+ public ActiveSpan makeActive(Span span) {
+ if (span instanceof SkywalkingSpan) {
+ return new SkywalkingActiveSpan((SkywalkingSpan)span);
+ } else {
+ throw new IllegalArgumentException("span must be a type of SkywalkingSpan");
+ }
}
private String fetchContextData(TextMap textMap) {
@@ -99,4 +107,5 @@ public class SkyWalkingTracer implements Tracer {
return null;
}
}
+
}
diff --git a/apm-application-toolkit/apm-toolkit-opentracing/src/main/java/org/skywalking/apm/toolkit/opentracing/Tag.java b/apm-application-toolkit/apm-toolkit-opentracing/src/main/java/org/skywalking/apm/toolkit/opentracing/Tag.java
new file mode 100644
index 0000000000000000000000000000000000000000..8a5fdc524385b1759999380dc06d0d43cc602777
--- /dev/null
+++ b/apm-application-toolkit/apm-toolkit-opentracing/src/main/java/org/skywalking/apm/toolkit/opentracing/Tag.java
@@ -0,0 +1,22 @@
+package org.skywalking.apm.toolkit.opentracing;
+
+/**
+ * @author wusheng
+ */
+public class Tag {
+ private String key;
+ private String value;
+
+ public Tag(String key, String value) {
+ this.key = key;
+ this.value = value;
+ }
+
+ public String getKey() {
+ return key;
+ }
+
+ public String getValue() {
+ return value;
+ }
+}
diff --git a/apm-application-toolkit/apm-toolkit-opentracing/src/main/resources/META-INF.services/io.opentracing.Tracer b/apm-application-toolkit/apm-toolkit-opentracing/src/main/resources/META-INF.services/io.opentracing.Tracer
index 4347701c7c584a842fb4b717caa3fff569cc4255..980fb4a6c32969c7249e4dd7b1d63d7fbf518b52 100644
--- a/apm-application-toolkit/apm-toolkit-opentracing/src/main/resources/META-INF.services/io.opentracing.Tracer
+++ b/apm-application-toolkit/apm-toolkit-opentracing/src/main/resources/META-INF.services/io.opentracing.Tracer
@@ -1 +1 @@
-SkyWalkingTracer
+org.skywalking.apm.toolkit.opentracing.SkyWalkingTracer
diff --git a/apm-application-toolkit/apm-toolkit-opentracing/src/test/java/org/skywalking/apm/toolkit/opentracing/SkyWalkingTracerTest.java b/apm-application-toolkit/apm-toolkit-opentracing/src/test/java/org/skywalking/apm/toolkit/opentracing/SkyWalkingTracerTest.java
deleted file mode 100644
index 93d03ac208d9d1892c7f24c8c29505b8a3af70ac..0000000000000000000000000000000000000000
--- a/apm-application-toolkit/apm-toolkit-opentracing/src/test/java/org/skywalking/apm/toolkit/opentracing/SkyWalkingTracerTest.java
+++ /dev/null
@@ -1,39 +0,0 @@
-package org.skywalking.apm.toolkit.opentracing;
-
-import io.opentracing.Span;
-import io.opentracing.SpanContext;
-import io.opentracing.Tracer;
-import io.opentracing.propagation.TextMap;
-import org.junit.Test;
-
-import java.util.Iterator;
-import java.util.Map;
-
-/**
- * Created by wusheng on 2016/12/21.
- */
-public class SkyWalkingTracerTest {
- @Test
- public void testBuildSpan() {
- Tracer tracer = SkyWalkingTracer.INSTANCE;
- Tracer.SpanBuilder spanBuilder = tracer.buildSpan("/http/serviceName");
-
- SpanContext context = new TextMapContext(new TextMap() {
-
- @Override
- public Iterator> iterator() {
- throw new UnsupportedOperationException(
- "TextMapInjectAdapter should only be used with Tracer.inject()");
- }
-
- @Override
- public void put(String key, String value) {
-
- }
- });
- spanBuilder.asChildOf(context).withTag("example.tag", "testtag");
- Span span = spanBuilder.start();
-
- span.finish();
- }
-}
diff --git a/apm-commons/apm-datacarrier/pom.xml b/apm-commons/apm-datacarrier/pom.xml
new file mode 100644
index 0000000000000000000000000000000000000000..098bf428e414a6209de735366e6af2d8e99acce1
--- /dev/null
+++ b/apm-commons/apm-datacarrier/pom.xml
@@ -0,0 +1,14 @@
+
+
+
+ apm-commons
+ org.skywalking
+ 3.2-2017
+
+ 4.0.0
+
+ apm-datacarrier
+
+
diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/datacarrier/DataCarrier.java b/apm-commons/apm-datacarrier/src/main/java/org/skywalking/apm/commons/datacarrier/DataCarrier.java
similarity index 86%
rename from apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/datacarrier/DataCarrier.java
rename to apm-commons/apm-datacarrier/src/main/java/org/skywalking/apm/commons/datacarrier/DataCarrier.java
index 92c60cf88c13b2c2734db474404e4d8a568af2b6..e0d6f92360090775549cd915581149314b54e8d7 100644
--- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/datacarrier/DataCarrier.java
+++ b/apm-commons/apm-datacarrier/src/main/java/org/skywalking/apm/commons/datacarrier/DataCarrier.java
@@ -1,11 +1,11 @@
-package org.skywalking.apm.agent.core.datacarrier;
+package org.skywalking.apm.commons.datacarrier;
-import org.skywalking.apm.agent.core.datacarrier.buffer.BufferStrategy;
-import org.skywalking.apm.agent.core.datacarrier.buffer.Channels;
-import org.skywalking.apm.agent.core.datacarrier.consumer.ConsumerPool;
-import org.skywalking.apm.agent.core.datacarrier.consumer.IConsumer;
-import org.skywalking.apm.agent.core.datacarrier.partition.IDataPartitioner;
-import org.skywalking.apm.agent.core.datacarrier.partition.SimpleRollingPartitioner;
+import org.skywalking.apm.commons.datacarrier.buffer.BufferStrategy;
+import org.skywalking.apm.commons.datacarrier.buffer.Channels;
+import org.skywalking.apm.commons.datacarrier.consumer.ConsumerPool;
+import org.skywalking.apm.commons.datacarrier.consumer.IConsumer;
+import org.skywalking.apm.commons.datacarrier.partition.IDataPartitioner;
+import org.skywalking.apm.commons.datacarrier.partition.SimpleRollingPartitioner;
/**
* DataCarrier main class.
diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/datacarrier/buffer/Buffer.java b/apm-commons/apm-datacarrier/src/main/java/org/skywalking/apm/commons/datacarrier/buffer/Buffer.java
similarity index 91%
rename from apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/datacarrier/buffer/Buffer.java
rename to apm-commons/apm-datacarrier/src/main/java/org/skywalking/apm/commons/datacarrier/buffer/Buffer.java
index cdf3a9025c48277693acceef4a51046b681ed943..7c798de7f88848e13af963b9302755ef71e22945 100644
--- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/datacarrier/buffer/Buffer.java
+++ b/apm-commons/apm-datacarrier/src/main/java/org/skywalking/apm/commons/datacarrier/buffer/Buffer.java
@@ -1,7 +1,7 @@
-package org.skywalking.apm.agent.core.datacarrier.buffer;
+package org.skywalking.apm.commons.datacarrier.buffer;
import java.util.LinkedList;
-import org.skywalking.apm.agent.core.datacarrier.common.AtomicRangeInteger;
+import org.skywalking.apm.commons.datacarrier.common.AtomicRangeInteger;
/**
* Created by wusheng on 2016/10/25.
diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/datacarrier/buffer/BufferStrategy.java b/apm-commons/apm-datacarrier/src/main/java/org/skywalking/apm/commons/datacarrier/buffer/BufferStrategy.java
similarity index 67%
rename from apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/datacarrier/buffer/BufferStrategy.java
rename to apm-commons/apm-datacarrier/src/main/java/org/skywalking/apm/commons/datacarrier/buffer/BufferStrategy.java
index 527756ee1db4c5ec4d8fa97d318e6eca809ddc3b..02ea1cc11de1435ac9d1be75ff154c585ad6c036 100644
--- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/datacarrier/buffer/BufferStrategy.java
+++ b/apm-commons/apm-datacarrier/src/main/java/org/skywalking/apm/commons/datacarrier/buffer/BufferStrategy.java
@@ -1,4 +1,4 @@
-package org.skywalking.apm.agent.core.datacarrier.buffer;
+package org.skywalking.apm.commons.datacarrier.buffer;
/**
* Created by wusheng on 2016/10/25.
diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/datacarrier/buffer/Channels.java b/apm-commons/apm-datacarrier/src/main/java/org/skywalking/apm/commons/datacarrier/buffer/Channels.java
similarity index 92%
rename from apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/datacarrier/buffer/Channels.java
rename to apm-commons/apm-datacarrier/src/main/java/org/skywalking/apm/commons/datacarrier/buffer/Channels.java
index 7dd6d8a4ad6f748586f569060bafa7f65cd7400e..e4b2e6182995c959de6c69a16d48b942b66b72fa 100644
--- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/datacarrier/buffer/Channels.java
+++ b/apm-commons/apm-datacarrier/src/main/java/org/skywalking/apm/commons/datacarrier/buffer/Channels.java
@@ -1,6 +1,6 @@
-package org.skywalking.apm.agent.core.datacarrier.buffer;
+package org.skywalking.apm.commons.datacarrier.buffer;
-import org.skywalking.apm.agent.core.datacarrier.partition.IDataPartitioner;
+import org.skywalking.apm.commons.datacarrier.partition.IDataPartitioner;
/**
* Channels of Buffer
diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/datacarrier/common/AtomicRangeInteger.java b/apm-commons/apm-datacarrier/src/main/java/org/skywalking/apm/commons/datacarrier/common/AtomicRangeInteger.java
similarity index 95%
rename from apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/datacarrier/common/AtomicRangeInteger.java
rename to apm-commons/apm-datacarrier/src/main/java/org/skywalking/apm/commons/datacarrier/common/AtomicRangeInteger.java
index 9e1407cc8144f99b94949c0207754c45064325dc..9b3ed36a754a5a3d7cac358141736e4a4e3e5636 100644
--- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/datacarrier/common/AtomicRangeInteger.java
+++ b/apm-commons/apm-datacarrier/src/main/java/org/skywalking/apm/commons/datacarrier/common/AtomicRangeInteger.java
@@ -1,4 +1,4 @@
-package org.skywalking.apm.agent.core.datacarrier.common;
+package org.skywalking.apm.commons.datacarrier.common;
import java.io.Serializable;
import java.util.concurrent.atomic.AtomicInteger;
diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/datacarrier/consumer/ConsumerCannotBeCreatedException.java b/apm-commons/apm-datacarrier/src/main/java/org/skywalking/apm/commons/datacarrier/consumer/ConsumerCannotBeCreatedException.java
similarity index 76%
rename from apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/datacarrier/consumer/ConsumerCannotBeCreatedException.java
rename to apm-commons/apm-datacarrier/src/main/java/org/skywalking/apm/commons/datacarrier/consumer/ConsumerCannotBeCreatedException.java
index a7683691dafb5d7ef4fae98c0e0a041608845aca..6cadcf6a2cb3e13491e70cae3c1ada568f1c368d 100644
--- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/datacarrier/consumer/ConsumerCannotBeCreatedException.java
+++ b/apm-commons/apm-datacarrier/src/main/java/org/skywalking/apm/commons/datacarrier/consumer/ConsumerCannotBeCreatedException.java
@@ -1,4 +1,4 @@
-package org.skywalking.apm.agent.core.datacarrier.consumer;
+package org.skywalking.apm.commons.datacarrier.consumer;
/**
* Created by wusheng on 2016/11/15.
diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/datacarrier/consumer/ConsumerPool.java b/apm-commons/apm-datacarrier/src/main/java/org/skywalking/apm/commons/datacarrier/consumer/ConsumerPool.java
similarity index 95%
rename from apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/datacarrier/consumer/ConsumerPool.java
rename to apm-commons/apm-datacarrier/src/main/java/org/skywalking/apm/commons/datacarrier/consumer/ConsumerPool.java
index 3b4ec68d0418c8cc35c46ff5ce4b36daed3fec64..75a2ad65159f426a8d30840ebd823ddd71388690 100644
--- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/datacarrier/consumer/ConsumerPool.java
+++ b/apm-commons/apm-datacarrier/src/main/java/org/skywalking/apm/commons/datacarrier/consumer/ConsumerPool.java
@@ -1,9 +1,9 @@
-package org.skywalking.apm.agent.core.datacarrier.consumer;
+package org.skywalking.apm.commons.datacarrier.consumer;
import java.util.ArrayList;
import java.util.concurrent.locks.ReentrantLock;
-import org.skywalking.apm.agent.core.datacarrier.buffer.Buffer;
-import org.skywalking.apm.agent.core.datacarrier.buffer.Channels;
+import org.skywalking.apm.commons.datacarrier.buffer.Buffer;
+import org.skywalking.apm.commons.datacarrier.buffer.Channels;
/**
* Pool of consumers
@@ -28,6 +28,7 @@ public class ConsumerPool {
prototype.init();
for (int i = 0; i < num; i++) {
consumerThreads[i] = new ConsumerThread("DataCarrier.Consumser." + i + ".Thread", prototype);
+ consumerThreads[i].setDaemon(true);
}
}
diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/datacarrier/consumer/ConsumerThread.java b/apm-commons/apm-datacarrier/src/main/java/org/skywalking/apm/commons/datacarrier/consumer/ConsumerThread.java
similarity index 95%
rename from apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/datacarrier/consumer/ConsumerThread.java
rename to apm-commons/apm-datacarrier/src/main/java/org/skywalking/apm/commons/datacarrier/consumer/ConsumerThread.java
index 811179562f9094bc2bc0254e26945c6b352c4d83..71b34d00f27fea7c0c4f677dc0f40ea83f63311f 100644
--- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/datacarrier/consumer/ConsumerThread.java
+++ b/apm-commons/apm-datacarrier/src/main/java/org/skywalking/apm/commons/datacarrier/consumer/ConsumerThread.java
@@ -1,8 +1,8 @@
-package org.skywalking.apm.agent.core.datacarrier.consumer;
+package org.skywalking.apm.commons.datacarrier.consumer;
import java.util.LinkedList;
import java.util.List;
-import org.skywalking.apm.agent.core.datacarrier.buffer.Buffer;
+import org.skywalking.apm.commons.datacarrier.buffer.Buffer;
/**
* Created by wusheng on 2016/10/25.
diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/datacarrier/consumer/IConsumer.java b/apm-commons/apm-datacarrier/src/main/java/org/skywalking/apm/commons/datacarrier/consumer/IConsumer.java
similarity index 78%
rename from apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/datacarrier/consumer/IConsumer.java
rename to apm-commons/apm-datacarrier/src/main/java/org/skywalking/apm/commons/datacarrier/consumer/IConsumer.java
index 70ee5b60fe506463a192eaa30ccafccd21634e32..4e42f4739041b668b8d9ec38461d33ecb5d8a031 100644
--- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/datacarrier/consumer/IConsumer.java
+++ b/apm-commons/apm-datacarrier/src/main/java/org/skywalking/apm/commons/datacarrier/consumer/IConsumer.java
@@ -1,4 +1,4 @@
-package org.skywalking.apm.agent.core.datacarrier.consumer;
+package org.skywalking.apm.commons.datacarrier.consumer;
import java.util.List;
diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/datacarrier/partition/IDataPartitioner.java b/apm-commons/apm-datacarrier/src/main/java/org/skywalking/apm/commons/datacarrier/partition/IDataPartitioner.java
similarity index 67%
rename from apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/datacarrier/partition/IDataPartitioner.java
rename to apm-commons/apm-datacarrier/src/main/java/org/skywalking/apm/commons/datacarrier/partition/IDataPartitioner.java
index 140b82236e466b6686d6b87a644f2c5dcf1d00c7..105bcbc4eb369b3721e18377cf74e2064c882aa5 100644
--- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/datacarrier/partition/IDataPartitioner.java
+++ b/apm-commons/apm-datacarrier/src/main/java/org/skywalking/apm/commons/datacarrier/partition/IDataPartitioner.java
@@ -1,4 +1,4 @@
-package org.skywalking.apm.agent.core.datacarrier.partition;
+package org.skywalking.apm.commons.datacarrier.partition;
/**
* Created by wusheng on 2016/10/25.
diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/datacarrier/partition/ProducerThreadPartitioner.java b/apm-commons/apm-datacarrier/src/main/java/org/skywalking/apm/commons/datacarrier/partition/ProducerThreadPartitioner.java
similarity index 82%
rename from apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/datacarrier/partition/ProducerThreadPartitioner.java
rename to apm-commons/apm-datacarrier/src/main/java/org/skywalking/apm/commons/datacarrier/partition/ProducerThreadPartitioner.java
index 118fd6327835a4b21baa6a1d97a18048594fc78b..3ebbee5924abefe9e0ca0c579e46d0a360a57c21 100644
--- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/datacarrier/partition/ProducerThreadPartitioner.java
+++ b/apm-commons/apm-datacarrier/src/main/java/org/skywalking/apm/commons/datacarrier/partition/ProducerThreadPartitioner.java
@@ -1,4 +1,4 @@
-package org.skywalking.apm.agent.core.datacarrier.partition;
+package org.skywalking.apm.commons.datacarrier.partition;
/**
* use threadid % total to partition
diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/datacarrier/partition/SimpleRollingPartitioner.java b/apm-commons/apm-datacarrier/src/main/java/org/skywalking/apm/commons/datacarrier/partition/SimpleRollingPartitioner.java
similarity index 88%
rename from apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/datacarrier/partition/SimpleRollingPartitioner.java
rename to apm-commons/apm-datacarrier/src/main/java/org/skywalking/apm/commons/datacarrier/partition/SimpleRollingPartitioner.java
index c1d92d4713ee5c34fa59f0957315530e70fe5dbe..e44c899634aeaecdc062f550547991079400f8d2 100644
--- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/datacarrier/partition/SimpleRollingPartitioner.java
+++ b/apm-commons/apm-datacarrier/src/main/java/org/skywalking/apm/commons/datacarrier/partition/SimpleRollingPartitioner.java
@@ -1,4 +1,4 @@
-package org.skywalking.apm.agent.core.datacarrier.partition;
+package org.skywalking.apm.commons.datacarrier.partition;
/**
* use normal int to rolling.
diff --git a/apm-commons/apm-datacarrier/src/test/java/org/skywalking/apm/commons/datacarrier/DataCarrierTest.java b/apm-commons/apm-datacarrier/src/test/java/org/skywalking/apm/commons/datacarrier/DataCarrierTest.java
new file mode 100644
index 0000000000000000000000000000000000000000..728ac36cd74e92dabadd94ea7dd66445118ff379
--- /dev/null
+++ b/apm-commons/apm-datacarrier/src/test/java/org/skywalking/apm/commons/datacarrier/DataCarrierTest.java
@@ -0,0 +1,149 @@
+package org.skywalking.apm.commons.datacarrier;
+
+import java.util.List;
+import org.junit.Assert;
+import org.junit.Test;
+import org.powermock.api.support.membermodification.MemberModifier;
+import org.skywalking.apm.commons.datacarrier.buffer.Buffer;
+import org.skywalking.apm.commons.datacarrier.buffer.BufferStrategy;
+import org.skywalking.apm.commons.datacarrier.buffer.Channels;
+import org.skywalking.apm.commons.datacarrier.consumer.IConsumer;
+import org.skywalking.apm.commons.datacarrier.partition.ProducerThreadPartitioner;
+import org.skywalking.apm.commons.datacarrier.partition.SimpleRollingPartitioner;
+
+/**
+ * Created by wusheng on 2016/10/25.
+ */
+public class DataCarrierTest {
+ @Test
+ public void testCreateDataCarrier() throws IllegalAccessException {
+ DataCarrier carrier = new DataCarrier(5, 100);
+ Assert.assertEquals(((Integer) (MemberModifier.field(DataCarrier.class, "bufferSize").get(carrier))).intValue(), 100);
+ Assert.assertEquals(((Integer) (MemberModifier.field(DataCarrier.class, "channelSize").get(carrier))).intValue(), 5);
+
+ Channels channels = (Channels) (MemberModifier.field(DataCarrier.class, "channels").get(carrier));
+ Assert.assertEquals(channels.getChannelSize(), 5);
+
+ Buffer buffer = channels.getBuffer(0);
+ Assert.assertEquals(buffer.getBufferSize(), 100);
+
+ Assert.assertEquals(MemberModifier.field(Buffer.class, "strategy").get(buffer), BufferStrategy.BLOCKING);
+ carrier.setBufferStrategy(BufferStrategy.IF_POSSIBLE);
+ Assert.assertEquals(MemberModifier.field(Buffer.class, "strategy").get(buffer), BufferStrategy.IF_POSSIBLE);
+
+ Assert.assertEquals(MemberModifier.field(Channels.class, "dataPartitioner").get(channels).getClass(), SimpleRollingPartitioner.class);
+ carrier.setPartitioner(new ProducerThreadPartitioner());
+ Assert.assertEquals(MemberModifier.field(Channels.class, "dataPartitioner").get(channels).getClass(), ProducerThreadPartitioner.class);
+ }
+
+ @Test
+ public void testProduce() throws IllegalAccessException {
+ DataCarrier carrier = new DataCarrier(2, 100);
+ Assert.assertTrue(carrier.produce(new SampleData().setName("a")));
+ Assert.assertTrue(carrier.produce(new SampleData().setName("b")));
+ Assert.assertTrue(carrier.produce(new SampleData().setName("c")));
+ Assert.assertTrue(carrier.produce(new SampleData().setName("d")));
+
+ Channels channels = (Channels) (MemberModifier.field(DataCarrier.class, "channels").get(carrier));
+ Buffer buffer1 = channels.getBuffer(0);
+ List result1 = buffer1.obtain(0, 100);
+
+ Buffer buffer2 = channels.getBuffer(1);
+ List result2 = buffer2.obtain(0, 100);
+
+ Assert.assertEquals(2, result1.size());
+ Assert.assertEquals(4, result1.size() + result2.size());
+
+
+ }
+
+ @Test
+ public void testOverrideProduce() throws IllegalAccessException {
+ DataCarrier carrier = new DataCarrier(2, 100);
+ carrier.setBufferStrategy(BufferStrategy.OVERRIDE);
+
+ for (int i = 0; i < 500; i++) {
+ Assert.assertTrue(carrier.produce(new SampleData().setName("d" + i)));
+ }
+
+ Channels channels = (Channels) (MemberModifier.field(DataCarrier.class, "channels").get(carrier));
+ Buffer buffer1 = channels.getBuffer(0);
+ List result1 = buffer1.obtain(0, 100);
+
+ Buffer buffer2 = channels.getBuffer(1);
+ List result2 = buffer2.obtain(0, 100);
+ Assert.assertEquals(200, result1.size() + result2.size());
+ }
+
+ @Test
+ public void testIfPossibleProduce() throws IllegalAccessException {
+ DataCarrier carrier = new DataCarrier(2, 100);
+ carrier.setBufferStrategy(BufferStrategy.IF_POSSIBLE);
+
+ for (int i = 0; i < 200; i++) {
+ Assert.assertTrue(carrier.produce(new SampleData().setName("d" + i)));
+ }
+
+ for (int i = 0; i < 200; i++) {
+ Assert.assertFalse(carrier.produce(new SampleData().setName("d" + i + "_2")));
+ }
+
+ Channels channels = (Channels) (MemberModifier.field(DataCarrier.class, "channels").get(carrier));
+ Buffer buffer1 = channels.getBuffer(0);
+ List result1 = buffer1.obtain(0, 100);
+
+ Buffer buffer2 = channels.getBuffer(1);
+ List result2 = buffer2.obtain(0, 100);
+ Assert.assertEquals(200, result1.size() + result2.size());
+ }
+
+ @Test
+ public void testBlockingProduce() throws IllegalAccessException {
+ final DataCarrier carrier = new DataCarrier(2, 100);
+
+ for (int i = 0; i < 200; i++) {
+ Assert.assertTrue(carrier.produce(new SampleData().setName("d" + i)));
+ }
+
+ long time1 = System.currentTimeMillis();
+ new Thread(new Runnable() {
+ @Override
+ public void run() {
+ try {
+ Thread.sleep(2000);
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ IConsumer consumer = new IConsumer() {
+ int i = 0;
+
+ @Override
+ public void init() {
+
+ }
+
+ @Override
+ public void consume(List data) {
+
+ }
+
+ @Override
+ public void onError(List data, Throwable t) {
+
+ }
+
+ @Override
+ public void onExit() {
+
+ }
+ };
+ carrier.consume(consumer, 1);
+ }
+ }).start();
+
+ carrier.produce(new SampleData().setName("blocking-data"));
+ long time2 = System.currentTimeMillis();
+
+ Assert.assertTrue(time2 - time1 > 2000);
+ }
+}
diff --git a/apm-commons/apm-datacarrier/src/test/java/org/skywalking/apm/commons/datacarrier/SampleData.java b/apm-commons/apm-datacarrier/src/test/java/org/skywalking/apm/commons/datacarrier/SampleData.java
new file mode 100644
index 0000000000000000000000000000000000000000..65db2db347eb3c5b0f5061af0ebf1d6d60b9980b
--- /dev/null
+++ b/apm-commons/apm-datacarrier/src/test/java/org/skywalking/apm/commons/datacarrier/SampleData.java
@@ -0,0 +1,28 @@
+package org.skywalking.apm.commons.datacarrier;
+
+/**
+ * Created by wusheng on 2016/10/25.
+ */
+public class SampleData {
+ private int intValue;
+
+ private String name;
+
+ public int getIntValue() {
+ return intValue;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public SampleData setIntValue(int intValue) {
+ this.intValue = intValue;
+ return this;
+ }
+
+ public SampleData setName(String name) {
+ this.name = name;
+ return this;
+ }
+}
diff --git a/apm-commons/apm-datacarrier/src/test/java/org/skywalking/apm/commons/datacarrier/common/AtomicRangeIntegerTest.java b/apm-commons/apm-datacarrier/src/test/java/org/skywalking/apm/commons/datacarrier/common/AtomicRangeIntegerTest.java
new file mode 100644
index 0000000000000000000000000000000000000000..aa417d59c87c548d9e80928897dc20ecb422c9ee
--- /dev/null
+++ b/apm-commons/apm-datacarrier/src/test/java/org/skywalking/apm/commons/datacarrier/common/AtomicRangeIntegerTest.java
@@ -0,0 +1,25 @@
+package org.skywalking.apm.commons.datacarrier.common;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import static org.junit.Assert.*;
+
+/**
+ * Created by xin on 2017/7/14.
+ */
+public class AtomicRangeIntegerTest {
+ @Test
+ public void testGetAndIncrement() {
+ AtomicRangeInteger atomicI = new AtomicRangeInteger(0, 10);
+ for (int i = 0; i < 10; i++) {
+ Assert.assertEquals(i, atomicI.getAndIncrement());
+ }
+ Assert.assertEquals(0, atomicI.getAndIncrement());
+ Assert.assertEquals(1, atomicI.get());
+ Assert.assertEquals(1, atomicI.intValue());
+ Assert.assertEquals(1, atomicI.longValue());
+ Assert.assertEquals(1, (int)atomicI.floatValue());
+ Assert.assertEquals(1, (int)atomicI.doubleValue());
+ }
+}
diff --git a/apm-commons/apm-datacarrier/src/test/java/org/skywalking/apm/commons/datacarrier/consumer/ConsumerPoolTest.java b/apm-commons/apm-datacarrier/src/test/java/org/skywalking/apm/commons/datacarrier/consumer/ConsumerPoolTest.java
new file mode 100644
index 0000000000000000000000000000000000000000..3158cd51b3389cc802c4b8ad4eac85f331884577
--- /dev/null
+++ b/apm-commons/apm-datacarrier/src/test/java/org/skywalking/apm/commons/datacarrier/consumer/ConsumerPoolTest.java
@@ -0,0 +1,41 @@
+package org.skywalking.apm.commons.datacarrier.consumer;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.powermock.api.support.membermodification.MemberModifier;
+import org.skywalking.apm.commons.datacarrier.SampleData;
+import org.skywalking.apm.commons.datacarrier.buffer.BufferStrategy;
+import org.skywalking.apm.commons.datacarrier.buffer.Channels;
+import org.skywalking.apm.commons.datacarrier.partition.SimpleRollingPartitioner;
+
+/**
+ * Created by wusheng on 2016/10/26.
+ */
+public class ConsumerPoolTest {
+ @Test
+ public void testBeginConsumerPool() throws IllegalAccessException {
+ Channels channels = new Channels(2, 100, new SimpleRollingPartitioner(), BufferStrategy.BLOCKING);
+ ConsumerPool pool = new ConsumerPool(channels, new SampleConsumer(), 2);
+ pool.begin();
+
+ ConsumerThread[] threads = (ConsumerThread[])MemberModifier.field(ConsumerPool.class, "consumerThreads").get(pool);
+ Assert.assertEquals(2, threads.length);
+ Assert.assertTrue(threads[0].isAlive());
+ Assert.assertTrue(threads[1].isAlive());
+ }
+
+ @Test
+ public void testCloseConsumerPool() throws InterruptedException, IllegalAccessException {
+ Channels channels = new Channels(2, 100, new SimpleRollingPartitioner(), BufferStrategy.BLOCKING);
+ ConsumerPool pool = new ConsumerPool(channels, new SampleConsumer(), 2);
+ pool.begin();
+
+ Thread.sleep(5000);
+ pool.close();
+ ConsumerThread[] threads = (ConsumerThread[])MemberModifier.field(ConsumerPool.class, "consumerThreads").get(pool);
+
+ Assert.assertEquals(2, threads.length);
+ Assert.assertFalse((Boolean)MemberModifier.field(ConsumerThread.class, "running").get(threads[0]));
+ Assert.assertFalse((Boolean)MemberModifier.field(ConsumerThread.class, "running").get(threads[1]));
+ }
+}
diff --git a/apm-commons/apm-datacarrier/src/test/java/org/skywalking/apm/commons/datacarrier/consumer/ConsumerTest.java b/apm-commons/apm-datacarrier/src/test/java/org/skywalking/apm/commons/datacarrier/consumer/ConsumerTest.java
new file mode 100644
index 0000000000000000000000000000000000000000..bbe816b1948baf0cfdcc5f6b9d7fd918784315e9
--- /dev/null
+++ b/apm-commons/apm-datacarrier/src/test/java/org/skywalking/apm/commons/datacarrier/consumer/ConsumerTest.java
@@ -0,0 +1,116 @@
+package org.skywalking.apm.commons.datacarrier.consumer;
+
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.concurrent.LinkedBlockingQueue;
+import org.junit.Assert;
+import org.junit.Test;
+import org.powermock.api.support.membermodification.MemberModifier;
+import org.skywalking.apm.commons.datacarrier.DataCarrier;
+import org.skywalking.apm.commons.datacarrier.SampleData;
+
+/**
+ * Created by wusheng on 2016/10/26.
+ */
+public class ConsumerTest {
+ public static LinkedBlockingQueue buffer = new LinkedBlockingQueue();
+
+ public static boolean isOccurError = false;
+
+ @Test
+ public void testConsumerLessThanChannel() throws IllegalAccessException {
+ final DataCarrier carrier = new DataCarrier(2, 100);
+
+ for (int i = 0; i < 100; i++) {
+ Assert.assertTrue(carrier.produce(new SampleData().setName("data" + i)));
+ }
+ SampleConsumer consumer = new SampleConsumer();
+
+ consumer.i = 100;
+ carrier.consume(SampleConsumer.class, 1);
+ Assert.assertEquals(1, ((SampleConsumer)getConsumer(carrier)).i);
+
+ SampleConsumer2 consumer2 = new SampleConsumer2();
+ consumer2.i = 100;
+ carrier.consume(consumer2, 1);
+ Assert.assertEquals(100, ((SampleConsumer2)getConsumer(carrier)).i);
+
+ carrier.shutdownConsumers();
+ }
+
+ @Test
+ public void testConsumerMoreThanChannel() throws IllegalAccessException, InterruptedException {
+ final DataCarrier carrier = new DataCarrier(2, 100);
+
+ for (int i = 0; i < 200; i++) {
+ Assert.assertTrue(carrier.produce(new SampleData().setName("data" + i)));
+ }
+ SampleConsumer consumer = new SampleConsumer();
+
+ carrier.consume(SampleConsumer.class, 5);
+
+ Thread.sleep(2000);
+
+ List result = new ArrayList();
+ buffer.drainTo(result);
+
+ Assert.assertEquals(200, result.size());
+
+ HashSet consumerCounter = new HashSet();
+ for (SampleData data : result) {
+ consumerCounter.add(data.getIntValue());
+ }
+ Assert.assertEquals(5, consumerCounter.size());
+ }
+
+ @Test
+ public void testConsumerOnError() {
+ final DataCarrier carrier = new DataCarrier(2, 100);
+
+ for (int i = 0; i < 200; i++) {
+ Assert.assertTrue(carrier.produce(new SampleData().setName("data" + i)));
+ }
+ SampleConsumer2 consumer = new SampleConsumer2();
+
+ consumer.onError = true;
+ carrier.consume(consumer, 5);
+
+ Assert.assertTrue(isOccurError);
+ }
+
+ class SampleConsumer2 implements IConsumer {
+ public int i = 1;
+
+ public boolean onError = false;
+
+ @Override
+ public void init() {
+
+ }
+
+ @Override
+ public void consume(List data) {
+ if (onError) {
+ throw new RuntimeException("consume exception");
+ }
+ }
+
+ @Override
+ public void onError(List data, Throwable t) {
+ isOccurError = true;
+ }
+
+ @Override
+ public void onExit() {
+
+ }
+ }
+
+ private IConsumer getConsumer(DataCarrier carrier) throws IllegalAccessException {
+ ConsumerPool pool = ((ConsumerPool)MemberModifier.field(DataCarrier.class, "consumerPool").get(carrier));
+ ConsumerThread[] threads = (ConsumerThread[])MemberModifier.field(ConsumerPool.class, "consumerThreads").get(pool);
+
+ return (IConsumer)MemberModifier.field(ConsumerThread.class, "consumer").get(threads[0]);
+ }
+}
diff --git a/apm-commons/apm-datacarrier/src/test/java/org/skywalking/apm/commons/datacarrier/consumer/SampleConsumer.java b/apm-commons/apm-datacarrier/src/test/java/org/skywalking/apm/commons/datacarrier/consumer/SampleConsumer.java
new file mode 100644
index 0000000000000000000000000000000000000000..aa18190815aaa87cff16bd6e7b20caecb92de35d
--- /dev/null
+++ b/apm-commons/apm-datacarrier/src/test/java/org/skywalking/apm/commons/datacarrier/consumer/SampleConsumer.java
@@ -0,0 +1,34 @@
+package org.skywalking.apm.commons.datacarrier.consumer;
+
+import java.util.List;
+import org.skywalking.apm.commons.datacarrier.SampleData;
+
+/**
+ * Created by wusheng on 2016/10/26.
+ */
+public class SampleConsumer implements IConsumer {
+ public int i = 1;
+
+ @Override
+ public void init() {
+
+ }
+
+ @Override
+ public void consume(List data) {
+ for(SampleData one : data) {
+ one.setIntValue(this.hashCode());
+ ConsumerTest.buffer.offer(one);
+ }
+ }
+
+ @Override
+ public void onError(List data, Throwable t) {
+
+ }
+
+ @Override
+ public void onExit() {
+
+ }
+}
diff --git a/apm-commons/apm-datacarrier/src/test/java/org/skywalking/apm/commons/datacarrier/partition/ProducerThreadPartitionerTest.java b/apm-commons/apm-datacarrier/src/test/java/org/skywalking/apm/commons/datacarrier/partition/ProducerThreadPartitionerTest.java
new file mode 100644
index 0000000000000000000000000000000000000000..0072471d5c09851ce716573b68af885269310ce4
--- /dev/null
+++ b/apm-commons/apm-datacarrier/src/test/java/org/skywalking/apm/commons/datacarrier/partition/ProducerThreadPartitionerTest.java
@@ -0,0 +1,19 @@
+package org.skywalking.apm.commons.datacarrier.partition;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.skywalking.apm.commons.datacarrier.SampleData;
+
+/**
+ * Created by wusheng on 2016/10/25.
+ */
+public class ProducerThreadPartitionerTest {
+ @Test
+ public void testPartition() {
+ int partitionNum = (int)Thread.currentThread().getId() % 10;
+ ProducerThreadPartitioner partitioner = new ProducerThreadPartitioner();
+ Assert.assertEquals(partitioner.partition(10, new SampleData()), partitionNum);
+ Assert.assertEquals(partitioner.partition(10, new SampleData()), partitionNum);
+ Assert.assertEquals(partitioner.partition(10, new SampleData()), partitionNum);
+ }
+}
diff --git a/apm-commons/apm-datacarrier/src/test/java/org/skywalking/apm/commons/datacarrier/partition/SimpleRollingPartitionerTest.java b/apm-commons/apm-datacarrier/src/test/java/org/skywalking/apm/commons/datacarrier/partition/SimpleRollingPartitionerTest.java
new file mode 100644
index 0000000000000000000000000000000000000000..07ca8562b51915ce8ad40e8a634168b311d0706e
--- /dev/null
+++ b/apm-commons/apm-datacarrier/src/test/java/org/skywalking/apm/commons/datacarrier/partition/SimpleRollingPartitionerTest.java
@@ -0,0 +1,18 @@
+package org.skywalking.apm.commons.datacarrier.partition;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.skywalking.apm.commons.datacarrier.SampleData;
+
+/**
+ * Created by wusheng on 2016/10/25.
+ */
+public class SimpleRollingPartitionerTest {
+ @Test
+ public void testPartition() {
+ SimpleRollingPartitioner partitioner = new SimpleRollingPartitioner();
+ Assert.assertEquals(partitioner.partition(10, new SampleData()), 0);
+ Assert.assertEquals(partitioner.partition(10, new SampleData()), 1);
+ Assert.assertEquals(partitioner.partition(10, new SampleData()), 2);
+ }
+}
diff --git a/apm-commons/apm-logging-log4j2/pom.xml b/apm-commons/apm-logging-log4j2/pom.xml
deleted file mode 100644
index ac89396f301fb3ba9c36f4e048421da105b2fd7e..0000000000000000000000000000000000000000
--- a/apm-commons/apm-logging-log4j2/pom.xml
+++ /dev/null
@@ -1,31 +0,0 @@
-
-
-
- apm-commons
- org.skywalking
- 3.2-2017
-
- 4.0.0
-
- apm-logging-log4j2
-
-
-
- org.skywalking
- apm-logging-api
- ${project.version}
-
-
- org.apache.logging.log4j
- log4j-core
- 2.8
-
-
- org.apache.logging.log4j
- log4j-api
- 2.8
-
-
-
diff --git a/apm-commons/apm-logging-log4j2/src/main/java/org/skywalking/apm/logging/log4j2/Log4j2Logger.java b/apm-commons/apm-logging-log4j2/src/main/java/org/skywalking/apm/logging/log4j2/Log4j2Logger.java
deleted file mode 100644
index 363d31db0412262eed5fb476eef661f5292afbfc..0000000000000000000000000000000000000000
--- a/apm-commons/apm-logging-log4j2/src/main/java/org/skywalking/apm/logging/log4j2/Log4j2Logger.java
+++ /dev/null
@@ -1,76 +0,0 @@
-package org.skywalking.apm.logging.log4j2;
-
-import org.apache.logging.log4j.LogManager;
-import org.apache.logging.log4j.Logger;
-import org.skywalking.apm.logging.ILog;
-
-/**
- * @author wusheng
- */
-public class Log4j2Logger implements ILog {
- private Logger delegateLogger;
-
- Log4j2Logger(Class> targetClass) {
- delegateLogger = LogManager.getFormatterLogger(targetClass);
- }
-
- @Override
- public void info(String format) {
- delegateLogger.info(format);
- }
-
- @Override
- public void info(String format, Object... arguments) {
- delegateLogger.info(format, arguments);
- }
-
- @Override
- public void warn(String format, Object... arguments) {
- delegateLogger.warn(format, arguments);
- }
-
- @Override
- public void error(String format, Throwable e) {
- delegateLogger.error(format, e);
- }
-
- @Override
- public void error(Throwable e, String format, Object... arguments) {
- delegateLogger.error(format, e, arguments);
- }
-
- @Override
- public boolean isDebugEnable() {
- return delegateLogger.isDebugEnabled();
- }
-
- @Override
- public boolean isInfoEnable() {
- return delegateLogger.isInfoEnabled();
- }
-
- @Override
- public boolean isWarnEnable() {
- return delegateLogger.isWarnEnabled();
- }
-
- @Override
- public boolean isErrorEnable() {
- return delegateLogger.isErrorEnabled();
- }
-
- @Override
- public void debug(String format) {
- delegateLogger.debug(format);
- }
-
- @Override
- public void debug(String format, Object... arguments) {
- delegateLogger.debug(format, arguments);
- }
-
- @Override
- public void error(String format) {
- delegateLogger.error(format);
- }
-}
diff --git a/apm-commons/apm-logging-log4j2/src/main/java/org/skywalking/apm/logging/log4j2/Log4j2Resolver.java b/apm-commons/apm-logging-log4j2/src/main/java/org/skywalking/apm/logging/log4j2/Log4j2Resolver.java
deleted file mode 100644
index 97da742c39c1cf40fe4151750b0473bb0a2a7777..0000000000000000000000000000000000000000
--- a/apm-commons/apm-logging-log4j2/src/main/java/org/skywalking/apm/logging/log4j2/Log4j2Resolver.java
+++ /dev/null
@@ -1,16 +0,0 @@
-package org.skywalking.apm.logging.log4j2;
-
-import org.skywalking.apm.logging.ILog;
-import org.skywalking.apm.logging.LogResolver;
-
-/**
- * The LogResolver is an implementation of {@link LogResolver},
- *
- * @author wusheng
- */
-public class Log4j2Resolver implements LogResolver {
- @Override
- public ILog getLogger(Class> clazz) {
- return new Log4j2Logger(clazz);
- }
-}
diff --git a/apm-commons/pom.xml b/apm-commons/pom.xml
index c28ff70e18333683bddfc72fdc2f938ed39285ac..aaaffca5757802f86042aaa86dab2888b9a8d29d 100644
--- a/apm-commons/pom.xml
+++ b/apm-commons/pom.xml
@@ -13,7 +13,7 @@
apm-utilapm-logging-api
- apm-logging-log4j2
+ apm-datacarrierapm-commons
diff --git a/apm-network/src/main/java/org/skywalking/apm/network/trace/component/Component.java b/apm-network/src/main/java/org/skywalking/apm/network/trace/component/Component.java
index 17a22a64c3a7d500be4ad12de6390a9db9432598..b84db3cefd86d7f0638e580c29ab2db23263f0f2 100644
--- a/apm-network/src/main/java/org/skywalking/apm/network/trace/component/Component.java
+++ b/apm-network/src/main/java/org/skywalking/apm/network/trace/component/Component.java
@@ -1,6 +1,11 @@
package org.skywalking.apm.network.trace.component;
/**
+ * The Component represents component library,
+ * which has been supported by skywalking sniffer.
+ *
+ * The supported list is in {@link ComponentsDefine}.
+ *
* @author wusheng
*/
public interface Component {
diff --git a/apm-network/src/main/java/org/skywalking/apm/network/trace/component/ComponentsDefine.java b/apm-network/src/main/java/org/skywalking/apm/network/trace/component/ComponentsDefine.java
index 4fb43f382069f5dde7a32c1d4bcb1c4d06a2c2e7..cdf1b61085ea2d3e3876affcaca2b4b386ee741c 100644
--- a/apm-network/src/main/java/org/skywalking/apm/network/trace/component/ComponentsDefine.java
+++ b/apm-network/src/main/java/org/skywalking/apm/network/trace/component/ComponentsDefine.java
@@ -1,6 +1,8 @@
package org.skywalking.apm.network.trace.component;
/**
+ * The supported list of skywalking java sniffer.
+ *
* @author wusheng
*/
public class ComponentsDefine {
diff --git a/apm-network/src/main/proto/TraceSegmentService.proto b/apm-network/src/main/proto/TraceSegmentService.proto
index 755356dc956e0a7f032ef04e9f91d3ebdf5f65e6..315165ebef2bf19ddc4b6a6daef35a45e67d6165 100644
--- a/apm-network/src/main/proto/TraceSegmentService.proto
+++ b/apm-network/src/main/proto/TraceSegmentService.proto
@@ -25,13 +25,14 @@ message TraceSegmentObject {
}
message TraceSegmentReference {
- string parentTraceSegmentId = 1;
- int32 parentSpanId = 2;
- int32 parentApplicationId = 3;
- string networkAddress = 4;
- int32 networkAddressId = 5;
- string entryServiceName = 6;
- int32 entryServiceId = 7;
+ RefType refType = 1;
+ string parentTraceSegmentId = 2;
+ int32 parentSpanId = 3;
+ int32 parentApplicationInstanceId = 4;
+ string networkAddress = 5;
+ int32 networkAddressId = 6;
+ string entryServiceName = 7;
+ int32 entryServiceId = 8;
}
message SpanObject {
@@ -52,6 +53,11 @@ message SpanObject {
repeated LogMessage logs = 15;
}
+enum RefType {
+ CrossProcess = 0;
+ CrossThread = 1;
+}
+
enum SpanType {
Entry = 0;
Exit = 1;
diff --git a/apm-sniffer/apm-agent-core/pom.xml b/apm-sniffer/apm-agent-core/pom.xml
index f94d04f9668231161327d8b330d01b48de1294cb..6749551f6b689dd4143bf3e73e2be423bc2a8935 100644
--- a/apm-sniffer/apm-agent-core/pom.xml
+++ b/apm-sniffer/apm-agent-core/pom.xml
@@ -77,6 +77,29 @@
${jetty.version}test
+
+ com.github.tomakehurst
+ wiremock
+ 2.6.0
+ test
+
+
+ io.grpc
+ grpc-testing
+ 1.4.0
+
+
+ mockito-core
+ org.mockito
+
+
+ test
+
+
+ org.skywalking
+ apm-datacarrier
+ ${project.version}
+
diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/conf/Config.java b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/conf/Config.java
index df95a68ccac3448ef31529f5231bd4c1d1c0cce5..6ffa2cfb5a3b869ce6eeded4a76db3493f732ccc 100644
--- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/conf/Config.java
+++ b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/conf/Config.java
@@ -34,6 +34,18 @@ public class Config {
}
public static class Collector {
+ /**
+ * grpc channel status check interval
+ */
+ public static long GRPC_CHANNEL_CHECK_INTERVAL = 30;
+ /**
+ * application and service registry check interval
+ */
+ public static long APP_AND_SERVICE_REGISTER_CHECK_INTERVAL = 10;
+ /**
+ * discovery rest check interval
+ */
+ public static long DISCOVERY_CHECK_INTERVAL = 60;
/**
* Collector REST-Service address.
* e.g.
@@ -45,7 +57,7 @@ public class Config {
/**
* Collector service discovery REST service name
*/
- public static String DISCOVERY_SERVICE_NAME = "grpc/addresses";
+ public static String DISCOVERY_SERVICE_NAME = "/grpc/addresses";
}
public static class Buffer {
diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/conf/RemoteDownstreamConfig.java b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/conf/RemoteDownstreamConfig.java
index 71df9b810100b307aa328d4d50bfdf66cc14d84e..02da5c3ece3c2413b8ac0f732ec9dee7c798c382 100644
--- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/conf/RemoteDownstreamConfig.java
+++ b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/conf/RemoteDownstreamConfig.java
@@ -5,11 +5,16 @@ import java.util.List;
import org.skywalking.apm.agent.core.dictionary.DictionaryUtil;
/**
+ * The RemoteDownstreamConfig includes configurations from collector side.
+ * All of them initialized null, Null-Value or empty collection.
+ *
* @author wusheng
*/
public class RemoteDownstreamConfig {
public static class Agent {
public volatile static int APPLICATION_ID = DictionaryUtil.nullValue();
+
+ public volatile static int APPLICATION_INSTANCE_ID = DictionaryUtil.nullValue();
}
public static class Collector {
diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/conf/SnifferConfigInitializer.java b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/conf/SnifferConfigInitializer.java
index 78043f98c237514aaeea38e31322cc3eb72b4ee3..2a619b1a5a6d0dfd060ba7fdeae68be2cf4901f4 100644
--- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/conf/SnifferConfigInitializer.java
+++ b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/conf/SnifferConfigInitializer.java
@@ -83,7 +83,7 @@ public class SnifferConfigInitializer {
/**
* Load the config file by the path, which is provided by system property, usually with a "-DconfigPath=" arg.
*
- * @return the config file {@link InputStream}, or null if not exist.
+ * @return the config file {@link InputStream}, or null if not needEnhance.
*/
private static InputStream loadConfigBySystemProperty() {
String configPath = System.getProperty("configPath");
@@ -107,7 +107,7 @@ public class SnifferConfigInitializer {
/**
* Load the config file, where the agent jar is.
*
- * @return the config file {@link InputStream}, or null if not exist.
+ * @return the config file {@link InputStream}, or null if not needEnhance.
*/
private static InputStream loadConfigFromAgentFolder() {
String agentBasePath = initAgentBasePath();
diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/AbstractTracerContext.java b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/AbstractTracerContext.java
index 9235a7994235e16e53bd5c55aea84e7dc88b4312..3b9d569d17543e57c08b40c0cc6cdda2b070dcca 100644
--- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/AbstractTracerContext.java
+++ b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/AbstractTracerContext.java
@@ -1,6 +1,9 @@
package org.skywalking.apm.agent.core.context;
import org.skywalking.apm.agent.core.context.trace.AbstractSpan;
+import org.skywalking.apm.agent.core.context.trace.EntrySpan;
+import org.skywalking.apm.agent.core.context.trace.ExitSpan;
+import org.skywalking.apm.agent.core.context.trace.LocalSpan;
/**
* The AbstractTracerContext represents the tracer context manager.
@@ -8,21 +11,89 @@ import org.skywalking.apm.agent.core.context.trace.AbstractSpan;
* @author wusheng
*/
public interface AbstractTracerContext {
+ /**
+ * Prepare for the cross-process propagation.
+ * How to initialize the carrier, depends on the implementation.
+ *
+ * @param carrier to carry the context for crossing process.
+ * @see {@link TracingContext} and {@link IgnoredTracerContext}
+ */
void inject(ContextCarrier carrier);
+ /**
+ * Build the reference between this segment and a cross-process segment.
+ * How to build, depends on the implementation.
+ *
+ * @param carrier carried the context from a cross-process segment.
+ * @see {@link TracingContext} and {@link IgnoredTracerContext}
+ */
void extract(ContextCarrier carrier);
+ /**
+ * Capture a snapshot for cross-thread propagation.
+ * It's a similar concept with ActiveSpan.Continuation in OpenTracing-java
+ * How to build, depends on the implementation.
+ *
+ * @return the {@link ContextSnapshot} , which includes the reference context.
+ * @see {@link TracingContext} and {@link IgnoredTracerContext}
+ */
+ ContextSnapshot capture();
+
+ /**
+ * Build the reference between this segment and a cross-thread segment.
+ * How to build, depends on the implementation.
+ *
+ * @param snapshot from {@link #capture()} in the parent thread.
+ * @see {@link TracingContext} and {@link IgnoredTracerContext}
+ */
+ void continued(ContextSnapshot snapshot);
+
+ /**
+ * Get the global trace id, if needEnhance.
+ * How to build, depends on the implementation.
+ *
+ * @return the string represents the id.
+ * @see {@link TracingContext} and {@link IgnoredTracerContext}
+ */
String getGlobalTraceId();
+ /**
+ * Create an entry span
+ *
+ * @param operationName most likely a service name
+ * @return the span represents an entry point of this segment.
+ * @see {@link EntrySpan} if the implementation is {@link TracingContext}
+ */
AbstractSpan createEntrySpan(String operationName);
+ /**
+ * Create a local span
+ *
+ * @param operationName most likely a local method signature, or business name.
+ * @return the span represents a local logic block.
+ * @see {@link LocalSpan} if the implementation is {@link TracingContext}
+ */
AbstractSpan createLocalSpan(String operationName);
+ /**
+ * Create an exit span
+ *
+ * @param operationName most likely a service name of remote
+ * @param remotePeer the network id(ip:port, hostname:port or ip1:port1,ip2,port, etc.)
+ * @return the span represent an exit point of this segment.
+ * @see {@link ExitSpan} if the implementation is {@link TracingContext}
+ */
AbstractSpan createExitSpan(String operationName, String remotePeer);
+ /**
+ * @return the active span of current tracing context(stack)
+ */
AbstractSpan activeSpan();
+ /**
+ * Finish the given span, and the given span should be the active span of current tracing context(stack)
+ *
+ * @param span to finish
+ */
void stopSpan(AbstractSpan span);
-
- void dispose();
}
diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/ContextCarrier.java b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/ContextCarrier.java
index 7e67765f87b0688d6ea7f53c29bcde698e615e62..fad0ab7260a9deed52e988a69b7f747fef934213 100644
--- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/ContextCarrier.java
+++ b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/ContextCarrier.java
@@ -23,7 +23,7 @@ public class ContextCarrier implements Serializable {
private int spanId = -1;
- private int applicationId = DictionaryUtil.nullValue();
+ private int applicationInstanceId = DictionaryUtil.nullValue();
private String peerHost;
@@ -45,7 +45,7 @@ public class ContextCarrier implements Serializable {
return StringUtil.join('|',
this.getTraceSegmentId(),
this.getSpanId() + "",
- this.getApplicationId() + "",
+ this.getApplicationInstanceId() + "",
this.getPeerHost(),
this.getEntryOperationName(),
this.serializeDistributedTraceIds());
@@ -66,7 +66,7 @@ public class ContextCarrier implements Serializable {
try {
this.traceSegmentId = parts[0];
this.spanId = Integer.parseInt(parts[1]);
- this.applicationId = Integer.parseInt(parts[2]);
+ this.applicationInstanceId = Integer.parseInt(parts[2]);
this.peerHost = parts[3];
this.entryOperationName = parts[4];
this.distributedTraceIds = deserializeDistributedTraceIds(parts[5]);
@@ -86,7 +86,7 @@ public class ContextCarrier implements Serializable {
public boolean isValid() {
return !StringUtil.isEmpty(traceSegmentId)
&& getSpanId() > -1
- && applicationId != DictionaryUtil.nullValue()
+ && applicationInstanceId != DictionaryUtil.nullValue()
&& !StringUtil.isEmpty(peerHost)
&& !StringUtil.isEmpty(entryOperationName)
&& distributedTraceIds != null;
@@ -120,12 +120,12 @@ public class ContextCarrier implements Serializable {
this.spanId = spanId;
}
- public int getApplicationId() {
- return applicationId;
+ public int getApplicationInstanceId() {
+ return applicationInstanceId;
}
- void setApplicationId(int applicationId) {
- this.applicationId = applicationId;
+ void setApplicationInstanceId(int applicationInstanceId) {
+ this.applicationInstanceId = applicationInstanceId;
}
public String getPeerHost() {
diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/ContextManager.java b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/ContextManager.java
index 6a7c96470f98ae55762aef4ad2e4d1001a4ae9d4..a344584645b8e8a76e300ec5ded4077f958139c2 100644
--- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/ContextManager.java
+++ b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/ContextManager.java
@@ -15,7 +15,9 @@ import org.skywalking.apm.util.StringUtil;
/**
* {@link ContextManager} controls the whole context of {@link TraceSegment}. Any {@link TraceSegment} relates to
* single-thread, so this context use {@link ThreadLocal} to maintain the context, and make sure, since a {@link
- * TraceSegment} starts, all ChildOf spans are in the same context.
What is 'ChildOf'? {@see
+ * TraceSegment} starts, all ChildOf spans are in the same context.
+ *
+ * What is 'ChildOf'? {@see
* https://github.com/opentracing/specification/blob/master/specification.md#references-between-spans}
*
*
Also, {@link ContextManager} delegates to all {@link AbstractTracerContext}'s major methods.
@@ -36,12 +38,9 @@ public class ContextManager implements TracingContextListener, BootService, Igno
}
context = new IgnoredTracerContext();
} else {
- if (RemoteDownstreamConfig.Agent.APPLICATION_ID == DictionaryUtil.nullValue()) {
- /**
- * Can't register to collector, no need to trace anything.
- */
- context = new IgnoredTracerContext();
- } else {
+ if (RemoteDownstreamConfig.Agent.APPLICATION_ID != DictionaryUtil.nullValue()
+ || RemoteDownstreamConfig.Agent.APPLICATION_INSTANCE_ID != DictionaryUtil.nullValue()
+ ) {
int suffixIdx = operationName.lastIndexOf(".");
if (suffixIdx > -1 && Config.Agent.IGNORE_SUFFIX.contains(operationName.substring(suffixIdx))) {
context = new IgnoredTracerContext();
@@ -53,6 +52,11 @@ public class ContextManager implements TracingContextListener, BootService, Igno
context = new IgnoredTracerContext();
}
}
+ } else {
+ /**
+ * Can't register to collector, no need to trace anything.
+ */
+ context = new IgnoredTracerContext();
}
}
CONTEXT.set(context);
@@ -65,7 +69,7 @@ public class ContextManager implements TracingContextListener, BootService, Igno
}
/**
- * @return the first global trace id if exist. Otherwise, "N/A".
+ * @return the first global trace id if needEnhance. Otherwise, "N/A".
*/
public static String getGlobalTraceId() {
AbstractTracerContext segment = CONTEXT.get();
@@ -104,12 +108,42 @@ public class ContextManager implements TracingContextListener, BootService, Igno
return span;
}
+ public static void inject(ContextCarrier carrier) {
+ get().inject(carrier);
+ }
+
+ public static void extract(ContextCarrier carrier) {
+ if (carrier == null) {
+ throw new IllegalArgumentException("ContextCarrier can't be null.");
+ }
+ if (carrier.isValid()) {
+ get().extract(carrier);
+ }
+ }
+
+ public static ContextSnapshot capture() {
+ return get().capture();
+ }
+
+ public static void continued(ContextSnapshot snapshot) {
+ if (snapshot == null) {
+ throw new IllegalArgumentException("ContextSnapshot can't be null.");
+ }
+ if (snapshot.isValid()) {
+ get().continued(snapshot);
+ }
+ }
+
public static AbstractSpan activeSpan() {
return get().activeSpan();
}
public static void stopSpan() {
- get().stopSpan(activeSpan());
+ stopSpan(activeSpan());
+ }
+
+ public static void stopSpan(AbstractSpan span) {
+ get().stopSpan(span);
}
@Override
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
new file mode 100644
index 0000000000000000000000000000000000000000..755a2275d8b0b0662ee96592fd381fd8ecbc1c36
--- /dev/null
+++ b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/ContextSnapshot.java
@@ -0,0 +1,53 @@
+package org.skywalking.apm.agent.core.context;
+
+import java.util.List;
+import org.skywalking.apm.agent.core.context.ids.DistributedTraceId;
+
+/**
+ * The ContextSnapshot is a snapshot for current context. The snapshot carries the info for building
+ * reference between two segments in two thread, but have a causal relationship.
+ *
+ * @author wusheng
+ */
+public class ContextSnapshot {
+ /**
+ * trace segment id of the parent trace segment.
+ */
+ private String traceSegmentId;
+
+ /**
+ * span id of the parent span, in parent trace segment.
+ */
+ private int spanId = -1;
+
+ /**
+ * {@link DistributedTraceId}
+ */
+ private List distributedTraceIds;
+
+ ContextSnapshot(String traceSegmentId, int spanId,
+ List distributedTraceIds) {
+ this.traceSegmentId = traceSegmentId;
+ this.spanId = spanId;
+ this.distributedTraceIds = distributedTraceIds;
+ }
+
+ public List getDistributedTraceIds() {
+ return distributedTraceIds;
+ }
+
+ public String getTraceSegmentId() {
+ return traceSegmentId;
+ }
+
+ public int getSpanId() {
+ return spanId;
+ }
+
+ public boolean isValid() {
+ return traceSegmentId != null
+ && spanId > -1
+ && distributedTraceIds != null
+ && distributedTraceIds.size() > 0;
+ }
+}
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 c09229e99c2a5f6b7435b6d6d911c3359fbe361a..4ad37e361a73b6403b534d0d5acf8cfddcca94c2 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
@@ -7,8 +7,9 @@ import org.skywalking.apm.agent.core.context.trace.NoopSpan;
/**
* The IgnoredTracerContext represent a context should be ignored.
- * So it just maintains the stack with integer depth.
- * All operations through this IgnoredTracerContext will be ignored, with low gc cost.
+ * So it just maintains the stack with an integer depth field.
+ *
+ * All operations through this will be ignored, and keep the memory and gc cost as low as possible.
*
* @author wusheng
*/
@@ -31,6 +32,14 @@ public class IgnoredTracerContext implements AbstractTracerContext {
}
+ @Override public ContextSnapshot capture() {
+ return new ContextSnapshot(null, -1, null);
+ }
+
+ @Override public void continued(ContextSnapshot snapshot) {
+
+ }
+
@Override
public String getGlobalTraceId() {
return "[Ignored Trace]";
@@ -67,11 +76,6 @@ public class IgnoredTracerContext implements AbstractTracerContext {
}
}
- @Override
- public void dispose() {
-
- }
-
public static class ListenerManager {
private static List LISTENERS = new LinkedList();
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 3c0038a6941823fd300e997fef52db39da424bd5..15e41c2a85bac32762880cc396d3414012400153 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
@@ -16,11 +16,29 @@ import org.skywalking.apm.agent.core.dictionary.PossibleFound;
import org.skywalking.apm.agent.core.sampling.SamplingService;
/**
+ * The TracingContext represents a core tracing logic controller.
+ * It build the final {@link TracingContext}, by the stack mechanism,
+ * which is similar with the codes work.
+ *
+ * In opentracing concept, it means, all spans in a segment tracing context(thread)
+ * are CHILD_OF relationship, but no FOLLOW_OF.
+ *
+ * In skywalking core concept, FOLLOW_OF is an abstract concept
+ * when cross-process MQ or cross-thread async/batch tasks happen,
+ * we used {@link TraceSegmentRef} for these scenarios.
+ * Check {@link TraceSegmentRef} which is from {@link ContextCarrier} or {@link ContextSnapshot}.
+ *
* @author wusheng
*/
public class TracingContext implements AbstractTracerContext {
+ /**
+ * @see {@link SamplingService}
+ */
private SamplingService samplingService;
+ /**
+ * The final {@link TraceSegment}, which includes all finished spans.
+ */
private TraceSegment segment;
/**
@@ -32,8 +50,14 @@ public class TracingContext implements AbstractTracerContext {
*/
private LinkedList activeSpanStack = new LinkedList();
+ /**
+ * A counter for the next span.
+ */
private int spanIdGenerator;
+ /**
+ * Initialize all fields with default value.
+ */
TracingContext() {
this.segment = new TraceSegment();
this.spanIdGenerator = 0;
@@ -42,6 +66,13 @@ public class TracingContext implements AbstractTracerContext {
}
}
+ /**
+ * Inject the context into the given carrier, only when the active span is an exit one.
+ *
+ * @param carrier to carry the context for crossing process.
+ * @throws IllegalStateException, if the active span isn't an exit one.
+ * @see {@link AbstractTracerContext#inject(ContextCarrier)}
+ */
@Override
public void inject(ContextCarrier carrier) {
AbstractTracingSpan span = this.activeSpan();
@@ -53,7 +84,7 @@ public class TracingContext implements AbstractTracerContext {
carrier.setTraceSegmentId(this.segment.getTraceSegmentId());
carrier.setSpanId(span.getSpanId());
- carrier.setApplicationId(segment.getApplicationId());
+ carrier.setApplicationInstanceId(segment.getApplicationId());
if (DictionaryUtil.isNull(exitSpan.getPeerId())) {
carrier.setPeerHost(exitSpan.getPeer());
@@ -81,17 +112,59 @@ public class TracingContext implements AbstractTracerContext {
carrier.setDistributedTraceIds(this.segment.getRelatedGlobalTraces());
}
+ /**
+ * Extract the carrier to build the reference for the pre segment.
+ *
+ * @param carrier carried the context from a cross-process segment.
+ * @see {@link AbstractTracerContext#extract(ContextCarrier)}
+ */
@Override
public void extract(ContextCarrier carrier) {
this.segment.ref(new TraceSegmentRef(carrier));
this.segment.relatedGlobalTraces(carrier.getDistributedTraceIds());
}
+ /**
+ * Capture the snapshot of current context.
+ *
+ * @return the snapshot of context for cross-thread propagation
+ * @see {@link AbstractTracerContext#capture()}
+ */
+ @Override
+ public ContextSnapshot capture() {
+ return new ContextSnapshot(segment.getTraceSegmentId(),
+ activeSpan().getSpanId(),
+ segment.getRelatedGlobalTraces()
+ );
+ }
+
+ /**
+ * Continue the context from the given snapshot of parent thread.
+ *
+ * @param snapshot from {@link #capture()} in the parent thread.
+ * @see {@link AbstractTracerContext#continued(ContextSnapshot)}
+ */
+ @Override
+ public void continued(ContextSnapshot snapshot) {
+ this.segment.ref(new TraceSegmentRef(snapshot));
+ this.segment.relatedGlobalTraces(snapshot.getDistributedTraceIds());
+ }
+
+ /**
+ * @return the first global trace id.
+ */
@Override
public String getGlobalTraceId() {
return segment.getRelatedGlobalTraces().get(0).get();
}
+ /**
+ * Create an entry span
+ *
+ * @param operationName most likely a service name
+ * @return span instance.
+ * @see {@link EntrySpan}
+ */
@Override
public AbstractSpan createEntrySpan(final String operationName) {
AbstractTracingSpan entrySpan;
@@ -129,6 +202,13 @@ public class TracingContext implements AbstractTracerContext {
}
}
+ /**
+ * Create a local span
+ *
+ * @param operationName most likely a local method signature, or business name.
+ * @return the span represents a local logic block.
+ * @see {@link LocalSpan}
+ */
@Override
public AbstractSpan createLocalSpan(final String operationName) {
AbstractTracingSpan parentSpan = peek();
@@ -150,6 +230,14 @@ public class TracingContext implements AbstractTracerContext {
return push(span);
}
+ /**
+ * Create an exit span
+ *
+ * @param operationName most likely a service name of remote
+ * @param remotePeer the network id(ip:port, hostname:port or ip1:port1,ip2,port, etc.)
+ * @return the span represent an exit point of this segment.
+ * @see {@link ExitSpan}
+ */
@Override
public AbstractSpan createExitSpan(final String operationName, final String remotePeer) {
AbstractTracingSpan exitSpan;
@@ -191,6 +279,9 @@ public class TracingContext implements AbstractTracerContext {
return exitSpan;
}
+ /**
+ * @return the active span of current context, the top element of {@link #activeSpanStack}
+ */
@Override
public AbstractTracingSpan activeSpan() {
AbstractTracingSpan span = peek();
@@ -200,6 +291,12 @@ public class TracingContext implements AbstractTracerContext {
return span;
}
+ /**
+ * Stop the given span, if and only if this one is the top element of {@link #activeSpanStack}.
+ * Because the tracing core must make sure the span must match in a stack module, like any program did.
+ *
+ * @param span to finish
+ */
@Override
public void stopSpan(AbstractSpan span) {
AbstractTracingSpan lastSpan = peek();
@@ -236,12 +333,10 @@ public class TracingContext implements AbstractTracerContext {
TracingContext.ListenerManager.notifyFinish(finishedSegment);
}
- @Override
- public void dispose() {
- this.segment = null;
- this.activeSpanStack = null;
- }
-
+ /**
+ * The ListenerManager represents an event notify for every registered listener, which are notified
+ * when the TracingContext finished, and {@link #segment} is ready for further process.
+ */
public static class ListenerManager {
private static List LISTENERS = new LinkedList();
diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/TracingContextListener.java b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/TracingContextListener.java
index d36f0b80a9b64db3b71a3031ed7308526b28c57a..42ed16baf0768dd7afff29301a71399c6e7e3fcc 100644
--- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/TracingContextListener.java
+++ b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/TracingContextListener.java
@@ -2,19 +2,6 @@ package org.skywalking.apm.agent.core.context;
import org.skywalking.apm.agent.core.context.trace.TraceSegment;
-/**
- * {@link TracingContextListener} is a status change listener of {@link TracerContext}.
- * Add a {@link TracingContextListener} implementation through {@link TracerContext}
- *
- * All this class's methods will be called concurrently. Make sure all implementations are thread-safe.
- *
- * Created by wusheng on 2017/2/17.
- */
public interface TracingContextListener {
- /**
- * This method will be called, after the {@link TracerContext#finish()}
- *
- * @param traceSegment finished {@link TraceSegment}
- */
void afterFinished(TraceSegment traceSegment);
}
diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/trace/AbstractSpan.java b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/trace/AbstractSpan.java
index c38957c892aff7ab45224ccd85a3b064e895845a..4ceb386a7ace137731be8d34bb9933fa09d7640d 100644
--- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/trace/AbstractSpan.java
+++ b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/trace/AbstractSpan.java
@@ -1,5 +1,6 @@
package org.skywalking.apm.agent.core.context.trace;
+import java.util.Map;
import org.skywalking.apm.network.trace.component.Component;
/**
@@ -11,10 +12,19 @@ import org.skywalking.apm.network.trace.component.Component;
public interface AbstractSpan {
/**
* Set the component id, which defines in {@link org.skywalking.apm.network.trace.component.ComponentsDefine}
+ *
* @param component
+ * @return the span for chaining.
*/
AbstractSpan setComponent(Component component);
+ /**
+ * Only use this method in explicit instrumentation, like opentracing-skywalking-bridge.
+ * It it higher recommend don't use this for performance consideration.
+ *
+ * @param componentName
+ * @return the span for chaining.
+ */
AbstractSpan setComponent(String componentName);
AbstractSpan setLayer(SpanLayer layer);
@@ -42,12 +52,23 @@ public interface AbstractSpan {
boolean isEntry();
/**
- * @return true if the actual span is a local span.
+ * @return true if the actual span is an exit span.
*/
- boolean isLocal();
+ boolean isExit();
/**
- * @return true if the actual span is an exit span.
+ * Record an event at a specific timestamp.
+ *
+ * @param timestamp The explicit timestamp for the log record.
+ * @param event the events
+ * @return the Span, for chaining
*/
- boolean isExit();
+ AbstractSpan log(long timestamp, Map event);
+
+ /**
+ * Sets the string name for the logical operation this span represents.
+ *
+ * @return this Span instance, for chaining
+ */
+ AbstractSpan setOperationName(String operationName);
}
diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/trace/AbstractTracingSpan.java b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/trace/AbstractTracingSpan.java
index 4efc51749fcc92f7b75a3ce935ab7966e3d2fad1..8a209aa956471eecc2c89226f89efd9eae4a5a28 100644
--- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/trace/AbstractTracingSpan.java
+++ b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/trace/AbstractTracingSpan.java
@@ -2,6 +2,7 @@ package org.skywalking.apm.agent.core.context.trace;
import java.util.LinkedList;
import java.util.List;
+import java.util.Map;
import org.skywalking.apm.agent.core.context.util.KeyValuePair;
import org.skywalking.apm.agent.core.context.util.ThrowableTransformer;
import org.skywalking.apm.agent.core.dictionary.DictionaryUtil;
@@ -86,7 +87,7 @@ public abstract class AbstractTracingSpan implements AbstractSpan {
return true;
}
- public AbstractSpan start() {
+ public AbstractTracingSpan start() {
this.startTime = System.currentTimeMillis();
return this;
}
@@ -97,7 +98,8 @@ public abstract class AbstractTracingSpan implements AbstractSpan {
* @param t any subclass of {@link Throwable}, which occurs in this span.
* @return the Span, for chaining
*/
- public AbstractSpan log(Throwable t) {
+ @Override
+ public AbstractTracingSpan log(Throwable t) {
if (logs == null) {
logs = new LinkedList();
}
@@ -106,22 +108,64 @@ public abstract class AbstractTracingSpan implements AbstractSpan {
.add(new KeyValuePair("error.kind", t.getClass().getName()))
.add(new KeyValuePair("message", t.getMessage()))
.add(new KeyValuePair("stack", ThrowableTransformer.INSTANCE.convert2String(t, 4000)))
- .build());
+ .build(System.currentTimeMillis()));
+ return this;
+ }
+
+ /**
+ * Record a common log with multi fields, for supporting opentracing-java
+ *
+ * @param fields
+ * @return the Span, for chaining
+ */
+ @Override
+ public AbstractTracingSpan log(long timestampMicroseconds, Map fields) {
+ if (logs == null) {
+ logs = new LinkedList();
+ }
+ LogDataEntity.Builder builder = new LogDataEntity.Builder();
+ for (Map.Entry entry : fields.entrySet()) {
+ builder.add(new KeyValuePair(entry.getKey(), entry.getValue().toString()));
+ }
+ logs.add(builder.build(timestampMicroseconds));
return this;
}
- public AbstractSpan errorOccurred() {
+ /**
+ * In the scope of this span tracing context, error occurred,
+ * in auto-instrumentation mechanism, almost means throw an exception.
+ *
+ * @return span instance, for chaining.
+ */
+ @Override
+ public AbstractTracingSpan errorOccurred() {
this.errorOccurred = true;
return this;
}
+ /**
+ * Set the operation name, just because these is not compress dictionary value for this name.
+ * Use the entire string temporarily, the agent will compress this name in async mode.
+ *
+ * @param operationName
+ * @return span instance, for chaining.
+ */
+ @Override
public AbstractTracingSpan setOperationName(String operationName) {
this.operationName = operationName;
+ this.operationId = DictionaryUtil.nullValue();
return this;
}
+ /**
+ * Set the operation id, which compress by the name.
+ *
+ * @param operationId
+ * @return span instance, for chaining.
+ */
public AbstractTracingSpan setOperationId(int operationId) {
this.operationId = operationId;
+ this.operationName = null;
return this;
}
@@ -138,19 +182,33 @@ public abstract class AbstractTracingSpan implements AbstractSpan {
}
@Override
- public AbstractSpan setLayer(SpanLayer layer) {
+ public AbstractTracingSpan setLayer(SpanLayer layer) {
this.layer = layer;
return this;
}
+ /**
+ * Set the component of this span, with internal supported.
+ * Highly recommend to use this way.
+ *
+ * @param component
+ * @return span instance, for chaining.
+ */
@Override
- public AbstractSpan setComponent(Component component) {
+ public AbstractTracingSpan setComponent(Component component) {
this.componentId = component.getId();
return this;
}
+ /**
+ * Set the component name.
+ * By using this, cost more memory and network.
+ *
+ * @param componentName
+ * @return span instance, for chaining.
+ */
@Override
- public AbstractSpan setComponent(String componentName) {
+ public AbstractTracingSpan setComponent(String componentName) {
this.componentName = componentName;
return this;
}
@@ -162,17 +220,27 @@ public abstract class AbstractTracingSpan implements AbstractSpan {
spanBuilder.setParentSpanId(parentSpanId);
spanBuilder.setStartTime(startTime);
spanBuilder.setEndTime(endTime);
- if (operationId == DictionaryUtil.nullValue()) {
+ if (operationId != DictionaryUtil.nullValue()) {
spanBuilder.setOperationNameId(operationId);
} else {
spanBuilder.setOperationName(operationName);
}
- spanBuilder.setSpanType(SpanType.Entry);
- spanBuilder.setSpanLayerValue(this.layer.getCode());
- if (componentId == DictionaryUtil.nullValue()) {
+ if (isEntry()) {
+ spanBuilder.setSpanType(SpanType.Entry);
+ } else if (isExit()) {
+ spanBuilder.setSpanType(SpanType.Exit);
+ } else {
+ spanBuilder.setSpanType(SpanType.Local);
+ }
+ if (this.layer != null) {
+ spanBuilder.setSpanLayerValue(this.layer.getCode());
+ }
+ if (componentId != DictionaryUtil.nullValue()) {
spanBuilder.setComponentId(componentId);
} else {
- spanBuilder.setComponent(componentName);
+ if (componentName != null) {
+ spanBuilder.setComponent(componentName);
+ }
}
spanBuilder.setIsError(errorOccurred);
if (this.tags != null) {
diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/trace/EntrySpan.java b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/trace/EntrySpan.java
index aae12a8a30a0f1bc0a2a650500fbddf51f0948fd..852b67a04dced6f8447beedde7544228642b32c6 100644
--- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/trace/EntrySpan.java
+++ b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/trace/EntrySpan.java
@@ -6,11 +6,14 @@ import org.skywalking.apm.network.trace.component.Component;
/**
* The EntrySpan represents a service provider point, such as Tomcat server entrance.
*
- * It is a start point of {@link TraceSegment}, even in a complex application, there maybe have multi entry point,
+ * It is a start point of {@link TraceSegment}, even in a complex application, there maybe have multi-layer entry point,
* the EntrySpan only represents the first one.
*
* But with the last EntrySpan's tags and logs, which have more details about a service provider.
*
+ * Such as: Tomcat Embed -> Dubbox
+ * The EntrySpan represents the Dubbox span.
+ *
* @author wusheng
*/
public class EntrySpan extends AbstractTracingSpan {
@@ -50,7 +53,7 @@ public class EntrySpan extends AbstractTracingSpan {
}
@Override
- public AbstractSpan setLayer(SpanLayer layer) {
+ public AbstractTracingSpan setLayer(SpanLayer layer) {
if (stackDepth == currentMaxDepth) {
return super.setLayer(layer);
} else {
@@ -59,7 +62,7 @@ public class EntrySpan extends AbstractTracingSpan {
}
@Override
- public AbstractSpan setComponent(Component component) {
+ public AbstractTracingSpan setComponent(Component component) {
if (stackDepth == currentMaxDepth) {
return super.setComponent(component);
} else {
@@ -68,7 +71,7 @@ public class EntrySpan extends AbstractTracingSpan {
}
@Override
- public AbstractSpan setComponent(String componentName) {
+ public AbstractTracingSpan setComponent(String componentName) {
if (stackDepth == currentMaxDepth) {
return super.setComponent(componentName);
} else {
@@ -85,6 +88,24 @@ public class EntrySpan extends AbstractTracingSpan {
}
}
+ @Override
+ public AbstractTracingSpan setOperationName(String operationName) {
+ if (stackDepth == currentMaxDepth) {
+ return super.setOperationName(operationName);
+ } else {
+ return this;
+ }
+ }
+
+ @Override
+ public AbstractTracingSpan setOperationId(int operationId) {
+ if (stackDepth == currentMaxDepth) {
+ return super.setOperationId(operationId);
+ } else {
+ return this;
+ }
+ }
+
@Override
public EntrySpan log(Throwable t) {
super.log(t);
@@ -95,10 +116,6 @@ public class EntrySpan extends AbstractTracingSpan {
return true;
}
- @Override public boolean isLocal() {
- return false;
- }
-
@Override public boolean isExit() {
return false;
}
diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/trace/ExitSpan.java b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/trace/ExitSpan.java
index 95fee05a9a06398468a755de37aae451e252567e..bed47ff121068b154123df4f0703f2b819b151fe 100644
--- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/trace/ExitSpan.java
+++ b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/trace/ExitSpan.java
@@ -5,13 +5,16 @@ import org.skywalking.apm.network.proto.SpanObject;
import org.skywalking.apm.network.trace.component.Component;
/**
- * The ExitSpan represents a service consumer point, such as Feign, Okhttp discovery for a Http service.
+ * The ExitSpan represents a service consumer point, such as Feign, Okhttp client for a Http service.
*
* It is an exit point or a leaf span(our old name) of trace tree.
- * In a single rpc call, because of a combination of discovery libs, there maybe contain multi exit point.
+ * In a single rpc call, because of a combination of discovery libs, there maybe contain multi-layer exit point:
*
* The ExitSpan only presents the first one.
*
+ * Such as: Dubbox -> Apache Httpcomponent -> ....(Remote)
+ * The ExitSpan represents the Dubbox span, and ignore the httpcomponent span's info.
+ *
* @author wusheng
*/
public class ExitSpan extends AbstractTracingSpan {
@@ -69,7 +72,7 @@ public class ExitSpan extends AbstractTracingSpan {
}
@Override
- public AbstractSpan setLayer(SpanLayer layer) {
+ public AbstractTracingSpan setLayer(SpanLayer layer) {
if (stackDepth == 1) {
return super.setLayer(layer);
} else {
@@ -78,7 +81,7 @@ public class ExitSpan extends AbstractTracingSpan {
}
@Override
- public AbstractSpan setComponent(Component component) {
+ public AbstractTracingSpan setComponent(Component component) {
if (stackDepth == 1) {
return super.setComponent(component);
} else {
@@ -87,7 +90,7 @@ public class ExitSpan extends AbstractTracingSpan {
}
@Override
- public AbstractSpan setComponent(String componentName) {
+ public AbstractTracingSpan setComponent(String componentName) {
if (stackDepth == 1) {
return super.setComponent(componentName);
} else {
@@ -105,14 +108,34 @@ public class ExitSpan extends AbstractTracingSpan {
@Override public SpanObject.Builder transform() {
SpanObject.Builder spanBuilder = super.transform();
- if (peerId == DictionaryUtil.nullValue()) {
+ if (peerId != DictionaryUtil.nullValue()) {
spanBuilder.setPeerId(peerId);
} else {
- spanBuilder.setPeer(peer);
+ if (peer != null) {
+ spanBuilder.setPeer(peer);
+ }
}
return spanBuilder;
}
+ @Override
+ public AbstractTracingSpan setOperationName(String operationName) {
+ if (stackDepth == 1) {
+ return super.setOperationName(operationName);
+ } else {
+ return this;
+ }
+ }
+
+ @Override
+ public AbstractTracingSpan setOperationId(int operationId) {
+ if (stackDepth == 1) {
+ return super.setOperationId(operationId);
+ } else {
+ return this;
+ }
+ }
+
public int getPeerId() {
return peerId;
}
@@ -125,10 +148,6 @@ public class ExitSpan extends AbstractTracingSpan {
return false;
}
- @Override public boolean isLocal() {
- return false;
- }
-
@Override public boolean isExit() {
return true;
}
diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/trace/LocalSpan.java b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/trace/LocalSpan.java
index 6ef653f891dd5f7e4e01e3b487b68329e5408be1..d89c5ea31456f0b39cc0e0916f6ae2d7d6ce38bf 100644
--- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/trace/LocalSpan.java
+++ b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/trace/LocalSpan.java
@@ -1,7 +1,5 @@
package org.skywalking.apm.agent.core.context.trace;
-import org.skywalking.apm.network.proto.SpanObject;
-
/**
* The LocalSpan represents a normal tracing point, such as a local method.
*
@@ -29,18 +27,10 @@ public class LocalSpan extends AbstractTracingSpan {
return this;
}
- @Override public SpanObject.Builder transform() {
- return null;
- }
-
@Override public boolean isEntry() {
return false;
}
- @Override public boolean isLocal() {
- return true;
- }
-
@Override public boolean isExit() {
return false;
}
diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/trace/LogDataEntity.java b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/trace/LogDataEntity.java
index e3b732aff45dd891e858c046ded2bb7ce4aeafd4..f79644d5c5f95d9629b45cab6f0efa07c94710fb 100644
--- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/trace/LogDataEntity.java
+++ b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/trace/LogDataEntity.java
@@ -12,9 +12,11 @@ import org.skywalking.apm.network.proto.LogMessage;
* @author wusheng
*/
public class LogDataEntity {
- protected List logs;
+ private long timestamp = 0;
+ private List logs;
- private LogDataEntity(List logs) {
+ private LogDataEntity(long timestamp, List logs) {
+ this.timestamp = timestamp;
this.logs = logs;
}
@@ -36,8 +38,8 @@ public class LogDataEntity {
return this;
}
- public LogDataEntity build() {
- return new LogDataEntity(logs);
+ public LogDataEntity build(long timestamp) {
+ return new LogDataEntity(timestamp, logs);
}
}
@@ -46,6 +48,7 @@ public class LogDataEntity {
for (KeyValuePair log : logs) {
logMessageBuilder.addData(log.transform());
}
+ logMessageBuilder.setTime(timestamp);
return logMessageBuilder.build();
}
}
diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/trace/NoopSpan.java b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/trace/NoopSpan.java
index b4138390c5acc5d7656e13450563c4bf39470cc1..e8bf330c61bdd64f4509601b5bbd940e6a0b45b4 100644
--- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/trace/NoopSpan.java
+++ b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/trace/NoopSpan.java
@@ -1,11 +1,13 @@
package org.skywalking.apm.agent.core.context.trace;
+import java.util.Map;
import org.skywalking.apm.agent.core.context.IgnoredTracerContext;
import org.skywalking.apm.network.trace.component.Component;
/**
* The NoopSpan represents a span implementation without any actual operation.
- * This span implementation is for {@link IgnoredTracerContext}.
+ * This span implementation is for {@link IgnoredTracerContext},
+ * for keeping the memory and gc cost as low as possible.
*
* @author wusheng
*/
@@ -13,7 +15,6 @@ public class NoopSpan implements AbstractSpan {
public NoopSpan() {
}
-
@Override
public AbstractSpan log(Throwable t) {
return this;
@@ -23,7 +24,7 @@ public class NoopSpan implements AbstractSpan {
return null;
}
- public void finish(){
+ public void finish() {
}
@@ -48,11 +49,15 @@ public class NoopSpan implements AbstractSpan {
return false;
}
- @Override public boolean isLocal() {
+ @Override public boolean isExit() {
return false;
}
- @Override public boolean isExit() {
- return false;
+ @Override public AbstractSpan log(long timestamp, Map event) {
+ return this;
+ }
+
+ @Override public AbstractSpan setOperationName(String operationName) {
+ return this;
}
}
diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/trace/TraceSegment.java b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/trace/TraceSegment.java
index dbca8a3c51543be92006bcd43aac36b3320208cd..000e719569e82eb5121a183f02771d46f88c8fab 100644
--- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/trace/TraceSegment.java
+++ b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/trace/TraceSegment.java
@@ -2,14 +2,11 @@ package org.skywalking.apm.agent.core.context.trace;
import java.util.LinkedList;
import java.util.List;
-import org.skywalking.apm.agent.core.conf.Config;
import org.skywalking.apm.agent.core.conf.RemoteDownstreamConfig;
import org.skywalking.apm.agent.core.context.ids.DistributedTraceId;
import org.skywalking.apm.agent.core.context.ids.DistributedTraceIds;
import org.skywalking.apm.agent.core.context.ids.GlobalIdGenerator;
import org.skywalking.apm.agent.core.context.ids.NewDistributedTraceId;
-import org.skywalking.apm.agent.core.dictionary.DictionaryManager;
-import org.skywalking.apm.agent.core.dictionary.PossibleFound;
import org.skywalking.apm.logging.ILog;
import org.skywalking.apm.logging.LogManager;
import org.skywalking.apm.network.proto.TraceSegmentObject;
@@ -51,14 +48,6 @@ public class TraceSegment {
*/
private List spans;
- /**
- * The applicationId represents a name of current application/JVM and indicates which is business
- * role in the cluster.
- *
- * e.g. account_app, billing_app
- */
- private int applicationId;
-
/**
* The relatedGlobalTraces represent a set of all related trace. Most time it contains only one
* element, because only one parent {@link TraceSegment} exists, but, in batch scenario, the num becomes greater
@@ -82,20 +71,6 @@ public class TraceSegment {
* and generate a new segment id.
*/
public TraceSegment() {
- this.applicationId = (Integer)DictionaryManager.findApplicationCodeSection()
- .find(Config.Agent.APPLICATION_CODE)
- .doInCondition(
- new PossibleFound.FoundAndObtain() {
- @Override public Object doProcess(int applicationId) {
- return applicationId;
- }
- },
- new PossibleFound.NotFoundAndObtain() {
- @Override public Object doProcess() {
- throw new IllegalStateException("Application id must not NULL.");
- }
- }
- );
this.traceSegmentId = GlobalIdGenerator.generate(ID_TYPE);
this.spans = new LinkedList();
this.relatedGlobalTraces = new DistributedTraceIds();
@@ -154,7 +129,7 @@ public class TraceSegment {
}
public int getApplicationId() {
- return applicationId;
+ return RemoteDownstreamConfig.Agent.APPLICATION_ID;
}
public boolean hasRef() {
@@ -206,8 +181,8 @@ public class TraceSegment {
for (AbstractTracingSpan span : this.spans) {
traceSegmentBuilder.addSpans(span.transform());
}
- traceSegmentBuilder.setApplicationId(this.applicationId);
- traceSegmentBuilder.setApplicationInstanceId(RemoteDownstreamConfig.Agent.APPLICATION_ID);
+ traceSegmentBuilder.setApplicationId(RemoteDownstreamConfig.Agent.APPLICATION_ID);
+ traceSegmentBuilder.setApplicationInstanceId(RemoteDownstreamConfig.Agent.APPLICATION_INSTANCE_ID);
upstreamBuilder.setSegment(traceSegmentBuilder.build().toByteString());
return upstreamBuilder.build();
@@ -219,7 +194,6 @@ public class TraceSegment {
"traceSegmentId='" + traceSegmentId + '\'' +
", refs=" + refs +
", spans=" + spans +
- ", applicationId='" + applicationId + '\'' +
", relatedGlobalTraces=" + relatedGlobalTraces +
'}';
}
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 abb5e2a6dbc6fc93f7f776a7137820b609c89a5c..1e2da121733152da9de828743558926a4909e36a 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
@@ -1,7 +1,9 @@
package org.skywalking.apm.agent.core.context.trace;
import org.skywalking.apm.agent.core.context.ContextCarrier;
+import org.skywalking.apm.agent.core.context.ContextSnapshot;
import org.skywalking.apm.agent.core.dictionary.DictionaryUtil;
+import org.skywalking.apm.network.proto.RefType;
import org.skywalking.apm.network.proto.TraceSegmentReference;
/**
@@ -11,11 +13,13 @@ import org.skywalking.apm.network.proto.TraceSegmentReference;
* Created by wusheng on 2017/2/17.
*/
public class TraceSegmentRef {
+ private SegmentRefType type;
+
private String traceSegmentId;
private int spanId = -1;
- private int applicationId;
+ private int applicationInstanceId;
private String peerHost;
@@ -31,9 +35,10 @@ public class TraceSegmentRef {
* @param carrier the valid cross-process propagation format.
*/
public TraceSegmentRef(ContextCarrier carrier) {
+ this.type = SegmentRefType.CROSS_PROCESS;
this.traceSegmentId = carrier.getTraceSegmentId();
this.spanId = carrier.getSpanId();
- this.applicationId = carrier.getApplicationId();
+ this.applicationInstanceId = carrier.getApplicationInstanceId();
String host = carrier.getPeerHost();
if (host.charAt(0) == '#') {
this.peerHost = host.substring(1);
@@ -48,6 +53,12 @@ public class TraceSegmentRef {
}
}
+ public TraceSegmentRef(ContextSnapshot snapshot) {
+ this.type = SegmentRefType.CROSS_THREAD;
+ this.traceSegmentId = snapshot.getTraceSegmentId();
+ this.spanId = snapshot.getSpanId();
+ }
+
public String getOperationName() {
return operationName;
}
@@ -58,19 +69,25 @@ public class TraceSegmentRef {
public TraceSegmentReference transform() {
TraceSegmentReference.Builder refBuilder = TraceSegmentReference.newBuilder();
- refBuilder.setParentTraceSegmentId(traceSegmentId);
- refBuilder.setParentSpanId(spanId);
- refBuilder.setParentApplicationId(applicationId);
- if (peerId == DictionaryUtil.nullValue()) {
- refBuilder.setNetworkAddress(peerHost);
- } else {
- refBuilder.setNetworkAddressId(peerId);
- }
- if (operationId == DictionaryUtil.nullValue()) {
- refBuilder.setEntryServiceName(operationName);
+ if (SegmentRefType.CROSS_PROCESS.equals(type)) {
+ refBuilder.setRefType(RefType.CrossProcess);
+ refBuilder.setParentApplicationInstanceId(applicationInstanceId);
+ if (peerId == DictionaryUtil.nullValue()) {
+ refBuilder.setNetworkAddress(peerHost);
+ } else {
+ refBuilder.setNetworkAddressId(peerId);
+ }
+ if (operationId == DictionaryUtil.nullValue()) {
+ refBuilder.setEntryServiceName(operationName);
+ } else {
+ refBuilder.setEntryServiceId(operationId);
+ }
} else {
- refBuilder.setEntryServiceId(operationId);
+ refBuilder.setRefType(RefType.CrossThread);
}
+ refBuilder.setParentTraceSegmentId(traceSegmentId);
+ refBuilder.setParentSpanId(spanId);
+
return refBuilder.build();
}
@@ -94,4 +111,9 @@ public class TraceSegmentRef {
result = 31 * result + spanId;
return result;
}
+
+ public enum SegmentRefType {
+ CROSS_PROCESS,
+ CROSS_THREAD
+ }
}
diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/dictionary/ApplicationDictionary.java b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/dictionary/ApplicationDictionary.java
index 5859717063cfbb9e96d4a6170348689c8a63d49f..295f4476df42c71707b231f497d950d73918e9d8 100644
--- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/dictionary/ApplicationDictionary.java
+++ b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/dictionary/ApplicationDictionary.java
@@ -4,6 +4,10 @@ import io.netty.util.internal.ConcurrentSet;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
+import org.skywalking.apm.network.proto.Application;
+import org.skywalking.apm.network.proto.ApplicationMapping;
+import org.skywalking.apm.network.proto.ApplicationRegisterServiceGrpc;
+import org.skywalking.apm.network.proto.KeyWithIntegerValue;
/**
* Map of application id to application code, which is from the collector side.
@@ -13,15 +17,29 @@ import java.util.concurrent.ConcurrentHashMap;
public enum ApplicationDictionary {
INSTANCE;
private Map applicationDictionary = new ConcurrentHashMap();
- private Set unRegisterApplication = new ConcurrentSet();
+ private Set unRegisterApplications = new ConcurrentSet();
public PossibleFound find(String applicationCode) {
Integer applicationId = applicationDictionary.get(applicationCode);
if (applicationId != null) {
return new Found(applicationId);
} else {
- unRegisterApplication.add(applicationCode);
+ unRegisterApplications.add(applicationCode);
return new NotFound();
}
}
+
+ public void syncRemoteDictionary(
+ ApplicationRegisterServiceGrpc.ApplicationRegisterServiceBlockingStub applicationRegisterServiceBlockingStub) {
+ if (unRegisterApplications.size() > 0) {
+ ApplicationMapping applicationMapping = applicationRegisterServiceBlockingStub.register(
+ Application.newBuilder().addAllApplicationCode(unRegisterApplications).build());
+ if (applicationMapping.getApplicationCount() > 0) {
+ for (KeyWithIntegerValue keyWithIntegerValue : applicationMapping.getApplicationList()) {
+ unRegisterApplications.remove(keyWithIntegerValue.getKey());
+ applicationDictionary.put(keyWithIntegerValue.getKey(), keyWithIntegerValue.getValue());
+ }
+ }
+ }
+ }
}
diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/dictionary/OperationNameDictionary.java b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/dictionary/OperationNameDictionary.java
index 5ada580287419741df8c5327574d1212efbe31db..9f575b50a2b52fdb175285a046aa2c9e7bb10217 100644
--- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/dictionary/OperationNameDictionary.java
+++ b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/dictionary/OperationNameDictionary.java
@@ -4,6 +4,11 @@ import io.netty.util.internal.ConcurrentSet;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
+import org.skywalking.apm.network.proto.ServiceNameCollection;
+import org.skywalking.apm.network.proto.ServiceNameDiscoveryServiceGrpc;
+import org.skywalking.apm.network.proto.ServiceNameElement;
+import org.skywalking.apm.network.proto.ServiceNameMappingCollection;
+import org.skywalking.apm.network.proto.ServiceNameMappingElement;
/**
* @author wusheng
@@ -11,7 +16,7 @@ import java.util.concurrent.ConcurrentHashMap;
public enum OperationNameDictionary {
INSTANCE;
private Map operationNameDictionary = new ConcurrentHashMap();
- private Set unRegisterOperationName = new ConcurrentSet();
+ private Set unRegisterOperationNames = new ConcurrentSet();
public PossibleFound find(int applicationId, String operationName) {
OperationNameKey key = new OperationNameKey(applicationId, operationName);
@@ -19,11 +24,35 @@ public enum OperationNameDictionary {
if (operationId != null) {
return new Found(applicationId);
} else {
- unRegisterOperationName.add(key);
+ unRegisterOperationNames.add(key);
return new NotFound();
}
}
+ public void syncRemoteDictionary(
+ ServiceNameDiscoveryServiceGrpc.ServiceNameDiscoveryServiceBlockingStub serviceNameDiscoveryServiceBlockingStub) {
+ if (unRegisterOperationNames.size() > 0) {
+ ServiceNameCollection.Builder builder = ServiceNameCollection.newBuilder();
+ for (OperationNameKey operationNameKey : unRegisterOperationNames) {
+ ServiceNameElement serviceNameElement = ServiceNameElement.newBuilder()
+ .setApplicationId(operationNameKey.getApplicationId())
+ .setServiceName(operationNameKey.getOperationName())
+ .build();
+ builder.addElements(serviceNameElement);
+ }
+ ServiceNameMappingCollection serviceNameMappingCollection = serviceNameDiscoveryServiceBlockingStub.discovery(builder.build());
+ if (serviceNameMappingCollection.getElementsCount() > 0) {
+ for (ServiceNameMappingElement serviceNameMappingElement : serviceNameMappingCollection.getElementsList()) {
+ OperationNameKey key = new OperationNameKey(
+ serviceNameMappingElement.getElement().getApplicationId(),
+ serviceNameMappingElement.getElement().getServiceName());
+ unRegisterOperationNames.remove(key);
+ operationNameDictionary.put(key, serviceNameMappingElement.getServiceId());
+ }
+ }
+ }
+ }
+
private class OperationNameKey {
private int applicationId;
private String operationName;
@@ -33,6 +62,14 @@ public enum OperationNameDictionary {
this.operationName = operationName;
}
+ public int getApplicationId() {
+ return applicationId;
+ }
+
+ public String getOperationName() {
+ return operationName;
+ }
+
@Override public boolean equals(Object o) {
if (this == o)
return true;
diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/dictionary/PossibleFound.java b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/dictionary/PossibleFound.java
index 89e924ec2ea1cae0b59970ef8a30db075c688a44..cc865a9a1724e4018e0b4040c91681693a216eb3 100644
--- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/dictionary/PossibleFound.java
+++ b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/dictionary/PossibleFound.java
@@ -1,7 +1,7 @@
package org.skywalking.apm.agent.core.dictionary;
/**
- * The PossibleFound represents a value, which may exist or not.
+ * The PossibleFound represents a value, which may needEnhance or not.
*
* @author wusheng
*/
diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/jvm/JVMService.java b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/jvm/JVMService.java
index 3fb217ee8786b38f589c096d4e6951300c4276cf..bf3189c76a20b07a1356dcc0932035042214e8a3 100644
--- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/jvm/JVMService.java
+++ b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/jvm/JVMService.java
@@ -1,34 +1,63 @@
package org.skywalking.apm.agent.core.jvm;
+import io.grpc.ManagedChannel;
import java.text.SimpleDateFormat;
import java.util.Date;
+import java.util.LinkedList;
import java.util.concurrent.Executors;
-import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
+import java.util.concurrent.locks.ReentrantLock;
import org.skywalking.apm.agent.core.boot.BootService;
+import org.skywalking.apm.agent.core.boot.ServiceManager;
+import org.skywalking.apm.agent.core.conf.RemoteDownstreamConfig;
+import org.skywalking.apm.agent.core.dictionary.DictionaryUtil;
import org.skywalking.apm.agent.core.jvm.cpu.CPUProvider;
+import org.skywalking.apm.agent.core.jvm.gc.GCProvider;
import org.skywalking.apm.agent.core.jvm.memory.MemoryProvider;
import org.skywalking.apm.agent.core.jvm.memorypool.MemoryPoolProvider;
+import org.skywalking.apm.agent.core.remote.GRPCChannelListener;
+import org.skywalking.apm.agent.core.remote.GRPCChannelManager;
+import org.skywalking.apm.agent.core.remote.GRPCChannelStatus;
+import org.skywalking.apm.logging.ILog;
+import org.skywalking.apm.logging.LogManager;
import org.skywalking.apm.network.proto.JVMMetric;
+import org.skywalking.apm.network.proto.JVMMetrics;
+import org.skywalking.apm.network.proto.JVMMetricsServiceGrpc;
+
+import static org.skywalking.apm.agent.core.remote.GRPCChannelStatus.CONNECTED;
/**
+ * The JVMService represents a timer,
+ * which collectors JVM cpu, memory, memorypool and gc info,
+ * and send the collected info to Collector through the channel provided by {@link GRPCChannelManager}
+ *
* @author wusheng
*/
public class JVMService implements BootService, Runnable {
+ private static final ILog logger = LogManager.getLogger(JVMService.class);
+ private ReentrantLock lock = new ReentrantLock();
+ private volatile LinkedList buffer = new LinkedList();
private SimpleDateFormat sdf = new SimpleDateFormat("ss");
- private volatile ScheduledFuture> scheduledFuture;
+ private volatile ScheduledFuture> collectMetricFuture;
+ private volatile ScheduledFuture> sendMetricFuture;
+ private volatile int lastBlockIdx = -1;
+ private Sender sender;
@Override
public void beforeBoot() throws Throwable {
-
+ sender = new Sender();
+ ServiceManager.INSTANCE.findService(GRPCChannelManager.class).addChannelListener(sender);
}
@Override
public void boot() throws Throwable {
- ScheduledExecutorService service = Executors
- .newSingleThreadScheduledExecutor();
- scheduledFuture = service.scheduleAtFixedRate(this, 0, 1, TimeUnit.SECONDS);
+ collectMetricFuture = Executors
+ .newSingleThreadScheduledExecutor()
+ .scheduleAtFixedRate(this, 0, 1, TimeUnit.SECONDS);
+ sendMetricFuture = Executors
+ .newSingleThreadScheduledExecutor()
+ .scheduleAtFixedRate(sender, 0, 15, TimeUnit.SECONDS);
}
@Override
@@ -38,16 +67,76 @@ public class JVMService implements BootService, Runnable {
@Override
public void run() {
- long currentTimeMillis = System.currentTimeMillis();
- Date day = new Date(currentTimeMillis);
- String second = sdf.format(day);
-
- if (Integer.parseInt(second) % 15 == 0) {
- JVMMetric.Builder JVMBuilder = JVMMetric.newBuilder();
- JVMBuilder.setTime(currentTimeMillis);
- JVMBuilder.setCpu(CPUProvider.INSTANCE.getCpuMetric());
- JVMBuilder.addAllMemory(MemoryProvider.INSTANCE.getMemoryMetricList());
- JVMBuilder.addAllMemoryPool(MemoryPoolProvider.INSTANCE.getMemoryPoolMetricList());
+ if (RemoteDownstreamConfig.Agent.APPLICATION_ID != DictionaryUtil.nullValue()
+ && RemoteDownstreamConfig.Agent.APPLICATION_INSTANCE_ID != DictionaryUtil.nullValue()
+ ) {
+ long currentTimeMillis = System.currentTimeMillis();
+ Date day = new Date(currentTimeMillis);
+ String second = sdf.format(day);
+ int blockIndex = Integer.parseInt(second) / 15;
+ if (blockIndex != lastBlockIdx) {
+ lastBlockIdx = blockIndex;
+ try {
+ JVMMetric.Builder jvmBuilder = JVMMetric.newBuilder();
+ jvmBuilder.setTime(currentTimeMillis);
+ jvmBuilder.setCpu(CPUProvider.INSTANCE.getCpuMetric());
+ jvmBuilder.addAllMemory(MemoryProvider.INSTANCE.getMemoryMetricList());
+ jvmBuilder.addAllMemoryPool(MemoryPoolProvider.INSTANCE.getMemoryPoolMetricList());
+ jvmBuilder.addAllGc(GCProvider.INSTANCE.getGCList());
+
+ JVMMetric jvmMetric = jvmBuilder.build();
+ lock.lock();
+ try {
+ buffer.add(jvmMetric);
+ while (buffer.size() > 4) {
+ buffer.removeFirst();
+ }
+ } finally {
+ lock.unlock();
+ }
+ } catch (Exception e) {
+ logger.error(e, "Collect JVM info fail.");
+ }
+ }
+ }
+ }
+
+ private class Sender implements Runnable, GRPCChannelListener {
+ private volatile GRPCChannelStatus status = GRPCChannelStatus.DISCONNECT;
+ private volatile JVMMetricsServiceGrpc.JVMMetricsServiceBlockingStub stub = null;
+
+ @Override
+ public void run() {
+ if (RemoteDownstreamConfig.Agent.APPLICATION_ID != DictionaryUtil.nullValue()
+ && RemoteDownstreamConfig.Agent.APPLICATION_INSTANCE_ID != DictionaryUtil.nullValue()
+ ) {
+ if (status == GRPCChannelStatus.CONNECTED) {
+ try {
+ JVMMetrics.Builder builder = JVMMetrics.newBuilder();
+ lock.lock();
+ try {
+ builder.addAllMetrics(buffer);
+ buffer.clear();
+ } finally {
+ lock.unlock();
+ }
+
+ builder.setApplicationInstanceId(RemoteDownstreamConfig.Agent.APPLICATION_INSTANCE_ID);
+ stub.collect(builder.build());
+ } catch (Throwable t) {
+ logger.error(t, "send JVM metrics to Collector fail.");
+ }
+ }
+ }
+ }
+
+ @Override
+ public void statusChanged(GRPCChannelStatus status) {
+ if (CONNECTED.equals(status)) {
+ ManagedChannel channel = ServiceManager.INSTANCE.findService(GRPCChannelManager.class).getManagedChannel();
+ stub = JVMMetricsServiceGrpc.newBlockingStub(channel);
+ }
+ this.status = status;
}
}
}
diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/jvm/gc/CMSGCModule.java b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/jvm/gc/CMSGCModule.java
new file mode 100644
index 0000000000000000000000000000000000000000..1943da4a9e35e83b514555bdbebf29778cd912d2
--- /dev/null
+++ b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/jvm/gc/CMSGCModule.java
@@ -0,0 +1,21 @@
+package org.skywalking.apm.agent.core.jvm.gc;
+
+import java.lang.management.GarbageCollectorMXBean;
+import java.util.List;
+
+/**
+ * @author wusheng
+ */
+public class CMSGCModule extends GCModule {
+ public CMSGCModule(List beans) {
+ super(beans);
+ }
+
+ @Override protected String getOldGCName() {
+ return "ConcurrentMarkSweep";
+ }
+
+ @Override protected String getNewGCName() {
+ return "ParNew";
+ }
+}
diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/jvm/gc/G1GCModule.java b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/jvm/gc/G1GCModule.java
new file mode 100644
index 0000000000000000000000000000000000000000..d82086d3d587c59c75a3533e77efbac665b8bb8e
--- /dev/null
+++ b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/jvm/gc/G1GCModule.java
@@ -0,0 +1,21 @@
+package org.skywalking.apm.agent.core.jvm.gc;
+
+import java.lang.management.GarbageCollectorMXBean;
+import java.util.List;
+
+/**
+ * @author wusheng
+ */
+public class G1GCModule extends GCModule {
+ public G1GCModule(List beans) {
+ super(beans);
+ }
+
+ @Override protected String getOldGCName() {
+ return "G1 Old Generation";
+ }
+
+ @Override protected String getNewGCName() {
+ return "G1 Young Generation";
+ }
+}
diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/jvm/gc/GCMetricAccessor.java b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/jvm/gc/GCMetricAccessor.java
new file mode 100644
index 0000000000000000000000000000000000000000..95109ed679eedfb50944cfd3cf781345e2c1cab3
--- /dev/null
+++ b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/jvm/gc/GCMetricAccessor.java
@@ -0,0 +1,11 @@
+package org.skywalking.apm.agent.core.jvm.gc;
+
+import java.util.List;
+import org.skywalking.apm.network.proto.GC;
+
+/**
+ * @author wusheng
+ */
+public interface GCMetricAccessor {
+ List getGCList();
+}
diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/jvm/gc/GCModule.java b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/jvm/gc/GCModule.java
new file mode 100644
index 0000000000000000000000000000000000000000..842613453d3a2b686d05f8323ab65e99d785667b
--- /dev/null
+++ b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/jvm/gc/GCModule.java
@@ -0,0 +1,47 @@
+package org.skywalking.apm.agent.core.jvm.gc;
+
+import java.lang.management.GarbageCollectorMXBean;
+import java.util.LinkedList;
+import java.util.List;
+import org.skywalking.apm.network.proto.GC;
+import org.skywalking.apm.network.proto.GCPhrase;
+
+/**
+ * @author wusheng
+ */
+public abstract class GCModule implements GCMetricAccessor {
+ private List beans;
+
+ public GCModule(List beans) {
+ this.beans = beans;
+ }
+
+ @Override
+ public List getGCList() {
+ List gcList = new LinkedList();
+ for (GarbageCollectorMXBean bean : beans) {
+ String name = bean.getName();
+ GCPhrase phrase;
+ if (name.equals(getNewGCName())) {
+ phrase = GCPhrase.NEW;
+ } else if (name.equals(getOldGCName())) {
+ phrase = GCPhrase.OLD;
+ } else {
+ continue;
+ }
+
+ gcList.add(
+ GC.newBuilder().setPhrase(phrase)
+ .setCount(bean.getCollectionCount())
+ .setTime(bean.getCollectionTime())
+ .build()
+ );
+ }
+
+ return gcList;
+ }
+
+ protected abstract String getOldGCName();
+
+ protected abstract String getNewGCName();
+}
diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/jvm/gc/GCProvider.java b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/jvm/gc/GCProvider.java
new file mode 100644
index 0000000000000000000000000000000000000000..a72e30e956664f3e4bae364440eca12bc96af5a9
--- /dev/null
+++ b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/jvm/gc/GCProvider.java
@@ -0,0 +1,52 @@
+package org.skywalking.apm.agent.core.jvm.gc;
+
+import java.lang.management.GarbageCollectorMXBean;
+import java.lang.management.ManagementFactory;
+import java.util.List;
+import org.skywalking.apm.network.proto.GC;
+
+/**
+ * @author wusheng
+ */
+public enum GCProvider {
+ INSTANCE;
+
+ private GCMetricAccessor metricAccessor;
+ private List beans;
+
+ GCProvider() {
+ beans = ManagementFactory.getGarbageCollectorMXBeans();
+ for (GarbageCollectorMXBean bean : beans) {
+ String name = bean.getName();
+ GCMetricAccessor accessor = findByBeanName(name);
+ if (accessor != null) {
+ metricAccessor = accessor;
+ break;
+ }
+ }
+ this.metricAccessor = new UnknowGC();
+ }
+
+ public List getGCList() {
+ return metricAccessor.getGCList();
+ }
+
+ private GCMetricAccessor findByBeanName(String name) {
+ if (name.indexOf("PS") > -1) {
+ //Parallel (Old) collector ( -XX:+UseParallelOldGC )
+ return new ParallelGCModule(beans);
+ } else if (name.indexOf("ConcurrentMarkSweep") > -1) {
+ // CMS collector ( -XX:+UseConcMarkSweepGC )
+ return new CMSGCModule(beans);
+ } else if (name.indexOf("G1") > -1) {
+ // G1 collector ( -XX:+UseG1GC )
+ return new G1GCModule(beans);
+ } else if (name.equals("MarkSweepCompact")) {
+ // Serial collector ( -XX:+UseSerialGC )
+ return new SerialGCModule(beans);
+ } else {
+ // Unknown
+ return null;
+ }
+ }
+}
diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/jvm/gc/ParallelGCModule.java b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/jvm/gc/ParallelGCModule.java
new file mode 100644
index 0000000000000000000000000000000000000000..441d3be7a20e271fbc6b81dceeeeca9bc0f0a65d
--- /dev/null
+++ b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/jvm/gc/ParallelGCModule.java
@@ -0,0 +1,22 @@
+package org.skywalking.apm.agent.core.jvm.gc;
+
+import java.lang.management.GarbageCollectorMXBean;
+import java.util.List;
+
+/**
+ * @author wusheng
+ */
+public class ParallelGCModule extends GCModule {
+ public ParallelGCModule(List beans) {
+ super(beans);
+ }
+
+ @Override protected String getOldGCName() {
+ return "PS MarkSweep";
+ }
+
+ @Override protected String getNewGCName() {
+ return "PS Scavenge";
+ }
+
+}
diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/jvm/gc/SerialGCModule.java b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/jvm/gc/SerialGCModule.java
new file mode 100644
index 0000000000000000000000000000000000000000..93c2468adfb0be0b4030f012be4727d361e79fa6
--- /dev/null
+++ b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/jvm/gc/SerialGCModule.java
@@ -0,0 +1,21 @@
+package org.skywalking.apm.agent.core.jvm.gc;
+
+import java.lang.management.GarbageCollectorMXBean;
+import java.util.List;
+
+/**
+ * @author wusheng
+ */
+public class SerialGCModule extends GCModule {
+ public SerialGCModule(List beans) {
+ super(beans);
+ }
+
+ @Override protected String getOldGCName() {
+ return "MarkSweepCompact";
+ }
+
+ @Override protected String getNewGCName() {
+ return "Copy";
+ }
+}
diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/jvm/gc/UnknowGC.java b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/jvm/gc/UnknowGC.java
new file mode 100644
index 0000000000000000000000000000000000000000..35b59272aa33f9ddf7469332b3531e80b5fdb25f
--- /dev/null
+++ b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/jvm/gc/UnknowGC.java
@@ -0,0 +1,19 @@
+package org.skywalking.apm.agent.core.jvm.gc;
+
+import java.util.LinkedList;
+import java.util.List;
+import org.skywalking.apm.network.proto.GC;
+import org.skywalking.apm.network.proto.GCPhrase;
+
+/**
+ * @author wusheng
+ */
+public class UnknowGC implements GCMetricAccessor {
+ @Override
+ public List getGCList() {
+ List gcList = new LinkedList();
+ gcList.add(GC.newBuilder().setPhrase(GCPhrase.NEW).build());
+ gcList.add(GC.newBuilder().setPhrase(GCPhrase.OLD).build());
+ return gcList;
+ }
+}
diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/jvm/memorypool/CMSCollectorModule.java b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/jvm/memorypool/CMSCollectorModule.java
new file mode 100644
index 0000000000000000000000000000000000000000..c6a96627f9df8d1d2d9c4954feaf14c5a271e974
--- /dev/null
+++ b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/jvm/memorypool/CMSCollectorModule.java
@@ -0,0 +1,37 @@
+package org.skywalking.apm.agent.core.jvm.memorypool;
+
+import java.lang.management.MemoryPoolMXBean;
+import java.util.List;
+
+/**
+ * @author wusheng
+ */
+public class CMSCollectorModule extends MemoryPoolModule {
+ public CMSCollectorModule(List beans) {
+ super(beans);
+ }
+
+ @Override protected String getPermName() {
+ return "CMS Perm Gen";
+ }
+
+ @Override protected String getCodeCacheName() {
+ return "Code Cache";
+ }
+
+ @Override protected String getEdenName() {
+ return "Par Eden Space";
+ }
+
+ @Override protected String getOldName() {
+ return "CMS Old Gen";
+ }
+
+ @Override protected String getSurvivorName() {
+ return "Par Survivor Space";
+ }
+
+ @Override protected String getMetaspaceName() {
+ return "Metaspace";
+ }
+}
diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/jvm/memorypool/G1CollectorModule.java b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/jvm/memorypool/G1CollectorModule.java
new file mode 100644
index 0000000000000000000000000000000000000000..cf2d679f5cce708820a12b7bb936ffb844db0bbf
--- /dev/null
+++ b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/jvm/memorypool/G1CollectorModule.java
@@ -0,0 +1,37 @@
+package org.skywalking.apm.agent.core.jvm.memorypool;
+
+import java.lang.management.MemoryPoolMXBean;
+import java.util.List;
+
+/**
+ * @author wusheng
+ */
+public class G1CollectorModule extends MemoryPoolModule {
+ public G1CollectorModule(List beans) {
+ super(beans);
+ }
+
+ @Override protected String getPermName() {
+ return "G1 Perm Gen";
+ }
+
+ @Override protected String getCodeCacheName() {
+ return "Code Cache";
+ }
+
+ @Override protected String getEdenName() {
+ return "G1 Eden Space";
+ }
+
+ @Override protected String getOldName() {
+ return "G1 Old Gen";
+ }
+
+ @Override protected String getSurvivorName() {
+ return "G1 Survivor Space";
+ }
+
+ @Override protected String getMetaspaceName() {
+ return "Metaspace";
+ }
+}
diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/jvm/memorypool/MemoryPoolModule.java b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/jvm/memorypool/MemoryPoolModule.java
index 5e1ccf258b7f21e033810db41f6ef0645f690998..cf0744ca58a73916957256bb64c7b09fe782f7b4 100644
--- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/jvm/memorypool/MemoryPoolModule.java
+++ b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/jvm/memorypool/MemoryPoolModule.java
@@ -35,17 +35,17 @@ public abstract class MemoryPoolModule implements MemoryPoolMetricAccessor {
type = PoolType.METASPACE_USAGE;
} else if (name.equals(getPermName())) {
type = PoolType.PERMGEN_USAGE;
+ } else {
+ continue;
}
- if (type != null) {
- MemoryUsage usage = bean.getUsage();
- poolList.add(MemoryPool.newBuilder().setType(type)
- .setInit(usage.getInit())
- .setMax(usage.getMax())
- .setCommited(usage.getCommitted())
- .setUsed(usage.getUsed())
- .build());
- }
+ MemoryUsage usage = bean.getUsage();
+ poolList.add(MemoryPool.newBuilder().setType(type)
+ .setInit(usage.getInit())
+ .setMax(usage.getMax())
+ .setCommited(usage.getCommitted())
+ .setUsed(usage.getUsed())
+ .build());
}
return poolList;
}
diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/jvm/memorypool/MemoryPoolProvider.java b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/jvm/memorypool/MemoryPoolProvider.java
index 31399872f9ab97bb81466d50660972bda4e31418..28f1e4caaa7cfbd044b8c617e1bea44897468e9b 100644
--- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/jvm/memorypool/MemoryPoolProvider.java
+++ b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/jvm/memorypool/MemoryPoolProvider.java
@@ -39,10 +39,10 @@ public enum MemoryPoolProvider {
return new ParallelCollectorModule(beans);
} else if (name.indexOf("CMS") > -1) {
// CMS collector ( -XX:+UseConcMarkSweepGC )
- return null;
+ return new CMSCollectorModule(beans);
} else if (name.indexOf("G1") > -1) {
// G1 collector ( -XX:+UseG1GC )
- return null;
+ return new G1CollectorModule(beans);
} else if (name.equals("Survivor Space")) {
// Serial collector ( -XX:+UseSerialGC )
return new SerialCollectorModule(beans);
diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/jvm/memorypool/ParallelCollectorModule.java b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/jvm/memorypool/ParallelCollectorModule.java
index d2c6fda63264abcfeba63687fce58f11547a6cef..6b108943b2d05e252c695f0faafd56bb42fb0f49 100644
--- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/jvm/memorypool/ParallelCollectorModule.java
+++ b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/jvm/memorypool/ParallelCollectorModule.java
@@ -6,7 +6,7 @@ import java.util.List;
/**
* @author wusheng
*/
-public class ParallelCollectorModule extends MemoryPoolModule{
+public class ParallelCollectorModule extends MemoryPoolModule {
public ParallelCollectorModule(List beans) {
super(beans);
diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/jvm/memorypool/UnknownMemoryPool.java b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/jvm/memorypool/UnknownMemoryPool.java
index 91755cafa4e8bc52327ba8c204ae2c42f6b7fd49..2adb2f95a30dec520803d66eb26f12f5e3830a22 100644
--- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/jvm/memorypool/UnknownMemoryPool.java
+++ b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/jvm/memorypool/UnknownMemoryPool.java
@@ -18,6 +18,6 @@ public class UnknownMemoryPool implements MemoryPoolMetricAccessor {
poolList.add(MemoryPool.newBuilder().setType(PoolType.SURVIVOR_USAGE).build());
poolList.add(MemoryPool.newBuilder().setType(PoolType.PERMGEN_USAGE).build());
poolList.add(MemoryPool.newBuilder().setType(PoolType.METASPACE_USAGE).build());
- return poolList;
+ return new LinkedList();
}
}
diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/AbstractClassEnhancePluginDefine.java b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/AbstractClassEnhancePluginDefine.java
index 008d49e8b9a6750f9f18ae7537ed6af3fb8afa0d..87bfae3ed3d3a17ba4befec60b1bb5dd1edad502 100644
--- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/AbstractClassEnhancePluginDefine.java
+++ b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/AbstractClassEnhancePluginDefine.java
@@ -2,6 +2,7 @@ package org.skywalking.apm.agent.core.plugin;
import net.bytebuddy.dynamic.DynamicType;
import org.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassEnhancePluginDefine;
+import org.skywalking.apm.agent.core.plugin.match.ClassMatch;
import org.skywalking.apm.util.StringUtil;
import org.skywalking.apm.logging.ILog;
import org.skywalking.apm.logging.LogManager;
@@ -63,11 +64,11 @@ public abstract class AbstractClassEnhancePluginDefine {
DynamicType.Builder> newClassBuilder, ClassLoader classLoader) throws PluginException;
/**
- * Define the classname of target class.
+ * Define the {@link ClassMatch} for filtering class.
*
- * @return class full name.
+ * @return {@link ClassMatch}
*/
- protected abstract String enhanceClassName();
+ protected abstract ClassMatch enhanceClass();
/**
* Witness classname list. Why need witness classname? Let's see like this: A library existed two released versions
diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/PluginBootstrap.java b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/PluginBootstrap.java
index d1b72047d63f246f155156a33e62675226226bf0..a355603d7e178aad8bbe76d6c31f9a1d28eb89da 100644
--- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/PluginBootstrap.java
+++ b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/PluginBootstrap.java
@@ -27,7 +27,7 @@ public class PluginBootstrap {
List resources = resolver.getResources();
if (resources == null || resources.size() == 0) {
- logger.info("no plugin files (skywalking-plugin.properties) found, continue to start application.");
+ logger.info("no plugin files (skywalking-plugin.def) found, continue to start application.");
return new ArrayList();
}
@@ -35,7 +35,7 @@ public class PluginBootstrap {
try {
PluginCfg.INSTANCE.load(pluginUrl.openStream());
} catch (Throwable t) {
- logger.error(t, "plugin [{}] init failure.", pluginUrl);
+ logger.error(t, "plugin file [{}] init failure.", pluginUrl);
}
}
diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/PluginCfg.java b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/PluginCfg.java
index 3fae43aa53de6fb6c0e143b778cb929dfee57c44..5949342ae407639fb315bf3295b62c6538603d17 100644
--- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/PluginCfg.java
+++ b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/PluginCfg.java
@@ -1,14 +1,15 @@
package org.skywalking.apm.agent.core.plugin;
+import org.skywalking.apm.agent.core.plugin.exception.IllegalPluginDefineException;
+import org.skywalking.apm.logging.ILog;
+import org.skywalking.apm.logging.LogManager;
+
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
-import org.skywalking.apm.agent.core.plugin.exception.IllegalPluginDefineException;
-import org.skywalking.apm.logging.ILog;
-import org.skywalking.apm.logging.LogManager;
public enum PluginCfg {
INSTANCE;
@@ -31,7 +32,7 @@ public enum PluginCfg {
pluginClassList.add(plugin);
}
} catch (IllegalPluginDefineException e) {
- logger.error("Failed to format plugin define.", e);
+ logger.error(e,"Failed to format plugin({}) define.", pluginDefine);
}
}
} finally {
diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/PluginFinder.java b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/PluginFinder.java
index 45ce1d5b5cb539709e1b95faceef7a78c0e4d4aa..271b32cee500ab8fce48b4b36d364dbc93c30d0b 100644
--- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/PluginFinder.java
+++ b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/PluginFinder.java
@@ -4,43 +4,75 @@ import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
+import net.bytebuddy.description.NamedElement;
+import net.bytebuddy.description.type.TypeDescription;
+import net.bytebuddy.matcher.ElementMatcher;
+import org.skywalking.apm.agent.core.plugin.bytebuddy.AbstractJunction;
+import org.skywalking.apm.agent.core.plugin.match.ClassMatch;
+import org.skywalking.apm.agent.core.plugin.match.IndirectMatch;
+import org.skywalking.apm.agent.core.plugin.match.NameMatch;
+
+import static net.bytebuddy.matcher.ElementMatchers.isInterface;
+import static net.bytebuddy.matcher.ElementMatchers.not;
/**
* The PluginFinder represents a finder , which assist to find the one
- * from the given {@link AbstractClassEnhancePluginDefine} list, by name match.
+ * from the given {@link AbstractClassEnhancePluginDefine} list.
*
* @author wusheng
*/
public class PluginFinder {
- private final Map> pluginDefineMap = new HashMap>();
+ private final Map nameMatchDefine = new HashMap();
+ private final List signatureMatchDefine = new LinkedList();
public PluginFinder(List plugins) {
for (AbstractClassEnhancePluginDefine plugin : plugins) {
- String enhanceClassName = plugin.enhanceClassName();
+ ClassMatch match = plugin.enhanceClass();
- if (enhanceClassName == null) {
+ if (match == null) {
continue;
}
- LinkedList pluginDefinesWithSameTarget = pluginDefineMap.get(enhanceClassName);
- if (pluginDefinesWithSameTarget == null) {
- pluginDefinesWithSameTarget = new LinkedList();
- pluginDefineMap.put(enhanceClassName, pluginDefinesWithSameTarget);
+ if (match instanceof NameMatch) {
+ NameMatch nameMatch = (NameMatch)match;
+ nameMatchDefine.put(nameMatch.getClassName(), plugin);
+ } else {
+ signatureMatchDefine.add(plugin);
}
-
- pluginDefinesWithSameTarget.add(plugin);
}
}
- public List find(String enhanceClassName) {
- if (pluginDefineMap.containsKey(enhanceClassName)) {
- return pluginDefineMap.get(enhanceClassName);
+ public AbstractClassEnhancePluginDefine find(TypeDescription typeDescription,
+ ClassLoader classLoader) {
+ String typeName = typeDescription.getTypeName();
+ if (nameMatchDefine.containsKey(typeName)) {
+ return nameMatchDefine.get(typeName);
+ }
+
+ for (AbstractClassEnhancePluginDefine pluginDefine : signatureMatchDefine) {
+ IndirectMatch match = (IndirectMatch)pluginDefine.enhanceClass();
+ if (match.isMatch(typeDescription)) {
+ return pluginDefine;
+ }
}
- throw new PluginException("Can not find plugin:" + enhanceClassName);
+ return null;
}
- public boolean exist(String enhanceClassName) {
- return pluginDefineMap.containsKey(enhanceClassName);
+ public ElementMatcher super TypeDescription> buildMatch() {
+ ElementMatcher.Junction judge = new AbstractJunction() {
+ @Override
+ public boolean matches(NamedElement target) {
+ return nameMatchDefine.containsKey(target.getActualName());
+ }
+ };
+ judge = judge.and(not(isInterface()));
+ for (AbstractClassEnhancePluginDefine define : signatureMatchDefine) {
+ ClassMatch match = define.enhanceClass();
+ if (match instanceof IndirectMatch) {
+ judge = judge.or(((IndirectMatch)match).buildJunction());
+ }
+ }
+ return judge;
}
}
diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/PluginResourcesResolver.java b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/PluginResourcesResolver.java
index b223364374959feca1f5fb61fd8afa01b9d4d639..34e56e93f9814ceab00cb19218c9a9d8914c147d 100644
--- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/PluginResourcesResolver.java
+++ b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/PluginResourcesResolver.java
@@ -24,10 +24,6 @@ public class PluginResourcesResolver {
try {
urls = getDefaultClassLoader().getResources("skywalking-plugin.def");
- if (!urls.hasMoreElements()) {
- logger.info("no plugin files (skywalking-plugin.def) found");
- }
-
while (urls.hasMoreElements()) {
URL pluginUrl = urls.nextElement();
cfgUrlPaths.add(pluginUrl);
diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/TracingBootstrap.java b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/TracingBootstrap.java
deleted file mode 100644
index 00e004a4ab953f58cbc75ecaec179e28ba5311e3..0000000000000000000000000000000000000000
--- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/TracingBootstrap.java
+++ /dev/null
@@ -1,74 +0,0 @@
-package org.skywalking.apm.agent.core.plugin;
-
-import net.bytebuddy.ByteBuddy;
-import net.bytebuddy.dynamic.ClassFileLocator;
-import net.bytebuddy.dynamic.DynamicType;
-import net.bytebuddy.dynamic.TypeResolutionStrategy;
-import net.bytebuddy.dynamic.loading.ClassLoadingStrategy;
-import net.bytebuddy.pool.TypePool;
-import org.skywalking.apm.logging.ILog;
-import org.skywalking.apm.logging.LogManager;
-
-import java.lang.reflect.InvocationTargetException;
-import java.util.Arrays;
-import java.util.List;
-
-/**
- * A test entrance for enhancing class.
- * This should be used only in bytecode-manipulate test.
- * And make sure, all classes which need to be enhanced, must not be loaded.
- *
- * @author wusheng
- */
-public class TracingBootstrap {
- private static final ILog logger = LogManager.getLogger(TracingBootstrap.class);
-
- private TracingBootstrap() {
- }
-
- /**
- * Main entrance for testing.
- *
- * @param args includes target classname ( which exists "public static void main(String[] args)" ) and arguments
- * list.
- * @throws PluginException
- * @throws ClassNotFoundException
- * @throws NoSuchMethodException
- * @throws InvocationTargetException
- * @throws IllegalAccessException
- */
- public static void main(String[] args)
- throws PluginException, ClassNotFoundException, NoSuchMethodException, InvocationTargetException,
- IllegalAccessException {
- if (args.length == 0) {
- throw new RuntimeException("bootstrap failure. need args[0] to be main class.");
- }
-
- List plugins = null;
-
- try {
- PluginBootstrap bootstrap = new PluginBootstrap();
- plugins = bootstrap.loadPlugins();
- } catch (Throwable t) {
- logger.error("PluginBootstrap start failure.", t);
- }
-
- for (AbstractClassEnhancePluginDefine plugin : plugins) {
- String enhanceClassName = plugin.enhanceClassName();
- TypePool.Resolution resolution = TypePool.Default.ofClassPath().describe(enhanceClassName);
- if (!resolution.isResolved()) {
- logger.error("Failed to resolve the class " + enhanceClassName, null);
- continue;
- }
- DynamicType.Builder> newClassBuilder =
- new ByteBuddy().rebase(resolution.resolve(), ClassFileLocator.ForClassLoader.ofClassPath());
- newClassBuilder = ((AbstractClassEnhancePluginDefine)plugin).define(enhanceClassName, newClassBuilder, TracingBootstrap.class.getClassLoader());
- newClassBuilder.make(new TypeResolutionStrategy.Active()).load(ClassLoader.getSystemClassLoader(), ClassLoadingStrategy.Default.INJECTION)
- .getLoaded();
- }
-
- String[] newArgs = Arrays.copyOfRange(args, 1, args.length);
-
- Class.forName(args[0]).getMethod("main", String[].class).invoke(null, new Object[] {newArgs});
- }
-}
diff --git a/apm-sniffer/apm-agent/src/main/java/org/skywalking/apm/agent/junction/AbstractJunction.java b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/bytebuddy/AbstractJunction.java
similarity index 89%
rename from apm-sniffer/apm-agent/src/main/java/org/skywalking/apm/agent/junction/AbstractJunction.java
rename to apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/bytebuddy/AbstractJunction.java
index 207dada85336674c82e733a7f9a8000697a1eaa8..2c4e7e603efc0c26426ba8714d24ea3bfed131f4 100644
--- a/apm-sniffer/apm-agent/src/main/java/org/skywalking/apm/agent/junction/AbstractJunction.java
+++ b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/bytebuddy/AbstractJunction.java
@@ -1,4 +1,4 @@
-package org.skywalking.apm.agent.junction;
+package org.skywalking.apm.agent.core.plugin.bytebuddy;
import net.bytebuddy.matcher.ElementMatcher;
diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/bytebuddy/AllObjectDefaultMethodsMatch.java b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/bytebuddy/AllObjectDefaultMethodsMatch.java
deleted file mode 100644
index a887c8fd76c78cba2dce8c3bab54b84e32ce51e4..0000000000000000000000000000000000000000
--- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/bytebuddy/AllObjectDefaultMethodsMatch.java
+++ /dev/null
@@ -1,63 +0,0 @@
-package org.skywalking.apm.agent.core.plugin.bytebuddy;
-
-import net.bytebuddy.description.method.MethodDescription;
-import net.bytebuddy.matcher.ElementMatcher;
-import net.bytebuddy.matcher.ElementMatchers;
-
-import static net.bytebuddy.matcher.ElementMatchers.named;
-import static net.bytebuddy.matcher.ElementMatchers.takesArguments;
-
-/**
- * match all methods, which inherits from {@link Object}
- *