Enable async tracking for some non-async frameworks
This will allow tracing of additional work being done inside the servlet context.
MODIFY
dd-java-agent/instrumentation/jetty-8/src/main/java/datadog/trace/instrumentation/jetty8/HandlerInstrumentation.java
dd-java-agent/instrumentation/jetty-8/src/main/java/datadog/trace/instrumentation/jetty8/HandlerInstrumentation.java
@@ -15,6 +15,7 @@ import datadog.trace.agent.tooling.HelperInjector;
import datadog.trace.agent.tooling.Instrumenter;
import datadog.trace.api.DDSpanTypes;
import datadog.trace.api.DDTags;
+import datadog.trace.context.TraceScope;
import io.opentracing.Scope;
import io.opentracing.Span;
import io.opentracing.SpanContext;
@@ -94,6 +95,10 @@ public final class HandlerInstrumentation extends Instrumenter.Configurable {
.withTag("span.origin.type", source.getClass().getName())
.startActive(false);
+ if (scope instanceof TraceScope) {
+ ((TraceScope) scope).setAsyncPropagation(true);
+ }
+
final Span span = scope.span();
Tags.HTTP_METHOD.set(span, req.getMethod());
Tags.HTTP_URL.set(span, req.getRequestURL().toString());

MODIFY
dd-java-agent/instrumentation/jms-1/src/main/java/datadog/trace/instrumentation/jms1/JMS1MessageListenerInstrumentation.java
dd-java-agent/instrumentation/jms-1/src/main/java/datadog/trace/instrumentation/jms1/JMS1MessageListenerInstrumentation.java
@@ -17,6 +17,7 @@ import datadog.trace.agent.tooling.DDTransformers;
import datadog.trace.agent.tooling.Instrumenter;
import datadog.trace.api.DDSpanTypes;
import datadog.trace.api.DDTags;
+import datadog.trace.context.TraceScope;
import datadog.trace.instrumentation.jms.util.MessagePropertyTextMap;
import io.opentracing.Scope;
import io.opentracing.Span;
@@ -64,7 +65,8 @@ public final class JMS1MessageListenerInstrumentation extends Instrumenter.Confi
final SpanContext extractedContext =
GlobalTracer.get().extract(Format.Builtin.TEXT_MAP, new MessagePropertyTextMap(message));
- return GlobalTracer.get()
+ final Scope scope =
+ GlobalTracer.get()
.buildSpan("jms.onMessage")
.asChildOf(extractedContext)
.withTag(DDTags.SERVICE_NAME, "jms")
@@ -74,6 +76,12 @@ public final class JMS1MessageListenerInstrumentation extends Instrumenter.Confi
.withTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_CONSUMER)
.withTag("span.origin.type", listener.getClass().getName())
.startActive(true);
+
+ if (scope instanceof TraceScope) {
+ ((TraceScope) scope).setAsyncPropagation(true);
+ }
+
+ return scope;
}
@Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class)

MODIFY
dd-java-agent/instrumentation/jms-2/src/main/java/datadog/trace/instrumentation/jms2/JMS2MessageListenerInstrumentation.java
dd-java-agent/instrumentation/jms-2/src/main/java/datadog/trace/instrumentation/jms2/JMS2MessageListenerInstrumentation.java
@@ -17,6 +17,7 @@ import datadog.trace.agent.tooling.DDTransformers;
import datadog.trace.agent.tooling.Instrumenter;
import datadog.trace.api.DDSpanTypes;
import datadog.trace.api.DDTags;
+import datadog.trace.context.TraceScope;
import datadog.trace.instrumentation.jms.util.MessagePropertyTextMap;
import io.opentracing.Scope;
import io.opentracing.Span;
@@ -64,7 +65,8 @@ public final class JMS2MessageListenerInstrumentation extends Instrumenter.Confi
final SpanContext extractedContext =
GlobalTracer.get().extract(Format.Builtin.TEXT_MAP, new MessagePropertyTextMap(message));
- return GlobalTracer.get()
+ final Scope scope =
+ GlobalTracer.get()
.buildSpan("jms.onMessage")
.asChildOf(extractedContext)
.withTag(DDTags.SERVICE_NAME, "jms")
@@ -74,6 +76,12 @@ public final class JMS2MessageListenerInstrumentation extends Instrumenter.Confi
.withTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_CONSUMER)
.withTag("span.origin.type", listener.getClass().getName())
.startActive(true);
+
+ if (scope instanceof TraceScope) {
+ ((TraceScope) scope).setAsyncPropagation(true);
+ }
+
+ return scope;
}
@Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class)

