diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/TracingContext.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/TracingContext.java index 16c9b321849f90d3ce22e7ac2fdf9a1b9f721106..1bff77743999117ee4c675e2c9fea1c1484d2760 100644 --- a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/TracingContext.java +++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/TracingContext.java @@ -248,35 +248,33 @@ public class TracingContext implements AbstractTracerContext { AbstractSpan entrySpan; final AbstractSpan parentSpan = peek(); final int parentSpanId = parentSpan == null ? -1 : parentSpan.getSpanId(); - if (parentSpan == null) { + if (parentSpan != null && parentSpan.isEntry()) { entrySpan = (AbstractTracingSpan)DictionaryManager.findOperationNameCodeSection() .findOnly(segment.getApplicationId(), operationName) .doInCondition(new PossibleFound.FoundAndObtain() { @Override public Object doProcess(int operationId) { - return new EntrySpan(spanIdGenerator++, parentSpanId, operationId); + return parentSpan.setOperationId(operationId); } }, new PossibleFound.NotFoundAndObtain() { @Override public Object doProcess() { - return new EntrySpan(spanIdGenerator++, parentSpanId, operationName); + return parentSpan.setOperationName(operationName); } }); - entrySpan.start(); - return push(entrySpan); - } else if (parentSpan.isEntry()) { + return entrySpan.start(); + } else { entrySpan = (AbstractTracingSpan)DictionaryManager.findOperationNameCodeSection() .findOnly(segment.getApplicationId(), operationName) .doInCondition(new PossibleFound.FoundAndObtain() { @Override public Object doProcess(int operationId) { - return parentSpan.setOperationId(operationId); + return new EntrySpan(spanIdGenerator++, parentSpanId, operationId); } }, new PossibleFound.NotFoundAndObtain() { @Override public Object doProcess() { - return parentSpan.setOperationName(operationName); + return new EntrySpan(spanIdGenerator++, parentSpanId, operationName); } }); - return entrySpan.start(); - } else { - throw new IllegalStateException("The Entry Span can't be the child of Non-Entry Span"); + entrySpan.start(); + return push(entrySpan); } }