Skip to content

Commit

Permalink
Fix RabbitMQ instrumentation consumption on empty headers (open-telem…
Browse files Browse the repository at this point in the history
…etry#4903)

* Handle null on headers getters

* early returns
  • Loading branch information
Asafb26 authored and RashmiRam committed May 23, 2022
1 parent a696d05 commit 926a18c
Showing 1 changed file with 16 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,33 @@

import io.opentelemetry.context.propagation.TextMapGetter;
import java.util.Collections;
import java.util.Map;

enum DeliveryRequestGetter implements TextMapGetter<DeliveryRequest> {
INSTANCE;

@Override
public Iterable<String> keys(DeliveryRequest carrier) {
return carrier != null
? carrier.getProperties().getHeaders().keySet()
: Collections.emptyList();
if (carrier == null) {
return Collections.emptyList();
}
Map<String, Object> 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<String, Object> headers = carrier.getProperties().getHeaders();
if (headers == null) {
return null;
}
Object obj = headers.get(key);
return obj == null ? null : obj.toString();
}
}

0 comments on commit 926a18c

Please sign in to comment.