From 79acca7ee8a456726018fe2c28584c4deebdb196 Mon Sep 17 00:00:00 2001 From: Lauri Tulmin Date: Fri, 2 Sep 2022 13:28:04 +0300 Subject: [PATCH] Fix flaky jaxrs async test (#6523) --- .../jaxrs/v2_0/JaxrsAnnotationsInstrumentation.java | 7 +------ .../jaxrs/v3_0/JaxrsAnnotationsInstrumentation.java | 7 +------ 2 files changed, 2 insertions(+), 12 deletions(-) diff --git a/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-annotations/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jaxrs/v2_0/JaxrsAnnotationsInstrumentation.java b/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-annotations/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jaxrs/v2_0/JaxrsAnnotationsInstrumentation.java index 5f0a43ed53b5..9caa2817c560 100644 --- a/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-annotations/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jaxrs/v2_0/JaxrsAnnotationsInstrumentation.java +++ b/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 static void stopSpan( 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 diff --git a/instrumentation/jaxrs/jaxrs-3.0/jaxrs-3.0-annotations/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jaxrs/v3_0/JaxrsAnnotationsInstrumentation.java b/instrumentation/jaxrs/jaxrs-3.0/jaxrs-3.0-annotations/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jaxrs/v3_0/JaxrsAnnotationsInstrumentation.java index 61f6055424ff..7ade02505b6b 100644 --- a/instrumentation/jaxrs/jaxrs-3.0/jaxrs-3.0-annotations/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jaxrs/v3_0/JaxrsAnnotationsInstrumentation.java +++ b/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 static void stopSpan( 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