Fix NoSuchElement exception for lazy injection. (#4488)

This commit is contained in:
吴晟 Wu Sheng 2020-03-11 16:50:34 +08:00 committed by GitHub
parent 6ea3a933a2
commit 6723f349c1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 10 additions and 1 deletions

View File

@ -79,6 +79,12 @@ public class TracingContext implements AbstractTracerContext {
* LinkedList#getLast()} instead of {@link #pop()}, {@link #push(AbstractSpan)}, {@link #peek()}
*/
private LinkedList<AbstractSpan> activeSpanStack = new LinkedList<>();
/**
* @since 7.0.0 SkyWalking support lazy injection through {@link ExitTypeSpan#inject(ContextCarrier)}. Due to that,
* the {@link #activeSpanStack} could be blank by then, this is a pointer forever to the first span, even the main
* thread tracing has been finished.
*/
private AbstractSpan firstSpan = null;
/**
* A counter for the next span.
@ -636,6 +642,9 @@ public class TracingContext implements AbstractTracerContext {
* @param span the {@code span} to push
*/
private AbstractSpan push(AbstractSpan span) {
if (firstSpan == null) {
firstSpan = span;
}
activeSpanStack.addLast(span);
return span;
}
@ -651,7 +660,7 @@ public class TracingContext implements AbstractTracerContext {
}
private AbstractSpan first() {
return activeSpanStack.getFirst();
return firstSpan;
}
private boolean isLimitMechanismWorking() {