diff --git a/README.adoc b/README.adoc index 24bcb627b..9aea84d9b 100644 --- a/README.adoc +++ b/README.adoc @@ -383,18 +383,20 @@ spring.sleuth: baggage-keys: - baz - bizarrecase - propagation-keys: - - foo - - upper_case + local-keys: + - bp + remote-keys: + - country-code + - x-vcap-request-id ---- .The code [source,java] ---- -initialSpan.tag("foo", - ExtraFieldPropagation.get(initialSpan.context(), "foo")); -initialSpan.tag("UPPER_CASE", - ExtraFieldPropagation.get(initialSpan.context(), "UPPER_CASE")); +static final BaggageField COUNTRY_CODE = BaggageField.create("country-code"); + +COUNTRY_CODE.updateValue(span.context(), "FO"); +Tags.BAGGAGE_FIELD.tag(COUNTRY_CODE, span); ---- [[sleuth-adding-project]] @@ -983,4 +985,4 @@ Go to `File` -> `Settings` -> `Other settings` -> `Checkstyle`. There click on t - `checkstyle.suppressions.file` - default suppressions. Please point it to the Spring Cloud Build's, `spring-cloud-build-tools/src/checkstyle/checkstyle-suppressions.xml` file either in your cloned repo or via the `https://raw.githubusercontent.com/spring-cloud/spring-cloud-build/master/spring-cloud-build-tools/src/checkstyle/checkstyle-suppressions.xml` URL. - `checkstyle.additional.suppressions.file` - this variable corresponds to suppressions in your local project. E.g. you're working on `spring-cloud-contract`. Then point to the `project-root/src/checkstyle/checkstyle-suppressions.xml` folder. Example for `spring-cloud-contract` would be: `/home/username/spring-cloud-contract/src/checkstyle/checkstyle-suppressions.xml`. -IMPORTANT: Remember to set the `Scan Scope` to `All sources` since we apply checkstyle rules for production and test sources. \ No newline at end of file +IMPORTANT: Remember to set the `Scan Scope` to `All sources` since we apply checkstyle rules for production and test sources. diff --git a/docs/src/main/asciidoc/_configprops.adoc b/docs/src/main/asciidoc/_configprops.adoc index 50258d8b3..b5547db82 100644 --- a/docs/src/main/asciidoc/_configprops.adoc +++ b/docs/src/main/asciidoc/_configprops.adoc @@ -16,7 +16,7 @@ |spring.sleuth.integration.enabled | true | Enable Spring Integration sleuth instrumentation. |spring.sleuth.integration.patterns | [!hystrixStreamOutput*, *, !channel*] | An array of patterns against which channel names will be matched. @see org.springframework.integration.config.GlobalChannelInterceptor#patterns() Defaults to any channel name not matching the Hystrix Stream and functional Stream channel names. |spring.sleuth.integration.websockets.enabled | true | Enable tracing for WebSockets. -|spring.sleuth.local-keys | | Same as {@link #propagationKeys} except that this field is not propagated to remote services. @see brave.propagation.ExtraFieldPropagation.FactoryBuilder#addRedactedField(String) +|spring.sleuth.local-keys | | Same as {@link #remoteKeys} except that this field is not propagated to remote services. @see brave.baggage.BaggagePropagationConfig.SingleBaggageField#local(BaggageField) |spring.sleuth.log.slf4j.enabled | true | Enable a {@link Slf4jScopeDecorator} that prints tracing information in the logs. |spring.sleuth.log.slf4j.whitelisted-mdc-keys | | A list of keys to be put from baggage to MDC. |spring.sleuth.messaging.enabled | false | Should messaging be turned on. @@ -28,7 +28,7 @@ |spring.sleuth.messaging.rabbit.enabled | true | Enable tracing of RabbitMQ. |spring.sleuth.messaging.rabbit.remote-service-name | rabbitmq | |spring.sleuth.opentracing.enabled | true | -|spring.sleuth.propagation-keys | | List of fields that are referenced the same in-process as it is on the wire. For example, the name "x-vcap-request-id" would be set as-is including the prefix.
Note: {@code fieldName} will be implicitly lower-cased. @see brave.propagation.ExtraFieldPropagation.FactoryBuilder#addField(String) +|spring.sleuth.remote-keys | | List of fields that are referenced the same in-process as it is on the wire. For example, the name "x-vcap-request-id" would be set as-is including the prefix.
Note: {@code fieldName} will be implicitly lower-cased. @see brave.baggage.BaggagePropagationConfig.SingleBaggageField#remote(BaggageField)
|spring.sleuth.propagation.tag.enabled | true | Enables a {@link TagPropagationFinishedSpanHandler} that adds extra propagated fields to span tags.
|spring.sleuth.propagation.tag.whitelisted-keys | | A list of keys to be put from extra propagation fields to span tags.
|spring.sleuth.reactor.decorate-on-each | true | When true decorates on each operator, will be less performing, but logging will always contain the tracing entries in each operator. When false decorates on last operator, will be more performing, but logging might not always contain the tracing entries.
diff --git a/docs/src/main/asciidoc/spring-cloud-sleuth.adoc b/docs/src/main/asciidoc/spring-cloud-sleuth.adoc
index 51d252c1f..ff8180336 100644
--- a/docs/src/main/asciidoc/spring-cloud-sleuth.adoc
+++ b/docs/src/main/asciidoc/spring-cloud-sleuth.adoc
@@ -88,13 +88,14 @@ In order to use the rate-limited sampler set the `spring.sleuth.sampler.rate` pr
== Baggage
With the `spring.sleuth.baggage-keys`, you set keys that get prefixed with `baggage-` for HTTP calls and `baggage_` for messaging.
-You can also use the `spring.sleuth.propagation-keys` property to pass a list of prefixed keys that are propagated to remote services without any prefix.
+You can also use the `spring.sleuth.remote-keys` property to pass a list of prefixed keys that are propagated to remote services without any prefix.
You can also use the `spring.sleuth.local-keys` property to pass a list keys that will be propagated locally but will not be propagated over the wire.
Notice that there's no `x-` in front of the header keys.
In order to automatically set the baggage values to Slf4j's MDC, you have to set
the `spring.sleuth.log.slf4j.whitelisted-mdc-keys` property with a list of whitelisted
-baggage and propagation keys. E.g. `spring.sleuth.log.slf4j.whitelisted-mdc-keys=foo` will set the value of the `foo` baggage into MDC.
+local or remote keys. E.g. `spring.sleuth.log.slf4j.whitelisted-mdc-keys=country-code` will set the
+value of the `country-code` baggage into MDC.
IMPORTANT: Remember that adding entries to MDC can drastically decrease the performance of your application!
diff --git a/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/autoconfig/PropertyBasedBaggageConfiguration.java b/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/autoconfig/PropertyBasedBaggageConfiguration.java
index 79a834d96..f09ac50d8 100644
--- a/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/autoconfig/PropertyBasedBaggageConfiguration.java
+++ b/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/autoconfig/PropertyBasedBaggageConfiguration.java
@@ -66,7 +66,7 @@ public class PropertyBasedBaggageConfiguration implements BeanFactoryPostProcess
baggageConfigs.add(SingleBaggageField.local(BaggageField.create(key)));
}
- for (String key : collectKeysOfType(env, "propagation")) {
+ for (String key : collectKeysOfType(env, "remote")) {
baggageConfigs.add(SingleBaggageField.remote(BaggageField.create(key)));
}
diff --git a/spring-cloud-sleuth-core/src/test/java/org/springframework/cloud/sleuth/autoconfig/TraceAutoConfigurationTests.java b/spring-cloud-sleuth-core/src/test/java/org/springframework/cloud/sleuth/autoconfig/TraceAutoConfigurationTests.java
index f780404e1..52bbf4978 100644
--- a/spring-cloud-sleuth-core/src/test/java/org/springframework/cloud/sleuth/autoconfig/TraceAutoConfigurationTests.java
+++ b/spring-cloud-sleuth-core/src/test/java/org/springframework/cloud/sleuth/autoconfig/TraceAutoConfigurationTests.java
@@ -92,31 +92,31 @@ public class TraceAutoConfigurationTests {
.run((context -> {
final Baggage bean = context.getBean(Baggage.class);
BDDAssertions.then(bean.fields).containsOnly(
- BaggageField.create("userId"),
- BaggageField.create("userName"));
+ BaggageField.create("country-code"),
+ BaggageField.create("x-vcap-request-id"));
}));
}
@Test
public void should_use_local_keys_from_properties() {
- this.contextRunner.withPropertyValues("spring.sleuth.local-keys=test-key")
+ this.contextRunner.withPropertyValues("spring.sleuth.local-keys=bp")
.withUserConfiguration(Baggage.class).run((context -> {
final Baggage bean = context.getBean(Baggage.class);
BDDAssertions.then(bean.fields)
- .containsExactly(BaggageField.create("test-key"));
+ .containsExactly(BaggageField.create("bp"));
}));
}
@Test
public void should_combine_baggage_beans_and_properties() {
- this.contextRunner.withPropertyValues("spring.sleuth.local-keys=test-key")
+ this.contextRunner.withPropertyValues("spring.sleuth.local-keys=bp")
.withUserConfiguration(WithBaggageBeans.class, Baggage.class)
.run((context -> {
final Baggage bean = context.getBean(Baggage.class);
BDDAssertions.then(bean.fields).containsOnly(
- BaggageField.create("userId"),
- BaggageField.create("userName"),
- BaggageField.create("test-key"));
+ BaggageField.create("country-code"),
+ BaggageField.create("x-vcap-request-id"),
+ BaggageField.create("bp"));
}));
}
@@ -151,13 +151,13 @@ public class TraceAutoConfigurationTests {
static class WithBaggageBeans {
@Bean
- BaggagePropagationConfig userId() {
- return SingleBaggageField.remote(BaggageField.create("userId"));
+ BaggagePropagationConfig countryCode() {
+ return SingleBaggageField.remote(BaggageField.create("country-code"));
}
@Bean
- BaggagePropagationConfig userName() {
- return SingleBaggageField.remote(BaggageField.create("userName"));
+ BaggagePropagationConfig requestId() {
+ return SingleBaggageField.remote(BaggageField.create("x-vcap-request-id"));
}
}
diff --git a/spring-cloud-sleuth-core/src/test/java/org/springframework/cloud/sleuth/instrument/multiple/MultipleHopsIntegrationTests.java b/spring-cloud-sleuth-core/src/test/java/org/springframework/cloud/sleuth/instrument/multiple/MultipleHopsIntegrationTests.java
index 20b8d00d2..818b892da 100644
--- a/spring-cloud-sleuth-core/src/test/java/org/springframework/cloud/sleuth/instrument/multiple/MultipleHopsIntegrationTests.java
+++ b/spring-cloud-sleuth-core/src/test/java/org/springframework/cloud/sleuth/instrument/multiple/MultipleHopsIntegrationTests.java
@@ -25,7 +25,6 @@ import brave.Span;
import brave.Tags;
import brave.Tracer;
import brave.Tracer.SpanInScope;
-import brave.Tracing;
import brave.baggage.BaggageField;
import brave.baggage.BaggagePropagationConfig;
import brave.baggage.BaggagePropagationConfig.SingleBaggageField;
@@ -57,11 +56,10 @@ import static org.springframework.boot.test.context.SpringBootTest.WebEnvironmen
@SpringBootTest(classes = MultipleHopsIntegrationTests.Config.class,
webEnvironment = RANDOM_PORT, properties = { "spring.sleuth.baggage-keys=baz",
- "spring.sleuth.propagation-keys=foo" })
+ "spring.sleuth.remote-keys=country-code" })
public class MultipleHopsIntegrationTests {
- @Autowired
- Tracing tracing;
+ static final BaggageField COUNTRY_CODE = BaggageField.create("country-code");
@Autowired
Tracer tracer;
@@ -106,19 +104,18 @@ public class MultipleHopsIntegrationTests {
@Test
public void should_propagate_the_baggage() {
// TODO: make a DemoBaggage type instead of saying to use the api directly
- BaggageField foo = BaggageField.create("foo");
BaggageField bar = BaggageField.create("bar");
BaggageField baz = BaggageField.create("baz");
// tag::baggage[]
Span initialSpan = this.tracer.nextSpan().name("span").start();
- foo.updateValue(initialSpan.context(), "1");
+ COUNTRY_CODE.updateValue(initialSpan.context(), "FO");
bar.updateValue(initialSpan.context(), "2");
// end::baggage[]
try (SpanInScope ws = this.tracer.withSpanInScope(initialSpan)) {
// tag::baggage_tag[]
- Tags.BAGGAGE_FIELD.tag(foo, initialSpan);
+ Tags.BAGGAGE_FIELD.tag(COUNTRY_CODE, initialSpan);
Tags.BAGGAGE_FIELD.tag(bar, initialSpan);
// end::baggage_tag[]
@@ -138,16 +135,16 @@ public class MultipleHopsIntegrationTests {
});
List