Spring Cloud Sleuth is treating comma separated Stream headers in an invalid way
without this change when you pass Stream message headers that are comma separated, Sleuth fails to add proper binding properties for them with this change we try to first split the headers (assuming that they might be comma based) and then we generate the proper header binding properties fixes #742
This commit is contained in:
@@ -84,7 +84,11 @@ public class StreamEnvironmentPostProcessor implements EnvironmentPostProcessor
|
||||
private int findStartIndex(ConfigurableEnvironment environment, String binder) {
|
||||
String prefix = "spring.cloud.stream." + binder + ".binder.headers";
|
||||
int i = 0;
|
||||
while (environment.getProperty(prefix + "[" + i + "]")!=null) {
|
||||
String oldHeaders = environment.getProperty(prefix);
|
||||
if (oldHeaders != null) {
|
||||
i = oldHeaders.split(",").length;
|
||||
}
|
||||
while (environment.getProperty(prefix + "[" + i + "]") != null) {
|
||||
i++;
|
||||
}
|
||||
return i;
|
||||
|
||||
@@ -16,6 +16,8 @@
|
||||
|
||||
package org.springframework.cloud.sleuth.stream;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
@@ -27,8 +29,6 @@ import org.springframework.cloud.sleuth.instrument.messaging.TraceMessageHeaders
|
||||
import org.springframework.core.env.ConfigurableEnvironment;
|
||||
import org.springframework.core.env.StandardEnvironment;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* @author Dave Syer
|
||||
*
|
||||
@@ -57,6 +57,16 @@ public class StreamEnvironmentPostProcessorTests {
|
||||
.isEqualTo(TraceMessageHeaders.SPAN_ID_NAME);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void should_append_tracing_headers_to_existing_ones_in_single_line() {
|
||||
EnvironmentTestUtils.addEnvironment(this.environment,
|
||||
"spring.cloud.stream.test.binder.headers=foo,bar");
|
||||
postProcess();
|
||||
assertThat(this.environment
|
||||
.getProperty("spring.cloud.stream.test.binder.headers[2]"))
|
||||
.isEqualTo(TraceMessageHeaders.SPAN_ID_NAME);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void should_not_append_tracing_headers_if_they_are_already_appended() {
|
||||
postProcess();
|
||||
|
||||
Reference in New Issue
Block a user