Fix flaky jersey jaxrs async test #6523
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
https://ge.opentelemetry.io/s/tr2jbhq7r4r2g/tests/:instrumentation:jaxrs:jaxrs-2.0:jaxrs-2.0-jersey-2.0:javaagent:test/JerseyJettyHttpServerTest/should%20handle%20failing%20AsyncResponse?expanded-stacktrace=WyIwLTEiXQ&top-execution=1
See tested endpoint
opentelemetry-java-instrumentation/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-common/testing/src/main/groovy/test/JaxRsTestResource.groovy
Lines 119 to 139 in c04a6a3
opentelemetry-java-instrumentation/instrumentation/jaxrs/jaxrs-common/testing/src/main/groovy/AbstractJaxRsHttpServerTest.groovy
Lines 120 to 159 in c04a6a3
For the
failed
test span should be ended inopentelemetry-java-instrumentation/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-annotations/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jaxrs/v2_0/JaxrsAsyncResponseInstrumentation.java
Lines 73 to 83 in c04a6a3
response.resume(new Exception("failure"))
call exits. Apparently it is possible that this call fromCompletableFuture.runAsync
thread runs concurrently with the main thread that is exiting theJaxRsTestResource.asyncOp
method and the span is ended inopentelemetry-java-instrumentation/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-annotations/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jaxrs/v2_0/JaxrsAnnotationsInstrumentation.java
Line 166 in c04a6a3
This change makes it so that when a jax-rs method has async response span is only ended when the async response is resumed or canceled. Exiting the jax-rs method will not end the span if the method has an async response.
Hopefully also fixes similar failure in resteasy tests
https://ge.opentelemetry.io/s/be55uszpcc2fk/tests/:instrumentation:jaxrs:jaxrs-3.0:jaxrs-3.0-resteasy-6.0:javaagent:test/ResteasyHttpServerTest/should%20handle%20failing%20AsyncResponse?expanded-stacktrace=WyIwIiwiMC0xIl0&top-execution=1