Catch exception in servlet context getter.
Request may finish after check has been perform but before context has
been read leading to exception in some implementations.
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
@@ -81,7 +81,12 @@ public class JettyHandlerAdvice {
} else {
final AtomicBoolean activated = new AtomicBoolean(false);
if (req.isAsyncStarted()) {
+ try {
req.getAsyncContext().addListener(new TagSettingAsyncListener(activated, span));
+ } catch (final IllegalStateException e) {
+ // org.eclipse.jetty.server.Request may throw an exception here if request became
+ // finished after check above. We just ignore that exception and move on.
+ }
}
if (!req.isAsyncStarted() && activated.compareAndSet(false, true)) {
Tags.HTTP_STATUS.set(span, resp.getStatus());

MODIFY
dd-java-agent/instrumentation/servlet-3/src/main/java/datadog/trace/instrumentation/servlet3/Servlet3Advice.java
dd-java-agent/instrumentation/servlet-3/src/main/java/datadog/trace/instrumentation/servlet3/Servlet3Advice.java
@@ -93,7 +93,12 @@ public class Servlet3Advice {
} else {
final AtomicBoolean activated = new AtomicBoolean(false);
if (req.isAsyncStarted()) {
+ try {
req.getAsyncContext().addListener(new TagSettingAsyncListener(activated, span));
+ } catch (final IllegalStateException e) {
+ // org.eclipse.jetty.server.Request may throw an exception here if request became
+ // finished after check above. We just ignore that exception and move on.
+ }
}
// Check again in case the request finished before adding the listener.
if (!req.isAsyncStarted() && activated.compareAndSet(false, true)) {

Catch exception in servlet context getter.

Request may finish after check has been perform but before context has
been read leading to exception in some implementations.