Merge branch '2.2.x'

This commit is contained in:
Adrian Cole
2020-05-16 15:15:37 +08:00
86 changed files with 437 additions and 110 deletions

View File

@@ -33,7 +33,7 @@
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>1.8</maven.compiler.source>
<spring-boot.version>2.3.0.BUILD-SNAPSHOT</spring-boot.version>
<brave.version>5.11.2</brave.version>
<brave.version>5.12.0</brave.version>
<okhttp.version>3.14.6</okhttp.version>
</properties>

View File

@@ -520,17 +520,17 @@ spring.zipkin.service.name: myService
=== Customization of Reported Spans
Before reporting spans (for example, to Zipkin) you may want to modify that span in some way.
You can do so by using the `FinishedSpanHandler` interface.
You can do so by implementing a `SpanHandler`.
In Sleuth, we generate spans with a fixed name.
Some users want to modify the name depending on values of tags.
You can implement the `FinishedSpanHandler` interface to alter that name.
You can implement the `SpanHandler` interface to alter that name.
The following example shows how to register two beans that implement `FinishedSpanHandler`:
The following example shows how to register two beans that implement `SpanHandler`:
[source,java]
----
include::{project-root}//spring-cloud-sleuth-core/src/test/java/org/springframework/cloud/sleuth/FinishedSpanHandlerTests.java[tags=finishedSpanHandler,indent=0]
include::{project-root}//spring-cloud-sleuth-core/src/test/java/org/springframework/cloud/sleuth/SpanHandlerTests.java[tags=spanHandler,indent=0]
----
The preceding example results in changing the name of the reported span to `foo bar`, just before it gets reported (for example, to Zipkin).

View File

@@ -243,7 +243,7 @@
<spring-cloud-stream.version>3.1.0.BUILD-SNAPSHOT</spring-cloud-stream.version>
<spring-cloud-netflix.version>3.0.0-SNAPSHOT</spring-cloud-netflix.version>
<spring-cloud-openfeign.version>3.0.0-SNAPSHOT</spring-cloud-openfeign.version>
<brave.version>5.11.2</brave.version>
<brave.version>5.12.0</brave.version>
<spring-security-boot-autoconfigure.version>2.1.7.RELEASE</spring-security-boot-autoconfigure.version>
<disable.nohttp.checks>false</disable.nohttp.checks>
<okhttp.version>3.14.6</okhttp.version>

View File

@@ -298,6 +298,7 @@
<artifactId>spring-boot-autoconfigure-processor</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>

View File

