A snapshot from the same thread would be properly 'continued' by ContextManager

This commit is contained in:
gaohongtao 2017-10-13 11:41:14 +08:00
parent 086c5ac0d4
commit 348ebd54dd
3 changed files with 4 additions and 11 deletions

View File

@ -153,7 +153,7 @@ public class ContextManager implements TracingContextListener, BootService, Igno
if (snapshot == null) {
throw new IllegalArgumentException("ContextSnapshot can't be null.");
}
if (snapshot.isValid()) {
if (snapshot.isValid() && !snapshot.getTraceSegmentId().equals(get().capture().getTraceSegmentId())) {
get().continued(snapshot);
}
}

View File

@ -113,8 +113,4 @@ public class ContextSnapshot {
public int getEntryApplicationInstanceId() {
return entryApplicationInstanceId;
}
public boolean fromCurrent() {
return traceSegmentId.equals(ContextManager.capture().getTraceSegmentId());
}
}

View File

@ -23,9 +23,9 @@ import com.dangdang.ddframe.rdb.sharding.executor.event.DMLExecutionEvent;
import com.dangdang.ddframe.rdb.sharding.executor.event.DQLExecutionEvent;
import com.dangdang.ddframe.rdb.sharding.executor.threadlocal.ExecutorDataMap;
import com.dangdang.ddframe.rdb.sharding.util.EventBusInstance;
import com.google.common.base.Joiner;
import com.google.common.eventbus.AllowConcurrentEvents;
import com.google.common.eventbus.Subscribe;
import java.util.stream.Collectors;
import org.skywalking.apm.agent.core.context.ContextManager;
import org.skywalking.apm.agent.core.context.ContextSnapshot;
import org.skywalking.apm.agent.core.context.tag.Tags;
@ -63,16 +63,13 @@ public class ExecuteEventListener {
case BEFORE_EXECUTE:
AbstractSpan span = ContextManager.createExitSpan("/SJDBC/BRANCH/" + operation, event.getDataSource());
if (ExecutorDataMap.getDataMap().containsKey(AsyncExecuteInterceptor.SNAPSHOT_DATA_KEY)) {
ContextSnapshot contextSnapshot = (ContextSnapshot)ExecutorDataMap.getDataMap().get(AsyncExecuteInterceptor.SNAPSHOT_DATA_KEY);
if (!contextSnapshot.fromCurrent()) {
ContextManager.continued(contextSnapshot);
}
ContextManager.continued((ContextSnapshot)ExecutorDataMap.getDataMap().get(AsyncExecuteInterceptor.SNAPSHOT_DATA_KEY));
}
Tags.DB_TYPE.set(span, "sql");
Tags.DB_INSTANCE.set(span, event.getDataSource());
Tags.DB_STATEMENT.set(span, event.getSql());
if (!event.getParameters().isEmpty()) {
Tags.DB_BIND_VARIABLES.set(span, event.getParameters().stream().map(Object::toString).collect(Collectors.joining(",")));
Tags.DB_BIND_VARIABLES.set(span, Joiner.on(",").join(event.getParameters()));
}
span.setComponent(ComponentsDefine.SHARDING_JDBC);
SpanLayer.asDB(span);