From 1fd449cddcdc81c76ecd96df491503f9ad315b37 Mon Sep 17 00:00:00 2001 From: wusheng Date: Wed, 28 Jun 2017 09:05:39 +0800 Subject: [PATCH] Finish the refactor of agent-core. --- .../agent/core/context/ContextCarrier.java | 22 +- .../agent/core/context/ContextManager.java | 18 +- .../core/context/IgnoredTracerContext.java | 16 +- .../apm/agent/core/context/Injectable.java | 5 +- .../apm/agent/core/context/TracerContext.java | 293 ------------------ .../agent/core/context/TracingContext.java | 99 ++++-- .../agent/core/context/tag/BooleanTag.java | 27 -- .../core/context/tag/BooleanTagItem.java | 24 -- .../apm/agent/core/context/tag/IntTag.java | 20 -- .../agent/core/context/tag/IntTagItem.java | 24 -- .../apm/agent/core/context/tag/StringTag.java | 2 +- .../agent/core/context/tag/StringTagItem.java | 24 -- .../apm/agent/core/context/tag/Tags.java | 7 +- .../core/context/trace/AbstractSpan.java | 55 +--- .../context/trace/AbstractTracingSpan.java | 76 ++++- .../agent/core/context/trace/EntrySpan.java | 12 +- .../agent/core/context/trace/ExitSpan.java | 34 +- .../agent/core/context/trace/LocalSpan.java | 4 + .../core/context/trace/LogDataEntity.java | 4 +- .../agent/core/context/trace/NoopSpan.java | 11 +- .../core/context/trace/TraceSegment.java | 41 ++- .../core/context/trace/TraceSegmentRef.java | 68 ++-- .../dictionary/ApplicationDictionary.java | 17 +- .../core/dictionary/DictionaryManager.java | 11 +- .../agent/core/dictionary/DictionaryUtil.java | 18 ++ .../dictionary/DictionaryValueHolder.java | 16 + .../apm/agent/core/dictionary/Found.java | 10 + .../dictionary/IDictionaryCompressible.java | 15 - .../apm/agent/core/dictionary/NotFound.java | 10 + .../dictionary/OperationNameDictionary.java | 55 ++++ .../agent/core/dictionary/PossibleFound.java | 32 +- .../core/queue/TraceSegmentProcessQueue.java | 1 - .../core/context/trace/LeafSpanTestCase.java | 4 - .../core/context/trace/SpanTestCase.java | 1 - .../SamplingTracerContextTestCase.java | 1 - .../apm/agent/core/tags/BooleanTagReader.java | 32 -- .../apm/agent/core/tags/IntTagReader.java | 32 -- .../apm/agent/core/tags/StringTagReader.java | 1 - .../plugin/dubbo/DubboInterceptorTest.java | 1 - .../v9/DefaultHttpClientInterceptorTest.java | 1 - .../v4/HttpClientExecuteInterceptorTest.java | 1 - .../plugin/jdbc/SWCallableStatementTest.java | 1 - .../apm/plugin/jdbc/SWConnectionTest.java | 1 - .../apm/plugin/jdbc/SWStatementTest.java | 1 - .../plugin/jdbc/SwPreparedStatementTest.java | 1 - .../jedis/v2/JedisMethodInterceptorTest.java | 1 - .../v3/MongoDBMethodInterceptorTest.java | 1 - .../v3/MongoDBWriteMethodInterceptorTest.java | 1 - .../motan/MotanConsumerInterceptorTest.java | 1 - .../motan/MotanProviderInterceptorTest.java | 1 - .../okhttp/v3/RealCallInterceptorTest.java | 1 - .../resin/v3/ResinV3InterceptorTest.java | 1 - .../resin/v4/ResinV4InterceptorTest.java | 1 - .../tomcat78x/TomcatInterceptorTest.java | 1 - .../context/MockTracingContextListener.java | 1 - .../trace/TraceSegmentBuilderFactory.java | 1 - .../mock/trace/tags/BooleanTagReader.java | 2 - .../sniffer/mock/trace/tags/IntTagReader.java | 2 - .../mock/trace/tags/StringTagReader.java | 1 - 59 files changed, 436 insertions(+), 729 deletions(-) delete mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/TracerContext.java delete mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/tag/BooleanTag.java delete mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/tag/BooleanTagItem.java delete mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/tag/IntTag.java delete mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/tag/IntTagItem.java delete mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/tag/StringTagItem.java create mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/dictionary/DictionaryUtil.java create mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/dictionary/DictionaryValueHolder.java create mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/dictionary/Found.java delete mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/dictionary/IDictionaryCompressible.java create mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/dictionary/NotFound.java create mode 100644 apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/dictionary/OperationNameDictionary.java delete mode 100644 apm-sniffer/apm-agent-core/src/test/java/org/skywalking/apm/agent/core/tags/BooleanTagReader.java delete mode 100644 apm-sniffer/apm-agent-core/src/test/java/org/skywalking/apm/agent/core/tags/IntTagReader.java 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 25d576f8e..ec216c2e1 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 @@ -9,8 +9,8 @@ import org.skywalking.apm.agent.core.context.trace.TraceSegment; import org.skywalking.apm.util.StringUtil; /** - * {@link ContextCarrier} is a data carrier of {@link TracerContext}. - * It holds the snapshot (current state) of {@link TracerContext}. + * {@link ContextCarrier} is a data carrier of {@link TracingContext}. + * It holds the snapshot (current state) of {@link TracingContext}. *

* Created by wusheng on 2017/2/17. */ @@ -20,20 +20,10 @@ public class ContextCarrier implements Serializable { */ private String traceSegmentId; - /** - * {@link Span#spanId} - */ private int spanId = -1; - /** - * {@link TraceSegment#applicationCode} - */ private String applicationCode; - /** - * Either {@link Span#peerHost} + {@link Span#port} or {@link Span#peers}, - * depend on which one of them is valid. - */ private String peerHost; /** @@ -120,6 +110,10 @@ public class ContextCarrier implements Serializable { this.applicationCode = applicationCode; } + public void setApplicationId(int applicationId) { + this.applicationCode = applicationId + ""; + } + public String getPeerHost() { return peerHost; } @@ -128,6 +122,10 @@ public class ContextCarrier implements Serializable { this.peerHost = peerHost; } + public void setPeerId(int peerId) { + this.peerHost = peerId + ""; + } + public List getDistributedTraceIds() { return distributedTraceIds; } 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 7664f195a..65d7fb991 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 @@ -10,13 +10,12 @@ import org.skywalking.apm.agent.core.sampling.SamplingService; import org.skywalking.apm.util.StringUtil; /** - * {@link TracerContext} controls the whole context of {@link TraceSegment}. Any {@link TraceSegment} relates to + * {@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 - * https://github.com/opentracing/specification/blob/master/specification.md#references-between-spans}

Also, {@link - * ContextManager} delegates to all {@link TracerContext}'s major methods: {@link TracerContext#createSpan(String, - * boolean)}, {@link TracerContext#activeSpan()}, {@link AbstractTracerContext#stopSpan(org.skywalking.apm.agent.core.context.trace.AbstractSpan)} - *

+ * https://github.com/opentracing/specification/blob/master/specification.md#references-between-spans} + * + *

Also, {@link ContextManager} delegates to all {@link AbstractTracerContext}'s major methods. * * @author wusheng */ @@ -37,10 +36,7 @@ public class ContextManager implements TracingContextListener, BootService, Igno if (forceSampling || samplingService.trySampling()) { context = new TracingContext(); } else { - /** - * {@link ContextType#AGGREGATED_TRACING} - * TODO - */ + context = new IgnoredTracerContext(); } } CONTEXT.set(context); @@ -90,7 +86,9 @@ public class ContextManager implements TracingContextListener, BootService, Igno throw new IllegalArgumentException("Injectable can't be null."); } AbstractTracerContext context = getOrCreate(operationName, false); - return context.createSpan(operationName, SpanType.EXIT); + AbstractSpan span = context.createSpan(operationName, SpanType.EXIT); + context.inject(injectable.getCarrier()); + return span; } public static AbstractSpan activeSpan() { 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 f30f06c7a..a07fdebbe 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 @@ -4,6 +4,7 @@ import java.util.LinkedList; import java.util.List; import org.skywalking.apm.agent.core.context.trace.AbstractSpan; import org.skywalking.apm.agent.core.context.trace.NoopSpan; +import org.skywalking.apm.agent.core.context.trace.SpanType; /** * The IgnoredTracerContext represent a context should be ignored. @@ -37,14 +38,14 @@ public class IgnoredTracerContext implements AbstractTracerContext { } @Override - public AbstractSpan createSpan(String operationName, boolean isLeaf) { - stackDepth++; - return NOOP_SPAN; + public AbstractSpan createSpan(String operationName, SpanType spanType) { + return createSpan(operationName, spanType, null); } @Override - public AbstractSpan createSpan(String operationName, long startTime, boolean isLeaf) { - return createSpan(operationName, isLeaf); + public AbstractSpan createSpan(String operationName, SpanType spanType, Injectable injectable) { + stackDepth++; + return NOOP_SPAN; } @Override @@ -60,11 +61,6 @@ public class IgnoredTracerContext implements AbstractTracerContext { } } - @Override - public void stopSpan(AbstractSpan span, Long endTime) { - stopSpan(span); - } - @Override public void dispose() { diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/Injectable.java b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/Injectable.java index 586892b27..fe9317f1e 100644 --- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/Injectable.java +++ b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/Injectable.java @@ -6,10 +6,7 @@ package org.skywalking.apm.agent.core.context; * @author wusheng */ public interface Injectable { - /** - * @param injectedCarrier notify the Injectable the {@link ContextCarrier} has been injected. - */ - void notify(ContextCarrier injectedCarrier); + ContextCarrier getCarrier(); /** * @return peer, represent ipv4, ipv6, hostname, or cluster addresses list. diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/TracerContext.java b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/TracerContext.java deleted file mode 100644 index 497831659..000000000 --- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/TracerContext.java +++ /dev/null @@ -1,293 +0,0 @@ -package org.skywalking.apm.agent.core.context; - -import java.util.LinkedList; -import java.util.List; -import org.skywalking.apm.agent.core.boot.ServiceManager; -import org.skywalking.apm.agent.core.conf.Config; -import org.skywalking.apm.agent.core.context.trace.AbstractSpan; -import org.skywalking.apm.agent.core.context.trace.TraceSegment; -import org.skywalking.apm.agent.core.context.trace.TraceSegmentRef; -import org.skywalking.apm.agent.core.sampling.SamplingService; - -/** - * {@link TracerContext} maintains the context. - * You manipulate (create/finish/get) spans and (inject/extract) context. - *

- * Created by wusheng on 2017/2/17. - */ -public final class TracerContext implements AbstractTracerContext { - private SamplingService samplingService; - - private TraceSegment segment; - - /** - * Active spans stored in a Stack, usually called 'ActiveSpanStack'. - * This {@link LinkedList} is the in-memory storage-structure. - *

- * I use {@link LinkedList#removeLast()}, {@link LinkedList#addLast(Object)} and {@link LinkedList#last} instead of - * {@link #pop()}, {@link #push(Span)}, {@link #peek()} - */ - private LinkedList activeSpanStack = new LinkedList(); - - private int spanIdGenerator; - - /** - * Create a {@link TraceSegment} and init {@link #spanIdGenerator} as 0; - */ - TracerContext() { - this.segment = new TraceSegment(Config.Agent.APPLICATION_CODE); - this.spanIdGenerator = 0; - if (samplingService == null) { - samplingService = ServiceManager.INSTANCE.findService(SamplingService.class); - } - } - - /** - * Create a new span, as an active span, by the given operationName - * - * @param operationName {@link Span#operationName} - * @return the new active span. - */ - public AbstractSpan createSpan(String operationName, boolean isLeaf) { - return this.createSpan(operationName, System.currentTimeMillis(), isLeaf); - } - - /** - * Create a new span, as an active span, by the given operationName and startTime; - * - * @param operationName {@link Span#operationName} - * @param startTime {@link Span#startTime} - * @param isLeaf is true, if the span is a leaf in trace tree. - * @return - */ - public AbstractSpan createSpan(String operationName, long startTime, boolean isLeaf) { - Span parentSpan = peek(); - Span span; - if (parentSpan == null) { - if (operationName != null) { - int suffixIdx = operationName.lastIndexOf("."); - if (suffixIdx > -1 && Config.Agent.IGNORE_SUFFIX.contains(operationName.substring(suffixIdx))) { - ContextManager.ContextSwitcher.INSTANCE.toNew(new IgnoredTracerContext(1)); - return ContextManager.activeSpan(); - } - } - - if (isLeaf) { - span = new LeafSpan(spanIdGenerator++, operationName, startTime); - } else { - span = new Span(spanIdGenerator++, operationName, startTime); - } - push(span); - } else { - /** - * Don't have ref yet, means this isn't part of distributed trace. - * Use sampling mechanism - * Only check this on the second span, - * because the {@link #extract(ContextCarrier)} invoke before create the second span. - */ - if (spanIdGenerator == 1) { - if (segment.hasRef()) { - samplingService.forceSampled(); - } else { - if (!samplingService.trySampling()) { - /** - * Don't sample this trace. - * Now, switch this trace as an {@link IgnoredTracerContext}, - * further more, we will provide an analytic tracer context for all metrics in this trace. - */ - ContextManager.ContextSwitcher.INSTANCE.toNew(new IgnoredTracerContext(2)); - return ContextManager.activeSpan(); - } - } - } - - if (parentSpan.isLeaf()) { - span = parentSpan; - LeafSpan leafSpan = (LeafSpan)span; - leafSpan.push(); - } else { - if (isLeaf) { - span = new LeafSpan(spanIdGenerator++, parentSpan, operationName, startTime); - } else { - span = new Span(spanIdGenerator++, parentSpan, operationName, startTime); - } - push(span); - } - } - return span; - } - - /** - * @return the active span of current context. - */ - public AbstractSpan activeSpan() { - Span span = peek(); - if (span == null) { - throw new IllegalStateException("No active span."); - } - return span; - } - - /** - * Stop the span. And finish the {@link #segment} if all {@link #activeSpanStack} elements are finished. - * - * @param span to finish. It must the the top element of {@link #activeSpanStack}. - */ - public void stopSpan(AbstractSpan span) { - stopSpan(span, System.currentTimeMillis()); - } - - /** - * @return the current trace id. - */ - public String getGlobalTraceId() { - return segment.getRelatedGlobalTraces().get(0).get(); - } - - public void stopSpan(AbstractSpan span, Long endTime) { - Span lastSpan = peek(); - if (lastSpan.isLeaf()) { - LeafSpan leafSpan = (LeafSpan)lastSpan; - leafSpan.pop(); - if (!leafSpan.isFinished()) { - return; - } - } - if (lastSpan == span) { - pop().finish(segment, endTime); - } else { - throw new IllegalStateException("Stopping the unexpected span = " + span); - } - - if (activeSpanStack.isEmpty()) { - this.finish(); - } - } - - @Override - public void dispose() { - this.segment = null; - this.activeSpanStack = null; - } - - /** - * Finish this context, and notify all {@link TracingContextListener}s, managed by {@link ListenerManager} - */ - private void finish() { - TraceSegment finishedSegment = segment.finish(); - /** - * Recheck the segment if the segment contains only one span. - * Because in the runtime, can't sure this segment is part of distributed trace. - * - * @see {@link #createSpan(String, long, boolean)} - */ - if (!segment.hasRef() && segment.isSingleSpanSegment()) { - if (!samplingService.trySampling()) { - finishedSegment.setIgnore(true); - } - } - ListenerManager.notifyFinish(finishedSegment); - } - - /** - * Give a snapshot of this {@link TracerContext}, - * and save current state to the given {@link ContextCarrier}. - * - * @param carrier holds the snapshot - */ - public void inject(ContextCarrier carrier) { - carrier.setTraceSegmentId(this.segment.getTraceSegmentId()); - Span span = (Span)this.activeSpan(); - carrier.setSpanId(span.getSpanId()); - carrier.setApplicationCode(Config.Agent.APPLICATION_CODE); - String host = span.getPeerHost(); - if (host != null) { - Integer port = span.getPort(); - carrier.setPeerHost(host + ":" + port); - } else { - carrier.setPeerHost(span.getPeers()); - } - carrier.setDistributedTraceIds(this.segment.getRelatedGlobalTraces()); - } - - /** - * Ref this {@link ContextCarrier} to this {@link TraceSegment} - * - * @param carrier holds the snapshot, if get this {@link ContextCarrier} from remote, make sure {@link - * ContextCarrier#deserialize(String)} called. - */ - public void extract(ContextCarrier carrier) { - if (carrier.isValid()) { - this.segment.ref(getRef(carrier)); - this.segment.relatedGlobalTraces(carrier.getDistributedTraceIds()); - } - } - - private TraceSegmentRef getRef(ContextCarrier carrier) { - TraceSegmentRef ref = new TraceSegmentRef(); - ref.setTraceSegmentId(carrier.getTraceSegmentId()); - ref.setSpanId(carrier.getSpanId()); - ref.setApplicationCode(carrier.getApplicationCode()); - ref.setPeerHost(carrier.getPeerHost()); - return ref; - } - - /** - * @return the top element of 'ActiveSpanStack', and remove it. - */ - private Span pop() { - return activeSpanStack.removeLast(); - } - - /** - * Add a new Span at the top of 'ActiveSpanStack' - * - * @param span - */ - private void push(Span span) { - activeSpanStack.addLast(span); - } - - /** - * @return the top element of 'ActiveSpanStack' only. - */ - private Span peek() { - if (activeSpanStack.isEmpty()) { - return null; - } - return activeSpanStack.getLast(); - } - - public static class ListenerManager { - private static List LISTENERS = new LinkedList(); - - /** - * Add the given {@link TracingContextListener} to {@link #LISTENERS} list. - * - * @param listener the new listener. - */ - public static synchronized void add(TracingContextListener listener) { - LISTENERS.add(listener); - } - - /** - * Notify the {@link ListenerManager} about the given {@link TraceSegment} have finished. - * And trigger {@link ListenerManager} to notify all {@link #LISTENERS} 's - * {@link TracingContextListener#afterFinished(TraceSegment)} - * - * @param finishedSegment - */ - static void notifyFinish(TraceSegment finishedSegment) { - for (TracingContextListener listener : LISTENERS) { - listener.afterFinished(finishedSegment); - } - } - - /** - * Clear the given {@link TracingContextListener} - */ - public static synchronized void remove(TracingContextListener listener) { - LISTENERS.remove(listener); - } - } -} 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 72c32d4f5..2d274a48d 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 @@ -11,6 +11,9 @@ import org.skywalking.apm.agent.core.context.trace.LocalSpan; import org.skywalking.apm.agent.core.context.trace.SpanType; import org.skywalking.apm.agent.core.context.trace.TraceSegment; import org.skywalking.apm.agent.core.context.trace.TraceSegmentRef; +import org.skywalking.apm.agent.core.dictionary.DictionaryManager; +import org.skywalking.apm.agent.core.dictionary.DictionaryUtil; +import org.skywalking.apm.agent.core.dictionary.PossibleFound; import org.skywalking.apm.agent.core.sampling.SamplingService; /** @@ -42,12 +45,29 @@ public class TracingContext implements AbstractTracerContext { @Override public void inject(ContextCarrier carrier) { + AbstractTracingSpan span = this.activeSpan(); + if (span.isExit()) { + throw new IllegalStateException("Inject can be done only in Exit Span"); + } + ExitSpan exitSpan = (ExitSpan)span; + carrier.setTraceSegmentId(this.segment.getTraceSegmentId()); + carrier.setSpanId(span.getSpanId()); + + carrier.setApplicationId(segment.getApplicationId()); + + if (DictionaryUtil.isNull(exitSpan.getPeerId())) { + carrier.setPeerHost(exitSpan.getPeer()); + } else { + carrier.setPeerId(exitSpan.getPeerId()); + } + + carrier.setDistributedTraceIds(this.segment.getRelatedGlobalTraces()); } @Override public void extract(ContextCarrier carrier) { - this.segment.ref(getRef(carrier)); + this.segment.ref(new TraceSegmentRef(carrier)); this.segment.relatedGlobalTraces(carrier.getDistributedTraceIds()); } @@ -69,23 +89,71 @@ public class TracingContext implements AbstractTracerContext { return span.start(); } - private AbstractTracingSpan createByType(int spanId, int parentSpanId, - String operationName, SpanType spanType, - String peerHost, AbstractTracingSpan parentSpan) { + private AbstractTracingSpan createByType(final int spanId, final int parentSpanId, + final String operationName, SpanType spanType, + final String peerHost, AbstractTracingSpan parentSpan) { switch (spanType) { case LOCAL: - return new LocalSpan(spanId, parentSpanId, operationName); + return (AbstractTracingSpan)DictionaryManager.findOperationNameCodeSection() + .find(segment.getApplicationId(), operationName) + .doInCondition(new PossibleFound.FoundAndObtain() { + @Override + public Object doProcess(int operationId) { + return new LocalSpan(spanId, parentSpanId, operationId); + } + }, new PossibleFound.NotFoundAndObtain() { + @Override + public Object doProcess() { + return new LocalSpan(spanId, parentSpanId, operationName); + } + }); case EXIT: if (parentSpan != null && parentSpan.isExit()) { return parentSpan; } else { - return new ExitSpan(spanId, parentSpanId, operationName, peerHost); + return (AbstractTracingSpan)DictionaryManager.findApplicationCodeSection() + .find(peerHost).doInCondition( + new PossibleFound.FoundAndObtain() { + @Override + public Object doProcess(final int applicationId) { + return DictionaryManager.findOperationNameCodeSection() + .find(applicationId, operationName) + .doInCondition( + new PossibleFound.FoundAndObtain() { + @Override + public Object doProcess(int peerId) { + return new ExitSpan(spanId, parentSpanId, applicationId, peerId); + } + }, new PossibleFound.NotFoundAndObtain() { + @Override + public Object doProcess() { + return new ExitSpan(spanId, parentSpanId, applicationId, peerHost); + } + }); + } + }, + new PossibleFound.NotFoundAndObtain() { + @Override + public Object doProcess() { + return new ExitSpan(spanId, parentSpanId, operationName, peerHost); + } + }); } case ENTRY: if (parentSpan.isEntry()) { return parentSpan; } else if (parentSpan == null) { - return new EntrySpan(spanId, parentSpanId, operationName); + return (AbstractTracingSpan)DictionaryManager.findOperationNameCodeSection() + .find(segment.getApplicationId(), operationName) + .doInCondition(new PossibleFound.FoundAndObtain() { + @Override public Object doProcess(int operationId) { + return new EntrySpan(spanId, parentSpanId, operationId); + } + }, new PossibleFound.NotFoundAndObtain() { + @Override public Object doProcess() { + return new EntrySpan(spanId, parentSpanId, operationName); + } + }); } else { throw new IllegalStateException("The Entry Span can't be the child of Non-Entry Span"); } @@ -121,7 +189,7 @@ public class TracingContext implements AbstractTracerContext { /** * Finish this context, and notify all {@link TracingContextListener}s, managed by {@link - * TracerContext.ListenerManager} + * TracingContext.ListenerManager} */ private void finish() { TraceSegment finishedSegment = segment.finish(); @@ -136,7 +204,7 @@ public class TracingContext implements AbstractTracerContext { finishedSegment.setIgnore(true); } } - TracerContext.ListenerManager.notifyFinish(finishedSegment); + TracingContext.ListenerManager.notifyFinish(finishedSegment); } @Override @@ -158,8 +226,8 @@ public class TracingContext implements AbstractTracerContext { } /** - * Notify the {@link TracerContext.ListenerManager} about the given {@link TraceSegment} have finished. - * And trigger {@link TracerContext.ListenerManager} to notify all {@link #LISTENERS} 's + * Notify the {@link TracingContext.ListenerManager} about the given {@link TraceSegment} have finished. + * And trigger {@link TracingContext.ListenerManager} to notify all {@link #LISTENERS} 's * {@link TracingContextListener#afterFinished(TraceSegment)} * * @param finishedSegment @@ -204,13 +272,4 @@ public class TracingContext implements AbstractTracerContext { } return activeSpanStack.getLast(); } - - private TraceSegmentRef getRef(ContextCarrier carrier) { - TraceSegmentRef ref = new TraceSegmentRef(); - ref.setTraceSegmentId(carrier.getTraceSegmentId()); - ref.setSpanId(carrier.getSpanId()); - ref.setApplicationCode(carrier.getApplicationCode()); - ref.setPeerHost(carrier.getPeerHost()); - return ref; - } } diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/tag/BooleanTag.java b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/tag/BooleanTag.java deleted file mode 100644 index e583da561..000000000 --- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/tag/BooleanTag.java +++ /dev/null @@ -1,27 +0,0 @@ -package org.skywalking.apm.agent.core.context.tag; - -import org.skywalking.apm.agent.core.context.trace.AbstractSpan; - -/** - * Do the same thing as {@link StringTag}, just with a {@link Boolean} value. - *

- * Created by wusheng on 2017/2/17. - */ -public class BooleanTag extends AbstractTag { - - private boolean defaultValue; - - public BooleanTag(String key, boolean defaultValue) { - super(key); - this.defaultValue = defaultValue; - } - - @Override - public void set(AbstractSpan span, Boolean tagValue) { - span.setTag(key, tagValue); - } - - public boolean defaultValue() { - return defaultValue; - } -} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/tag/BooleanTagItem.java b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/tag/BooleanTagItem.java deleted file mode 100644 index a419e1142..000000000 --- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/tag/BooleanTagItem.java +++ /dev/null @@ -1,24 +0,0 @@ -package org.skywalking.apm.agent.core.context.tag; - -/** - * The tag item with String key and Boolean value. - * - * @author wusheng - */ -public class BooleanTagItem { - private String key; - private boolean value; - - public BooleanTagItem(String key, boolean value) { - this.key = key; - this.value = value; - } - - public String getKey() { - return key; - } - - public boolean getValue() { - return value; - } -} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/tag/IntTag.java b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/tag/IntTag.java deleted file mode 100644 index 2b1e7e88d..000000000 --- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/tag/IntTag.java +++ /dev/null @@ -1,20 +0,0 @@ -package org.skywalking.apm.agent.core.context.tag; - -import org.skywalking.apm.agent.core.context.trace.AbstractSpan; - -/** - * Do the same thing as {@link StringTag}, just with a {@link Integer} value. - *

- * Created by wusheng on 2017/2/18. - */ -public class IntTag extends AbstractTag { - public IntTag(String key) { - super(key); - } - - @Override - public void set(AbstractSpan span, Integer tagValue) { - span.setTag(super.key, tagValue); - } - -} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/tag/IntTagItem.java b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/tag/IntTagItem.java deleted file mode 100644 index 3efc3d40f..000000000 --- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/tag/IntTagItem.java +++ /dev/null @@ -1,24 +0,0 @@ -package org.skywalking.apm.agent.core.context.tag; - -/** - * The tag item with String key and Int value. - * - * @author wusheng - */ -public class IntTagItem { - private String key; - private int value; - - public IntTagItem(String key, int value) { - this.key = key; - this.value = value; - } - - public String getKey() { - return key; - } - - public int getValue() { - return value; - } -} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/tag/StringTag.java b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/tag/StringTag.java index 8fdc8d83c..d24df984d 100644 --- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/tag/StringTag.java +++ b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/tag/StringTag.java @@ -15,6 +15,6 @@ public class StringTag extends AbstractTag { @Override public void set(AbstractSpan span, String tagValue) { - span.setTag(key, tagValue); + span.tag(key, tagValue); } } diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/tag/StringTagItem.java b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/tag/StringTagItem.java deleted file mode 100644 index c6ce6da25..000000000 --- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/tag/StringTagItem.java +++ /dev/null @@ -1,24 +0,0 @@ -package org.skywalking.apm.agent.core.context.tag; - -/** - * The tag item with String key and String value. - * - * @author wusheng - */ -public final class StringTagItem { - private String key; - private String value; - - public StringTagItem(String key, String value) { - this.key = key; - this.value = value; - } - - public String getKey() { - return key; - } - - public String getValue() { - return value; - } -} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/tag/Tags.java b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/tag/Tags.java index 11c36a9f2..09f72b7f1 100644 --- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/tag/Tags.java +++ b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/tag/Tags.java @@ -20,7 +20,7 @@ public final class Tags { /** * STATUS_CODE records the http status code of the response. */ - public static final IntTag STATUS_CODE = new IntTag("status_code"); + public static final StringTag STATUS_CODE = new StringTag("status_code"); /** * SPAN_KIND hints at the relationship between spans, e.g. client/server. @@ -71,11 +71,6 @@ public final class Tags { */ public static final StringTag COMPONENT = new StringTag("component"); - /** - * ERROR indicates whether a Span ended in an error state. - */ - public static final BooleanTag ERROR = new BooleanTag("error", false); - /** * DB_TYPE records database type, such as sql, redis, cassandra and so on. */ 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 b21a6ee6f..b02f4cb8c 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,9 +1,5 @@ package org.skywalking.apm.agent.core.context.trace; -import java.util.LinkedList; -import java.util.List; -import org.skywalking.apm.agent.core.context.util.KeyValuePair; -import org.skywalking.apm.agent.core.context.util.ThrowableTransformer; /** * The AbstractSpan represents the span's skeleton, @@ -11,39 +7,13 @@ import org.skywalking.apm.agent.core.context.util.ThrowableTransformer; * * @author wusheng */ -public abstract class AbstractSpan { - protected String operationName; - /** - * The start time of this Span. - */ - protected long startTime; - /** - * The end time of this Span. - */ - protected long endTime; - - /** - * Log is a concept from OpenTracing spec. - *

- * {@see https://github.com/opentracing/specification/blob/master/specification.md#log-structured-data} - */ - protected List logs; - - protected AbstractSpan(String operationName) { - this.operationName = operationName; - } - - public AbstractSpan start() { - this.startTime = System.currentTimeMillis(); - return this; - } - +public interface AbstractSpan { /** * Set a key:value tag on the Span. * * @return this Span instance, for chaining */ - public abstract AbstractSpan tag(String key, String value); + AbstractSpan tag(String key, String value); /** * Record an exception event of the current walltime timestamp. @@ -51,31 +21,22 @@ public abstract class AbstractSpan { * @param t any subclass of {@link Throwable}, which occurs in this span. * @return the Span, for chaining */ - public AbstractSpan log(Throwable t) { - if (logs == null) { - logs = new LinkedList(); - } - logs.add(new LogDataEntity.Builder() - .add(new KeyValuePair("event", "error")) - .add(new KeyValuePair("error.kind", t.getClass().getName())) - .add(new KeyValuePair("message", t.getMessage())) - .add(new KeyValuePair("stack", ThrowableTransformer.INSTANCE.convert2String(t, 4000))) - .build()); - return this; - } + AbstractSpan log(Throwable t); + + void errorOccurred(); /** * @return true if the actual span is an entry span. */ - public abstract boolean isEntry(); + boolean isEntry(); /** * @return true if the actual span is a local span. */ - public abstract boolean isLocal(); + boolean isLocal(); /** * @return true if the actual span is an exit span. */ - public abstract boolean isExit(); + boolean isExit(); } 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 1f04b02da..161a0b496 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 @@ -3,6 +3,8 @@ package org.skywalking.apm.agent.core.context.trace; import java.util.LinkedList; import java.util.List; 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; /** * The AbstractTracingSpan represents a group of {@link AbstractSpan} implementations, @@ -10,17 +12,51 @@ import org.skywalking.apm.agent.core.context.util.KeyValuePair; * * @author wusheng */ -public abstract class AbstractTracingSpan extends AbstractSpan { +public abstract class AbstractTracingSpan implements AbstractSpan { protected int spanId; protected int parentSpanId; protected List tags; + protected String operationName; + protected int operationId; + /** + * The start time of this Span. + */ + protected long startTime; + /** + * The end time of this Span. + */ + protected long endTime; + /** + * Error has occurred in the scope of span. + */ + protected boolean errorOccurred = false; + + /** + * Log is a concept from OpenTracing spec. + *

+ * {@see https://github.com/opentracing/specification/blob/master/specification.md#log-structured-data} + */ + protected List logs; protected AbstractTracingSpan(int spanId, int parentSpanId, String operationName) { - super(operationName); + this.operationName = operationName; + this.operationId = DictionaryUtil.nullValue(); this.spanId = spanId; this.parentSpanId = parentSpanId; } + protected AbstractTracingSpan(int spanId, int parentSpanId, int operationId) { + this.operationName = null; + this.operationId = operationId; + this.spanId = spanId; + this.parentSpanId = parentSpanId; + } + + /** + * Set a key:value tag on the Span. + * + * @return this Span instance, for chaining + */ @Override public AbstractTracingSpan tag(String key, String value) { if (tags == null) { @@ -41,4 +77,40 @@ public abstract class AbstractTracingSpan extends AbstractSpan { owner.archive(this); return true; } + + public AbstractSpan start() { + this.startTime = System.currentTimeMillis(); + return this; + } + + /** + * Record an exception event of the current walltime timestamp. + * + * @param t any subclass of {@link Throwable}, which occurs in this span. + * @return the Span, for chaining + */ + public AbstractSpan log(Throwable t) { + if (logs == null) { + logs = new LinkedList(); + } + logs.add(new LogDataEntity.Builder() + .add(new KeyValuePair("event", "error")) + .add(new KeyValuePair("error.kind", t.getClass().getName())) + .add(new KeyValuePair("message", t.getMessage())) + .add(new KeyValuePair("stack", ThrowableTransformer.INSTANCE.convert2String(t, 4000))) + .build()); + return this; + } + + public void errorOccurred() { + this.errorOccurred = true; + } + + public int getSpanId() { + return spanId; + } + + public int getOperationId() { + return operationId; + } } 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 7922bcb33..ef6cdd223 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 @@ -12,10 +12,18 @@ package org.skywalking.apm.agent.core.context.trace; */ public class EntrySpan extends AbstractTracingSpan { private int stackDepth; + private int currentMaxDepth; public EntrySpan(int spanId, int parentSpanId, String operationName) { super(spanId, parentSpanId, operationName); this.stackDepth = 0; + this.currentMaxDepth = 0; + } + + public EntrySpan(int spanId, int parentSpanId, int operationId) { + super(spanId, parentSpanId, operationId); + this.stackDepth = 0; + this.currentMaxDepth = 0; } /** @@ -23,7 +31,7 @@ public class EntrySpan extends AbstractTracingSpan { */ @Override public EntrySpan start() { - if (++stackDepth == 1) { + if ((currentMaxDepth = ++stackDepth) == 1) { super.start(); } clearWhenRestart(); @@ -32,7 +40,7 @@ public class EntrySpan extends AbstractTracingSpan { @Override public EntrySpan tag(String key, String value) { - if (stackDepth == 1) { + if (stackDepth == currentMaxDepth) { super.tag(key, value); } return this; 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 e216efdf3..6265917aa 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 @@ -1,5 +1,7 @@ package org.skywalking.apm.agent.core.context.trace; +import org.skywalking.apm.agent.core.dictionary.DictionaryUtil; + /** * The ExitSpan represents a service consumer point, such as Feign, Okhttp client for a Http service. * @@ -12,12 +14,28 @@ package org.skywalking.apm.agent.core.context.trace; */ public class ExitSpan extends AbstractTracingSpan { private int stackDepth; - private String peerPoint; + private String peer; + private int peerId; - public ExitSpan(int spanId, int parentSpanId, String operationName, String peerPoint) { + public ExitSpan(int spanId, int parentSpanId, String operationName, String peer) { super(spanId, parentSpanId, operationName); this.stackDepth = 0; - this.peerPoint = peerPoint; + this.peer = peer; + this.peerId = DictionaryUtil.nullValue(); + } + + public ExitSpan(int spanId, int parentSpanId, int operationId, int peerId) { + super(spanId, parentSpanId, operationId); + this.stackDepth = 0; + this.peer = null; + this.peerId = peerId; + } + + public ExitSpan(int spanId, int parentSpanId, int operationId, String peer) { + super(spanId, parentSpanId, operationId); + this.stackDepth = 0; + this.peer = peer; + this.peerId = DictionaryUtil.nullValue(); } /** @@ -43,7 +61,7 @@ public class ExitSpan extends AbstractTracingSpan { public boolean finish(TraceSegment owner) { if (--stackDepth == 0) { return super.finish(owner); - }else{ + } else { return false; } } @@ -56,6 +74,14 @@ public class ExitSpan extends AbstractTracingSpan { return this; } + public int getPeerId() { + return peerId; + } + + public String getPeer() { + return peer; + } + @Override public boolean isEntry() { return false; } 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 83cddb4c0..e28edce34 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 @@ -7,6 +7,10 @@ package org.skywalking.apm.agent.core.context.trace; */ public class LocalSpan extends AbstractTracingSpan { + public LocalSpan(int spanId, int parentSpanId, int operationId) { + super(spanId, parentSpanId, operationId); + } + public LocalSpan(int spanId, int parentSpanId, String operationName) { super(spanId, parentSpanId, operationName); } 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 6a1eedb97..1c6156aeb 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 @@ -28,14 +28,14 @@ public class LogDataEntity { logs = new LinkedList(); } - public Builder add(KeyValuePair... fields){ + public Builder add(KeyValuePair... fields) { for (KeyValuePair field : fields) { logs.add(field); } return this; } - public LogDataEntity build(){ + public LogDataEntity build() { return new LogDataEntity(logs); } } 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 7e538bb62..1967c2ae0 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 @@ -8,19 +8,14 @@ import org.skywalking.apm.agent.core.context.IgnoredTracerContext; * * @author wusheng */ -public class NoopSpan extends AbstractSpan { +public class NoopSpan implements AbstractSpan { public NoopSpan() { - super(null); } - @Override - public void start() { - super.start(); - } @Override public AbstractSpan log(Throwable t) { - return super.log(t); + return this; } public void finish(){ @@ -29,7 +24,7 @@ public class NoopSpan extends AbstractSpan { @Override public AbstractSpan tag(String key, String value) { - return null; + return this; } @Override public boolean isEntry() { 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 467c463b9..14da2494c 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 @@ -8,7 +8,6 @@ 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.IDictionaryCompressible; import org.skywalking.apm.agent.core.dictionary.PossibleFound; import org.skywalking.apm.logging.ILog; import org.skywalking.apm.logging.LogManager; @@ -20,9 +19,10 @@ import org.skywalking.apm.logging.LogManager; * TraceSegment} means the segment, which exists in current {@link Thread}. And the distributed trace is formed by multi * {@link TraceSegment}s, because the distributed trace crosses multi-processes, multi-threads. *

- * Created by wusheng on 2017/2/17. + * + * @author wusheng */ -public class TraceSegment implements IDictionaryCompressible { +public class TraceSegment { private static final ILog logger = LogManager.getLogger(TraceSegment.class); private static final String ID_TYPE = "Segment"; @@ -89,14 +89,20 @@ public class TraceSegment implements IDictionaryCompressible { * and generate a new segment id. */ public TraceSegment() { - DictionaryManager.findApplicationCodeSection() - .find(Config.Agent.APPLICATION_CODE, this) - .ifFound(new PossibleFound.Setter() { - @Override - public void set(int value) { - applicationId = value; + 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.startTime = System.currentTimeMillis(); this.traceSegmentId = GlobalIdGenerator.generate(ID_TYPE); this.spans = new LinkedList(); @@ -164,6 +170,10 @@ public class TraceSegment implements IDictionaryCompressible { return endTime; } + public int getApplicationId() { + return applicationId; + } + public boolean hasRef() { return !(refs == null || refs.size() == 0); } @@ -196,15 +206,4 @@ public class TraceSegment implements IDictionaryCompressible { ", relatedGlobalTraces=" + relatedGlobalTraces + '}'; } - - /** - * If compress is incomplete, this segment will be ignored. - */ - @Override - public void incomplete(String notFoundKey) { - if (logger.isDebugEnable()) { - logger.debug("Segment[{}] ignored, cause by compress key [{}] not found.", this.traceSegmentId, notFoundKey); - } - this.ignore = true; - } } 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 a9e2c7c97..69439ae9b 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,5 +1,9 @@ package org.skywalking.apm.agent.core.context.trace; +import java.util.List; +import org.skywalking.apm.agent.core.context.ContextCarrier; +import org.skywalking.apm.agent.core.context.ids.DistributedTraceId; + /** * {@link TraceSegmentRef} is like a pointer, which ref to another {@link TraceSegment}, * use {@link #spanId} point to the exact span of the ref {@link TraceSegment}. @@ -7,9 +11,6 @@ package org.skywalking.apm.agent.core.context.trace; * Created by wusheng on 2017/2/17. */ public class TraceSegmentRef { - /** - * {@link TraceSegment#traceSegmentId} - */ private String traceSegmentId; private int spanId = -1; @@ -19,51 +20,16 @@ public class TraceSegmentRef { private String peerHost; /** - * Create a {@link TraceSegmentRef} instance, without any data. + * {@link DistributedTraceId} */ - public TraceSegmentRef() { - } + private List distributedTraceIds; - public String getTraceSegmentId() { - return traceSegmentId; - } - - public void setTraceSegmentId(String traceSegmentId) { - this.traceSegmentId = traceSegmentId; - } - - public int getSpanId() { - return spanId; - } - - public void setSpanId(int spanId) { - this.spanId = spanId; - } - - public String getApplicationCode() { - return applicationCode; - } - - public void setApplicationCode(String applicationCode) { - this.applicationCode = applicationCode; - } - - public String getPeerHost() { - return peerHost; - } - - public void setPeerHost(String peerHost) { - this.peerHost = peerHost; - } - - @Override - public String toString() { - return "TraceSegmentRef{" + - "traceSegmentId='" + traceSegmentId + '\'' + - ", spanId=" + spanId + - ", applicationCode='" + applicationCode + '\'' + - ", peerHost='" + peerHost + '\'' + - '}'; + public TraceSegmentRef(ContextCarrier carrier) { + this.traceSegmentId = carrier.getTraceSegmentId(); + this.spanId = carrier.getSpanId(); + this.applicationCode = carrier.getApplicationCode(); + this.peerHost = carrier.getPeerHost(); + this.distributedTraceIds = carrier.getDistributedTraceIds(); } @Override @@ -73,13 +39,17 @@ public class TraceSegmentRef { if (o == null || getClass() != o.getClass()) return false; - TraceSegmentRef that = (TraceSegmentRef) o; + TraceSegmentRef ref = (TraceSegmentRef)o; - return traceSegmentId != null ? traceSegmentId.equals(that.traceSegmentId) : that.traceSegmentId == null; + if (spanId != ref.spanId) + return false; + return traceSegmentId.equals(ref.traceSegmentId); } @Override public int hashCode() { - return traceSegmentId != null ? traceSegmentId.hashCode() : 0; + int result = traceSegmentId.hashCode(); + result = 31 * result + spanId; + return result; } } 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 2d25fd33f..585971706 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 @@ -1,5 +1,10 @@ package org.skywalking.apm.agent.core.dictionary; +import io.netty.util.internal.ConcurrentSet; +import java.util.Map; +import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; + /** * Map of application id to application code, which is from the collector side. * @@ -7,8 +12,16 @@ package org.skywalking.apm.agent.core.dictionary; */ public enum ApplicationDictionary { INSTANCE; + private Map applicationDictionary = new ConcurrentHashMap(); + private Set unRegisterApplication = new ConcurrentSet(); - public PossibleFound find(String applicationCode, IDictionaryCompressible compressedOwner) { - + public PossibleFound find(String applicationCode) { + Integer applicationId = applicationDictionary.get(applicationCode); + if (applicationId != null) { + return new Found(applicationId); + } else { + unRegisterApplication.add(applicationCode); + return new NotFound(); + } } } diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/dictionary/DictionaryManager.java b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/dictionary/DictionaryManager.java index 45a509287..9c6dfffbb 100644 --- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/dictionary/DictionaryManager.java +++ b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/dictionary/DictionaryManager.java @@ -5,9 +5,16 @@ package org.skywalking.apm.agent.core.dictionary; */ public class DictionaryManager { /** - * @return {@link ApplicationDictionary} to find applicationId + * @return {@link ApplicationDictionary} to find application id for application code and network address. */ - public static ApplicationDictionary findApplicationCodeSection(){ + public static ApplicationDictionary findApplicationCodeSection() { return ApplicationDictionary.INSTANCE; } + + /** + * @return {@link OperationNameDictionary} to find service id. + */ + public static OperationNameDictionary findOperationNameCodeSection() { + return OperationNameDictionary.INSTANCE; + } } diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/dictionary/DictionaryUtil.java b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/dictionary/DictionaryUtil.java new file mode 100644 index 000000000..8a0758cb5 --- /dev/null +++ b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/dictionary/DictionaryUtil.java @@ -0,0 +1,18 @@ +package org.skywalking.apm.agent.core.dictionary; + +/** + * @author wusheng + */ +public class DictionaryUtil { + public static int nullValue() { + return -1; + } + + public static boolean isNull(int value) { + return value == nullValue(); + } + + public static boolean isNull(String text) { + return text == null; + } +} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/dictionary/DictionaryValueHolder.java b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/dictionary/DictionaryValueHolder.java new file mode 100644 index 000000000..d02eae589 --- /dev/null +++ b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/dictionary/DictionaryValueHolder.java @@ -0,0 +1,16 @@ +package org.skywalking.apm.agent.core.dictionary; + +/** + * @author wusheng + */ +public class DictionaryValueHolder { + private int value = DictionaryUtil.nullValue(); + + public int getValue() { + return value; + } + + public void setValue(int value) { + this.value = value; + } +} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/dictionary/Found.java b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/dictionary/Found.java new file mode 100644 index 000000000..f1398959c --- /dev/null +++ b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/dictionary/Found.java @@ -0,0 +1,10 @@ +package org.skywalking.apm.agent.core.dictionary; + +/** + * @author wusheng + */ +public class Found extends PossibleFound { + public Found(int value) { + super(value); + } +} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/dictionary/IDictionaryCompressible.java b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/dictionary/IDictionaryCompressible.java deleted file mode 100644 index c5e01e17e..000000000 --- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/dictionary/IDictionaryCompressible.java +++ /dev/null @@ -1,15 +0,0 @@ -package org.skywalking.apm.agent.core.dictionary; - -/** - * The IDictionaryCompressible implementation are objects which supported compressing by dictionary. - * - * - * @author wusheng - */ -public interface IDictionaryCompressible { - /** - * The Dictionary notifies, when compress key isn't found, - * means compress fail this time. - */ - void incomplete(String notFoundKey); -} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/dictionary/NotFound.java b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/dictionary/NotFound.java new file mode 100644 index 000000000..5887a180c --- /dev/null +++ b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/dictionary/NotFound.java @@ -0,0 +1,10 @@ +package org.skywalking.apm.agent.core.dictionary; + +/** + * @author wusheng + */ +public class NotFound extends PossibleFound { + public NotFound() { + super(); + } +} 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 new file mode 100644 index 000000000..5ada58028 --- /dev/null +++ b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/dictionary/OperationNameDictionary.java @@ -0,0 +1,55 @@ +package org.skywalking.apm.agent.core.dictionary; + +import io.netty.util.internal.ConcurrentSet; +import java.util.Map; +import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; + +/** + * @author wusheng + */ +public enum OperationNameDictionary { + INSTANCE; + private Map operationNameDictionary = new ConcurrentHashMap(); + private Set unRegisterOperationName = new ConcurrentSet(); + + public PossibleFound find(int applicationId, String operationName) { + OperationNameKey key = new OperationNameKey(applicationId, operationName); + Integer operationId = operationNameDictionary.get(key); + if (operationId != null) { + return new Found(applicationId); + } else { + unRegisterOperationName.add(key); + return new NotFound(); + } + } + + private class OperationNameKey { + private int applicationId; + private String operationName; + + public OperationNameKey(int applicationId, String operationName) { + this.applicationId = applicationId; + this.operationName = operationName; + } + + @Override public boolean equals(Object o) { + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; + + OperationNameKey key = (OperationNameKey)o; + + if (applicationId != key.applicationId) + return false; + return operationName.equals(key.operationName); + } + + @Override public int hashCode() { + int result = applicationId; + result = 31 * result + operationName.hashCode(); + return result; + } + } +} 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 ef986982b..89e924ec2 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 @@ -5,7 +5,7 @@ package org.skywalking.apm.agent.core.dictionary; * * @author wusheng */ -public class PossibleFound { +public abstract class PossibleFound { private boolean found; private int value; @@ -18,13 +18,35 @@ public class PossibleFound { this.found = false; } - public void ifFound(Setter setter) { + public void doInCondition(Found condition1, NotFound condition2) { if (found) { - setter.set(value); + condition1.doProcess(value); + } else { + condition2.doProcess(); } } - public interface Setter { - void set(int value); + public Object doInCondition(FoundAndObtain condition1, NotFoundAndObtain condition2) { + if (found) { + return condition1.doProcess(value); + } else { + return condition2.doProcess(); + } + } + + public interface Found { + void doProcess(int value); + } + + public interface NotFound { + void doProcess(); + } + + public interface FoundAndObtain { + Object doProcess(int value); + } + + public interface NotFoundAndObtain { + Object doProcess(); } } diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/queue/TraceSegmentProcessQueue.java b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/queue/TraceSegmentProcessQueue.java index bed46a740..74327bc28 100644 --- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/queue/TraceSegmentProcessQueue.java +++ b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/queue/TraceSegmentProcessQueue.java @@ -8,7 +8,6 @@ import java.util.LinkedList; import java.util.List; import org.skywalking.apm.agent.core.conf.Config; import org.skywalking.apm.agent.core.boot.StatusBootService; -import org.skywalking.apm.agent.core.context.TracerContext; import org.skywalking.apm.agent.core.context.TracingContextListener; import org.skywalking.apm.agent.core.context.trace.TraceSegment; import org.skywalking.apm.logging.ILog; diff --git a/apm-sniffer/apm-agent-core/src/test/java/org/skywalking/apm/agent/core/context/trace/LeafSpanTestCase.java b/apm-sniffer/apm-agent-core/src/test/java/org/skywalking/apm/agent/core/context/trace/LeafSpanTestCase.java index f79a983d0..499ecbea9 100644 --- a/apm-sniffer/apm-agent-core/src/test/java/org/skywalking/apm/agent/core/context/trace/LeafSpanTestCase.java +++ b/apm-sniffer/apm-agent-core/src/test/java/org/skywalking/apm/agent/core/context/trace/LeafSpanTestCase.java @@ -2,11 +2,7 @@ package org.skywalking.apm.agent.core.context.trace; import org.junit.Assert; import org.junit.Test; -import org.skywalking.apm.agent.core.tags.BooleanTagReader; -import org.skywalking.apm.agent.core.tags.IntTagReader; import org.skywalking.apm.agent.core.tags.StringTagReader; -import org.skywalking.apm.agent.core.context.tag.BooleanTag; -import org.skywalking.apm.agent.core.context.tag.IntTag; import org.skywalking.apm.agent.core.context.tag.StringTag; /** diff --git a/apm-sniffer/apm-agent-core/src/test/java/org/skywalking/apm/agent/core/context/trace/SpanTestCase.java b/apm-sniffer/apm-agent-core/src/test/java/org/skywalking/apm/agent/core/context/trace/SpanTestCase.java index e68e8c959..86f3adcc5 100644 --- a/apm-sniffer/apm-agent-core/src/test/java/org/skywalking/apm/agent/core/context/trace/SpanTestCase.java +++ b/apm-sniffer/apm-agent-core/src/test/java/org/skywalking/apm/agent/core/context/trace/SpanTestCase.java @@ -4,7 +4,6 @@ import java.lang.reflect.Field; import java.util.List; import org.junit.Assert; import org.junit.Test; -import org.skywalking.apm.agent.core.tags.BooleanTagReader; import org.skywalking.apm.agent.core.tags.StringTagReader; import org.skywalking.apm.agent.core.context.tag.Tags; diff --git a/apm-sniffer/apm-agent-core/src/test/java/org/skywalking/apm/agent/core/sampling/SamplingTracerContextTestCase.java b/apm-sniffer/apm-agent-core/src/test/java/org/skywalking/apm/agent/core/sampling/SamplingTracerContextTestCase.java index a1f625666..e34e97cf0 100644 --- a/apm-sniffer/apm-agent-core/src/test/java/org/skywalking/apm/agent/core/sampling/SamplingTracerContextTestCase.java +++ b/apm-sniffer/apm-agent-core/src/test/java/org/skywalking/apm/agent/core/sampling/SamplingTracerContextTestCase.java @@ -7,7 +7,6 @@ import org.junit.Test; import org.skywalking.apm.agent.core.boot.ServiceManager; import org.skywalking.apm.agent.core.conf.Config; import org.skywalking.apm.agent.core.context.ContextManager; -import org.skywalking.apm.agent.core.context.TracerContext; import org.skywalking.apm.agent.core.context.TracingContextListener; import org.skywalking.apm.agent.core.context.tag.Tags; import org.skywalking.apm.agent.core.context.trace.AbstractSpan; diff --git a/apm-sniffer/apm-agent-core/src/test/java/org/skywalking/apm/agent/core/tags/BooleanTagReader.java b/apm-sniffer/apm-agent-core/src/test/java/org/skywalking/apm/agent/core/tags/BooleanTagReader.java deleted file mode 100644 index 326e5fdc7..000000000 --- a/apm-sniffer/apm-agent-core/src/test/java/org/skywalking/apm/agent/core/tags/BooleanTagReader.java +++ /dev/null @@ -1,32 +0,0 @@ -package org.skywalking.apm.agent.core.tags; - -import java.lang.reflect.Field; -import java.util.List; -import org.skywalking.apm.agent.core.context.tag.BooleanTag; -import org.skywalking.apm.agent.core.context.tag.BooleanTagItem; - -/** - * @author wusheng - */ -public class BooleanTagReader { - public static Boolean get(Span span, BooleanTag tag) { - List tagsWithBoolList = null; - try { - Field tagsWithBool = Span.class.getDeclaredField("tagsWithBool"); - tagsWithBool.setAccessible(true); - tagsWithBoolList = (List)tagsWithBool.get(span); - } catch (IllegalAccessException e) { - e.printStackTrace(); - } catch (NoSuchFieldException e) { - e.printStackTrace(); - } - - for (BooleanTagItem item : tagsWithBoolList) { - if (tag.key().equals(item.getKey())) { - return item.getValue(); - } - } - return tag.defaultValue(); - } - -} diff --git a/apm-sniffer/apm-agent-core/src/test/java/org/skywalking/apm/agent/core/tags/IntTagReader.java b/apm-sniffer/apm-agent-core/src/test/java/org/skywalking/apm/agent/core/tags/IntTagReader.java deleted file mode 100644 index 6e168ec58..000000000 --- a/apm-sniffer/apm-agent-core/src/test/java/org/skywalking/apm/agent/core/tags/IntTagReader.java +++ /dev/null @@ -1,32 +0,0 @@ -package org.skywalking.apm.agent.core.tags; - -import java.lang.reflect.Field; -import java.util.List; -import org.skywalking.apm.agent.core.context.tag.IntTag; -import org.skywalking.apm.agent.core.context.tag.IntTagItem; - -/** - * @author wusheng - */ -public class IntTagReader { - public static Integer get(Span span, IntTag tag) { - List tagsWithIntList = null; - try { - Field tagsWithInt = Span.class.getDeclaredField("tagsWithInt"); - tagsWithInt.setAccessible(true); - tagsWithIntList = (List)tagsWithInt.get(span); - } catch (IllegalAccessException e) { - e.printStackTrace(); - } catch (NoSuchFieldException e) { - e.printStackTrace(); - } - - for (IntTagItem item : tagsWithIntList) { - if (tag.key().equals(item.getKey())) { - return item.getValue(); - } - } - return null; - } - -} diff --git a/apm-sniffer/apm-agent-core/src/test/java/org/skywalking/apm/agent/core/tags/StringTagReader.java b/apm-sniffer/apm-agent-core/src/test/java/org/skywalking/apm/agent/core/tags/StringTagReader.java index d15816650..8bc71ad04 100644 --- a/apm-sniffer/apm-agent-core/src/test/java/org/skywalking/apm/agent/core/tags/StringTagReader.java +++ b/apm-sniffer/apm-agent-core/src/test/java/org/skywalking/apm/agent/core/tags/StringTagReader.java @@ -3,7 +3,6 @@ package org.skywalking.apm.agent.core.tags; import java.lang.reflect.Field; import java.util.List; import org.skywalking.apm.agent.core.context.tag.StringTag; -import org.skywalking.apm.agent.core.context.tag.StringTagItem; /** * @author wusheng diff --git a/apm-sniffer/apm-sdk-plugin/dubbo-plugin/src/test/java/org/skywalking/apm/plugin/dubbo/DubboInterceptorTest.java b/apm-sniffer/apm-sdk-plugin/dubbo-plugin/src/test/java/org/skywalking/apm/plugin/dubbo/DubboInterceptorTest.java index 10ce1990b..735f50fbf 100644 --- a/apm-sniffer/apm-sdk-plugin/dubbo-plugin/src/test/java/org/skywalking/apm/plugin/dubbo/DubboInterceptorTest.java +++ b/apm-sniffer/apm-sdk-plugin/dubbo-plugin/src/test/java/org/skywalking/apm/plugin/dubbo/DubboInterceptorTest.java @@ -18,7 +18,6 @@ import org.powermock.modules.junit4.PowerMockRunner; import org.skywalking.apm.agent.core.boot.ServiceManager; import org.skywalking.apm.agent.core.conf.Config; import org.skywalking.apm.agent.core.context.ContextCarrier; -import org.skywalking.apm.agent.core.context.TracerContext; import org.skywalking.apm.agent.core.plugin.interceptor.EnhancedClassInstanceContext; import org.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodInvokeContext; import org.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; diff --git a/apm-sniffer/apm-sdk-plugin/feign-default-http-9.x-plugin/src/test/java/org/skywalking/apm/plugin/feign/http/v9/DefaultHttpClientInterceptorTest.java b/apm-sniffer/apm-sdk-plugin/feign-default-http-9.x-plugin/src/test/java/org/skywalking/apm/plugin/feign/http/v9/DefaultHttpClientInterceptorTest.java index 1db4b6077..5771cea05 100644 --- a/apm-sniffer/apm-sdk-plugin/feign-default-http-9.x-plugin/src/test/java/org/skywalking/apm/plugin/feign/http/v9/DefaultHttpClientInterceptorTest.java +++ b/apm-sniffer/apm-sdk-plugin/feign-default-http-9.x-plugin/src/test/java/org/skywalking/apm/plugin/feign/http/v9/DefaultHttpClientInterceptorTest.java @@ -14,7 +14,6 @@ import org.mockito.Mock; import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.modules.junit4.PowerMockRunner; import org.skywalking.apm.agent.core.boot.ServiceManager; -import org.skywalking.apm.agent.core.context.TracerContext; import org.skywalking.apm.agent.core.plugin.interceptor.EnhancedClassInstanceContext; import org.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodInvokeContext; import org.skywalking.apm.sniffer.mock.context.MockTracingContextListener; diff --git a/apm-sniffer/apm-sdk-plugin/httpClient-4.x-plugin/src/test/java/org/skywalking/apm/plugin/httpClient/v4/HttpClientExecuteInterceptorTest.java b/apm-sniffer/apm-sdk-plugin/httpClient-4.x-plugin/src/test/java/org/skywalking/apm/plugin/httpClient/v4/HttpClientExecuteInterceptorTest.java index 786c5ec9d..ccf4ca391 100644 --- a/apm-sniffer/apm-sdk-plugin/httpClient-4.x-plugin/src/test/java/org/skywalking/apm/plugin/httpClient/v4/HttpClientExecuteInterceptorTest.java +++ b/apm-sniffer/apm-sdk-plugin/httpClient-4.x-plugin/src/test/java/org/skywalking/apm/plugin/httpClient/v4/HttpClientExecuteInterceptorTest.java @@ -11,7 +11,6 @@ import org.powermock.api.mockito.PowerMockito; import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.modules.junit4.PowerMockRunner; import org.skywalking.apm.agent.core.boot.ServiceManager; -import org.skywalking.apm.agent.core.context.TracerContext; import org.skywalking.apm.agent.core.plugin.interceptor.EnhancedClassInstanceContext; import org.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodInvokeContext; import org.skywalking.apm.sniffer.mock.context.MockTracingContextListener; diff --git a/apm-sniffer/apm-sdk-plugin/jdbc-plugin/src/test/java/org/skywalking/apm/plugin/jdbc/SWCallableStatementTest.java b/apm-sniffer/apm-sdk-plugin/jdbc-plugin/src/test/java/org/skywalking/apm/plugin/jdbc/SWCallableStatementTest.java index f4d44f1f3..d0271ef64 100644 --- a/apm-sniffer/apm-sdk-plugin/jdbc-plugin/src/test/java/org/skywalking/apm/plugin/jdbc/SWCallableStatementTest.java +++ b/apm-sniffer/apm-sdk-plugin/jdbc-plugin/src/test/java/org/skywalking/apm/plugin/jdbc/SWCallableStatementTest.java @@ -12,7 +12,6 @@ import org.mockito.Matchers; import org.mockito.Mock; import org.mockito.runners.MockitoJUnitRunner; import org.skywalking.apm.agent.core.boot.ServiceManager; -import org.skywalking.apm.agent.core.context.TracerContext; import org.skywalking.apm.sniffer.mock.context.MockTracingContextListener; import org.skywalking.apm.sniffer.mock.context.SegmentAssert; import org.skywalking.apm.agent.core.context.trace.TraceSegment; diff --git a/apm-sniffer/apm-sdk-plugin/jdbc-plugin/src/test/java/org/skywalking/apm/plugin/jdbc/SWConnectionTest.java b/apm-sniffer/apm-sdk-plugin/jdbc-plugin/src/test/java/org/skywalking/apm/plugin/jdbc/SWConnectionTest.java index 9f167d4be..7297c58bf 100644 --- a/apm-sniffer/apm-sdk-plugin/jdbc-plugin/src/test/java/org/skywalking/apm/plugin/jdbc/SWConnectionTest.java +++ b/apm-sniffer/apm-sdk-plugin/jdbc-plugin/src/test/java/org/skywalking/apm/plugin/jdbc/SWConnectionTest.java @@ -8,7 +8,6 @@ import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.runners.MockitoJUnitRunner; import org.skywalking.apm.agent.core.boot.ServiceManager; -import org.skywalking.apm.agent.core.context.TracerContext; import org.skywalking.apm.sniffer.mock.context.MockTracingContextListener; import org.skywalking.apm.sniffer.mock.context.SegmentAssert; import org.skywalking.apm.agent.core.context.trace.TraceSegment; diff --git a/apm-sniffer/apm-sdk-plugin/jdbc-plugin/src/test/java/org/skywalking/apm/plugin/jdbc/SWStatementTest.java b/apm-sniffer/apm-sdk-plugin/jdbc-plugin/src/test/java/org/skywalking/apm/plugin/jdbc/SWStatementTest.java index 1c3226db9..88872f7ca 100644 --- a/apm-sniffer/apm-sdk-plugin/jdbc-plugin/src/test/java/org/skywalking/apm/plugin/jdbc/SWStatementTest.java +++ b/apm-sniffer/apm-sdk-plugin/jdbc-plugin/src/test/java/org/skywalking/apm/plugin/jdbc/SWStatementTest.java @@ -10,7 +10,6 @@ import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.runners.MockitoJUnitRunner; import org.skywalking.apm.agent.core.boot.ServiceManager; -import org.skywalking.apm.agent.core.context.TracerContext; import org.skywalking.apm.sniffer.mock.context.MockTracingContextListener; import org.skywalking.apm.sniffer.mock.context.SegmentAssert; import org.skywalking.apm.agent.core.context.trace.TraceSegment; diff --git a/apm-sniffer/apm-sdk-plugin/jdbc-plugin/src/test/java/org/skywalking/apm/plugin/jdbc/SwPreparedStatementTest.java b/apm-sniffer/apm-sdk-plugin/jdbc-plugin/src/test/java/org/skywalking/apm/plugin/jdbc/SwPreparedStatementTest.java index 4a59e27fe..ee87a0af6 100644 --- a/apm-sniffer/apm-sdk-plugin/jdbc-plugin/src/test/java/org/skywalking/apm/plugin/jdbc/SwPreparedStatementTest.java +++ b/apm-sniffer/apm-sdk-plugin/jdbc-plugin/src/test/java/org/skywalking/apm/plugin/jdbc/SwPreparedStatementTest.java @@ -13,7 +13,6 @@ import org.mockito.Matchers; import org.mockito.Mock; import org.mockito.runners.MockitoJUnitRunner; import org.skywalking.apm.agent.core.boot.ServiceManager; -import org.skywalking.apm.agent.core.context.TracerContext; import org.skywalking.apm.sniffer.mock.context.MockTracingContextListener; import org.skywalking.apm.sniffer.mock.context.SegmentAssert; import org.skywalking.apm.agent.core.context.trace.TraceSegment; diff --git a/apm-sniffer/apm-sdk-plugin/jedis-2.x-plugin/src/test/java/org/skywalking/apm/plugin/jedis/v2/JedisMethodInterceptorTest.java b/apm-sniffer/apm-sdk-plugin/jedis-2.x-plugin/src/test/java/org/skywalking/apm/plugin/jedis/v2/JedisMethodInterceptorTest.java index 0a342c6a4..8d38da6c3 100644 --- a/apm-sniffer/apm-sdk-plugin/jedis-2.x-plugin/src/test/java/org/skywalking/apm/plugin/jedis/v2/JedisMethodInterceptorTest.java +++ b/apm-sniffer/apm-sdk-plugin/jedis-2.x-plugin/src/test/java/org/skywalking/apm/plugin/jedis/v2/JedisMethodInterceptorTest.java @@ -11,7 +11,6 @@ import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.runners.MockitoJUnitRunner; import org.skywalking.apm.agent.core.boot.ServiceManager; -import org.skywalking.apm.agent.core.context.TracerContext; import org.skywalking.apm.agent.core.plugin.interceptor.EnhancedClassInstanceContext; import org.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodInvokeContext; import org.skywalking.apm.sniffer.mock.context.MockTracingContextListener; diff --git a/apm-sniffer/apm-sdk-plugin/mongodb-3.x-plugin/src/test/java/org/skywalking/apm/plugin/mongodb/v3/MongoDBMethodInterceptorTest.java b/apm-sniffer/apm-sdk-plugin/mongodb-3.x-plugin/src/test/java/org/skywalking/apm/plugin/mongodb/v3/MongoDBMethodInterceptorTest.java index d9c458d24..dd9598ea2 100644 --- a/apm-sniffer/apm-sdk-plugin/mongodb-3.x-plugin/src/test/java/org/skywalking/apm/plugin/mongodb/v3/MongoDBMethodInterceptorTest.java +++ b/apm-sniffer/apm-sdk-plugin/mongodb-3.x-plugin/src/test/java/org/skywalking/apm/plugin/mongodb/v3/MongoDBMethodInterceptorTest.java @@ -16,7 +16,6 @@ import org.mockito.runners.MockitoJUnitRunner; import org.powermock.api.mockito.PowerMockito; import org.skywalking.apm.agent.core.boot.ServiceManager; import org.skywalking.apm.agent.core.conf.Config; -import org.skywalking.apm.agent.core.context.TracerContext; import org.skywalking.apm.agent.core.plugin.interceptor.EnhancedClassInstanceContext; import org.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodInvokeContext; import org.skywalking.apm.sniffer.mock.context.MockTracingContextListener; diff --git a/apm-sniffer/apm-sdk-plugin/mongodb-3.x-plugin/src/test/java/org/skywalking/apm/plugin/mongodb/v3/MongoDBWriteMethodInterceptorTest.java b/apm-sniffer/apm-sdk-plugin/mongodb-3.x-plugin/src/test/java/org/skywalking/apm/plugin/mongodb/v3/MongoDBWriteMethodInterceptorTest.java index 35b8ccf77..887516dbd 100644 --- a/apm-sniffer/apm-sdk-plugin/mongodb-3.x-plugin/src/test/java/org/skywalking/apm/plugin/mongodb/v3/MongoDBWriteMethodInterceptorTest.java +++ b/apm-sniffer/apm-sdk-plugin/mongodb-3.x-plugin/src/test/java/org/skywalking/apm/plugin/mongodb/v3/MongoDBWriteMethodInterceptorTest.java @@ -17,7 +17,6 @@ import org.mockito.runners.MockitoJUnitRunner; import org.powermock.api.mockito.PowerMockito; import org.skywalking.apm.agent.core.boot.ServiceManager; import org.skywalking.apm.agent.core.conf.Config; -import org.skywalking.apm.agent.core.context.TracerContext; import org.skywalking.apm.agent.core.plugin.interceptor.EnhancedClassInstanceContext; import org.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodInvokeContext; import org.skywalking.apm.sniffer.mock.context.MockTracingContextListener; diff --git a/apm-sniffer/apm-sdk-plugin/motan-plugin/src/test/java/org/skywalking/apm/plugin/motan/MotanConsumerInterceptorTest.java b/apm-sniffer/apm-sdk-plugin/motan-plugin/src/test/java/org/skywalking/apm/plugin/motan/MotanConsumerInterceptorTest.java index bee18bd84..36797179d 100644 --- a/apm-sniffer/apm-sdk-plugin/motan-plugin/src/test/java/org/skywalking/apm/plugin/motan/MotanConsumerInterceptorTest.java +++ b/apm-sniffer/apm-sdk-plugin/motan-plugin/src/test/java/org/skywalking/apm/plugin/motan/MotanConsumerInterceptorTest.java @@ -12,7 +12,6 @@ import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.runners.MockitoJUnitRunner; import org.skywalking.apm.agent.core.boot.ServiceManager; -import org.skywalking.apm.agent.core.context.TracerContext; import org.skywalking.apm.agent.core.plugin.interceptor.EnhancedClassInstanceContext; import org.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodInvokeContext; import org.skywalking.apm.sniffer.mock.context.MockTracingContextListener; diff --git a/apm-sniffer/apm-sdk-plugin/motan-plugin/src/test/java/org/skywalking/apm/plugin/motan/MotanProviderInterceptorTest.java b/apm-sniffer/apm-sdk-plugin/motan-plugin/src/test/java/org/skywalking/apm/plugin/motan/MotanProviderInterceptorTest.java index 623da3934..692e850b2 100644 --- a/apm-sniffer/apm-sdk-plugin/motan-plugin/src/test/java/org/skywalking/apm/plugin/motan/MotanProviderInterceptorTest.java +++ b/apm-sniffer/apm-sdk-plugin/motan-plugin/src/test/java/org/skywalking/apm/plugin/motan/MotanProviderInterceptorTest.java @@ -13,7 +13,6 @@ import org.mockito.Mock; import org.mockito.runners.MockitoJUnitRunner; import org.skywalking.apm.agent.core.boot.ServiceManager; import org.skywalking.apm.agent.core.conf.Config; -import org.skywalking.apm.agent.core.context.TracerContext; import org.skywalking.apm.agent.core.plugin.interceptor.EnhancedClassInstanceContext; import org.skywalking.apm.agent.core.plugin.interceptor.enhance.ConstructorInvokeContext; import org.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodInvokeContext; diff --git a/apm-sniffer/apm-sdk-plugin/okhttp-3.x-plugin/src/test/java/org/skywalking/apm/plugin/okhttp/v3/RealCallInterceptorTest.java b/apm-sniffer/apm-sdk-plugin/okhttp-3.x-plugin/src/test/java/org/skywalking/apm/plugin/okhttp/v3/RealCallInterceptorTest.java index 2264db161..88c12bfa1 100644 --- a/apm-sniffer/apm-sdk-plugin/okhttp-3.x-plugin/src/test/java/org/skywalking/apm/plugin/okhttp/v3/RealCallInterceptorTest.java +++ b/apm-sniffer/apm-sdk-plugin/okhttp-3.x-plugin/src/test/java/org/skywalking/apm/plugin/okhttp/v3/RealCallInterceptorTest.java @@ -11,7 +11,6 @@ import org.mockito.Mock; import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.modules.junit4.PowerMockRunner; import org.skywalking.apm.agent.core.boot.ServiceManager; -import org.skywalking.apm.agent.core.context.TracerContext; import org.skywalking.apm.agent.core.plugin.interceptor.EnhancedClassInstanceContext; import org.skywalking.apm.agent.core.plugin.interceptor.enhance.ConstructorInvokeContext; import org.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodInvokeContext; diff --git a/apm-sniffer/apm-sdk-plugin/resin-3.x-plugin/src/test/java/org/skywalking/apm/plugin/resin/v3/ResinV3InterceptorTest.java b/apm-sniffer/apm-sdk-plugin/resin-3.x-plugin/src/test/java/org/skywalking/apm/plugin/resin/v3/ResinV3InterceptorTest.java index 22f3696d4..52d8bcf8e 100644 --- a/apm-sniffer/apm-sdk-plugin/resin-3.x-plugin/src/test/java/org/skywalking/apm/plugin/resin/v3/ResinV3InterceptorTest.java +++ b/apm-sniffer/apm-sdk-plugin/resin-3.x-plugin/src/test/java/org/skywalking/apm/plugin/resin/v3/ResinV3InterceptorTest.java @@ -11,7 +11,6 @@ import org.mockito.Mock; import org.mockito.runners.MockitoJUnitRunner; import org.skywalking.apm.agent.core.boot.ServiceManager; import org.skywalking.apm.agent.core.conf.Config; -import org.skywalking.apm.agent.core.context.TracerContext; import org.skywalking.apm.agent.core.plugin.interceptor.EnhancedClassInstanceContext; import org.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodInvokeContext; import org.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; diff --git a/apm-sniffer/apm-sdk-plugin/resin-4.x-plugin/src/test/java/org/skywalking/apm/plugin/resin/v4/ResinV4InterceptorTest.java b/apm-sniffer/apm-sdk-plugin/resin-4.x-plugin/src/test/java/org/skywalking/apm/plugin/resin/v4/ResinV4InterceptorTest.java index 0f916d04f..59fffed35 100644 --- a/apm-sniffer/apm-sdk-plugin/resin-4.x-plugin/src/test/java/org/skywalking/apm/plugin/resin/v4/ResinV4InterceptorTest.java +++ b/apm-sniffer/apm-sdk-plugin/resin-4.x-plugin/src/test/java/org/skywalking/apm/plugin/resin/v4/ResinV4InterceptorTest.java @@ -11,7 +11,6 @@ import org.mockito.Mock; import org.mockito.runners.MockitoJUnitRunner; import org.skywalking.apm.agent.core.boot.ServiceManager; import org.skywalking.apm.agent.core.conf.Config; -import org.skywalking.apm.agent.core.context.TracerContext; import org.skywalking.apm.agent.core.plugin.interceptor.EnhancedClassInstanceContext; import org.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodInvokeContext; import org.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; diff --git a/apm-sniffer/apm-sdk-plugin/tomcat-7.x-8.x-plugin/src/test/java/org/skywalking/apm/plugin/tomcat78x/TomcatInterceptorTest.java b/apm-sniffer/apm-sdk-plugin/tomcat-7.x-8.x-plugin/src/test/java/org/skywalking/apm/plugin/tomcat78x/TomcatInterceptorTest.java index 6a90a41ce..b717c7f98 100644 --- a/apm-sniffer/apm-sdk-plugin/tomcat-7.x-8.x-plugin/src/test/java/org/skywalking/apm/plugin/tomcat78x/TomcatInterceptorTest.java +++ b/apm-sniffer/apm-sdk-plugin/tomcat-7.x-8.x-plugin/src/test/java/org/skywalking/apm/plugin/tomcat78x/TomcatInterceptorTest.java @@ -11,7 +11,6 @@ import org.mockito.Mock; import org.mockito.runners.MockitoJUnitRunner; import org.skywalking.apm.agent.core.boot.ServiceManager; import org.skywalking.apm.agent.core.conf.Config; -import org.skywalking.apm.agent.core.context.TracerContext; import org.skywalking.apm.agent.core.plugin.interceptor.EnhancedClassInstanceContext; import org.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodInvokeContext; import org.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; diff --git a/apm-sniffer/apm-sniffer-mock/src/main/java/org/skywalking/apm/sniffer/mock/context/MockTracingContextListener.java b/apm-sniffer/apm-sniffer-mock/src/main/java/org/skywalking/apm/sniffer/mock/context/MockTracingContextListener.java index fb5ff17bb..317c73593 100644 --- a/apm-sniffer/apm-sniffer-mock/src/main/java/org/skywalking/apm/sniffer/mock/context/MockTracingContextListener.java +++ b/apm-sniffer/apm-sniffer-mock/src/main/java/org/skywalking/apm/sniffer/mock/context/MockTracingContextListener.java @@ -1,7 +1,6 @@ package org.skywalking.apm.sniffer.mock.context; import org.junit.Assert; -import org.skywalking.apm.agent.core.context.TracerContext; import org.skywalking.apm.agent.core.context.TracingContextListener; import org.skywalking.apm.agent.core.context.trace.TraceSegment; diff --git a/apm-sniffer/apm-sniffer-mock/src/main/java/org/skywalking/apm/sniffer/mock/trace/TraceSegmentBuilderFactory.java b/apm-sniffer/apm-sniffer-mock/src/main/java/org/skywalking/apm/sniffer/mock/trace/TraceSegmentBuilderFactory.java index bd0bff11e..261ef8919 100644 --- a/apm-sniffer/apm-sniffer-mock/src/main/java/org/skywalking/apm/sniffer/mock/trace/TraceSegmentBuilderFactory.java +++ b/apm-sniffer/apm-sniffer-mock/src/main/java/org/skywalking/apm/sniffer/mock/trace/TraceSegmentBuilderFactory.java @@ -1,6 +1,5 @@ package org.skywalking.apm.sniffer.mock.trace; -import org.skywalking.apm.agent.core.context.TracerContext; import org.skywalking.apm.sniffer.mock.context.MockTracingContextListener; import org.skywalking.apm.sniffer.mock.trace.builders.trace.*; import org.skywalking.apm.agent.core.context.trace.TraceSegment; diff --git a/apm-sniffer/apm-sniffer-mock/src/main/java/org/skywalking/apm/sniffer/mock/trace/tags/BooleanTagReader.java b/apm-sniffer/apm-sniffer-mock/src/main/java/org/skywalking/apm/sniffer/mock/trace/tags/BooleanTagReader.java index 52543fc9e..b58819d67 100644 --- a/apm-sniffer/apm-sniffer-mock/src/main/java/org/skywalking/apm/sniffer/mock/trace/tags/BooleanTagReader.java +++ b/apm-sniffer/apm-sniffer-mock/src/main/java/org/skywalking/apm/sniffer/mock/trace/tags/BooleanTagReader.java @@ -2,8 +2,6 @@ package org.skywalking.apm.sniffer.mock.trace.tags; import java.lang.reflect.Field; import java.util.List; -import org.skywalking.apm.agent.core.context.tag.BooleanTag; -import org.skywalking.apm.agent.core.context.tag.BooleanTagItem; /** * @author wusheng diff --git a/apm-sniffer/apm-sniffer-mock/src/main/java/org/skywalking/apm/sniffer/mock/trace/tags/IntTagReader.java b/apm-sniffer/apm-sniffer-mock/src/main/java/org/skywalking/apm/sniffer/mock/trace/tags/IntTagReader.java index 53fcc396c..3056f7e31 100644 --- a/apm-sniffer/apm-sniffer-mock/src/main/java/org/skywalking/apm/sniffer/mock/trace/tags/IntTagReader.java +++ b/apm-sniffer/apm-sniffer-mock/src/main/java/org/skywalking/apm/sniffer/mock/trace/tags/IntTagReader.java @@ -2,8 +2,6 @@ package org.skywalking.apm.sniffer.mock.trace.tags; import java.lang.reflect.Field; import java.util.List; -import org.skywalking.apm.agent.core.context.tag.IntTag; -import org.skywalking.apm.agent.core.context.tag.IntTagItem; /** * @author wusheng diff --git a/apm-sniffer/apm-sniffer-mock/src/main/java/org/skywalking/apm/sniffer/mock/trace/tags/StringTagReader.java b/apm-sniffer/apm-sniffer-mock/src/main/java/org/skywalking/apm/sniffer/mock/trace/tags/StringTagReader.java index d36be00d9..91b2b18dc 100644 --- a/apm-sniffer/apm-sniffer-mock/src/main/java/org/skywalking/apm/sniffer/mock/trace/tags/StringTagReader.java +++ b/apm-sniffer/apm-sniffer-mock/src/main/java/org/skywalking/apm/sniffer/mock/trace/tags/StringTagReader.java @@ -3,7 +3,6 @@ package org.skywalking.apm.sniffer.mock.trace.tags; import java.lang.reflect.Field; import java.util.List; import org.skywalking.apm.agent.core.context.tag.StringTag; -import org.skywalking.apm.agent.core.context.tag.StringTagItem; /** * @author wusheng