From fcee4fd4245d436a76d1f22e24ff01df0e5a9ed6 Mon Sep 17 00:00:00 2001 From: Marcin Grzejszczak Date: Wed, 17 Jun 2020 11:46:53 +0200 Subject: [PATCH] Added deprecation warning messages for baggage --- docs/src/main/asciidoc/_configprops.adoc | 6 ++--- .../sleuth/autoconfig/SleuthProperties.java | 27 +++++++++++++++++++ .../sleuth/log/SleuthSlf4jProperties.java | 17 ++++++++++++ 3 files changed, 47 insertions(+), 3 deletions(-) diff --git a/docs/src/main/asciidoc/_configprops.adoc b/docs/src/main/asciidoc/_configprops.adoc index 07d281a19..56cb52a46 100644 --- a/docs/src/main/asciidoc/_configprops.adoc +++ b/docs/src/main/asciidoc/_configprops.adoc @@ -20,9 +20,9 @@ |spring.sleuth.integration.websockets.enabled | true | Enable tracing for WebSockets. |spring.sleuth.keys.http.headers | | Additional headers that should be added as tags if they exist. If the header value is multi-valued, the tag value will be a comma-separated, single-quoted list. |spring.sleuth.keys.http.prefix | http. | Prefix for header names if they are added as tags. -|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 #propagationKeys} except that this field is not propagated to remote services. @see brave.propagation.ExtraFieldPropagation.FactoryBuilder#addRedactedField(String) @deprecated use {@code spring.sleuth.baggage.local-fields} property |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.log.slf4j.whitelisted-mdc-keys | | A list of keys to be put from baggage to MDC. @deprecated use spring.sleuth.baggage.correlation-fields property |spring.sleuth.messaging.enabled | false | Should messaging be turned on. |spring.sleuth.messaging.jms.enabled | true | Enable tracing of JMS. |spring.sleuth.messaging.jms.remote-service-name | jms | @@ -32,7 +32,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.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) @deprecated use {@code spring.sleuth.baggage.remote-fields} property |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/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/autoconfig/SleuthProperties.java b/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/autoconfig/SleuthProperties.java index 90726e9ed..1b7543744 100644 --- a/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/autoconfig/SleuthProperties.java +++ b/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/autoconfig/SleuthProperties.java @@ -19,6 +19,10 @@ package org.springframework.cloud.sleuth.autoconfig; import java.util.ArrayList; import java.util.List; +import brave.baggage.BaggagePropagationConfig; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + import org.springframework.boot.context.properties.ConfigurationProperties; /** @@ -31,6 +35,8 @@ import org.springframework.boot.context.properties.ConfigurationProperties; // TODO: Hide in 3.x, if it isn't already deleted public class SleuthProperties { + private static final Log log = LogFactory.getLog(SleuthProperties.class); + private boolean enabled = true; /** When true, generate 128-bit trace IDs instead of 64-bit ones. */ @@ -50,6 +56,7 @@ public class SleuthProperties { * @see brave.propagation.ExtraFieldPropagation.FactoryBuilder#addPrefixedFields(String, * java.util.Collection) */ + @Deprecated private List baggageKeys = new ArrayList<>(); /** @@ -60,7 +67,9 @@ public class SleuthProperties { * Note: {@code fieldName} will be implicitly lower-cased. * * @see brave.propagation.ExtraFieldPropagation.FactoryBuilder#addField(String) + * @deprecated use {@code spring.sleuth.baggage.remote-fields} property */ + @Deprecated private List propagationKeys = new ArrayList<>(); /** @@ -68,7 +77,9 @@ public class SleuthProperties { * services. * * @see brave.propagation.ExtraFieldPropagation.FactoryBuilder#addRedactedField(String) + * @deprecated use {@code spring.sleuth.baggage.local-fields} property */ + @Deprecated private List localKeys = new ArrayList<>(); public boolean isEnabled() { @@ -100,6 +111,14 @@ public class SleuthProperties { } public void setBaggageKeys(List baggageKeys) { + log.warn("[spring.sleuth.baggage-keys] will be removed in a future release." + + "To change header names define a @Bean of type " + + BaggagePropagationConfig.SingleBaggageField.class.getName() + + ". The preferable approach is to migrate " + + "to using [spring.sleuth.baggage.remote-keys]. The [spring.sleuth.baggage-keys] would prefix the headers " + + "with [baggage_] and [baggage-] so unless all of your applications migrate, to remain backward compatible " + + "you would have to add e.g. for [spring.sleuth.baggage-keys=foo] an entry " + + "[spring.sleuth.baggage.remote-keys=foo,baggage-foo,baggage_foo] and eventually migrate to [spring.sleuth.baggage.remote-keys=foo]"); this.baggageKeys = baggageKeys; } @@ -108,6 +127,7 @@ public class SleuthProperties { } public void setPropagationKeys(List propagationKeys) { + warning("spring.sleuth.propagation-keys", "spring.sleuth.baggage.remote-fields"); this.propagationKeys = propagationKeys; } @@ -116,7 +136,14 @@ public class SleuthProperties { } public void setLocalKeys(List localKeys) { + warning("spring.sleuth.local-keys", "spring.sleuth.baggage.local-fields"); this.localKeys = localKeys; } + private void warning(String currentKey, String newKey) { + log.warn("The [" + currentKey + + "] property is deprecated and is removed in the next major release version of Sleuth. Please use [" + + newKey + "]"); + } + } diff --git a/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/log/SleuthSlf4jProperties.java b/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/log/SleuthSlf4jProperties.java index ffcdddd96..62a5a7824 100644 --- a/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/log/SleuthSlf4jProperties.java +++ b/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/log/SleuthSlf4jProperties.java @@ -19,6 +19,9 @@ package org.springframework.cloud.sleuth.log; import java.util.ArrayList; import java.util.List; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + import org.springframework.boot.context.properties.ConfigurationProperties; /** @@ -31,6 +34,8 @@ import org.springframework.boot.context.properties.ConfigurationProperties; // TODO: Hide in 3.x, if it isn't already deleted public class SleuthSlf4jProperties { + private static final Log log = LogFactory.getLog(SleuthSlf4jProperties.class); + /** * Enable a {@link Slf4jScopeDecorator} that prints tracing information in the logs. */ @@ -38,10 +43,14 @@ public class SleuthSlf4jProperties { /** * A list of keys to be put from baggage to MDC. + * @deprecated use spring.sleuth.baggage.correlation-fields property */ + @Deprecated private List whitelistedMdcKeys = new ArrayList<>(); public boolean isEnabled() { + warning("spring.sleuth.log.slf4j.enabled", + "spring.sleuth.baggage.correlation-enabled"); return this.enabled; } @@ -54,7 +63,15 @@ public class SleuthSlf4jProperties { } public void setWhitelistedMdcKeys(List whitelistedMdcKeys) { + warning("spring.sleuth.log.slf4j.whitelisted-mdc-keys", + "spring.sleuth.baggage.correlation-fields"); this.whitelistedMdcKeys = whitelistedMdcKeys; } + private void warning(String currentKey, String newKey) { + log.warn("The [" + currentKey + + "] property is deprecated and is removed in the next major release version of Sleuth. Please use [" + + newKey + "]"); + } + }