Skip to content

Commit

Permalink
Fix NPE in the RabbitMQ instrumentation (#8021)
Browse files Browse the repository at this point in the history
Fixes #8020
  • Loading branch information
Mateusz Rzeszutek committed Mar 9, 2023
1 parent 96fd1d7 commit 0dccc3a
Showing 1 changed file with 12 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@

package io.opentelemetry.javaagent.instrumentation.rabbitmq;

import static java.util.Collections.emptyList;
import static java.util.Collections.singletonList;

import io.opentelemetry.instrumentation.api.instrumenter.messaging.MessagingAttributesGetter;
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import javax.annotation.Nullable;

enum RabbitDeliveryAttributesGetter implements MessagingAttributesGetter<DeliveryRequest, Void> {
Expand Down Expand Up @@ -72,10 +75,14 @@ public String getMessageId(DeliveryRequest request, @Nullable Void unused) {

@Override
public List<String> getMessageHeader(DeliveryRequest request, String name) {
Object value = request.getProperties().getHeaders().get(name);
if (value != null) {
return Collections.singletonList(value.toString());
Map<String, Object> headers = request.getProperties().getHeaders();
if (headers == null) {
return emptyList();
}
Object value = headers.get(name);
if (value == null) {
return emptyList();
}
return Collections.emptyList();
return singletonList(value.toString());
}
}

0 comments on commit 0dccc3a

Please sign in to comment.