Stop creating a "top level" servlet span when in a forward/include situation.
Effectively reverting
The expectation is that these are not really separate external requests, but a semantic way of processing a single request.
MODIFY
dd-java-agent/instrumentation/servlet/request-2/src/main/java/datadog/trace/instrumentation/servlet2/Servlet2Advice.java
dd-java-agent/instrumentation/servlet/request-2/src/main/java/datadog/trace/instrumentation/servlet2/Servlet2Advice.java
@@ -2,7 +2,6 @@ package datadog.trace.instrumentation.servlet2;
import static datadog.trace.agent.decorator.HttpServerDecorator.DD_SPAN_ATTRIBUTE;
import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.activateSpan;
-import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.activeSpan;
import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.propagate;
import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.startSpan;
import static datadog.trace.instrumentation.servlet2.HttpServletRequestExtractAdapter.GETTER;
@@ -29,11 +28,11 @@ public class Servlet2Advice {
@Advice.Argument(0) final ServletRequest request,
@Advice.Argument(value = 1, readOnly = false, typing = Assigner.Typing.DYNAMIC)
ServletResponse response) {
- final boolean hasActiveTrace = activeSpan() != null;
+
final boolean hasServletTrace = request.getAttribute(DD_SPAN_ATTRIBUTE) instanceof AgentSpan;
final boolean invalidRequest = !(request instanceof HttpServletRequest);
- if (invalidRequest || (hasActiveTrace && hasServletTrace)) {
- // Tracing might already be applied by the FilterChain. If so ignore this.
+ if (invalidRequest || hasServletTrace) {
+ // Tracing might already be applied by the FilterChain or a parent request (forward/include).
return null;
}

MODIFY
dd-java-agent/instrumentation/servlet/request-3/src/main/java/datadog/trace/instrumentation/servlet3/Servlet3Advice.java
dd-java-agent/instrumentation/servlet/request-3/src/main/java/datadog/trace/instrumentation/servlet3/Servlet3Advice.java
@@ -2,7 +2,6 @@ package datadog.trace.instrumentation.servlet3;
import static datadog.trace.agent.decorator.HttpServerDecorator.DD_SPAN_ATTRIBUTE;
import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.activateSpan;
-import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.activeSpan;
import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.propagate;
import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.startSpan;
import static datadog.trace.instrumentation.servlet3.HttpServletRequestExtractAdapter.GETTER;
@@ -29,11 +28,10 @@ public class Servlet3Advice {
@Advice.Argument(0) final ServletRequest request,
@Advice.Argument(1) final ServletResponse response) {
- final boolean hasActiveTrace = activeSpan() != null;
final boolean hasServletTrace = request.getAttribute(DD_SPAN_ATTRIBUTE) instanceof AgentSpan;
final boolean invalidRequest = !(request instanceof HttpServletRequest);
- if (invalidRequest || (hasActiveTrace && hasServletTrace)) {
- // Tracing might already be applied by the FilterChain. If so ignore this.
+ if (invalidRequest || hasServletTrace) {
+ // Tracing might already be applied by the FilterChain or a parent request (forward/include).
return null;
}

MODIFY
dd-java-agent/instrumentation/servlet/src/main/java/datadog/trace/instrumentation/servlet/dispatcher/RequestDispatcherInstrumentation.java
dd-java-agent/instrumentation/servlet/src/main/java/datadog/trace/instrumentation/servlet/dispatcher/RequestDispatcherInstrumentation.java
@@ -68,7 +68,7 @@ public final class RequestDispatcherInstrumentation extends Instrumenter.Default
.and(takesArgument(0, named("javax.servlet.ServletRequest")))
.and(takesArgument(1, named("javax.servlet.ServletResponse")))
.and(isPublic()),
- RequestDispatcherAdvice.class.getName());
+ getClass().getName() + "$RequestDispatcherAdvice");
}
public static class RequestDispatcherAdvice {

MODIFY
dd-java-agent/instrumentation/servlet/src/main/java/datadog/trace/instrumentation/servlet/filter/FilterInstrumentation.java
dd-java-agent/instrumentation/servlet/src/main/java/datadog/trace/instrumentation/servlet/filter/FilterInstrumentation.java
@@ -61,7 +61,7 @@ public final class FilterInstrumentation extends Instrumenter.Default {
.and(takesArgument(0, named("javax.servlet.ServletRequest")))
.and(takesArgument(1, named("javax.servlet.ServletResponse")))
.and(isPublic()),
- FilterAdvice.class.getName());
+ getClass().getName() + "$FilterAdvice");
}
public static class FilterAdvice {

MODIFY
dd-java-agent/instrumentation/servlet/src/main/java/datadog/trace/instrumentation/servlet/http/HttpServletInstrumentation.java
dd-java-agent/instrumentation/servlet/src/main/java/datadog/trace/instrumentation/servlet/http/HttpServletInstrumentation.java
@@ -67,7 +67,7 @@ public final class HttpServletInstrumentation extends Instrumenter.Default {
.and(takesArgument(0, named("javax.servlet.http.HttpServletRequest")))
.and(takesArgument(1, named("javax.servlet.http.HttpServletResponse")))
.and(isProtected().or(isPublic())),
- HttpServletAdvice.class.getName());
+ getClass().getName() + "$HttpServletAdvice");
}
public static class HttpServletAdvice {

Stop creating a "top level" servlet span when in a forward/include situation.

Effectively reverting https://github.com/DataDog/dd-trace-java/commit/6703bd96bbbb2527dc7788a8785635563a3a2988

The expectation is that these are not really separate external requests, but a semantic way of processing a single request.