Finish the context based on #stopSpan result, rather than listener.
This commit is contained in:
parent
b3e043569c
commit
930e73f1a1
|
|
@ -98,8 +98,9 @@ public interface AbstractTracerContext {
|
|||
* Finish the given span, and the given span should be the active span of current tracing context(stack)
|
||||
*
|
||||
* @param span to finish
|
||||
* @return true when context should be clear.
|
||||
*/
|
||||
void stopSpan(AbstractSpan span);
|
||||
boolean stopSpan(AbstractSpan span);
|
||||
|
||||
/**
|
||||
* Notify this context, current span is going to be finished async in another thread.
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ public interface AsyncSpan {
|
|||
* called.
|
||||
*
|
||||
* This method must be called
|
||||
*
|
||||
*
|
||||
* 1. In original thread(tracing context).
|
||||
* 2. Current span is active span.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ import org.apache.skywalking.apm.util.StringUtil;
|
|||
*
|
||||
* @author wusheng
|
||||
*/
|
||||
public class ContextManager implements TracingContextListener, BootService, IgnoreTracerContextListener {
|
||||
public class ContextManager implements BootService {
|
||||
private static final ILog logger = LogManager.getLogger(ContextManager.class);
|
||||
private static ThreadLocal<AbstractTracerContext> CONTEXT = new ThreadLocal<AbstractTracerContext>();
|
||||
private static ThreadLocal<RuntimeContext> RUNTIME_CONTEXT = new ThreadLocal<RuntimeContext>();
|
||||
|
|
@ -166,7 +166,9 @@ public class ContextManager implements TracingContextListener, BootService, Igno
|
|||
}
|
||||
|
||||
public static void stopSpan(AbstractSpan span) {
|
||||
get().stopSpan(span);
|
||||
if (get().stopSpan(span)) {
|
||||
CONTEXT.remove();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -176,8 +178,6 @@ public class ContextManager implements TracingContextListener, BootService, Igno
|
|||
|
||||
@Override
|
||||
public void boot() {
|
||||
ContextManagerExtendService service = ServiceManager.INSTANCE.findService(ContextManagerExtendService.class);
|
||||
service.registerListeners(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -189,16 +189,6 @@ public class ContextManager implements TracingContextListener, BootService, Igno
|
|||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterFinished(TraceSegment traceSegment) {
|
||||
CONTEXT.remove();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterFinished(IgnoredTracerContext traceSegment) {
|
||||
CONTEXT.remove();
|
||||
}
|
||||
|
||||
public static boolean isActive() {
|
||||
return get() != null;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,9 +18,7 @@
|
|||
|
||||
package org.apache.skywalking.apm.agent.core.context;
|
||||
|
||||
import org.apache.skywalking.apm.agent.core.boot.BootService;
|
||||
import org.apache.skywalking.apm.agent.core.boot.DefaultImplementor;
|
||||
import org.apache.skywalking.apm.agent.core.boot.ServiceManager;
|
||||
import org.apache.skywalking.apm.agent.core.boot.*;
|
||||
import org.apache.skywalking.apm.agent.core.conf.Config;
|
||||
import org.apache.skywalking.apm.agent.core.sampling.SamplingService;
|
||||
|
||||
|
|
@ -45,11 +43,6 @@ public class ContextManagerExtendService implements BootService {
|
|||
|
||||
}
|
||||
|
||||
public void registerListeners(ContextManager manager) {
|
||||
TracingContext.ListenerManager.add(manager);
|
||||
IgnoredTracerContext.ListenerManager.add(manager);
|
||||
}
|
||||
|
||||
public AbstractTracerContext createTraceContext(String operationName, boolean forceSampling) {
|
||||
AbstractTracerContext context;
|
||||
int suffixIdx = operationName.lastIndexOf(".");
|
||||
|
|
|
|||
|
|
@ -16,17 +16,14 @@
|
|||
*
|
||||
*/
|
||||
|
||||
|
||||
package org.apache.skywalking.apm.agent.core.context;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan;
|
||||
import org.apache.skywalking.apm.agent.core.context.trace.NoopSpan;
|
||||
import java.util.*;
|
||||
import org.apache.skywalking.apm.agent.core.context.trace.*;
|
||||
|
||||
/**
|
||||
* The <code>IgnoredTracerContext</code> represent a context should be ignored.
|
||||
* So it just maintains the stack with an integer depth field.
|
||||
* The <code>IgnoredTracerContext</code> represent a context should be ignored. 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.
|
||||
*
|
||||
|
|
@ -88,11 +85,12 @@ public class IgnoredTracerContext implements AbstractTracerContext {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void stopSpan(AbstractSpan span) {
|
||||
public boolean stopSpan(AbstractSpan span) {
|
||||
stackDepth--;
|
||||
if (stackDepth == 0) {
|
||||
ListenerManager.notifyFinish(this);
|
||||
}
|
||||
return stackDepth == 0;
|
||||
}
|
||||
|
||||
@Override public AbstractTracerContext awaitFinishAsync() {
|
||||
|
|
|
|||
|
|
@ -391,7 +391,7 @@ public class TracingContext implements AbstractTracerContext {
|
|||
* @param span to finish
|
||||
*/
|
||||
@Override
|
||||
public void stopSpan(AbstractSpan span) {
|
||||
public boolean stopSpan(AbstractSpan span) {
|
||||
AbstractSpan lastSpan = peek();
|
||||
if (lastSpan == span) {
|
||||
if (lastSpan instanceof AbstractTracingSpan) {
|
||||
|
|
@ -409,6 +409,8 @@ public class TracingContext implements AbstractTracerContext {
|
|||
if (checkFinishConditions()) {
|
||||
finish();
|
||||
}
|
||||
|
||||
return activeSpanStack.isEmpty();
|
||||
}
|
||||
|
||||
@Override public AbstractTracerContext awaitFinishAsync() {
|
||||
|
|
|
|||
Loading…
Reference in New Issue