Better handle Jetty async calls
Do same thing we do for servlets
@@ -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();
+ }
}
}
}
