From 61a0a6f7774f59c91303beac63c9073c312ade5c Mon Sep 17 00:00:00 2001 From: Theodor Mihalache Date: Mon, 18 Jul 2022 13:14:13 +0300 Subject: [PATCH] OpenTelemetry: NPE in HttpInstrumenterVertxTracer.RouteGetter when request got cancelled Fixed NPE in HttpInstrumenterVertxTracer$RouteGetter when request got cancelled Signed-off-by: Theodor Mihalache --- .../tracing/vertx/HttpInstrumenterVertxTracer.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/extensions/opentelemetry/opentelemetry/runtime/src/main/java/io/quarkus/opentelemetry/runtime/tracing/vertx/HttpInstrumenterVertxTracer.java b/extensions/opentelemetry/opentelemetry/runtime/src/main/java/io/quarkus/opentelemetry/runtime/tracing/vertx/HttpInstrumenterVertxTracer.java index 0e21f0d2bdbc3..eb09123fb61bb 100644 --- a/extensions/opentelemetry/opentelemetry/runtime/src/main/java/io/quarkus/opentelemetry/runtime/tracing/vertx/HttpInstrumenterVertxTracer.java +++ b/extensions/opentelemetry/opentelemetry/runtime/src/main/java/io/quarkus/opentelemetry/runtime/tracing/vertx/HttpInstrumenterVertxTracer.java @@ -4,6 +4,7 @@ import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.HTTP_CLIENT_IP; import static io.quarkus.opentelemetry.runtime.OpenTelemetryConfig.INSTRUMENTATION_NAME; +import java.util.Collections; import java.util.List; import java.util.function.BiConsumer; @@ -151,7 +152,7 @@ public String get(final io.opentelemetry.context.Context context, final HttpRequ return route; } - if (HttpResponseStatus.NOT_FOUND.code() == response.statusCode()) { + if (response != null && HttpResponseStatus.NOT_FOUND.code() == response.statusCode()) { return "/*"; } @@ -231,12 +232,12 @@ public Long requestContentLengthUncompressed(final HttpRequest request, final Ht @Override public Integer statusCode(final HttpRequest request, final HttpResponse response) { - return response.statusCode(); + return response != null ? response.statusCode() : 499; } @Override public Long responseContentLength(final HttpRequest request, final HttpResponse response) { - return getContentLength(response.headers()); + return response != null ? getContentLength(response.headers()) : 0; } @Override @@ -246,7 +247,7 @@ public Long responseContentLengthUncompressed(final HttpRequest request, final H @Override public List responseHeader(final HttpRequest request, final HttpResponse response, final String name) { - return response.headers().getAll(name); + return response != null ? response.headers().getAll(name) : Collections.emptyList(); } private static Long getContentLength(final MultiMap headers) {