@@ -1,12 +1,12 @@
|
||||
package org.springframework.cloud.sleuth.instrument.messaging;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
|
||||
import org.springframework.cloud.sleuth.Span;
|
||||
import org.springframework.cloud.sleuth.SpanTextMap;
|
||||
import org.springframework.cloud.sleuth.util.TextMapUtil;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
|
||||
/**
|
||||
* Default implementation for messaging
|
||||
*
|
||||
@@ -62,7 +62,7 @@ public class HeaderBasedMessagingExtractor implements MessagingSpanTextMapExtrac
|
||||
setParentIdIfApplicable(carrier, spanBuilder, TraceMessageHeaders.PARENT_ID_NAME);
|
||||
spanBuilder.remote(true);
|
||||
for (Map.Entry<String, String> entry : carrier.entrySet()) {
|
||||
if (entry.getKey().startsWith(Span.SPAN_BAGGAGE_HEADER_PREFIX + TraceMessageHeaders.HEADER_DELIMITER)) {
|
||||
if (entry.getKey().toLowerCase().startsWith(Span.SPAN_BAGGAGE_HEADER_PREFIX + TraceMessageHeaders.HEADER_DELIMITER)) {
|
||||
spanBuilder.baggage(unprefixedKey(entry.getKey()), entry.getValue());
|
||||
}
|
||||
}
|
||||
@@ -82,7 +82,7 @@ public class HeaderBasedMessagingExtractor implements MessagingSpanTextMapExtrac
|
||||
}
|
||||
|
||||
private String unprefixedKey(String key) {
|
||||
return key.substring(key.indexOf(TraceMessageHeaders.HEADER_DELIMITER) + 1);
|
||||
return key.substring(key.indexOf(TraceMessageHeaders.HEADER_DELIMITER) + 1).toLowerCase();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
package org.springframework.cloud.sleuth.instrument.web;
|
||||
|
||||
import java.lang.invoke.MethodHandles;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.cloud.sleuth.Span;
|
||||
import org.springframework.cloud.sleuth.SpanTextMap;
|
||||
import org.springframework.cloud.sleuth.util.TextMapUtil;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.lang.invoke.MethodHandles;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* Default implementation, compatible with Zipkin propagation.
|
||||
*
|
||||
@@ -101,7 +101,7 @@ public class ZipkinHttpSpanExtractor implements HttpSpanExtractor {
|
||||
span.exportable(false);
|
||||
}
|
||||
for (Map.Entry<String, String> entry : carrier.entrySet()) {
|
||||
if (entry.getKey().startsWith(Span.SPAN_BAGGAGE_HEADER_PREFIX + HEADER_DELIMITER)) {
|
||||
if (entry.getKey().toLowerCase().startsWith(Span.SPAN_BAGGAGE_HEADER_PREFIX + HEADER_DELIMITER)) {
|
||||
span.baggage(unprefixedKey(entry.getKey()), entry.getValue());
|
||||
}
|
||||
}
|
||||
@@ -109,7 +109,7 @@ public class ZipkinHttpSpanExtractor implements HttpSpanExtractor {
|
||||
}
|
||||
|
||||
private String unprefixedKey(String key) {
|
||||
return key.substring(key.indexOf(HEADER_DELIMITER) + 1);
|
||||
return key.substring(key.indexOf(HEADER_DELIMITER) + 1).toLowerCase();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -16,16 +16,16 @@
|
||||
|
||||
package org.springframework.cloud.sleuth.instrument.messaging;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.cloud.sleuth.Span;
|
||||
import org.springframework.messaging.MessageHeaders;
|
||||
import org.springframework.messaging.support.MessageBuilder;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
|
||||
import static org.assertj.core.api.Assertions.fail;
|
||||
import static org.springframework.cloud.sleuth.assertions.SleuthAssertions.then;
|
||||
|
||||
@@ -64,6 +64,21 @@ public class MessagingSpanExtractorTests {
|
||||
then(span.traceIdString()).isEqualTo(traceId128);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void should_propagate_baggage_headers() {
|
||||
String traceId128 = "463ac35c9f6413ad48485a3953bb6124";
|
||||
|
||||
Span span = this.extractor.joinTrace(
|
||||
new MessagingTextMap(MessageBuilder.withPayload("")
|
||||
.copyHeaders(headers(traceId128, randomId()))));
|
||||
|
||||
then(span)
|
||||
.hasBaggageItem("foo", "foofoo")
|
||||
.hasBaggageItem("bar", "barbar");
|
||||
then(span.getBaggageItem("Foo")).isEqualTo("foofoo");
|
||||
then(span.getBaggageItem("BAr")).isEqualTo("barbar");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void should_set_random_spanid_if_header_value_is_invalid() {
|
||||
try {
|
||||
@@ -107,6 +122,8 @@ public class MessagingSpanExtractorTests {
|
||||
if (StringUtils.hasText(parentId)) {
|
||||
map.put(TraceMessageHeaders.PARENT_ID_NAME, parentId);
|
||||
}
|
||||
map.put("baggage_foo", "foofoo");
|
||||
map.put("BAGGAGE_BAR", "barbar");
|
||||
return new MessageHeaders(map);
|
||||
}
|
||||
|
||||
|
||||
@@ -73,11 +73,13 @@ public class MultipleHopsIntegrationTests {
|
||||
//tag::baggage[]
|
||||
Span initialSpan = this.tracer.createSpan("span");
|
||||
initialSpan.setBaggageItem("foo", "bar");
|
||||
initialSpan.setBaggageItem("UPPER_CASE", "someValue");
|
||||
//end::baggage[]
|
||||
|
||||
try {
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.put("baggage-baz", Collections.singletonList("baz"));
|
||||
headers.put("BAGGAGE-bizarreCASE", Collections.singletonList("value"));
|
||||
RequestEntity requestEntity = new RequestEntity(headers, HttpMethod.GET,
|
||||
URI.create("http://localhost:" + this.config.port + "/greeting"));
|
||||
this.restTemplate.exchange(requestEntity, String.class);
|
||||
@@ -85,7 +87,9 @@ public class MultipleHopsIntegrationTests {
|
||||
await().atMost(5, SECONDS).until(() -> {
|
||||
then(new ListOfSpans(this.arrayListSpanAccumulator.getSpans()))
|
||||
.everySpanHasABaggage("foo", "bar")
|
||||
.anySpanHasABaggage("baz", "baz");
|
||||
.everySpanHasABaggage("upper_case", "someValue")
|
||||
.anySpanHasABaggage("baz", "baz")
|
||||
.anySpanHasABaggage("bizarrecase", "value");
|
||||
});
|
||||
} finally {
|
||||
this.tracer.close(initialSpan);
|
||||
|
||||
Reference in New Issue
Block a user