This commit is contained in:
Marcin Grzejszczak
2018-12-17 10:59:55 +01:00
parent 7c04ee4c7f
commit 7a3e7e01f5
6 changed files with 26 additions and 20 deletions

View File

@@ -35,7 +35,7 @@ import org.springframework.context.annotation.Configuration;
public class SleuthTagPropagationAutoConfiguration {
@Configuration
@ConditionalOnProperty(value = "spring.sleuth.propagation.tag.enabled")
@ConditionalOnProperty(value = "spring.sleuth.propagation.tag.enabled", matchIfMissing = true)
@EnableConfigurationProperties(SleuthTagPropagationProperties.class)
protected static class TagPropagationConfiguration {

View File

@@ -16,11 +16,11 @@
package org.springframework.cloud.sleuth.propagation;
import org.springframework.boot.context.properties.ConfigurationProperties;
import java.util.ArrayList;
import java.util.List;
import org.springframework.boot.context.properties.ConfigurationProperties;
/**
* Configuration properties of tag propagation.
*
@@ -50,7 +50,7 @@ public class SleuthTagPropagationProperties {
}
public List<String> getWhitelistedKeys() {
return whitelistedKeys;
return this.whitelistedKeys;
}
public void setWhitelistedKeys(List<String> whitelistedKeys) {

View File

@@ -16,15 +16,16 @@
package org.springframework.cloud.sleuth.propagation;
import java.util.AbstractMap;
import java.util.Collection;
import java.util.stream.Stream;
import brave.handler.FinishedSpanHandler;
import brave.handler.MutableSpan;
import brave.propagation.ExtraFieldPropagation;
import brave.propagation.TraceContext;
import org.springframework.cloud.sleuth.autoconfig.SleuthProperties;
import java.util.AbstractMap;
import java.util.Collection;
import java.util.stream.Stream;
import org.springframework.cloud.sleuth.autoconfig.SleuthProperties;
import static java.util.Objects.nonNull;
@@ -49,7 +50,7 @@ public class TagPropagationFinishedSpanHandler extends FinishedSpanHandler {
@Override
public boolean handle(TraceContext context, MutableSpan span) {
Stream.of(sleuthProperties.getBaggageKeys(), sleuthProperties.getPropagationKeys())
Stream.of(this.sleuthProperties.getBaggageKeys(), this.sleuthProperties.getPropagationKeys())
.flatMap(Collection::stream)
.filter(key -> this.tagPropagationProperties.getWhitelistedKeys().contains(key))
.map(baggageItemKey -> new AbstractMap.SimpleEntry<>(baggageItemKey,

View File

@@ -37,8 +37,10 @@ public class SleuthTagPropagationAutoConfigurationTests {
}
@Test
public void shouldNotCreateHandlerByDefault() {
public void shouldNotCreateHandlerByDisablingIt() {
this.contextRunner
.withPropertyValues("spring.sleuth.propagation.tag.whitelisted-keys=some-key")
.withPropertyValues("spring.sleuth.propagation.tag.enabled=false")
.withUserConfiguration(TraceAutoConfiguration.class)
.run((context) -> {
assertThat(context).doesNotHaveBean(TagPropagationFinishedSpanHandler.class);
@@ -46,9 +48,8 @@ public class SleuthTagPropagationAutoConfigurationTests {
}
@Test
public void shouldCreateHandlerWhenEnabled() {
public void shouldCreateHandler() {
this.contextRunner
.withPropertyValues("spring.sleuth.propagation.tag.enabled=true")
.withPropertyValues("spring.sleuth.propagation.tag.whitelisted-keys=some-key")
.withUserConfiguration(TraceAutoConfiguration.class)
.run((context) -> {

View File

@@ -15,6 +15,9 @@
*/
package org.springframework.cloud.sleuth.propagation;
import java.util.List;
import java.util.Map;
import brave.ScopedSpan;
import brave.Tracer;
import brave.propagation.ExtraFieldPropagation;
@@ -23,6 +26,7 @@ import brave.sampler.Sampler;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.test.context.SpringBootTest;
@@ -31,9 +35,6 @@ import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.test.context.junit4.SpringRunner;
import java.util.List;
import java.util.Map;
import static org.assertj.core.api.Assertions.assertThat;
/**
@@ -63,9 +64,9 @@ public class TagPropagationFinishedSpanHandlerTest {
@Before
public void setUp() {
arrayListSpanReporter.clear();
span = tracer.startScopedSpan("my-scoped-span");
TraceContext context = span.context();
this.arrayListSpanReporter.clear();
this.span = this.tracer.startScopedSpan("my-scoped-span");
TraceContext context = this.span.context();
ExtraFieldPropagation.set(context, BAGGAGE_KEY, BAGGAGE_VALUE);
ExtraFieldPropagation.set(context, PROPAGATION_KEY, PROPAGATION_VALUE);
ExtraFieldPropagation.set(context, "others-propagation", "some value");
@@ -73,9 +74,9 @@ public class TagPropagationFinishedSpanHandlerTest {
@Test
public void shouldReportWithBaggageInTags() {
span.finish();
this.span.finish();
List<zipkin2.Span> spans = arrayListSpanReporter.getSpans();
List<zipkin2.Span> spans = this.arrayListSpanReporter.getSpans();
assertThat(spans).hasSize(1);
Map<String, String> tags = spans.get(0).tags();
assertThat(tags).hasSize(2);