OpenLiberty / open-liberty

Open Liberty is a highly composable, fast to start, dynamic application server runtime environment
https://openliberty.io
Eclipse Public License 2.0
1.15k stars 587 forks source link

Nullpointer exception with opentelemetry agent and async request #23476

Open sdehors-ibm opened 1 year ago

sdehors-ibm commented 1 year ago

Describe the bug
Opentelemetry agent (with latest version 1.20.1) throws exceptions when tracing jax-rs async calls

[INFO] [WARNING ] SRVE8504W: The following uncaught exception was thrown by the AsyncListener: [io.opentelemetry.javaagent.instrumentation.servlet.v3_0.Servlet3Accessor$Listener] during onComplete: [java.lang.NullPointerException
[INFO]  at io.opentelemetry.javaagent.instrumentation.servlet.v3_0.Servlet3Accessor.isResponseCommitted(Servlet3Accessor.java:70)
[INFO]  at io.opentelemetry.javaagent.instrumentation.servlet.v3_0.Servlet3Accessor.isResponseCommitted(Servlet3Accessor.java:19)
[INFO]  at io.opentelemetry.javaagent.instrumentation.servlet.ServletHttpAttributesGetter.statusCode(ServletHttpAttributesGetter.java:72)
[INFO]  at io.opentelemetry.javaagent.instrumentation.servlet.ServletHttpAttributesGetter.statusCode(ServletHttpAttributesGetter.java:12)
[INFO]  at io.opentelemetry.javaagent.shaded.instrumentation.api.instrumenter.http.HttpCommonAttributesExtractor.onEnd(HttpCommonAttributesExtractor.java:65)
[INFO]  at io.opentelemetry.javaagent.shaded.instrumentation.api.instrumenter.http.HttpServerAttributesExtractor.onEnd(HttpServerAttributesExtractor.java:132)
[INFO]  at io.opentelemetry.javaagent.shaded.instrumentation.api.instrumenter.Instrumenter.doEnd(Instrumenter.java:224)
[INFO]  at io.opentelemetry.javaagent.shaded.instrumentation.api.instrumenter.Instrumenter.end(Instrumenter.java:144)
[INFO]  at io.opentelemetry.javaagent.instrumentation.servlet.AsyncRequestCompletionListener.onComplete(AsyncRequestCompletionListener.java:37)
[INFO]  at io.opentelemetry.javaagent.instrumentation.servlet.v3_0.Servlet3Accessor$Listener.onComplete(Servlet3Accessor.java:82)
[INFO]  at com.ibm.ws.webcontainer.async.AsyncListenerEntry.invokeOnComplete(AsyncListenerEntry.java:87)
[INFO]  at [internal classes]
[INFO] ]

Steps to Reproduce
start liberty with jvm option: -javaagent:/opentelemetry-javaagent-1.20.1.jar

This jaxrs endpoint reproduces the bug:

@GET
 @Produces(MediaType.APPLICATION_JSON)
 @Path("async")
 public CompletableFuture<String> getExternalResourceAsync(@QueryParam("wait") long wait) throws URISyntaxException {

        HttpRequest get = HttpRequest.newBuilder()
                .uri(new URI("https://github.com"))
                .GET()
                .build();

        CompletableFuture<HttpResponse<String>> response = client.sendAsync(get, BodyHandlers.ofString());

        return response.thenApply(r -> r.statusCode() + " : " + r.body());
    }

Expected behavior
There should be no exception thrown and tracing should work.

It seems the async event passed to AsyncListener does not contain any response.

Diagnostic information:



**Additional context**  
The problem is not visible with restfulWS-3.0
florian-signoret-ibm commented 1 year ago

Hello, It would be great to have this fixed, it is preventing me from using telemetry on my env. Thanks!! Florian

pemily commented 1 year ago

Same, I hope it will be fixed soon