Use scope when opening JMS span
MODIFY
dd-java-agent/instrumentation/jms/src/main/java/datadog/trace/instrumentation/jms/JMSMessageConsumerInstrumentation.java
dd-java-agent/instrumentation/jms/src/main/java/datadog/trace/instrumentation/jms/JMSMessageConsumerInstrumentation.java
@@ -10,6 +10,7 @@ import static net.bytebuddy.matcher.ElementMatchers.takesArguments;
import com.google.auto.service.AutoService;
import datadog.trace.agent.tooling.Instrumenter;
+import io.opentracing.Scope;
import io.opentracing.Span;
import io.opentracing.SpanContext;
import io.opentracing.Tracer;
@@ -92,6 +93,7 @@ public final class JMSMessageConsumerInstrumentation extends Instrumenter.Defaul
}
final Span span = spanBuilder.start();
+ try (final Scope scope = GlobalTracer.get().scopeManager().activate(span, true)) {
CONSUMER_DECORATE.afterStart(span);
if (message == null) {
CONSUMER_DECORATE.onReceive(span, method);
@@ -100,7 +102,7 @@ public final class JMSMessageConsumerInstrumentation extends Instrumenter.Defaul
}
CONSUMER_DECORATE.onError(span, throwable);
CONSUMER_DECORATE.beforeFinish(span);
- span.finish();
+ }
}
}
}

Use scope when opening JMS span