Better handle Jetty async calls
Do same thing we do for servlets
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
@@ -78,19 +78,20 @@ public class JettyHandlerAdvice {
}
scope.close();
span.finish(); // Finish the span manually since finishSpanOnClose was false
- } else if (req.isAsyncStarted()) {
+ } else {
final AtomicBoolean activated = new AtomicBoolean(false);
- // what if async is already finished? This would not be called
+ if (req.isAsyncStarted()) {
req.getAsyncContext().addListener(new TagSettingAsyncListener(activated, span));
- scope.close();
- } else {
+ }
+ if (!req.isAsyncStarted() && activated.compareAndSet(false, true)) {
Tags.HTTP_STATUS.set(span, resp.getStatus());
if (scope instanceof TraceScope) {
((TraceScope) scope).setAsyncPropagation(false);
}
- scope.close();
span.finish(); // Finish the span manually since finishSpanOnClose was false
}
+ scope.close();
+ }
}
}
}

Better handle Jetty async calls

Do same thing we do for servlets