Add traceId/spanId as request attributes
MODIFY
dd-java-agent/instrumentation/grizzly-2/src/main/java/datadog/trace/instrumentation/grizzly/GrizzlyHttpHandlerInstrumentation.java
dd-java-agent/instrumentation/grizzly-2/src/main/java/datadog/trace/instrumentation/grizzly/GrizzlyHttpHandlerInstrumentation.java
@@ -13,6 +13,8 @@ import static net.bytebuddy.matcher.ElementMatchers.takesArgument;
import com.google.auto.service.AutoService;
import datadog.trace.agent.tooling.Instrumenter;
+import datadog.trace.api.CorrelationIdentifier;
+import datadog.trace.api.GlobalTracer;
import datadog.trace.bootstrap.instrumentation.api.AgentScope;
import datadog.trace.bootstrap.instrumentation.api.AgentSpan;
import datadog.trace.bootstrap.instrumentation.api.AgentSpan.Context;
@@ -81,6 +83,8 @@ public class GrizzlyHttpHandlerInstrumentation extends Instrumenter.Default {
scope.setAsyncPropagation(true);
request.setAttribute(DD_SPAN_ATTRIBUTE, span);
+ request.setAttribute(CorrelationIdentifier.getTraceIdKey(), GlobalTracer.get().getTraceId());
+ request.setAttribute(CorrelationIdentifier.getSpanIdKey(), GlobalTracer.get().getSpanId());
request.addAfterServiceListener(SpanClosingListener.LISTENER);
return scope;

MODIFY
dd-java-agent/instrumentation/jetty-8/src/main/java/datadog/trace/instrumentation/jetty8/JettyHandlerAdvice.java
dd-java-agent/instrumentation/jetty-8/src/main/java/datadog/trace/instrumentation/jetty8/JettyHandlerAdvice.java
@@ -7,7 +7,9 @@ import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.startSpan;
import static datadog.trace.instrumentation.jetty8.HttpServletRequestExtractAdapter.GETTER;
import static datadog.trace.instrumentation.jetty8.JettyDecorator.DECORATE;
+import datadog.trace.api.CorrelationIdentifier;
import datadog.trace.api.DDTags;
+import datadog.trace.api.GlobalTracer;
import datadog.trace.bootstrap.instrumentation.api.AgentScope;
import datadog.trace.bootstrap.instrumentation.api.AgentSpan;
import datadog.trace.bootstrap.instrumentation.api.Tags;
@@ -41,6 +43,8 @@ public class JettyHandlerAdvice {
final AgentScope scope = activateSpan(span, false);
scope.setAsyncPropagation(true);
req.setAttribute(DD_SPAN_ATTRIBUTE, span);
+ req.setAttribute(CorrelationIdentifier.getTraceIdKey(), GlobalTracer.get().getTraceId());
+ req.setAttribute(CorrelationIdentifier.getSpanIdKey(), GlobalTracer.get().getSpanId());
return scope;
}

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
@@ -7,7 +7,9 @@ import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.startSpan;
import static datadog.trace.instrumentation.servlet2.HttpServletRequestExtractAdapter.GETTER;
import static datadog.trace.instrumentation.servlet2.Servlet2Decorator.DECORATE;
+import datadog.trace.api.CorrelationIdentifier;
import datadog.trace.api.DDTags;
+import datadog.trace.api.GlobalTracer;
import datadog.trace.bootstrap.InstrumentationContext;
import datadog.trace.bootstrap.instrumentation.api.AgentScope;
import datadog.trace.bootstrap.instrumentation.api.AgentSpan;
@@ -56,10 +58,15 @@ public class Servlet2Advice {
DECORATE.onConnection(span, httpServletRequest);
DECORATE.onRequest(span, httpServletRequest);
- httpServletRequest.setAttribute(DD_SPAN_ATTRIBUTE, span);
-
final AgentScope scope = activateSpan(span, true);
scope.setAsyncPropagation(true);
+
+ httpServletRequest.setAttribute(DD_SPAN_ATTRIBUTE, span);
+ httpServletRequest.setAttribute(
+ CorrelationIdentifier.getTraceIdKey(), GlobalTracer.get().getTraceId());
+ httpServletRequest.setAttribute(
+ CorrelationIdentifier.getSpanIdKey(), GlobalTracer.get().getSpanId());
+
return scope;
}

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
@@ -7,7 +7,9 @@ import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.startSpan;
import static datadog.trace.instrumentation.servlet3.HttpServletRequestExtractAdapter.GETTER;
import static datadog.trace.instrumentation.servlet3.Servlet3Decorator.DECORATE;
+import datadog.trace.api.CorrelationIdentifier;
import datadog.trace.api.DDTags;
+import datadog.trace.api.GlobalTracer;
import datadog.trace.bootstrap.InstrumentationContext;
import datadog.trace.bootstrap.instrumentation.api.AgentScope;
import datadog.trace.bootstrap.instrumentation.api.AgentSpan;
@@ -51,10 +53,15 @@ public class Servlet3Advice {
DECORATE.onConnection(span, httpServletRequest);
DECORATE.onRequest(span, httpServletRequest);
- httpServletRequest.setAttribute(DD_SPAN_ATTRIBUTE, span);
-
final AgentScope scope = activateSpan(span, false);
scope.setAsyncPropagation(true);
+
+ httpServletRequest.setAttribute(DD_SPAN_ATTRIBUTE, span);
+ httpServletRequest.setAttribute(
+ CorrelationIdentifier.getTraceIdKey(), GlobalTracer.get().getTraceId());
+ httpServletRequest.setAttribute(
+ CorrelationIdentifier.getSpanIdKey(), GlobalTracer.get().getSpanId());
+
return scope;
}

Add traceId/spanId as request attributes