@@ -36,7 +36,10 @@ import org.springframework.core.annotation.AnnotationUtils;
* @author Marcin Grzejszczak
* @since 1.0.0
* @see SpanName
* @deprecated This type should have never been public and will be hidden or removed in
* 3.0
*/
@Deprecated
public class DefaultSpanNamer implements SpanNamer {
private static boolean isDefaultToString(Object delegate, String spanName) {

View File

@@ -23,7 +23,10 @@ import org.springframework.boot.context.properties.ConfigurationProperties;
*
* @author Marcin Grzejszczak
* @since 1.0.11
* @deprecated This type should have never been public and will be hidden or removed in
* 3.0
*/
@Deprecated
@ConfigurationProperties("spring.sleuth")
public class SleuthProperties {

View File

@@ -25,9 +25,8 @@ import brave.ErrorParser;
import brave.Tracer;
import brave.Tracing;
import brave.TracingCustomizer;
import brave.handler.FinishedSpanHandler;
import brave.handler.SpanHandler;
import brave.propagation.CurrentTraceContext;
import brave.propagation.CurrentTraceContext.ScopeDecorator;
import brave.propagation.CurrentTraceContextCustomizer;
import brave.propagation.Propagation;
import brave.propagation.ThreadLocalCurrentTraceContext;
@@ -67,7 +66,10 @@ import org.springframework.util.StringUtils;
* @author Marcin Grzejszczak
* @author Tim Ysewyn
* @since 2.0.0
* @deprecated This type should have never been public and will be hidden or removed in
* 3.0
*/
@Deprecated
@Configuration(proxyBeanMethods = false)
@ConditionalOnProperty(value = "spring.sleuth.enabled", matchIfMissing = true)
@EnableConfigurationProperties(SleuthProperties.class)
@@ -85,10 +87,7 @@ public class TraceAutoConfiguration {
public static final String DEFAULT_SERVICE_NAME = "default";
@Autowired(required = false)
List<FinishedSpanHandler> finishedSpanHandlers = new ArrayList<>();
@Autowired(required = false)
List<CurrentTraceContext.ScopeDecorator> scopeDecorators = new ArrayList<>();
List<SpanHandler> spanHandlers = new ArrayList<>();
@Autowired(required = false)
List<TracingCustomizer> tracingCustomizers = new ArrayList<>();
@@ -109,8 +108,8 @@ public class TraceAutoConfiguration {
spanReporters != null ? spanReporters : Collections.emptyList()))
.traceId128Bit(sleuthProperties.isTraceId128())
.supportsJoin(sleuthProperties.isSupportsJoin());
for (FinishedSpanHandler finishedSpanHandlerFactory : this.finishedSpanHandlers) {
builder.addFinishedSpanHandler(finishedSpanHandlerFactory);
for (SpanHandler spanHandlerFactory : this.spanHandlers) {
builder.addSpanHandler(spanHandlerFactory);
}
for (TracingCustomizer customizer : this.tracingCustomizers) {
customizer.customize(builder);
@@ -134,11 +133,20 @@ public class TraceAutoConfiguration {
List<CurrentTraceContextCustomizer> currentTraceContextCustomizers = new ArrayList<>();
@Bean
CurrentTraceContext sleuthCurrentTraceContext(CurrentTraceContext.Builder builder) {
for (ScopeDecorator scopeDecorator : this.scopeDecorators) {
CurrentTraceContext sleuthCurrentTraceContext(CurrentTraceContext.Builder builder,
@Nullable List<CurrentTraceContext.ScopeDecorator> scopeDecorators,
@Nullable List<CurrentTraceContextCustomizer> currentTraceContextCustomizers) {
if (scopeDecorators == null) {
scopeDecorators = Collections.emptyList();
}
if (currentTraceContextCustomizers == null) {
currentTraceContextCustomizers = Collections.emptyList();
}
for (CurrentTraceContext.ScopeDecorator scopeDecorator : scopeDecorators) {
builder.addScopeDecorator(scopeDecorator);
}
for (CurrentTraceContextCustomizer customizer : this.currentTraceContextCustomizers) {
for (CurrentTraceContextCustomizer customizer : currentTraceContextCustomizers) {
customizer.customize(builder);
}
return builder.build();

View File

@@ -33,7 +33,10 @@ import org.springframework.core.env.PropertySource;
* @author Dave Syer
* @author Marcin Grzejszczak
* @since 2.0.0
* @deprecated This type should have never been public and will be hidden or removed in
* 3.0
*/
@Deprecated
public class TraceEnvironmentPostProcessor implements EnvironmentPostProcessor {
private static final String PROPERTY_SOURCE_NAME = "defaultProperties";

View File

@@ -28,7 +28,10 @@ import org.springframework.context.annotation.Configuration;
*
* @author Jesus Alonso
* @since 2.1.0
* @deprecated This type should have never been public and will be hidden or removed in
* 3.0
*/
@Deprecated
@Configuration(proxyBeanMethods = false)
@ConditionalOnProperty(value = "spring.sleuth.scheduled.enabled", matchIfMissing = true)
@EnableConfigurationProperties({ SleuthAsyncProperties.class,

View File

@@ -35,7 +35,10 @@ import org.springframework.scheduling.annotation.AsyncConfigurer;
*
* @author Dave Syer
* @since 1.0.0
* @deprecated This type should have never been public and will be hidden or removed in
* 3.0
*/
@Deprecated
@Configuration(proxyBeanMethods = false)
@ConditionalOnBean(AsyncConfigurer.class)
@AutoConfigureBefore(AsyncDefaultAutoConfiguration.class)

View File

@@ -52,7 +52,10 @@ import org.springframework.scheduling.annotation.AsyncConfigurerSupport;
* @since 1.0.0
* @see LazyTraceExecutor
* @see TraceAsyncAspect
* @deprecated This type should have never been public and will be hidden or removed in
* 3.0
*/
@Deprecated
@Configuration(proxyBeanMethods = false)
@EnableConfigurationProperties({ SleuthAsyncProperties.class,
SleuthSchedulingProperties.class })

View File

@@ -29,7 +29,10 @@ import org.springframework.scheduling.annotation.AsyncConfigurerSupport;
*
* @author Dave Syer
* @since 1.0.0
* @deprecated This type should have never been public and will be hidden or removed in
* 3.0
*/
@Deprecated
public class LazyTraceAsyncCustomizer extends AsyncConfigurerSupport {
private final BeanFactory beanFactory;

View File

@@ -35,7 +35,10 @@ import org.springframework.core.task.AsyncTaskExecutor;
*
* @author Marcin Grzejszczak
* @since 2.1.0
* @deprecated This type should have never been public and will be hidden or removed in
* 3.0
*/
@Deprecated
public class LazyTraceAsyncTaskExecutor implements AsyncTaskExecutor {
private static final Log log = LogFactory.getLog(LazyTraceAsyncTaskExecutor.class);

View File

@@ -32,7 +32,10 @@ import org.springframework.cloud.sleuth.SpanNamer;
*
* @author Dave Syer
* @since 1.0.0
* @deprecated This type should have never been public and will be hidden or removed in
* 3.0
*/
@Deprecated
public class LazyTraceExecutor implements Executor {
private static final Log log = LogFactory.getLog(LazyTraceExecutor.class);

View File

@@ -39,7 +39,10 @@ import org.springframework.util.concurrent.ListenableFuture;
*
* @author Marcin Grzejszczak
* @since 1.0.10
* @deprecated This type should have never been public and will be hidden or removed in
* 3.0
*/
@Deprecated
@SuppressWarnings("serial")
public class LazyTraceThreadPoolTaskExecutor extends ThreadPoolTaskExecutor {

View File

@@ -26,8 +26,10 @@ import org.springframework.boot.context.properties.ConfigurationProperties;
*
* @author Jesus Alonso
* @since 2.1.0
* @deprecated This type should have never been public and will be hidden or removed in
* 3.0
*/
@Deprecated
@ConfigurationProperties(prefix = "spring.sleuth.async")
public class SleuthAsyncProperties {

View File

@@ -36,7 +36,10 @@ import org.springframework.util.ReflectionUtils;
* @author Marcin Grzejszczak
* @since 1.0.0
* @see Tracer
* @deprecated This type should have never been public and will be hidden or removed in
* 3.0
*/
@Deprecated
@Aspect
public class TraceAsyncAspect {

View File

@@ -32,7 +32,10 @@ import org.springframework.util.concurrent.ListenableFuture;
* @since 1.0.0
* @see brave.propagation.CurrentTraceContext#wrap(Runnable)
* @see brave.propagation.CurrentTraceContext#wrap(Callable)
* @deprecated This type should have never been public and will be hidden or removed in
* 3.0
*/
@Deprecated
public class TraceAsyncListenableTaskExecutor implements AsyncListenableTaskExecutor {
private final AsyncListenableTaskExecutor delegate;

View File

@@ -33,7 +33,10 @@ import org.springframework.cloud.sleuth.SpanNamer;
* @author Spencer Gibb
* @author Marcin Grzejszczak
* @since 1.0.0
* @deprecated This type should have never been public and will be hidden or removed in
* 3.0
*/
@Deprecated
public class TraceCallable<V> implements Callable<V> {
/**

View File

@@ -30,7 +30,10 @@ import org.springframework.cloud.sleuth.SpanNamer;
* @author Spencer Gibb
* @author Marcin Grzejszczak
* @since 1.0.0
* @deprecated This type should have never been public and will be hidden or removed in
* 3.0
*/
@Deprecated
public class TraceRunnable implements Runnable {
/**

View File

@@ -36,7 +36,10 @@ import org.springframework.cloud.sleuth.SpanNamer;
*
* @author Gaurav Rai Mazra
* @since 1.0.0
* @deprecated This type should have never been public and will be hidden or removed in
* 3.0
*/
@Deprecated
public class TraceableExecutorService implements ExecutorService {
final ExecutorService delegate;

View File

@@ -29,7 +29,10 @@ import org.springframework.beans.factory.BeanFactory;
*
* @author Gaurav Rai Mazra
* @since 1.0.0
* @deprecated This type should have never been public and will be hidden or removed in
* 3.0
*/
@Deprecated
public class TraceableScheduledExecutorService extends TraceableExecutorService
implements ScheduledExecutorService {

View File

@@ -42,7 +42,10 @@ import org.springframework.context.annotation.Configuration;
*
* @author Marcin Grzejszczak
* @since 2.2.1
* @deprecated This type should have never been public and will be hidden or removed in
* 3.0
*/
@Deprecated
@Configuration(proxyBeanMethods = false)
@AutoConfigureAfter(TraceAutoConfiguration.class)
@ConditionalOnClass(CircuitBreaker.class)

View File

@@ -23,7 +23,10 @@ import org.springframework.boot.context.properties.ConfigurationProperties;
*
* @author Marcin Grzejszczak
* @since 2.2.1
* @deprecated This type should have never been public and will be hidden or removed in
* 3.0
*/
@Deprecated
@ConfigurationProperties("spring.sleuth.circuitbreaker")
public class SleuthCircuitBreakerProperties {

View File

@@ -27,7 +27,10 @@ import brave.Tracer;
*
* @param <T> type returned by the fallback
* @since 2.2.1
* @deprecated This type should have never been public and will be hidden or removed in
* 3.0
*/
@Deprecated
public class TraceFunction<T> implements Function<Throwable, T> {
private final Tracer tracer;

View File

@@ -27,7 +27,10 @@ import brave.Tracer;
*
* @param <T> type returned by the supplier
* @since 2.2.1
* @deprecated This type should have never been public and will be hidden or removed in
* 3.0
*/
@Deprecated
public class TraceSupplier<T> implements Supplier<T> {
private final Tracer tracer;

View File

@@ -35,6 +35,7 @@ import io.grpc.inprocess.InProcessChannelBuilder;
*
* @author Tyler Van Gorder
*/
// TODO: research why we need to continue to maintain this given current libraries
public class SpringAwareManagedChannelBuilder {
private List<GrpcManagedChannelBuilderCustomizer> customizers;

View File

@@ -40,7 +40,10 @@ import org.springframework.context.annotation.Bean;
* brave-instrumentation-grpc are on the classpath.
*
* @author Tyler Van Gorder
* @deprecated This type should have never been public and will be hidden or removed in
* 3.0
*/
@Deprecated
@ConditionalOnClass({ GrpcTracing.class, GRpcGlobalInterceptor.class })
@ConditionalOnProperty(value = "spring.sleuth.grpc.enabled", matchIfMissing = true)
@ConditionalOnBean(RpcTracing.class)

View File

@@ -40,7 +40,10 @@ import org.springframework.kafka.config.StreamsBuilderFactoryBean;
* Auto-configuration} enables Kafka Streams span creation and reporting.
*
* @author Tim te Beek
* @deprecated This type should have never been public and will be hidden or removed in
* 3.0
*/
@Deprecated
@Configuration(proxyBeanMethods = false)
@ConditionalOnBean(Tracing.class)
@AutoConfigureAfter({ TraceAutoConfiguration.class })

View File

@@ -23,7 +23,10 @@ import org.springframework.boot.context.properties.ConfigurationProperties;
*
* @author Marcin Grzejszczak
* @since 2.0.0
* @deprecated This type should have never been public and will be hidden or removed in
* 3.0
*/
@Deprecated
@ConfigurationProperties("spring.sleuth")
public class SleuthMessagingProperties {

View File

@@ -77,7 +77,10 @@ import org.springframework.util.ReflectionUtils;
*
* @author Marcin Grzejszczak
* @since 2.0.0
* @deprecated This type should have never been public and will be hidden or removed in
* 3.0
*/
@Deprecated
@Configuration(proxyBeanMethods = false)
@ConditionalOnBean(Tracing.class)
@ConditionalOnClass(MessagingTracing.class)

View File

@@ -39,7 +39,10 @@ import org.springframework.messaging.support.MessageHeaderAccessor;
* @author Spencer Gibb
* @since 1.0.0
* @see TracingChannelInterceptor
* @deprecated This type should have never been public and will be hidden or removed in
* 3.0
*/
@Deprecated
@Configuration(proxyBeanMethods = false)
@ConditionalOnClass(GlobalChannelInterceptor.class)
@ConditionalOnBean(Tracing.class)

View File

@@ -56,7 +56,10 @@ import org.springframework.util.ClassUtils;
* manipulation by other interceptors.
*
* @author Marcin Grzejszczak
* @deprecated This type should have never been public and will be hidden or removed in
* 3.0
*/
@Deprecated
public final class TracingChannelInterceptor extends ChannelInterceptorAdapter
implements ExecutorChannelInterceptor {

View File

@@ -37,7 +37,10 @@ import org.springframework.web.socket.config.annotation.StompEndpointRegistry;
* @author Dave Syer
* @since 1.0.0
* @see AbstractWebSocketMessageBrokerConfigurer
* @deprecated This type should have never been public and will be hidden or removed in
* 3.0
*/
@Deprecated
@Configuration(proxyBeanMethods = false)
@ConditionalOnClass(DelegatingWebSocketMessageBrokerConfiguration.class)
@ConditionalOnBean(Tracing.class)

View File

@@ -37,7 +37,10 @@ import org.springframework.context.annotation.Configuration;
* @author Spencer Gibb
* @author Marcin Grzejszczak
* @since 2.0.0
* @deprecated This type should have never been public and will be hidden or removed in
* 3.0
*/
@Deprecated
@Configuration(proxyBeanMethods = false)
@ConditionalOnProperty(value = "spring.sleuth.opentracing.enabled", matchIfMissing = true)
@ConditionalOnBean(Tracing.class)

View File

@@ -23,7 +23,10 @@ import org.springframework.boot.context.properties.ConfigurationProperties;
*
* @author Marcin Grzejszczak
* @since 2.0.0
* @deprecated This type should have never been public and will be hidden or removed in
* 3.0
*/
@Deprecated
@ConfigurationProperties("spring.sleuth.opentracing")
public class SleuthOpentracingProperties {

View File

@@ -36,7 +36,10 @@ import org.springframework.context.annotation.Configuration;
*
* @author Branden Cash
* @since 2.2.0
* @deprecated This type should have never been public and will be hidden or removed in
* 3.0
*/
@Deprecated
@Configuration(proxyBeanMethods = false)
@ConditionalOnBean({ Tracing.class, Scheduler.class })
@AutoConfigureAfter({ TraceAutoConfiguration.class, QuartzAutoConfiguration.class })

View File

@@ -39,6 +39,8 @@ import org.springframework.context.ConfigurableApplicationContext;
* @author Stephane Maldini
* @since 2.0.0
*/
// TODO: this is public as it is used out of package, but unlikely intended to be
// non-internal
public abstract class ReactorSleuth {
private static final Log log = LogFactory.getLog(ReactorSleuth.class);

View File

@@ -23,7 +23,10 @@ import org.springframework.boot.context.properties.ConfigurationProperties;
*
* @author Marcin Grzejszczak
* @since 2.0.2
* @deprecated This type should have never been public and will be hidden or removed in
* 3.0
*/
@Deprecated
@ConfigurationProperties("spring.sleuth.reactor")
public class SleuthReactorProperties {

View File

@@ -55,7 +55,10 @@ import static org.springframework.cloud.sleuth.instrument.reactor.TraceReactorAu
* @author Stephane Maldini
* @author Marcin Grzejszczak
* @since 2.0.0
* @deprecated This type should have never been public and will be hidden or removed in
* 3.0
*/
@Deprecated
@Configuration(proxyBeanMethods = false)
@ConditionalOnProperty(value = "spring.sleuth.reactor.enabled", matchIfMissing = true)
@ConditionalOnClass(Mono.class)

View File

@@ -39,7 +39,10 @@ import org.springframework.context.annotation.Configuration;
*
* @author Chao Chang
* @since 2.2.0
* @deprecated This type should have never been public and will be hidden or removed in
* 3.0
*/
@Deprecated
@Configuration(proxyBeanMethods = false)
@ConditionalOnProperty(value = "spring.sleuth.redis.enabled", matchIfMissing = true)
@ConditionalOnBean({ Tracing.class, ClientResources.class })

View File

@@ -22,7 +22,10 @@ import org.springframework.boot.context.properties.ConfigurationProperties;
* Sleuth Redis properties.
*
* @author Daniel Albuquerque
* @deprecated This type should have never been public and will be hidden or removed in
* 3.0
*/
@Deprecated
@ConfigurationProperties("spring.sleuth.redis")
public class TraceRedisProperties {

View File

@@ -41,7 +41,10 @@ import org.springframework.lang.Nullable;
* Auto-configuration} related to RPC based communication.
*
* @since 2.2.0
* @deprecated This type should have never been public and will be hidden or removed in
* 3.0
*/
@Deprecated
@Configuration(proxyBeanMethods = false)
@ConditionalOnProperty(name = "spring.sleuth.rpc.enabled", havingValue = "true",
matchIfMissing = true)

View File

@@ -37,7 +37,10 @@ import org.springframework.context.annotation.Configuration;
*
* @author Shivang Shah
* @since 1.0.0
* @deprecated This type should have never been public and will be hidden or removed in
* 3.0
*/
@Deprecated
@Configuration(proxyBeanMethods = false)
@AutoConfigureAfter(TraceAutoConfiguration.class)
@ConditionalOnBean(Tracing.class)

View File

@@ -23,7 +23,10 @@ import org.springframework.boot.context.properties.ConfigurationProperties;
*
* @author Arthur Gavlyukovskiy
* @since 1.0.12
* @deprecated This type should have never been public and will be hidden or removed in
* 3.0
*/
@Deprecated
@ConfigurationProperties("spring.sleuth.rxjava.schedulers")
public class SleuthRxJavaSchedulersProperties {

View File

@@ -24,7 +24,10 @@ import org.springframework.boot.context.properties.ConfigurationProperties;
*
* @author Arthur Gavlyukovskiy
* @since 1.0.12
* @deprecated This type should have never been public and will be hidden or removed in
* 3.0
*/
@Deprecated
@ConfigurationProperties("spring.sleuth.scheduled")
public class SleuthSchedulingProperties {

View File

@@ -41,7 +41,10 @@ import org.springframework.lang.Nullable;
* @author Spencer Gibb
* @since 1.0.0
* @see Tracing
* @deprecated This type should have never been public and will be hidden or removed in
* 3.0
*/
@Deprecated
@Aspect
public class TraceSchedulingAspect {

View File

@@ -37,7 +37,10 @@ import org.springframework.context.annotation.Configuration;
* @author Spencer Gibb
* @since 1.0.0
* @see TraceSchedulingAspect
* @deprecated This type should have never been public and will be hidden or removed in
* 3.0
*/
@Deprecated
@Configuration(proxyBeanMethods = false)
@ConditionalOnClass(name = "org.aspectj.lang.ProceedingJoinPoint")
@ConditionalOnProperty(value = "spring.sleuth.scheduled.enabled", matchIfMissing = true)

View File

@@ -29,11 +29,9 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
* Filter running after {@link brave.servlet.TracingFilter} that logs uncaught exceptions.
*
* @author Marcin Grzejszczak
* @since 2.0.0
* @deprecated Since 2.2.3 this is disabled by default and will be removed in 3.0
*/
@Deprecated
class ExceptionLoggingFilter implements Filter {
private static final Log log = LogFactory.getLog(ExceptionLoggingFilter.class);

View File

@@ -24,7 +24,10 @@ import org.springframework.boot.context.properties.NestedConfigurationProperty;
*
* @author Arthur Gavlyukovskiy
* @since 1.0.12
* @deprecated This type should have never been public and will be hidden or removed in
* 3.0
*/
@Deprecated
@ConfigurationProperties("spring.sleuth.web")
public class SleuthWebProperties {

View File

@@ -45,7 +45,10 @@ import org.springframework.lang.Nullable;
*
* @author Marcin Grzejszczak
* @since 2.0.0
* @deprecated This type should have never been public and will be hidden or removed in
* 3.0
*/
@Deprecated
@Configuration(proxyBeanMethods = false)
@ConditionalOnBean(TraceWebAutoConfiguration.class)
@ConditionalOnProperty(name = "spring.sleuth.http.enabled", havingValue = "true",

View File

@@ -51,7 +51,10 @@ import org.springframework.web.context.request.async.WebAsyncTask;
* @since 1.0.0
* @see org.springframework.stereotype.Controller
* @see org.springframework.web.client.RestOperations
* @deprecated This type should have never been public and will be hidden or removed in
* 3.0
*/
@Deprecated
@SuppressWarnings("ArgNamesWarningsInspection")
@Aspect
public class TraceWebAspect {

View File

@@ -53,7 +53,10 @@ import org.springframework.util.StringUtils;
* @author Marcin Grzejszczak
* @author Tim Ysewyn
* @since 1.0.0
* @deprecated This type should have never been public and will be hidden or removed in
* 3.0
*/
@Deprecated
@Configuration(proxyBeanMethods = false)
@ConditionalOnProperty(value = "spring.sleuth.web.enabled", matchIfMissing = true)
@ConditionalOnBean(Tracing.class)

View File

@@ -51,7 +51,10 @@ import org.springframework.web.server.WebFilterChain;
*
* @author Marcin Grzejszczak
* @since 2.0.0
* @deprecated This type should have never been public and will be hidden or removed in
* 3.0
*/
@Deprecated
public final class TraceWebFilter implements WebFilter, Ordered {
/**

View File

@@ -32,7 +32,10 @@ import org.springframework.context.annotation.Configuration;
*
* @author Marcin Grzejszczak
* @since 2.0.0
* @deprecated This type should have never been public and will be hidden or removed in
* 3.0
*/
@Deprecated
@Configuration(proxyBeanMethods = false)
@ConditionalOnProperty(value = "spring.sleuth.web.enabled", matchIfMissing = true)
@ConditionalOnWebApplication(type = ConditionalOnWebApplication.Type.REACTIVE)

View File

@@ -52,7 +52,10 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
* @author Marcin Grzejszczak
* @author Spencer Gibb
* @since 1.0.0
* @deprecated This type should have never been public and will be hidden or removed in
* 3.0
*/
@Deprecated
@Configuration(proxyBeanMethods = false)
@ConditionalOnProperty(value = "spring.sleuth.web.enabled", matchIfMissing = true)
@ConditionalOnWebApplication(type = ConditionalOnWebApplication.Type.SERVLET)
@@ -83,10 +86,8 @@ public class TraceWebServletAutoConfiguration {
return filterRegistrationBean;
}
// TODO: Rename to exception-logging-filter for 3.0
@Bean
@ConditionalOnProperty(value = "spring.sleuth.web.exception-logging-filter-enabled",
matchIfMissing = true)
@ConditionalOnProperty("spring.sleuth.web.exception-logging-filter-enabled")
public FilterRegistrationBean exceptionThrowingFilter(
SleuthWebProperties webProperties) {
FilterRegistrationBean filterRegistrationBean = new FilterRegistrationBean(

View File

@@ -44,7 +44,10 @@ import org.springframework.web.client.AsyncRestTemplate;
*
* @author Marcin Grzejszczak
* @since 1.0.0
* @deprecated This type should have never been public and will be hidden or removed in
* 3.0
*/
@Deprecated
@Configuration(proxyBeanMethods = false)
@SleuthWebClientEnabled
@ConditionalOnProperty(value = "spring.sleuth.web.async.client.enabled",

View File

@@ -62,7 +62,10 @@ import org.springframework.web.reactive.function.client.WebClient;
*
* @author Marcin Grzejszczak
* @since 1.0.0
* @deprecated This type should have never been public and will be hidden or removed in
* 3.0
*/
@Deprecated
@Configuration(proxyBeanMethods = false)
@SleuthWebClientEnabled
@ConditionalOnBean(HttpTracing.class)

View File

@@ -24,7 +24,9 @@ import feign.Retryer;
* Feign. For the 1.0.x stream we add it here.
*
* @author Ryan Baxter
* @deprecated This type will be removed in 3.0
*/
@Deprecated
public class NeverRetry implements Retryer {
/**

View File

@@ -23,7 +23,10 @@ import org.springframework.boot.context.properties.ConfigurationProperties;
*
* @author Marcin Grzejszczak
* @since 2.0.2
* @deprecated This type should have never been public and will be hidden or removed in
* 3.0
*/
@Deprecated
@ConfigurationProperties("spring.sleuth.feign")
public class SleuthFeignProperties {

View File

@@ -37,7 +37,10 @@ import org.springframework.cloud.openfeign.loadbalancer.FeignBlockingLoadBalance
* @author Olga Maciaszek-Sharma
* @since 2.2.0
* @see FeignBlockingLoadBalancerClient
* @deprecated This type should have never been public and will be hidden or removed in
* 3.0
*/
@Deprecated
public class TraceFeignBlockingLoadBalancerClient
extends FeignBlockingLoadBalancerClient {

View File

@@ -41,7 +41,10 @@ import org.springframework.context.annotation.Scope;
*
* @author Marcin Grzejszczak
* @since 1.0.0
* @deprecated This type should have never been public and will be hidden or removed in
* 3.0
*/
@Deprecated
@Configuration(proxyBeanMethods = false)
@ConditionalOnProperty(value = "spring.sleuth.feign.enabled", matchIfMissing = true)
@ConditionalOnClass({ Client.class, FeignContext.class })

View File

@@ -42,7 +42,10 @@ import org.springframework.util.Assert;
* @author Marcin Grzejszczak
* @author Adrian Cole
* @since 1.0.0
* @deprecated This type should have never been public and will be hidden or removed in
* 3.0
*/
@Deprecated
public class ProbabilityBasedSampler extends Sampler {
private final AtomicInteger counter = new AtomicInteger(0);

View File

@@ -33,7 +33,10 @@ import org.springframework.context.annotation.Configuration;
* @author Marcin Grzejszczak
* @see SamplerCondition
* @since 2.1.0
* @deprecated This type should have never been public and will be hidden or removed in
* 3.0
*/
@Deprecated
@Configuration(proxyBeanMethods = false)
@EnableConfigurationProperties(SamplerProperties.class)
// This is not auto-configuration, but it was in the past. Leaving the name as

View File

@@ -17,7 +17,7 @@
package org.springframework.cloud.sleuth.sampler;
import brave.TracingCustomizer;
import brave.handler.FinishedSpanHandler;
import brave.handler.SpanHandler;
import brave.sampler.Sampler;
import org.springframework.boot.autoconfigure.condition.AnyNestedCondition;
@@ -48,7 +48,7 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
* <ul>
* <li>{@code zipkin2.reporter.Reporter} - what's used by Zipkin or others like
* Stackdriver</li>
* <li>{@link FinishedSpanHandler} - only accepts sampled data</li>
* <li>{@link SpanHandler} - only accepts sampled data</li>
* <li>{@link TracingCustomizer} - can configure one of the above</li>
* </ul>
*
@@ -69,8 +69,8 @@ final class SamplerCondition extends AnyNestedCondition {
}
@ConditionalOnBean(FinishedSpanHandler.class)
static final class FinishedSpanHandlerAvailable {
@ConditionalOnBean(SpanHandler.class)
static final class SpanHandlerAvailable {
}

View File

@@ -24,7 +24,10 @@ import org.springframework.boot.context.properties.ConfigurationProperties;
* @author Marcin Grzejszczak
* @author Adrian Cole
* @since 1.0.0
* @deprecated This type should have never been public and will be hidden or removed in
* 3.0
*/
@Deprecated
@ConfigurationProperties("spring.sleuth.sampler")
public class SamplerProperties {

View File

@@ -27,7 +27,9 @@ import zipkin2.reporter.Reporter;
*
* @author Marcin Grzejszczak
* @since 2.0.0
* @deprecated This type will be removed in 3.0. Use io.zipkin.brave:brave-tests instead
*/
@Deprecated
public class ArrayListSpanReporter implements Reporter<Span> {
private final List<Span> spans = new ArrayList<>();

View File

@@ -23,7 +23,9 @@ import org.springframework.util.StringUtils;
*
* @author Adrian Cole
* @since 1.0.2
* @deprecated This type should have been internal. It will be hidden or removed in 3.0
*/
@Deprecated
public final class SpanNameUtil {
static final int MAX_NAME_LENGTH = 50;

View File

@@ -46,7 +46,10 @@ import org.springframework.lang.Nullable;
*
* @author Marcin Grzejszczak
* @since 2.1.1
* @deprecated This type should have never been public and will be hidden or removed in
* 3.0
*/
@Deprecated
public final class TracingJmsListenerEndpointRegistry
extends JmsListenerEndpointRegistry {

View File

@@ -18,8 +18,8 @@ package org.springframework.cloud.sleuth;
import brave.Span;
import brave.Tracer;
import brave.handler.FinishedSpanHandler;
import brave.handler.MutableSpan;
import brave.handler.SpanHandler;
import brave.propagation.TraceContext;
import brave.sampler.Sampler;
import org.assertj.core.api.BDDAssertions;
@@ -40,10 +40,9 @@ import static org.springframework.boot.test.context.SpringBootTest.WebEnvironmen
/**
* @author Marcin Grzejszczak
*/
@SpringBootTest(
classes = FinishedSpanHandlerTests.FinishedSpanHandlerAspectTestsConfig.class,
@SpringBootTest(classes = SpanHandlerTests.SpanHandlerAspectTestsConfig.class,
webEnvironment = NONE)
public class FinishedSpanHandlerTests {
public class SpanHandlerTests {
@Autowired
ArrayListSpanReporter reporter;
@@ -68,7 +67,7 @@ public class FinishedSpanHandlerTests {
@Configuration
@EnableAutoConfiguration(exclude = IntegrationAutoConfiguration.class)
static class FinishedSpanHandlerAspectTestsConfig {
static class SpanHandlerAspectTestsConfig {
@Bean
Sampler sampler() {
@@ -80,12 +79,13 @@ public class FinishedSpanHandlerTests {
return new ArrayListSpanReporter();
}
// tag::finishedSpanHandler[]
// tag::spanHandler[]
@Bean
FinishedSpanHandler handlerOne() {
return new FinishedSpanHandler() {
SpanHandler handlerOne() {
return new SpanHandler() {
@Override
public boolean handle(TraceContext traceContext, MutableSpan span) {
public boolean end(TraceContext traceContext, MutableSpan span,
Cause cause) {
span.name("foo");
return true; // keep this span
}
@@ -93,16 +93,17 @@ public class FinishedSpanHandlerTests {
}
@Bean
FinishedSpanHandler handlerTwo() {
return new FinishedSpanHandler() {
SpanHandler handlerTwo() {
return new SpanHandler() {
@Override
public boolean handle(TraceContext traceContext, MutableSpan span) {
public boolean end(TraceContext traceContext, MutableSpan span,
Cause cause) {
span.name(span.name() + " bar");
return true; // keep this span
}
};
}
// end::finishedSpanHandler[]
// end::spanHandler[]
}

View File

@@ -19,6 +19,7 @@ package org.springframework.cloud.sleuth.autoconfig;
import brave.Tracing;
import brave.baggage.BaggagePropagation;
import brave.propagation.B3Propagation;
import brave.propagation.B3Propagation.Format;
import brave.propagation.B3SinglePropagation;
import brave.propagation.Propagation;
import org.assertj.core.api.BDDAssertions;
@@ -34,14 +35,20 @@ import org.springframework.context.support.GenericApplicationContext;
public class TraceAutoConfigurationPropagationCustomizationTests {
// Default for spring-messaging is on 2.2.x is MULTI, though 3.x it is
// SINGLE_NO_PARENT
// spring-cloud/spring-cloud-sleuth#1607
Propagation.Factory defaultB3Propagation = B3Propagation.newFactoryBuilder()
.injectFormat(Format.SINGLE_NO_PARENT).build();
private final ApplicationContextRunner contextRunner = new ApplicationContextRunner()
.withConfiguration(AutoConfigurations.of(TraceAutoConfiguration.class));
@Test
public void stillCreatesDefault() {
this.contextRunner.run((context) -> {
BDDAssertions.then(context.getBean(Tracing.class).propagation())
.isInstanceOf(B3Propagation.class);
BDDAssertions.then(context.getBean(Propagation.Factory.class))
.isEqualTo(defaultB3Propagation);
});
}
@@ -60,7 +67,7 @@ public class TraceAutoConfigurationPropagationCustomizationTests {
this.contextRunner.withPropertyValues("spring.application.name=")
.run((context) -> {
BDDAssertions.then(context.getBean(Tracing.class).propagation())
.isInstanceOf(B3Propagation.class);
.isEqualTo(defaultB3Propagation);
});
}

View File

@@ -70,9 +70,8 @@ public class TraceBaggageConfigurationTests {
static ListAssert<Tuple> assertThatBaggageFieldNameToKeyNames(
AssertableApplicationContext context) {
return assertThat(context.getBean(Propagation.Factory.class))
.extracting("handlersWithKeyNames")
.asInstanceOf(InstanceOfAssertFactories.ARRAY)
.extracting("handler.field.name", "keyNames")
.extracting("configs").asInstanceOf(InstanceOfAssertFactories.ARRAY)
.extracting("field.name", "keyNames.toArray")
.asInstanceOf(InstanceOfAssertFactories.list(Tuple.class));
}

View File

@@ -18,8 +18,8 @@ package org.springframework.cloud.sleuth.sampler;
import brave.Tracing;
import brave.TracingCustomizer;
import brave.handler.FinishedSpanHandler;
import brave.handler.MutableSpan;
import brave.handler.SpanHandler;
import brave.propagation.TraceContext;
import brave.sampler.RateLimitingSampler;
import brave.sampler.Sampler;
@@ -52,12 +52,11 @@ public class SamplerAutoConfigurationTests {
}
@Test
void should_use_RateLimitedSampler_withFinishedSpanHandler() {
this.contextRunner.withUserConfiguration(WithFinishedSpanHandler.class)
.run((context -> {
final Sampler bean = context.getBean(Sampler.class);
BDDAssertions.then(bean).isInstanceOf(RateLimitingSampler.class);
}));
void should_use_RateLimitedSampler_withSpanHandler() {
this.contextRunner.withUserConfiguration(WithSpanHandler.class).run((context -> {
final Sampler bean = context.getBean(Sampler.class);
BDDAssertions.then(bean).isInstanceOf(RateLimitingSampler.class);
}));
}
@Test
@@ -138,13 +137,13 @@ public class SamplerAutoConfigurationTests {
}
@Configuration
static class WithFinishedSpanHandler {
static class WithSpanHandler {
@Bean
FinishedSpanHandler finishedSpanHandler() {
return new FinishedSpanHandler() {
SpanHandler spanHandler() {
return new SpanHandler() {
@Override
public boolean handle(TraceContext context, MutableSpan span) {
public boolean end(TraceContext context, MutableSpan span, Cause cause) {
return true;
}
};

View File

@@ -31,8 +31,8 @@
<name>spring-cloud-sleuth-dependencies</name>
<description>Spring Cloud Sleuth Dependencies</description>
<properties>
<brave.version>5.11.2</brave.version>
<brave.opentracing.version>0.36.2</brave.opentracing.version>
<brave.version>5.12.0</brave.version>
<brave.opentracing.version>0.37.0</brave.opentracing.version>
<grpc.spring.boot.version>3.4.1</grpc.spring.boot.version>
</properties>
<dependencyManagement>
@@ -69,6 +69,12 @@
<groupId>io.opentracing.brave</groupId>
<artifactId>brave-opentracing</artifactId>
<version>${brave.opentracing.version}</version>
<exclusions>
<exclusion>
<groupId>io.zipkin.brave</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- GRPC -->
<dependency>

View File

@@ -69,11 +69,6 @@
<artifactId>spring-cloud-sleuth-sample-test-core</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.zipkin.zipkin2</groupId>
<artifactId>zipkin</artifactId>
<version>2.19.3</version>
</dependency>
</dependencies>
</dependencyManagement>

View File

@@ -105,10 +105,6 @@
<artifactId>awaitility</artifactId>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>io.zipkin.zipkin2</groupId>
<artifactId>zipkin</artifactId>
</dependency>
<dependency>
<groupId>io.projectreactor</groupId>
<artifactId>reactor-core</artifactId>

View File

@@ -79,6 +79,10 @@
<groupId>io.zipkin.reporter2</groupId>
<artifactId>zipkin-reporter</artifactId>
</dependency>
<dependency>
<groupId>io.zipkin.reporter2</groupId>
<artifactId>zipkin-reporter-brave</artifactId>
</dependency>
<dependency>
<groupId>io.zipkin.reporter2</groupId>
<artifactId>zipkin-sender-kafka</artifactId>

View File

@@ -41,7 +41,10 @@ import org.springframework.util.StringUtils;
*
* @author Dave Syer
* @since 1.0.0
* @deprecated This type should have never been public and will be hidden or removed in
* 3.0
*/
@Deprecated
public class DefaultEndpointLocator implements EndpointLocator,
ApplicationListener<ServletWebServerInitializedEvent> {

View File

@@ -32,7 +32,10 @@ import org.springframework.web.client.RestTemplate;
*
* @author Marcin Grzejszczak
* @since 1.1.0
* @deprecated This type should have never been public and will be hidden or removed in
* 3.0
*/
@Deprecated
public class DefaultZipkinRestTemplateCustomizer implements ZipkinRestTemplateCustomizer {
private final ZipkinProperties zipkinProperties;

View File

@@ -16,11 +16,8 @@
package org.springframework.cloud.sleuth.zipkin2;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -63,7 +60,10 @@ import org.springframework.web.client.RestTemplate;
* @since 1.0.0
* @see ZipkinRestTemplateCustomizer
* @see DefaultZipkinRestTemplateCustomizer
* @deprecated This type should have never been public and will be hidden or removed in
* 3.0
*/
@Deprecated
@Configuration(proxyBeanMethods = false)
@EnableConfigurationProperties(ZipkinProperties.class)
@ConditionalOnProperty(value = { "spring.sleuth.enabled", "spring.zipkin.enabled" },
@@ -92,43 +92,56 @@ public class ZipkinAutoConfiguration {
@ConditionalOnMissingBean(name = REPORTER_BEAN_NAME)
public Reporter<Span> reporter(ReporterMetrics reporterMetrics,
ZipkinProperties zipkin, @Qualifier(SENDER_BEAN_NAME) Sender sender) {
CheckResult checkResult = checkResult(sender, 1_000L);
logCheckResult(sender, checkResult);
// historical constraint. Note: AsyncReporter supports memory bounds
AsyncReporter<Span> asyncReporter = AsyncReporter.builder(sender)
.queuedMaxSpans(1000)
.messageTimeout(zipkin.getMessageTimeout(), TimeUnit.SECONDS)
.metrics(reporterMetrics).build(zipkin.getEncoder());
CheckResult checkResult = checkResult(asyncReporter);
logCheckResult(asyncReporter, checkResult);
return asyncReporter;
}
private void logCheckResult(AsyncReporter asyncReporter, CheckResult checkResult) {
private void logCheckResult(Sender sender, CheckResult checkResult) {
if (log.isDebugEnabled() && checkResult != null && checkResult.ok()) {
log.debug("Check result of the [" + asyncReporter.toString() + "] is ["
+ checkResult + "]");
log.debug("Check result of the [" + sender.toString() + "] is [" + checkResult
+ "]");
}
else if (checkResult != null && !checkResult.ok()) {
log.warn("Check result of the [" + asyncReporter.toString()
+ "] contains an error [" + checkResult + "]");
log.warn("Check result of the [" + sender.toString() + "] contains an error ["
+ checkResult + "]");
}
}
private CheckResult checkResult(AsyncReporter<Span> asyncReporter) {
ExecutorService executor = Executors.newSingleThreadExecutor();
Callable<CheckResult> task = asyncReporter::check;
Future<CheckResult> future = executor.submit(task);
/** Limits {@link Sender#check()} to {@code deadlineMillis}. */
static CheckResult checkResult(Sender sender, long deadlineMillis) {
CheckResult[] outcome = new CheckResult[1];
Thread thread = new Thread(sender + " check()") {
@Override
public void run() {
try {
outcome[0] = sender.check();
}
catch (Throwable e) {
outcome[0] = CheckResult.failed(e);
}
}
};
thread.start();
try {
return future.get(1, TimeUnit.SECONDS);
thread.join(deadlineMillis);
if (outcome[0] != null) {
return outcome[0];
}
thread.interrupt();
return CheckResult.failed(new TimeoutException(
thread.getName() + " timed out after " + deadlineMillis + "ms"));
}
catch (Exception ex) {
log.warn(
"An exception took place when trying to retrieve the check result. Will return null.",
ex);
return null;
}
finally {
future.cancel(true);
executor.shutdown();
catch (InterruptedException e) {
Thread.currentThread().interrupt();
return CheckResult.failed(e);
}
}

View File

@@ -25,7 +25,10 @@ import org.springframework.boot.context.properties.ConfigurationProperties;
*
* @author Spencer Gibb
* @since 1.0.0
* @deprecated This type should have never been public and will be hidden or removed in
* 3.0
*/
@Deprecated
@ConfigurationProperties("spring.zipkin")
public class ZipkinProperties {

View File

@@ -18,11 +18,12 @@ package org.springframework.cloud.sleuth.zipkin2;
import java.io.IOException;
import java.util.List;
import java.util.concurrent.TimeoutException;
import brave.Span;
import brave.Tracing;
import brave.handler.FinishedSpanHandler;
import brave.handler.MutableSpan;
import brave.handler.SpanHandler;
import brave.propagation.TraceContext;
import brave.sampler.Sampler;
import okhttp3.mockwebserver.MockWebServer;
@@ -32,6 +33,7 @@ import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import zipkin2.Call;
import zipkin2.CheckResult;
import zipkin2.codec.Encoding;
import zipkin2.reporter.AsyncReporter;
import zipkin2.reporter.Reporter;
@@ -51,7 +53,10 @@ import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.mock.env.MockEnvironment;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.BDDAssertions.then;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
/**
* Not using {@linkplain SpringBootTest} as we need to change properties per test.
@@ -293,6 +298,77 @@ public class ZipkinAutoConfigurationTests {
Awaitility.await().untilAsserted(() -> then(sender.isSpanSent()).isTrue());
}
@Test
public void checkResult_onTime() {
Sender sender = mock(Sender.class);
when(sender.check()).thenReturn(CheckResult.OK);
assertThat(ZipkinAutoConfiguration.checkResult(sender, 200).ok()).isTrue();
}
@Test
public void checkResult_onTime_notOk() {
Sender sender = mock(Sender.class);
RuntimeException exception = new RuntimeException("dead");
when(sender.check()).thenReturn(CheckResult.failed(exception));
assertThat(ZipkinAutoConfiguration.checkResult(sender, 200).error())
.isSameAs(exception);
}
/** Bug in {@link Sender} as it shouldn't throw */
@Test
public void checkResult_thrown() {
Sender sender = mock(Sender.class);
RuntimeException exception = new RuntimeException("dead");
when(sender.check()).thenThrow(exception);
assertThat(ZipkinAutoConfiguration.checkResult(sender, 200).error())
.isSameAs(exception);
}
@Test
public void checkResult_slow() {
assertThat(ZipkinAutoConfiguration.checkResult(new Sender() {
@Override
public CheckResult check() {
try {
Thread.sleep(500L);
}
catch (InterruptedException e) {
throw new AssertionError(e);
}
return CheckResult.OK;
}
@Override
public Encoding encoding() {
return Encoding.JSON;
}
@Override
public int messageMaxBytes() {
return 0;
}
@Override
public int messageSizeInBytes(List<byte[]> list) {
return 0;
}
@Override
public Call<Void> sendSpans(List<byte[]> list) {
return Call.create(null);
}
@Override
public String toString() {
return "FakeSender{}";
}
}, 200).error()).isInstanceOf(TimeoutException.class)
.hasMessage("FakeSender{} check() timed out after 200ms");
}
@Configuration
protected static class Config {
@@ -307,10 +383,11 @@ public class ZipkinAutoConfigurationTests {
protected static class HandlerHanldersConfig {
@Bean
FinishedSpanHandler handlerOne() {
return new FinishedSpanHandler() {
SpanHandler handlerOne() {
return new SpanHandler() {
@Override
public boolean handle(TraceContext traceContext, MutableSpan span) {
public boolean end(TraceContext traceContext, MutableSpan span,
Cause cause) {
span.name("foo");
return true; // keep this span
}
@@ -318,10 +395,11 @@ public class ZipkinAutoConfigurationTests {
}
@Bean
FinishedSpanHandler handlerTwo() {
return new FinishedSpanHandler() {
SpanHandler handlerTwo() {
return new SpanHandler() {
@Override
public boolean handle(TraceContext traceContext, MutableSpan span) {
public boolean end(TraceContext traceContext, MutableSpan span,
Cause cause) {
span.name(span.name() + " bar");
return true; // keep this span
}

View File

@@ -5,7 +5,7 @@
<suppressions>
<suppress files=".*/test/.*" checks="JavadocVariable"/>
<suppress files=".*ReactorSleuth\.java" checks="InnerAssignment"/>
<suppress files=".*FinishedSpanHandlerTests.*" checks="LineLengthCheck"/>
<suppress files=".*SpanHandlerTests.*" checks="LineLengthCheck"/>
<suppress files=".*GrpcTracingIntegrationTests.*" checks="LineLengthCheck"/>
<suppress files=".*IgnoreAutoConfiguredSkipPatternsIntegrationTests.*" checks="LineLengthCheck"/>
<suppress files=".*RestTemplateTraceAspectIntegrationTests.*" checks="LineLengthCheck"/>
@@ -16,7 +16,7 @@
<suppress files=".*SleuthNewSpanParserAnnotationDisableTests.*" checks="LineLengthCheck"/>
<suppress files=".*SpanAdjusterTests.*" checks="LineLengthCheck"/>
<suppress files=".*SpringDataInstrumentationTests.*" checks="LineLengthCheck"/>
<suppress files=".*TagPropagationFinishedSpanHandlerTest.*" checks="LineLengthCheck"/>
<suppress files=".*TagPropagationSpanHandlerTest.*" checks="LineLengthCheck"/>
<suppress files=".*TraceAsyncIntegrationTests.*" checks="LineLengthCheck"/>
<suppress files=".*TraceAutoConfigurationWithDisabledSleuthTests.*" checks="LineLengthCheck"/>
<suppress files=".*TraceFilterIntegrationTests.*" checks="LineLengthCheck"/>

View File

@@ -22,9 +22,14 @@ import java.util.List;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import brave.Span.Kind;
import brave.handler.MutableSpan;
import brave.handler.SpanHandler;
import brave.http.HttpRequest;
import brave.http.HttpRequestParser;
import brave.propagation.CurrentTraceContext;
import brave.propagation.CurrentTraceContext.Scope;
import brave.propagation.TraceContext;
import brave.sampler.Sampler;
import brave.sampler.SamplerFunction;
import org.apache.commons.logging.Log;
@@ -33,6 +38,8 @@ import org.assertj.core.api.BDDAssertions;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import zipkin2.Span;
import org.springframework.beans.factory.annotation.Autowired;
@@ -65,6 +72,9 @@ import static org.assertj.core.api.BDDAssertions.then;
@ExtendWith(OutputCaptureExtension.class)
public class TraceFilterWebIntegrationTests {
private static final Logger log = LoggerFactory
.getLogger(TraceFilterWebIntegrationTests.class);
@Autowired
CurrentTraceContext currentTraceContext;
@@ -93,7 +103,8 @@ public class TraceFilterWebIntegrationTests {
}
@Test
public void should_not_create_a_span_for_error_controller(CapturedOutput capture) {
public void exception_logging_span_handler_logs_synchronous_exceptions(
CapturedOutput capture) {
try {
new RestTemplate().getForObject("http://localhost:" + port() + "/",
String.class);
@@ -108,7 +119,7 @@ public class TraceFilterWebIntegrationTests {
.containsEntry("mvc.controller.class", "ExceptionThrowingController")
.containsEntry("error",
"Request processing failed; nested exception is java.lang.RuntimeException: Throwing exception");
// issue#714
// Trace IDs in logs: issue#714
String hex = fromFirstTraceFilterFlow.traceId();
thenLogsForExceptionLoggingFilterContainTracingInformation(capture, hex);
}
@@ -168,6 +179,31 @@ public class TraceFilterWebIntegrationTests {
return new BlockingQueueSpanReporter();
}
@Bean
SpanHandler uncaughtExceptionThrown(CurrentTraceContext currentTraceContext) {
return new SpanHandler() {
@Override
public boolean end(TraceContext context, MutableSpan span, Cause cause) {
if (span.kind() != Kind.SERVER || span.error() == null
|| !log.isErrorEnabled()) {
return true; // don't add overhead as we only log server errors
}
// In TracingFilter, the exception is raised in scope. This is is more
// explicit to ensure it works in other tech such as WebFlux.
try (Scope scope = currentTraceContext.maybeScope(context)) {
log.error("Uncaught exception thrown", span.error());
}
return true;
}
@Override
public String toString() {
return "UncaughtExceptionThrown";
}
};
}
@Bean
Sampler alwaysSampler() {
return Sampler.ALWAYS_SAMPLE;

View File

@@ -37,9 +37,9 @@ public class TraceWebServletAutoConfigurationTests {
TraceWebServletAutoConfiguration.class));
@Test
public void shouldCreateExceptionLoggingFilterBeanByDefault() {
public void shouldNotCreateExceptionLoggingFilterBeanByDefault() {
this.contextRunner.run((context) -> {
assertThat(context).hasBean(EXCEPTION_LOGGING_FILTER_BEAN_NAME);
assertThat(context).doesNotHaveBean(EXCEPTION_LOGGING_FILTER_BEAN_NAME);
});
}

View File

@@ -36,11 +36,11 @@ import org.reactivestreams.Subscription;
import reactor.core.publisher.BaseSubscriber;
import reactor.core.publisher.Mono;
import reactor.netty.http.client.HttpClient;
import zipkin2.Span;
import org.springframework.cloud.sleuth.instrument.reactor.TraceReactorAutoConfigurationAccessorConfiguration;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import static brave.Span.Kind.CLIENT;
import static org.assertj.core.api.Assertions.assertThat;
/**
@@ -170,7 +170,7 @@ abstract class ITSpringConfiguredReactorClient
assertThat(server.getRequestCount()).isOne();
reporter.takeRemoteSpanWithError(Span.Kind.CLIENT, "CANCELLED");
this.spanHandler.takeRemoteSpanWithErrorMessage(CLIENT, "CANCELLED");
}
}