Fix flaky jaxrs async test
MODIFY
instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-annotations/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jaxrs/v2_0/JaxrsAnnotationsInstrumentation.java
instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-annotations/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jaxrs/v2_0/JaxrsAnnotationsInstrumentation.java
@@ -151,18 +151,13 @@ public class JaxrsAnnotationsInstrumentation implements TypeInstrumentation {
CompletionStage<?> asyncReturnValue =
returnValue instanceof CompletionStage ? (CompletionStage<?>) returnValue : null;
-
- if (asyncResponse != null && !asyncResponse.isSuspended()) {
- // Clear span from the asyncResponse. Logically this should never happen. Added to be safe.
- VirtualField.find(AsyncResponse.class, AsyncResponseData.class).set(asyncResponse, null);
- }
if (asyncReturnValue != null) {
// span finished by CompletionStageFinishCallback
asyncReturnValue =
asyncReturnValue.handle(
new CompletionStageFinishCallback<>(instrumenter(), context, handlerData));
}
- if ((asyncResponse == null || !asyncResponse.isSuspended()) && asyncReturnValue == null) {
+ if (asyncResponse == null && asyncReturnValue == null) {
instrumenter().end(context, handlerData, null, null);
}
// else span finished by AsyncResponse*Advice

MODIFY
instrumentation/jaxrs/jaxrs-3.0/jaxrs-3.0-annotations/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jaxrs/v3_0/JaxrsAnnotationsInstrumentation.java
instrumentation/jaxrs/jaxrs-3.0/jaxrs-3.0-annotations/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jaxrs/v3_0/JaxrsAnnotationsInstrumentation.java
@@ -151,18 +151,13 @@ public class JaxrsAnnotationsInstrumentation implements TypeInstrumentation {
CompletionStage<?> asyncReturnValue =
returnValue instanceof CompletionStage ? (CompletionStage<?>) returnValue : null;
-
- if (asyncResponse != null && !asyncResponse.isSuspended()) {
- // Clear span from the asyncResponse. Logically this should never happen. Added to be safe.
- VirtualField.find(AsyncResponse.class, AsyncResponseData.class).set(asyncResponse, null);
- }
if (asyncReturnValue != null) {
// span finished by CompletionStageFinishCallback
asyncReturnValue =
asyncReturnValue.handle(
new CompletionStageFinishCallback<>(instrumenter(), context, handlerData));
}
- if ((asyncResponse == null || !asyncResponse.isSuspended()) && asyncReturnValue == null) {
+ if (asyncResponse == null && asyncReturnValue == null) {
instrumenter().end(context, handlerData, null, null);
}
// else span finished by AsyncResponse*Advice

Fix flaky jaxrs async test (#6523)