|
1 | 1 | package datadog.trace.core.scopemanager; |
2 | 2 |
|
3 | 3 | import static datadog.trace.api.ConfigDefaults.DEFAULT_ASYNC_PROPAGATING; |
| 4 | +import static datadog.trace.api.telemetry.LogCollector.SEND_TELEMETRY; |
4 | 5 | import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.noopScope; |
5 | 6 | import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.noopSpan; |
6 | 7 | import static datadog.trace.core.scopemanager.ContinuableScope.CONTEXT; |
@@ -238,15 +239,24 @@ public void closePrevious(final boolean finishSpan) { |
238 | 239 |
|
239 | 240 | // close any immediately previous iteration scope |
240 | 241 | final ContinuableScope top = scopeStack.top; |
241 | | - if (top != null && top.source() == ITERATION) { |
242 | | - if (iterationKeepAlive > 0) { // skip depth check because cancelling is cheap |
243 | | - cancelRootIterationScopeCleanup(scopeStack, top); |
244 | | - } |
245 | | - top.close(); |
246 | | - scopeStack.cleanup(); |
247 | | - AgentSpan span = top.span(); |
248 | | - if (finishSpan && span != null) { |
249 | | - span.finishWithEndToEnd(); |
| 242 | + if (top != null) { |
| 243 | + if (top.source() == ITERATION) { |
| 244 | + if (iterationKeepAlive > 0) { // skip depth check because cancelling is cheap |
| 245 | + cancelRootIterationScopeCleanup(scopeStack, top); |
| 246 | + } |
| 247 | + top.close(); |
| 248 | + scopeStack.cleanup(); |
| 249 | + AgentSpan span = top.span(); |
| 250 | + if (finishSpan && span != null) { |
| 251 | + span.finishWithEndToEnd(); |
| 252 | + } |
| 253 | + } else { |
| 254 | + log.debug( |
| 255 | + SEND_TELEMETRY, |
| 256 | + "Scope found at top of stack has source {} when we expect {}. Current span at the top of the stack {}.", |
| 257 | + top, |
| 258 | + ITERATION, |
| 259 | + top.span()); |
250 | 260 | } |
251 | 261 | } |
252 | 262 | } |
|
0 commit comments