Polish
This commit is contained in:
@@ -456,6 +456,9 @@ baggage and propagation keys. E.g. `spring.sleuth.log.slf4j.whitelisted-mdc-keys
|
||||
|
||||
IMPORTANT: Remember that adding entries to MDC can drastically decrease the performance of your application!
|
||||
|
||||
If you want to add the baggage entries as tags, to make it possible to search for spans via the baggage entries, you can set the value of
|
||||
`spring.sleuth.propagation.tag.whitelisted-keys` with a list of whitelisted baggage keys. To disable the feature you have to pass the `spring.sleuth.propagation.tag.enabled=false` property.
|
||||
|
||||
==== Extracting a Propagated Context
|
||||
|
||||
The `TraceContext.Extractor<C>` reads trace identifiers and sampling status from an incoming request or message.
|
||||
|
||||
@@ -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 {
|
||||
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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) -> {
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user