From 926a18c20e8e983e09a1ac9d882757f2fb6f5423 Mon Sep 17 00:00:00 2001 From: Asaf Ben Aharon Date: Tue, 14 Dec 2021 22:01:16 +0200 Subject: [PATCH] Fix RabbitMQ instrumentation consumption on empty headers (#4903) * Handle null on headers getters * early returns --- .../rabbitmq/DeliveryRequestGetter.java | 23 +++++++++++++------ 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/instrumentation/rabbitmq-2.7/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/rabbitmq/DeliveryRequestGetter.java b/instrumentation/rabbitmq-2.7/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/rabbitmq/DeliveryRequestGetter.java index 888ba142b35e..def8878644ec 100644 --- a/instrumentation/rabbitmq-2.7/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/rabbitmq/DeliveryRequestGetter.java +++ b/instrumentation/rabbitmq-2.7/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/rabbitmq/DeliveryRequestGetter.java @@ -7,24 +7,33 @@ import io.opentelemetry.context.propagation.TextMapGetter; import java.util.Collections; +import java.util.Map; enum DeliveryRequestGetter implements TextMapGetter { INSTANCE; @Override public Iterable keys(DeliveryRequest carrier) { - return carrier != null - ? carrier.getProperties().getHeaders().keySet() - : Collections.emptyList(); + if (carrier == null) { + return Collections.emptyList(); + } + Map headers = carrier.getProperties().getHeaders(); + if (headers == null) { + return Collections.emptyList(); + } + return headers.keySet(); } @Override public String get(DeliveryRequest carrier, String key) { - if (carrier != null) { - Object obj = carrier.getProperties().getHeaders().get(key); - return obj == null ? null : obj.toString(); - } else { + if (carrier == null) { + return null; + } + Map headers = carrier.getProperties().getHeaders(); + if (headers == null) { return null; } + Object obj = headers.get(key); + return obj == null ? null : obj.toString(); } }