Fix entry and exit span methods bug.
This commit is contained in:
parent
9d100902de
commit
888e0484bb
|
|
@ -77,10 +77,11 @@ public class TracingContext implements AbstractTracerContext {
|
|||
|
||||
@Override
|
||||
public AbstractSpan createEntrySpan(final String operationName) {
|
||||
AbstractTracingSpan entrySpan;
|
||||
AbstractTracingSpan parentSpan = peek();
|
||||
final int parentSpanId = parentSpan == null ? -1 : parentSpan.getSpanId();
|
||||
if (parentSpan == null) {
|
||||
AbstractTracingSpan span = (AbstractTracingSpan)DictionaryManager.findOperationNameCodeSection()
|
||||
entrySpan = (AbstractTracingSpan)DictionaryManager.findOperationNameCodeSection()
|
||||
.find(segment.getApplicationId(), operationName)
|
||||
.doInCondition(new PossibleFound.FoundAndObtain() {
|
||||
@Override public Object doProcess(int operationId) {
|
||||
|
|
@ -91,9 +92,10 @@ public class TracingContext implements AbstractTracerContext {
|
|||
return new EntrySpan(spanIdGenerator++, parentSpanId, operationName);
|
||||
}
|
||||
});
|
||||
return push(span);
|
||||
entrySpan.start();
|
||||
return push(entrySpan);
|
||||
} else if (parentSpan.isEntry()) {
|
||||
return parentSpan;
|
||||
return parentSpan.start();
|
||||
} else {
|
||||
throw new IllegalStateException("The Entry Span can't be the child of Non-Entry Span");
|
||||
}
|
||||
|
|
@ -116,17 +118,19 @@ public class TracingContext implements AbstractTracerContext {
|
|||
return new LocalSpan(spanIdGenerator++, parentSpanId, operationName);
|
||||
}
|
||||
});
|
||||
span.start();
|
||||
return push(span);
|
||||
}
|
||||
|
||||
@Override
|
||||
public AbstractSpan createExitSpan(final String operationName, final String remotePeer) {
|
||||
AbstractTracingSpan exitSpan;
|
||||
AbstractTracingSpan parentSpan = peek();
|
||||
if (parentSpan != null && parentSpan.isExit()) {
|
||||
return parentSpan;
|
||||
exitSpan = parentSpan;
|
||||
} else {
|
||||
final int parentSpanId = parentSpan == null ? -1 : parentSpan.getSpanId();
|
||||
AbstractTracingSpan span = (AbstractTracingSpan)DictionaryManager.findApplicationCodeSection()
|
||||
exitSpan = (AbstractTracingSpan)DictionaryManager.findApplicationCodeSection()
|
||||
.find(remotePeer).doInCondition(
|
||||
new PossibleFound.FoundAndObtain() {
|
||||
@Override
|
||||
|
|
@ -153,8 +157,10 @@ public class TracingContext implements AbstractTracerContext {
|
|||
return new ExitSpan(spanIdGenerator++, parentSpanId, operationName, remotePeer);
|
||||
}
|
||||
});
|
||||
return push(span);
|
||||
exitSpan.start();
|
||||
push(exitSpan);
|
||||
}
|
||||
return exitSpan;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -1,5 +1,8 @@
|
|||
package org.skywalking.apm.agent.core.context.trace;
|
||||
|
||||
import org.skywalking.apm.agent.core.dictionary.DictionaryUtil;
|
||||
import org.skywalking.apm.network.trace.component.Component;
|
||||
|
||||
/**
|
||||
* The <code>EntrySpan</code> represents a service provider point, such as Tomcat server entrance.
|
||||
*
|
||||
|
|
@ -46,6 +49,33 @@ public class EntrySpan extends AbstractTracingSpan {
|
|||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AbstractSpan setLayer(SpanLayer layer) {
|
||||
if (stackDepth == currentMaxDepth) {
|
||||
return super.setLayer(layer);
|
||||
} else {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public AbstractSpan setComponent(Component component) {
|
||||
if (stackDepth == currentMaxDepth) {
|
||||
return super.setComponent(component);
|
||||
} else {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public AbstractSpan setComponent(String componentName) {
|
||||
if (stackDepth == currentMaxDepth) {
|
||||
return super.setComponent(componentName);
|
||||
} else {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean finish(TraceSegment owner) {
|
||||
if (--stackDepth == 0) {
|
||||
|
|
@ -74,6 +104,9 @@ public class EntrySpan extends AbstractTracingSpan {
|
|||
}
|
||||
|
||||
private void clearWhenRestart() {
|
||||
this.componentId = DictionaryUtil.nullValue();
|
||||
this.componentName = null;
|
||||
this.layer = null;
|
||||
this.logs = null;
|
||||
this.tags = null;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
package org.skywalking.apm.agent.core.context.trace;
|
||||
|
||||
import org.skywalking.apm.agent.core.dictionary.DictionaryUtil;
|
||||
import org.skywalking.apm.network.trace.component.Component;
|
||||
|
||||
/**
|
||||
* The <code>ExitSpan</code> represents a service consumer point, such as Feign, Okhttp discovery for a Http service.
|
||||
|
|
@ -66,6 +67,33 @@ public class ExitSpan extends AbstractTracingSpan {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public AbstractSpan setLayer(SpanLayer layer) {
|
||||
if (stackDepth == 1) {
|
||||
return super.setLayer(layer);
|
||||
} else {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public AbstractSpan setComponent(Component component) {
|
||||
if (stackDepth == 1) {
|
||||
return super.setComponent(component);
|
||||
} else {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public AbstractSpan setComponent(String componentName) {
|
||||
if (stackDepth == 1) {
|
||||
return super.setComponent(componentName);
|
||||
} else {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ExitSpan log(Throwable t) {
|
||||
if (stackDepth == 1) {
|
||||
|
|
|
|||
|
|
@ -31,6 +31,11 @@ public class TraceSegmentRef {
|
|||
*/
|
||||
private List<DistributedTraceId> distributedTraceIds;
|
||||
|
||||
/**
|
||||
* Transform a {@link ContextCarrier} to the <code>TraceSegmentRef</code>
|
||||
*
|
||||
* @param carrier the valid cross-process propagation format.
|
||||
*/
|
||||
public TraceSegmentRef(ContextCarrier carrier) {
|
||||
this.traceSegmentId = carrier.getTraceSegmentId();
|
||||
this.spanId = carrier.getSpanId();
|
||||
|
|
|
|||
Loading…
Reference in New Issue