MODIFY
dd-java-agent/instrumentation/servlet-2/src/main/java/datadog/trace/instrumentation/servlet2/FilterChain2Instrumentation.java
dd-java-agent/instrumentation/servlet-2/src/main/java/datadog/trace/instrumentation/servlet2/FilterChain2Instrumentation.java
@@ -16,6 +16,7 @@ import datadog.trace.agent.tooling.DDTransformers;
import datadog.trace.agent.tooling.Instrumenter;
import datadog.trace.api.DDSpanTypes;
import datadog.trace.api.DDTags;
+import datadog.trace.context.TraceScope;
import io.opentracing.Scope;
import io.opentracing.Span;
import io.opentracing.SpanContext;
@@ -84,6 +85,10 @@ public final class FilterChain2Instrumentation extends Instrumenter.Configurable
.withTag(DDTags.SPAN_TYPE, DDSpanTypes.WEB_SERVLET)
.startActive(true);
+ if (scope instanceof TraceScope) {
+ ((TraceScope) scope).setAsyncPropagation(true);
+ }
+
final Span span = scope.span();
Tags.COMPONENT.set(span, "java-web-servlet");
Tags.HTTP_METHOD.set(span, ((HttpServletRequest) req).getMethod());

MODIFY
dd-java-agent/instrumentation/servlet-2/src/main/java/datadog/trace/instrumentation/servlet2/HttpServlet2Instrumentation.java
dd-java-agent/instrumentation/servlet-2/src/main/java/datadog/trace/instrumentation/servlet2/HttpServlet2Instrumentation.java
@@ -17,6 +17,7 @@ import datadog.trace.agent.tooling.HelperInjector;
import datadog.trace.agent.tooling.Instrumenter;
import datadog.trace.api.DDSpanTypes;
import datadog.trace.api.DDTags;
+import datadog.trace.context.TraceScope;
import io.opentracing.Scope;
import io.opentracing.Span;
import io.opentracing.SpanContext;
@@ -86,6 +87,10 @@ public final class HttpServlet2Instrumentation extends Instrumenter.Configurable
.withTag(DDTags.SPAN_TYPE, DDSpanTypes.WEB_SERVLET)
.startActive(true);
+ if (scope instanceof TraceScope) {
+ ((TraceScope) scope).setAsyncPropagation(true);
+ }
+
final Span span = scope.span();
Tags.COMPONENT.set(span, "java-web-servlet");
Tags.HTTP_METHOD.set(span, req.getMethod());

MODIFY
dd-java-agent/instrumentation/servlet-3/src/main/java/datadog/trace/instrumentation/servlet3/FilterChain3Instrumentation.java
dd-java-agent/instrumentation/servlet-3/src/main/java/datadog/trace/instrumentation/servlet3/FilterChain3Instrumentation.java
@@ -17,6 +17,7 @@ import datadog.trace.agent.tooling.HelperInjector;
import datadog.trace.agent.tooling.Instrumenter;
import datadog.trace.api.DDSpanTypes;
import datadog.trace.api.DDTags;
+import datadog.trace.context.TraceScope;
import io.opentracing.Scope;
import io.opentracing.Span;
import io.opentracing.SpanContext;
@@ -89,6 +90,10 @@ public final class FilterChain3Instrumentation extends Instrumenter.Configurable
.withTag(DDTags.SPAN_TYPE, DDSpanTypes.WEB_SERVLET)
.startActive(false);
+ if (scope instanceof TraceScope) {
+ ((TraceScope) scope).setAsyncPropagation(true);
+ }
+
final Span span = scope.span();
Tags.COMPONENT.set(span, "java-web-servlet");
Tags.HTTP_METHOD.set(span, ((HttpServletRequest) req).getMethod());

MODIFY
dd-java-agent/instrumentation/servlet-3/src/main/java/datadog/trace/instrumentation/servlet3/HttpServlet3Instrumentation.java
dd-java-agent/instrumentation/servlet-3/src/main/java/datadog/trace/instrumentation/servlet3/HttpServlet3Instrumentation.java
@@ -17,6 +17,7 @@ import datadog.trace.agent.tooling.HelperInjector;
import datadog.trace.agent.tooling.Instrumenter;
import datadog.trace.api.DDSpanTypes;
import datadog.trace.api.DDTags;
+import datadog.trace.context.TraceScope;
import io.opentracing.Scope;
import io.opentracing.Span;
import io.opentracing.SpanContext;
@@ -85,6 +86,10 @@ public final class HttpServlet3Instrumentation extends Instrumenter.Configurable
.withTag(DDTags.SPAN_TYPE, DDSpanTypes.WEB_SERVLET)
.startActive(false);
+ if (scope instanceof TraceScope) {
+ ((TraceScope) scope).setAsyncPropagation(true);
+ }
+
final Span span = scope.span();
Tags.COMPONENT.set(span, "java-web-servlet");
Tags.HTTP_METHOD.set(span, req.getMethod());

Enable async tracking for some non-async frameworks

This will allow tracing of additional work being done inside the servlet context.