Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,14 @@
import net.bytebuddy.asm.Advice;
import net.bytebuddy.description.type.TypeDescription;
import net.bytebuddy.matcher.ElementMatcher;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public final class JMSMessageConsumerInstrumentation
implements Instrumenter.ForTypeHierarchy, Instrumenter.HasMethodAdvice {
private final String namespace;
private static final Logger log =
LoggerFactory.getLogger(JMSMessageConsumerInstrumentation.class);

public JMSMessageConsumerInstrumentation(String namespace) {
this.namespace = namespace;
Expand Down Expand Up @@ -164,6 +168,7 @@ public static void afterReceive(
CONSUMER_DECORATE.onError(span, throwable);

activateNext(span); // scope is left open until next message or it times out
log.debug("Expecting the following `ITERATION` span to be finished {}", span);

SessionState sessionState = consumerState.getSessionState();
if (sessionState.isClientAcknowledge()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package datadog.trace.core.scopemanager;

import static datadog.trace.api.ConfigDefaults.DEFAULT_ASYNC_PROPAGATING;
import static datadog.trace.api.telemetry.LogCollector.SEND_TELEMETRY;
import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.noopScope;
import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.noopSpan;
import static datadog.trace.core.scopemanager.ContinuableScope.CONTEXT;
Expand Down Expand Up @@ -238,15 +239,24 @@ public void closePrevious(final boolean finishSpan) {

// close any immediately previous iteration scope
final ContinuableScope top = scopeStack.top;
if (top != null && top.source() == ITERATION) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To minimize the change scope, you could keep this as is and add else if (top!=null) instead.

if (iterationKeepAlive > 0) { // skip depth check because cancelling is cheap
cancelRootIterationScopeCleanup(scopeStack, top);
}
top.close();
scopeStack.cleanup();
AgentSpan span = top.span();
if (finishSpan && span != null) {
span.finishWithEndToEnd();
if (top != null) {
if (top.source() == ITERATION) {
if (iterationKeepAlive > 0) { // skip depth check because cancelling is cheap
cancelRootIterationScopeCleanup(scopeStack, top);
}
top.close();
scopeStack.cleanup();
AgentSpan span = top.span();
if (finishSpan && span != null) {
span.finishWithEndToEnd();
}
} else {
log.debug(
SEND_TELEMETRY,
"Scope found at top of stack has source {} when we expect {}. Current span at the top of the stack {}.",
top,
Copy link
Copy Markdown
Contributor

@ygree ygree Feb 18, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of the source, it will output the scope and context. Did you mean to write "top.source()" instead?

ITERATION,
top.span());
}
}
}
Expand Down