Moves to Brave's ErrorParser and ScopedSpan

This commit is contained in:
Adrian Cole
2018-04-05 14:18:09 +08:00
committed by Adrian Cole
parent 9ddbde2fe3
commit c5654003f8
39 changed files with 210 additions and 453 deletions

View File

@@ -272,9 +272,9 @@
<spring-cloud-stream.version>Elmhurst.BUILD-SNAPSHOT</spring-cloud-stream.version>
<spring-cloud-netflix.version>2.0.0.BUILD-SNAPSHOT</spring-cloud-netflix.version>
<spring-cloud-openfeign.version>2.0.0.BUILD-SNAPSHOT</spring-cloud-openfeign.version>
<brave.version>4.18.2</brave.version>
<brave.version>4.19.0</brave.version>
<!-- Version set until zipkin-junit gets defined in Brave BOM -->
<zipkin.version>2.6.1</zipkin.version>
<zipkin.version>2.7.0</zipkin.version>
<spring-security-boot-autoconfigure.version>2.0.0.RELEASE</spring-security-boot-autoconfigure.version>
</properties>

View File

@@ -1,38 +0,0 @@
/*
* Copyright 2013-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.cloud.sleuth;
import brave.SpanCustomizer;
/**
* Contract for hooking into process of adding error response tags.
* This interface is only called when an exception is thrown upon receiving a response.
* (e.g. a response of 500 may not be an exception).
*
* @author Marcin Grzejszczak
* @since 1.2.1
*/
public interface ErrorParser {
/**
* Allows setting of tags when an exception was thrown when the response was received.
*
* @param span - current span in context
* @param error - error that was thrown upon receiving a response
*/
void parseErrorTags(SpanCustomizer span, Throwable error);
}

View File

@@ -1,47 +0,0 @@
/*
* Copyright 2013-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.cloud.sleuth;
import brave.SpanCustomizer;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
* {@link ErrorParser} that sets the error tag for an exportable span.
*
* @author Marcin Grzejszczak
* @since 1.2.1
*/
public class ExceptionMessageErrorParser implements ErrorParser {
private static final Log log = LogFactory.getLog(ExceptionMessageErrorParser.class);
@Override
public void parseErrorTags(SpanCustomizer span, Throwable error) {
if (span != null && error != null) {
String errorMsg = getExceptionMessage(error);
if (log.isDebugEnabled()) {
log.debug("Adding an error tag [" + errorMsg + "] to span " + span);
}
span.tag("error", errorMsg);
}
}
private String getExceptionMessage(Throwable e) {
return e.getMessage() != null ? e.getMessage() : e.toString();
}
}

View File

@@ -37,7 +37,6 @@ import org.springframework.aop.support.annotation.AnnotationClassFilter;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.BeanFactoryAware;
import org.springframework.cloud.sleuth.ErrorParser;
import org.springframework.core.annotation.AnnotationUtils;
import org.springframework.util.ReflectionUtils;
import org.springframework.util.StringUtils;
@@ -177,7 +176,6 @@ class SleuthInterceptor implements IntroductionInterceptor, BeanFactoryAware {
private NewSpanParser newSpanParser;
private Tracer tracer;
private SpanTagAnnotationHandler spanTagAnnotationHandler;
private ErrorParser errorParser;
@Override
public Object invoke(MethodInvocation invocation) throws Throwable {
@@ -213,7 +211,7 @@ class SleuthInterceptor implements IntroductionInterceptor, BeanFactoryAware {
if (hasLog) {
logEvent(span, log + ".afterFailure");
}
errorParser().parseErrorTags(span.customizer(), e);
span.error(e);
throw e;
} finally {
if (hasLog) {
@@ -268,13 +266,6 @@ class SleuthInterceptor implements IntroductionInterceptor, BeanFactoryAware {
return this.spanTagAnnotationHandler;
}
private ErrorParser errorParser() {
if (this.errorParser == null) {
this.errorParser = this.beanFactory.getBean(ErrorParser.class);
}
return this.errorParser;
}
@Override public boolean implementsInterface(Class<?> intf) {
return true;
}

View File

@@ -20,6 +20,7 @@ import java.util.ArrayList;
import java.util.List;
import brave.CurrentSpanCustomizer;
import brave.ErrorParser;
import brave.Tracer;
import brave.Tracing;
import brave.context.log4j2.ThreadContextCurrentTraceContext;
@@ -34,8 +35,6 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.cloud.sleuth.DefaultSpanNamer;
import org.springframework.cloud.sleuth.ErrorParser;
import org.springframework.cloud.sleuth.ExceptionMessageErrorParser;
import org.springframework.cloud.sleuth.SpanAdjuster;
import org.springframework.cloud.sleuth.SpanNamer;
import org.springframework.cloud.sleuth.TraceKeys;
@@ -66,9 +65,13 @@ public class TraceAutoConfiguration {
Propagation.Factory factory,
CurrentTraceContext currentTraceContext,
Reporter<zipkin2.Span> reporter,
Sampler sampler, SleuthProperties sleuthProperties) {
Sampler sampler,
ErrorParser errorParser,
SleuthProperties sleuthProperties
) {
return Tracing.newBuilder()
.sampler(sampler)
.errorParser(errorParser)
.localServiceName(serviceName)
.propagationFactory(factory)
.currentTraceContext(currentTraceContext)
@@ -143,8 +146,8 @@ public class TraceAutoConfiguration {
@Bean
@ConditionalOnMissingBean
ErrorParser sleuthErrorParser() {
return new ExceptionMessageErrorParser();
ErrorParser errorParser() {
return new ErrorParser();
}
@Bean

View File

@@ -18,14 +18,12 @@ package org.springframework.cloud.sleuth.instrument.async;
import java.util.concurrent.Executor;
import brave.Tracer;
import brave.Tracing;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
import org.springframework.cloud.sleuth.DefaultSpanNamer;
import org.springframework.cloud.sleuth.ErrorParser;
import org.springframework.cloud.sleuth.ExceptionMessageErrorParser;
import org.springframework.cloud.sleuth.SpanNamer;
/**
@@ -38,11 +36,10 @@ public class LazyTraceExecutor implements Executor {
private static final Log log = LogFactory.getLog(LazyTraceExecutor.class);
private Tracer tracer;
private Tracing tracing;
private final BeanFactory beanFactory;
private final Executor delegate;
private SpanNamer spanNamer;
private ErrorParser errorParser;
public LazyTraceExecutor(BeanFactory beanFactory, Executor delegate) {
this.beanFactory = beanFactory;
@@ -51,16 +48,16 @@ public class LazyTraceExecutor implements Executor {
@Override
public void execute(Runnable command) {
if (this.tracer == null) {
if (this.tracing == null) {
try {
this.tracer = this.beanFactory.getBean(Tracer.class);
this.tracing = this.beanFactory.getBean(Tracing.class);
}
catch (NoSuchBeanDefinitionException e) {
this.delegate.execute(command);
return;
}
}
this.delegate.execute(new TraceRunnable(this.tracer, spanNamer(), errorParser(), command));
this.delegate.execute(new TraceRunnable(this.tracing, spanNamer(), command));
}
// due to some race conditions trace keys might not be ready yet
@@ -76,19 +73,4 @@ public class LazyTraceExecutor implements Executor {
}
return this.spanNamer;
}
// due to some race conditions trace keys might not be ready yet
private ErrorParser errorParser() {
if (this.errorParser == null) {
try {
this.errorParser = this.beanFactory.getBean(ErrorParser.class);
}
catch (NoSuchBeanDefinitionException e) {
log.warn("ErrorParser bean not found - will provide a manually created instance");
return new ExceptionMessageErrorParser();
}
}
return this.errorParser;
}
}

View File

@@ -22,14 +22,12 @@ import java.util.concurrent.RejectedExecutionHandler;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.ThreadPoolExecutor;
import brave.Tracer;
import brave.Tracing;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
import org.springframework.cloud.sleuth.DefaultSpanNamer;
import org.springframework.cloud.sleuth.ErrorParser;
import org.springframework.cloud.sleuth.ExceptionMessageErrorParser;
import org.springframework.cloud.sleuth.SpanNamer;
import org.springframework.core.task.TaskDecorator;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
@@ -46,11 +44,10 @@ public class LazyTraceThreadPoolTaskExecutor extends ThreadPoolTaskExecutor {
private static final Log log = LogFactory.getLog(LazyTraceThreadPoolTaskExecutor.class);
private Tracer tracer;
private final BeanFactory beanFactory;
private final ThreadPoolTaskExecutor delegate;
private Tracing tracing;
private SpanNamer spanNamer;
private ErrorParser errorParser;
public LazyTraceThreadPoolTaskExecutor(BeanFactory beanFactory,
ThreadPoolTaskExecutor delegate) {
@@ -60,32 +57,32 @@ public class LazyTraceThreadPoolTaskExecutor extends ThreadPoolTaskExecutor {
@Override
public void execute(Runnable task) {
this.delegate.execute(new TraceRunnable(tracer(), spanNamer(), errorParser(), task));
this.delegate.execute(new TraceRunnable(tracing(), spanNamer(), task));
}
@Override
public void execute(Runnable task, long startTimeout) {
this.delegate.execute(new TraceRunnable(tracer(), spanNamer(), errorParser(), task), startTimeout);
this.delegate.execute(new TraceRunnable(tracing(), spanNamer(), task), startTimeout);
}
@Override
public Future<?> submit(Runnable task) {
return this.delegate.submit(new TraceRunnable(tracer(), spanNamer(), errorParser(), task));
return this.delegate.submit(new TraceRunnable(tracing(), spanNamer(), task));
}
@Override
public <T> Future<T> submit(Callable<T> task) {
return this.delegate.submit(new TraceCallable<>(tracer(), spanNamer(), errorParser(), task));
return this.delegate.submit(new TraceCallable<>(tracing(), spanNamer(), task));
}
@Override
public ListenableFuture<?> submitListenable(Runnable task) {
return this.delegate.submitListenable(new TraceRunnable(tracer(), spanNamer(), errorParser(), task));
return this.delegate.submitListenable(new TraceRunnable(tracing(), spanNamer(), task));
}
@Override
public <T> ListenableFuture<T> submitListenable(Callable<T> task) {
return this.delegate.submitListenable(new TraceCallable<>(tracer(), spanNamer(), errorParser(), task));
return this.delegate.submitListenable(new TraceCallable<>(tracing(), spanNamer(), task));
}
@Override public boolean prefersShortLivedTasks() {
@@ -229,11 +226,11 @@ public class LazyTraceThreadPoolTaskExecutor extends ThreadPoolTaskExecutor {
this.delegate.setTaskDecorator(taskDecorator);
}
private Tracer tracer() {
if (this.tracer == null) {
this.tracer = this.beanFactory.getBean(Tracer.class);
private Tracing tracing() {
if (this.tracing == null) {
this.tracing = this.beanFactory.getBean(Tracing.class);
}
return this.tracer;
return this.tracing;
}
private SpanNamer spanNamer() {
@@ -248,17 +245,4 @@ public class LazyTraceThreadPoolTaskExecutor extends ThreadPoolTaskExecutor {
}
return this.spanNamer;
}
private ErrorParser errorParser() {
if (this.errorParser == null) {
try {
this.errorParser = this.beanFactory.getBean(ErrorParser.class);
}
catch (NoSuchBeanDefinitionException e) {
log.warn("ErrorParser bean not found - will provide a manually created instance");
return new ExceptionMessageErrorParser();
}
}
return this.errorParser;
}
}

View File

@@ -16,11 +16,12 @@
package org.springframework.cloud.sleuth.instrument.async;
import brave.ScopedSpan;
import brave.Tracing;
import brave.propagation.TraceContext;
import java.util.concurrent.Callable;
import brave.Span;
import brave.Tracer;
import org.springframework.cloud.sleuth.ErrorParser;
import org.springframework.cloud.sleuth.SpanNamer;
/**
@@ -42,31 +43,29 @@ public class TraceCallable<V> implements Callable<V> {
private final Tracer tracer;
private final Callable<V> delegate;
private final Span span;
private final ErrorParser errorParser;
private final TraceContext parent;
private final String spanName;
public TraceCallable(Tracer tracer, SpanNamer spanNamer, ErrorParser errorParser, Callable<V> delegate) {
this(tracer, spanNamer, errorParser, delegate, null);
public TraceCallable(Tracing tracing, SpanNamer spanNamer, Callable<V> delegate) {
this(tracing, spanNamer, delegate, null);
}
public TraceCallable(Tracer tracer, SpanNamer spanNamer, ErrorParser errorParser, Callable<V> delegate, String name) {
this.tracer = tracer;
public TraceCallable(Tracing tracing, SpanNamer spanNamer, Callable<V> delegate, String name) {
this.tracer = tracing.tracer();
this.delegate = delegate;
String spanName = name != null ? name : spanNamer.name(delegate, DEFAULT_SPAN_NAME);
this.span = this.tracer.nextSpan().name(spanName);
this.errorParser = errorParser;
this.parent = tracing.currentTraceContext().get();
this.spanName = name != null ? name : spanNamer.name(delegate, DEFAULT_SPAN_NAME);
}
@Override public V call() throws Exception {
Throwable error = null;
try (Tracer.SpanInScope ws = this.tracer.withSpanInScope(this.span.start())) {
ScopedSpan span = this.tracer.startScopedSpanWithParent(this.spanName, this.parent);
try {
return this.delegate.call();
} catch (Exception | Error e) {
error = e;
span.error(e);
throw e;
} finally {
this.errorParser.parseErrorTags(this.span.customizer(), error);
this.span.finish();
span.finish();
}
}
}

View File

@@ -16,10 +16,10 @@
package org.springframework.cloud.sleuth.instrument.async;
import brave.Span;
import brave.ScopedSpan;
import brave.Tracer;
import brave.Tracer.SpanInScope;
import org.springframework.cloud.sleuth.ErrorParser;
import brave.Tracing;
import brave.propagation.TraceContext;
import org.springframework.cloud.sleuth.SpanNamer;
/**
@@ -41,32 +41,30 @@ public class TraceRunnable implements Runnable {
private final Tracer tracer;
private final Runnable delegate;
private final Span span;
private final ErrorParser errorParser;
private final TraceContext parent;
private final String spanName;
public TraceRunnable(Tracer tracer, SpanNamer spanNamer, ErrorParser errorParser, Runnable delegate) {
this(tracer, spanNamer, errorParser, delegate, null);
public TraceRunnable(Tracing tracing, SpanNamer spanNamer, Runnable delegate) {
this(tracing, spanNamer, delegate, null);
}
public TraceRunnable(Tracer tracer, SpanNamer spanNamer, ErrorParser errorParser, Runnable delegate, String name) {
this.tracer = tracer;
public TraceRunnable(Tracing tracing, SpanNamer spanNamer, Runnable delegate, String name) {
this.tracer = tracing.tracer();
this.delegate = delegate;
String spanName = name != null ? name : spanNamer.name(delegate, DEFAULT_SPAN_NAME);
this.span = this.tracer.nextSpan().name(spanName);
this.errorParser = errorParser;
this.parent = tracing.currentTraceContext().get();
this.spanName = name != null ? name : spanNamer.name(delegate, DEFAULT_SPAN_NAME);
}
@Override
public void run() {
Throwable error = null;
try (SpanInScope ws = this.tracer.withSpanInScope(this.span.start())) {
this.delegate.run();
} catch (RuntimeException | Error e) {
error = e;
throw e;
} finally {
this.errorParser.parseErrorTags(this.span.customizer(), error);
this.span.finish();
}
ScopedSpan span = this.tracer.startScopedSpanWithParent(this.spanName, this.parent);
try {
this.delegate.run();
} catch (Exception | Error e) {
span.error(e);
throw e;
} finally {
span.finish();
}
}
}

View File

@@ -25,9 +25,8 @@ import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import brave.Tracer;
import brave.Tracing;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.cloud.sleuth.ErrorParser;
import org.springframework.cloud.sleuth.SpanNamer;
/**
@@ -38,11 +37,10 @@ import org.springframework.cloud.sleuth.SpanNamer;
*/
public class TraceableExecutorService implements ExecutorService {
final ExecutorService delegate;
Tracer tracer;
private final String spanName;
Tracing tracing;
SpanNamer spanNamer;
BeanFactory beanFactory;
ErrorParser errorParser;
public TraceableExecutorService(BeanFactory beanFactory, final ExecutorService delegate) {
this(beanFactory, delegate, null);
@@ -56,7 +54,7 @@ public class TraceableExecutorService implements ExecutorService {
@Override
public void execute(Runnable command) {
final Runnable r = new TraceRunnable(tracer(), spanNamer(), errorParser(), command, this.spanName);
final Runnable r = new TraceRunnable(tracing(), spanNamer(), command, this.spanName);
this.delegate.execute(r);
}
@@ -87,19 +85,19 @@ public class TraceableExecutorService implements ExecutorService {
@Override
public <T> Future<T> submit(Callable<T> task) {
Callable<T> c = new TraceCallable<>(tracer(), spanNamer(), errorParser(), task, this.spanName);
Callable<T> c = new TraceCallable<>(tracing(), spanNamer(), task, this.spanName);
return this.delegate.submit(c);
}
@Override
public <T> Future<T> submit(Runnable task, T result) {
Runnable r = new TraceRunnable(tracer(), spanNamer(), errorParser(), task, this.spanName);
Runnable r = new TraceRunnable(tracing(), spanNamer(), task, this.spanName);
return this.delegate.submit(r, result);
}
@Override
public Future<?> submit(Runnable task) {
Runnable r = new TraceRunnable(tracer(), spanNamer(), errorParser(), task, this.spanName);
Runnable r = new TraceRunnable(tracing(), spanNamer(), task, this.spanName);
return this.delegate.submit(r);
}
@@ -129,17 +127,17 @@ public class TraceableExecutorService implements ExecutorService {
List<Callable<T>> ts = new ArrayList<>();
for (Callable<T> task : tasks) {
if (!(task instanceof TraceCallable)) {
ts.add(new TraceCallable<>(tracer(), spanNamer(), errorParser(), task, this.spanName));
ts.add(new TraceCallable<>(tracing(), spanNamer(), task, this.spanName));
}
}
return ts;
}
Tracer tracer() {
if (this.tracer == null && this.beanFactory != null) {
this.tracer = this.beanFactory.getBean(Tracer.class);
Tracing tracing() {
if (this.tracing == null && this.beanFactory != null) {
this.tracing = this.beanFactory.getBean(Tracing.class);
}
return this.tracer;
return this.tracing;
}
SpanNamer spanNamer() {
@@ -148,11 +146,4 @@ public class TraceableExecutorService implements ExecutorService {
}
return this.spanNamer;
}
ErrorParser errorParser() {
if (this.errorParser == null) {
this.errorParser = this.beanFactory.getBean(ErrorParser.class);
}
return this.errorParser;
}
}

View File

@@ -42,25 +42,25 @@ public class TraceableScheduledExecutorService extends TraceableExecutorService
@Override
public ScheduledFuture<?> schedule(Runnable command, long delay, TimeUnit unit) {
Runnable r = new TraceRunnable(tracer(), spanNamer(), errorParser(), command);
Runnable r = new TraceRunnable(tracing(), spanNamer(), command);
return getScheduledExecutorService().schedule(r, delay, unit);
}
@Override
public <V> ScheduledFuture<V> schedule(Callable<V> callable, long delay, TimeUnit unit) {
Callable<V> c = new TraceCallable<>(tracer(), spanNamer(), errorParser(), callable);
Callable<V> c = new TraceCallable<>(tracing(), spanNamer(), callable);
return getScheduledExecutorService().schedule(c, delay, unit);
}
@Override
public ScheduledFuture<?> scheduleAtFixedRate(Runnable command, long initialDelay, long period, TimeUnit unit) {
Runnable r = new TraceRunnable(tracer(), spanNamer(), errorParser(), command);
Runnable r = new TraceRunnable(tracing(), spanNamer(), command);
return getScheduledExecutorService().scheduleAtFixedRate(r, initialDelay, period, unit);
}
@Override
public ScheduledFuture<?> scheduleWithFixedDelay(Runnable command, long initialDelay, long delay, TimeUnit unit) {
Runnable r = new TraceRunnable(tracer(), spanNamer(), errorParser(), command);
Runnable r = new TraceRunnable(tracing(), spanNamer(), command);
return getScheduledExecutorService().scheduleWithFixedDelay(r, initialDelay, delay, unit);
}

View File

@@ -16,13 +16,11 @@
package org.springframework.cloud.sleuth.instrument.hystrix;
import brave.Tracer;
import brave.Tracing;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.cloud.sleuth.ErrorParser;
import org.springframework.cloud.sleuth.SpanNamer;
import org.springframework.cloud.sleuth.autoconfig.TraceAutoConfiguration;
import org.springframework.context.annotation.Bean;
@@ -46,10 +44,9 @@ import com.netflix.hystrix.HystrixCommand;
@ConditionalOnProperty(value = "spring.sleuth.hystrix.strategy.enabled", matchIfMissing = true)
public class SleuthHystrixAutoConfiguration {
@Bean SleuthHystrixConcurrencyStrategy sleuthHystrixConcurrencyStrategy(Tracer tracer,
SpanNamer spanNamer, ErrorParser errorParser) {
return new SleuthHystrixConcurrencyStrategy(tracer, spanNamer,
errorParser);
@Bean SleuthHystrixConcurrencyStrategy sleuthHystrixConcurrencyStrategy(Tracing tracing,
SpanNamer spanNamer) {
return new SleuthHystrixConcurrencyStrategy(tracing, spanNamer);
}
}

View File

@@ -21,7 +21,7 @@ import java.util.concurrent.Callable;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import brave.Tracer;
import brave.Tracing;
import com.netflix.hystrix.HystrixThreadPoolKey;
import com.netflix.hystrix.HystrixThreadPoolProperties;
import com.netflix.hystrix.strategy.HystrixPlugins;
@@ -35,7 +35,6 @@ import com.netflix.hystrix.strategy.properties.HystrixPropertiesStrategy;
import com.netflix.hystrix.strategy.properties.HystrixProperty;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.cloud.sleuth.ErrorParser;
import org.springframework.cloud.sleuth.SpanNamer;
import org.springframework.cloud.sleuth.instrument.async.TraceCallable;
@@ -53,16 +52,13 @@ public class SleuthHystrixConcurrencyStrategy extends HystrixConcurrencyStrategy
private static final Log log = LogFactory
.getLog(SleuthHystrixConcurrencyStrategy.class);
private final Tracer tracer;
private final Tracing tracing;
private final SpanNamer spanNamer;
private final ErrorParser errorParser;
private HystrixConcurrencyStrategy delegate;
public SleuthHystrixConcurrencyStrategy(Tracer tracer,
SpanNamer spanNamer, ErrorParser errorParser) {
this.tracer = tracer;
public SleuthHystrixConcurrencyStrategy(Tracing tracing, SpanNamer spanNamer) {
this.tracing = tracing;
this.spanNamer = spanNamer;
this.errorParser = errorParser;
try {
this.delegate = HystrixPlugins.getInstance().getConcurrencyStrategy();
if (this.delegate instanceof SleuthHystrixConcurrencyStrategy) {
@@ -114,8 +110,8 @@ public class SleuthHystrixConcurrencyStrategy extends HystrixConcurrencyStrategy
if (wrappedCallable instanceof TraceCallable) {
return wrappedCallable;
}
return new TraceCallable<>(this.tracer, this.spanNamer,
this.errorParser, wrappedCallable, HYSTRIX_COMPONENT);
return new TraceCallable<>(this.tracing, this.spanNamer,
wrappedCallable, HYSTRIX_COMPONENT);
}
@Override

View File

@@ -16,13 +16,13 @@
package org.springframework.cloud.sleuth.instrument.web;
import brave.ErrorParser;
import javax.servlet.http.HttpServletResponse;
import brave.SpanCustomizer;
import brave.http.HttpAdapter;
import brave.http.HttpClientParser;
import brave.http.HttpServerParser;
import org.springframework.cloud.sleuth.ErrorParser;
import org.springframework.cloud.sleuth.TraceKeys;
/**
@@ -43,6 +43,10 @@ class SleuthHttpServerParser extends HttpServerParser {
this.traceKeys = traceKeys;
}
@Override protected ErrorParser errorParser() {
return this.errorParser;
}
@Override protected <Req> String spanName(HttpAdapter<Req, ?> adapter,
Req req) {
return this.clientParser.spanName(adapter, req);
@@ -53,11 +57,6 @@ class SleuthHttpServerParser extends HttpServerParser {
this.clientParser.request(adapter, req, customizer);
}
@Override
protected void error(Integer httpStatus, Throwable error, SpanCustomizer customizer) {
this.errorParser.parseErrorTags(customizer, error);
}
@Override
public <Resp> void response(HttpAdapter<?, Resp> adapter, Resp res, Throwable error,
SpanCustomizer customizer) {

View File

@@ -16,6 +16,7 @@
package org.springframework.cloud.sleuth.instrument.web;
import brave.ErrorParser;
import brave.Tracing;
import brave.http.HttpAdapter;
import brave.http.HttpClientParser;
@@ -28,7 +29,6 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.cloud.sleuth.ErrorParser;
import org.springframework.cloud.sleuth.TraceKeys;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@@ -88,8 +88,12 @@ public class TraceHttpAutoConfiguration {
@ConditionalOnProperty(name = "spring.sleuth.http.legacy.enabled",
havingValue = "false", matchIfMissing = true)
@ConditionalOnMissingBean
HttpClientParser httpClientParser() {
return new HttpClientParser();
HttpClientParser httpClientParser(ErrorParser errorParser) {
return new HttpClientParser() {
@Override protected ErrorParser errorParser() {
return errorParser;
}
};
}
@Bean

View File

@@ -19,13 +19,13 @@ package org.springframework.cloud.sleuth.instrument.web;
import java.lang.reflect.Field;
import java.util.concurrent.Callable;
import brave.Tracer;
import brave.Tracing;
import brave.propagation.TraceContext;
import org.apache.commons.logging.Log;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.cloud.sleuth.ErrorParser;
import org.springframework.cloud.sleuth.SpanNamer;
import org.springframework.cloud.sleuth.instrument.async.TraceCallable;
import org.springframework.web.context.request.async.WebAsyncTask;
@@ -44,7 +44,7 @@ import org.springframework.web.context.request.async.WebAsyncTask;
* </ul>
* <p/>
* For controllers an around aspect is created that wraps the {@link Callable#call()}
* method execution in {@link org.springframework.cloud.sleuth.TraceCallable}
* method execution in {@link TraceCallable}
* <p/>
*
* This aspect will continue a span created by the TraceFilter. It will not create
@@ -67,15 +67,12 @@ public class TraceWebAspect {
private static final Log log = org.apache.commons.logging.LogFactory
.getLog(TraceWebAspect.class);
private final Tracer tracer;
private final Tracing tracing;
private final SpanNamer spanNamer;
private final ErrorParser errorParser;
public TraceWebAspect(Tracer tracer, SpanNamer spanNamer,
ErrorParser errorParser) {
this.tracer = tracer;
public TraceWebAspect(Tracing tracing, SpanNamer spanNamer) {
this.tracing = tracing;
this.spanNamer = spanNamer;
this.errorParser = errorParser;
}
@Pointcut("@within(org.springframework.web.bind.annotation.RestController)")
@@ -100,33 +97,33 @@ public class TraceWebAspect {
@SuppressWarnings("unchecked")
public Object wrapWithCorrelationId(ProceedingJoinPoint pjp) throws Throwable {
Callable<Object> callable = (Callable<Object>) pjp.proceed();
if (this.tracer.currentSpan() != null) {
if (log.isDebugEnabled()) {
log.debug("Wrapping callable with span [" + this.tracer.currentSpan() + "]");
}
return new TraceCallable<>(this.tracer, this.spanNamer, this.errorParser, callable);
}
else {
TraceContext currentSpan = this.tracing.currentTraceContext().get();
if (currentSpan == null) {
return callable;
}
if (log.isDebugEnabled()) {
log.debug("Wrapping callable with span [" + currentSpan + "]");
}
return new TraceCallable<>(this.tracing, this.spanNamer, callable);
}
@Around("anyControllerOrRestControllerWithPublicWebAsyncTaskMethod()")
public Object wrapWebAsyncTaskWithCorrelationId(ProceedingJoinPoint pjp) throws Throwable {
final WebAsyncTask<?> webAsyncTask = (WebAsyncTask<?>) pjp.proceed();
if (this.tracer.currentSpan() != null) {
try {
if (log.isDebugEnabled()) {
log.debug("Wrapping callable with span [" + this.tracer.currentSpan()
+ "]");
}
Field callableField = WebAsyncTask.class.getDeclaredField("callable");
callableField.setAccessible(true);
callableField.set(webAsyncTask, new TraceCallable<>(this.tracer, this.spanNamer,
this.errorParser, webAsyncTask.getCallable()));
} catch (NoSuchFieldException ex) {
log.warn("Cannot wrap webAsyncTask's callable with TraceCallable", ex);
TraceContext currentSpan = this.tracing.currentTraceContext().get();
if (currentSpan == null) {
return webAsyncTask;
}
try {
if (log.isDebugEnabled()) {
log.debug("Wrapping callable with span [" + currentSpan + "]");
}
Field callableField = WebAsyncTask.class.getDeclaredField("callable");
callableField.setAccessible(true);
callableField.set(webAsyncTask, new TraceCallable<>(this.tracing, this.spanNamer,
webAsyncTask.getCallable()));
} catch (NoSuchFieldException ex) {
log.warn("Cannot wrap webAsyncTask's callable with TraceCallable", ex);
}
return webAsyncTask;
}

View File

@@ -16,7 +16,7 @@
package org.springframework.cloud.sleuth.instrument.web;
import brave.Tracer;
import brave.Tracing;
import brave.http.HttpTracing;
import brave.servlet.TracingFilter;
import brave.spring.webmvc.SpanCustomizingAsyncHandlerInterceptor;
@@ -27,7 +27,6 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.cloud.sleuth.ErrorParser;
import org.springframework.cloud.sleuth.SpanNamer;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
@@ -71,8 +70,8 @@ public class TraceWebServletAutoConfiguration {
}
@Bean
TraceWebAspect traceWebAspect(Tracer tracer, SpanNamer spanNamer, ErrorParser errorParser) {
return new TraceWebAspect(tracer, spanNamer, errorParser);
TraceWebAspect traceWebAspect(Tracing tracing, SpanNamer spanNamer) {
return new TraceWebAspect(tracing, spanNamer);
}
@Bean

View File

@@ -1,77 +0,0 @@
/*
* Copyright 2013-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.cloud.sleuth;
import java.util.AbstractMap;
import brave.Span;
import brave.Tracer;
import brave.Tracing;
import brave.propagation.CurrentTraceContext;
import org.junit.Before;
import org.junit.Test;
import org.springframework.cloud.sleuth.util.ArrayListSpanReporter;
import static org.assertj.core.api.BDDAssertions.then;
/**
* @author Marcin Grzejszczak
*/
public class ExceptionMessageErrorParserTests {
ArrayListSpanReporter reporter = new ArrayListSpanReporter();
Tracing tracing = Tracing.newBuilder()
.currentTraceContext(CurrentTraceContext.Default.create())
.spanReporter(this.reporter)
.build();
Tracer tracer = this.tracing.tracer();
@Before
public void setup() {
this.reporter.clear();
}
@Test
public void should_append_tag_for_exportable_span() throws Exception {
Throwable e = new RuntimeException("foo");
Span span = this.tracer.nextSpan();
new ExceptionMessageErrorParser().parseErrorTags(span, e);
span.finish();
then(this.reporter.getSpans()).hasSize(1);
then(this.reporter.getSpans().get(0).tags()).contains(new AbstractMap.SimpleEntry<>("error", "foo"));
}
@Test
public void should_not_throw_an_exception_when_span_is_null() throws Exception {
new ExceptionMessageErrorParser().parseErrorTags(null, null);
then(this.reporter.getSpans()).isEmpty();
}
@Test
public void should_not_append_tag_for_non_exportable_span() throws Exception {
Span span = this.tracer.nextSpan();
new ExceptionMessageErrorParser().parseErrorTags(span, null);
span.finish();
then(this.reporter.getSpans()).isEmpty();
}
}

View File

@@ -27,14 +27,12 @@ import java.util.concurrent.Future;
import brave.Span;
import brave.Tracer;
import brave.Tracing;
import brave.propagation.CurrentTraceContext;
import brave.propagation.StrictCurrentTraceContext;
import brave.sampler.Sampler;
import org.assertj.core.api.BDDAssertions;
import org.junit.Before;
import org.junit.Test;
import org.springframework.cloud.sleuth.DefaultSpanNamer;
import org.springframework.cloud.sleuth.ErrorParser;
import org.springframework.cloud.sleuth.ExceptionMessageErrorParser;
import org.springframework.cloud.sleuth.SpanName;
import org.springframework.cloud.sleuth.SpanNamer;
import org.springframework.cloud.sleuth.instrument.async.TraceCallable;
@@ -55,12 +53,12 @@ public class SpringCloudSleuthDocTests {
ArrayListSpanReporter reporter = new ArrayListSpanReporter();
Tracing tracing = Tracing.newBuilder()
.currentTraceContext(CurrentTraceContext.Default.create())
.currentTraceContext(new StrictCurrentTraceContext())
.sampler(Sampler.ALWAYS_SAMPLE)
.spanReporter(this.reporter)
.build();
Tracer tracer = this.tracing.tracer();
Tracer tracer = tracing.tracer();
@Before
public void setup() {
this.reporter.clear();
@@ -91,10 +89,9 @@ public class SpringCloudSleuthDocTests {
throws ExecutionException, InterruptedException {
ExecutorService executorService = Executors.newSingleThreadExecutor();
SpanNamer spanNamer = new DefaultSpanNamer();
ErrorParser errorParser = new ExceptionMessageErrorParser();
// tag::span_name_annotated_runnable_execution[]
Runnable runnable = new TraceRunnable(tracer, spanNamer, errorParser,
Runnable runnable = new TraceRunnable(tracing, spanNamer,
new TaxCountingRunnable());
Future<?> future = executorService.submit(runnable);
// ... some additional logic ...
@@ -112,10 +109,9 @@ public class SpringCloudSleuthDocTests {
throws ExecutionException, InterruptedException {
ExecutorService executorService = Executors.newSingleThreadExecutor();
SpanNamer spanNamer = new DefaultSpanNamer();
ErrorParser errorParser = new ExceptionMessageErrorParser();
// tag::span_name_to_string_runnable_execution[]
Runnable runnable = new TraceRunnable(tracer, spanNamer, errorParser, new Runnable() {
Runnable runnable = new TraceRunnable(tracing, spanNamer, new Runnable() {
@Override public void run() {
// perform logic
}
@@ -252,7 +248,6 @@ public class SpringCloudSleuthDocTests {
@Test
public void should_wrap_runnable_in_its_sleuth_representative() {
SpanNamer spanNamer = new DefaultSpanNamer();
ErrorParser errorParser = new ExceptionMessageErrorParser();
// tag::trace_runnable[]
Runnable runnable = new Runnable() {
@Override
@@ -266,8 +261,8 @@ public class SpringCloudSleuthDocTests {
}
};
// Manual `TraceRunnable` creation with explicit "calculateTax" Span name
Runnable traceRunnable = new TraceRunnable(tracer, spanNamer, errorParser,
runnable, "calculateTax");
Runnable traceRunnable = new TraceRunnable(tracing, spanNamer, runnable,
"calculateTax");
// Wrapping `Runnable` with `Tracing`. That way the current span will be available
// in the thread of `Runnable`
Runnable traceRunnableFromTracer = tracing.currentTraceContext().wrap(runnable);
@@ -279,7 +274,6 @@ public class SpringCloudSleuthDocTests {
@Test
public void should_wrap_callable_in_its_sleuth_representative() {
SpanNamer spanNamer = new DefaultSpanNamer();
ErrorParser errorParser = new ExceptionMessageErrorParser();
// tag::trace_callable[]
Callable<String> callable = new Callable<String>() {
@Override
@@ -293,8 +287,8 @@ public class SpringCloudSleuthDocTests {
}
};
// Manual `TraceCallable` creation with explicit "calculateTax" Span name
Callable<String> traceCallable = new TraceCallable<>(tracer, spanNamer, errorParser,
callable, "calculateTax");
Callable<String> traceCallable = new TraceCallable<>(tracing, spanNamer, callable,
"calculateTax");
// Wrapping `Callable` with `Tracing`. That way the current span will be available
// in the thread of `Callable`
Callable<String> traceCallableFromTracer = tracing.currentTraceContext().wrap(callable);

View File

@@ -1,7 +1,7 @@
package org.springframework.cloud.sleuth.instrument.async;
import brave.Tracing;
import brave.propagation.CurrentTraceContext;
import brave.propagation.StrictCurrentTraceContext;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.reflect.MethodSignature;
@@ -21,7 +21,7 @@ public class TraceAsyncAspectTest {
ArrayListSpanReporter reporter = new ArrayListSpanReporter();
Tracing tracing = Tracing.newBuilder()
.currentTraceContext(CurrentTraceContext.Default.create())
.currentTraceContext(new StrictCurrentTraceContext())
.spanReporter(this.reporter)
.build();
ProceedingJoinPoint point = Mockito.mock(ProceedingJoinPoint.class);

View File

@@ -23,7 +23,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
import brave.Span;
import brave.Tracer;
import brave.Tracing;
import brave.propagation.CurrentTraceContext;
import brave.propagation.StrictCurrentTraceContext;
import org.assertj.core.api.BDDAssertions;
import org.awaitility.Awaitility;
import org.junit.Test;
@@ -37,7 +37,7 @@ public class TraceAsyncListenableTaskExecutorTest {
AsyncListenableTaskExecutor delegate = new SimpleAsyncTaskExecutor();
Tracing tracing = Tracing.newBuilder()
.currentTraceContext(CurrentTraceContext.Default.create())
.currentTraceContext(new StrictCurrentTraceContext())
.build();
Tracer tracer = this.tracing.tracer();
TraceAsyncListenableTaskExecutor traceAsyncListenableTaskExecutor = new TraceAsyncListenableTaskExecutor(

View File

@@ -23,13 +23,12 @@ import java.util.concurrent.Executors;
import brave.Span;
import brave.Tracer;
import brave.Tracing;
import brave.propagation.CurrentTraceContext;
import brave.propagation.StrictCurrentTraceContext;
import org.junit.After;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.junit.MockitoJUnitRunner;
import org.springframework.cloud.sleuth.DefaultSpanNamer;
import org.springframework.cloud.sleuth.ExceptionMessageErrorParser;
import org.springframework.cloud.sleuth.SpanName;
import org.springframework.cloud.sleuth.util.ArrayListSpanReporter;
@@ -41,7 +40,7 @@ public class TraceCallableTests {
ExecutorService executor = Executors.newSingleThreadExecutor();
ArrayListSpanReporter reporter = new ArrayListSpanReporter();
Tracing tracing = Tracing.newBuilder()
.currentTraceContext(CurrentTraceContext.Default.create())
.currentTraceContext(new StrictCurrentTraceContext())
.spanReporter(this.reporter)
.build();
Tracer tracer = this.tracing.tracer();
@@ -134,13 +133,13 @@ public class TraceCallableTests {
private Span whenCallableGetsSubmitted(Callable<Span> callable)
throws InterruptedException, java.util.concurrent.ExecutionException {
return this.executor.submit(new TraceCallable<>(this.tracing.tracer(), new DefaultSpanNamer(),
new ExceptionMessageErrorParser(), callable)).get();
return this.executor.submit(new TraceCallable<>(this.tracing, new DefaultSpanNamer(),
callable)).get();
}
private Span whenATraceKeepingCallableGetsSubmitted()
throws InterruptedException, java.util.concurrent.ExecutionException {
return this.executor.submit(new TraceCallable<>(this.tracing.tracer(), new DefaultSpanNamer(),
new ExceptionMessageErrorParser(), new TraceKeepingCallable())).get();
return this.executor.submit(new TraceCallable<>(this.tracing, new DefaultSpanNamer(),
new TraceKeepingCallable())).get();
}
private Span whenNonTraceableCallableGetsSubmitted(Callable<Span> callable)

View File

@@ -23,13 +23,12 @@ import java.util.concurrent.atomic.AtomicReference;
import brave.Span;
import brave.Tracer;
import brave.Tracing;
import brave.propagation.CurrentTraceContext;
import brave.propagation.StrictCurrentTraceContext;
import org.junit.After;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.junit.MockitoJUnitRunner;
import org.springframework.cloud.sleuth.DefaultSpanNamer;
import org.springframework.cloud.sleuth.ExceptionMessageErrorParser;
import org.springframework.cloud.sleuth.SpanName;
import org.springframework.cloud.sleuth.util.ArrayListSpanReporter;
@@ -41,7 +40,7 @@ public class TraceRunnableTests {
ExecutorService executor = Executors.newSingleThreadExecutor();
ArrayListSpanReporter reporter = new ArrayListSpanReporter();
Tracing tracing = Tracing.newBuilder()
.currentTraceContext(CurrentTraceContext.Default.create())
.currentTraceContext(new StrictCurrentTraceContext())
.spanReporter(this.reporter)
.build();
Tracer tracer = this.tracing.tracer();
@@ -124,8 +123,8 @@ public class TraceRunnableTests {
}
private void whenRunnableGetsSubmitted(Runnable runnable) throws Exception {
this.executor.submit(new TraceRunnable(this.tracing.tracer(), new DefaultSpanNamer(),
new ExceptionMessageErrorParser(), runnable)).get();
this.executor.submit(new TraceRunnable(this.tracing, new DefaultSpanNamer(),
runnable)).get();
}
private void whenNonTraceableRunnableGetsSubmitted(Runnable runnable)

View File

@@ -28,10 +28,11 @@ import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import brave.ScopedSpan;
import brave.Span;
import brave.Tracer;
import brave.Tracing;
import brave.propagation.CurrentTraceContext;
import brave.propagation.StrictCurrentTraceContext;
import org.assertj.core.api.BDDAssertions;
import org.junit.After;
import org.junit.Before;
@@ -44,8 +45,6 @@ import org.mockito.Mockito;
import org.mockito.junit.MockitoJUnitRunner;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.cloud.sleuth.DefaultSpanNamer;
import org.springframework.cloud.sleuth.ErrorParser;
import org.springframework.cloud.sleuth.ExceptionMessageErrorParser;
import org.springframework.cloud.sleuth.SpanNamer;
import org.springframework.cloud.sleuth.util.ArrayListSpanReporter;
@@ -61,7 +60,7 @@ public class TraceableExecutorServiceTests {
ExecutorService traceManagerableExecutorService;
ArrayListSpanReporter reporter = new ArrayListSpanReporter();
Tracing tracing = Tracing.newBuilder()
.currentTraceContext(CurrentTraceContext.Default.create())
.currentTraceContext(new StrictCurrentTraceContext())
.spanReporter(this.reporter)
.build();
Tracer tracer = this.tracing.tracer();
@@ -86,15 +85,15 @@ public class TraceableExecutorServiceTests {
@Test
public void should_propagate_trace_id_and_set_new_span_when_traceable_executor_service_is_executed()
throws Exception {
Span span = this.tracer.nextSpan().name("http:PARENT");
try (Tracer.SpanInScope ws = this.tracer.withSpanInScope(span.start())) {
ScopedSpan span = this.tracer.startScopedSpan("http:PARENT");
try {
CompletableFuture.allOf(runnablesExecutedViaTraceManagerableExecutorService()).get();
} finally {
span.finish();
}
then(this.spanVerifyingRunnable.traceIds.stream().distinct()
.collect(toList())).containsOnly(span.context().traceId());
.collect(toList())).hasSize(1);
then(this.spanVerifyingRunnable.spanIds.stream().distinct()
.collect(toList())).hasSize(TOTAL_THREADS);
}
@@ -139,8 +138,7 @@ public class TraceableExecutorServiceTests {
private List callables() {
List list = new ArrayList<>();
list.add(new TraceCallable<>(this.tracing.tracer(), new DefaultSpanNamer(),
new ExceptionMessageErrorParser(), () -> "foo"));
list.add(new TraceCallable<>(this.tracing, new DefaultSpanNamer(), () -> "foo"));
list.add((Callable) () -> "bar");
return list;
}
@@ -171,9 +169,8 @@ public class TraceableExecutorServiceTests {
}
BeanFactory beanFactory() {
BDDMockito.given(this.beanFactory.getBean(Tracer.class)).willReturn(this.tracer);
BDDMockito.given(this.beanFactory.getBean(Tracing.class)).willReturn(this.tracing);
BDDMockito.given(this.beanFactory.getBean(SpanNamer.class)).willReturn(new DefaultSpanNamer());
BDDMockito.given(this.beanFactory.getBean(ErrorParser.class)).willReturn(new ExceptionMessageErrorParser());
return this.beanFactory;
}

View File

@@ -21,9 +21,8 @@ import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import java.util.function.Predicate;
import brave.Tracer;
import brave.Tracing;
import brave.propagation.CurrentTraceContext;
import brave.propagation.StrictCurrentTraceContext;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -34,8 +33,6 @@ import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.cloud.sleuth.DefaultSpanNamer;
import org.springframework.cloud.sleuth.ErrorParser;
import org.springframework.cloud.sleuth.ExceptionMessageErrorParser;
import org.springframework.cloud.sleuth.SpanNamer;
import static org.mockito.ArgumentMatchers.any;
@@ -49,7 +46,7 @@ import static org.mockito.BDDMockito.then;
public class TraceableScheduledExecutorServiceTest {
Tracing tracing = Tracing.newBuilder()
.currentTraceContext(CurrentTraceContext.Default.create())
.currentTraceContext(new StrictCurrentTraceContext())
.build();
@Mock
BeanFactory beanFactory;
@@ -123,9 +120,8 @@ public class TraceableScheduledExecutorServiceTest {
}
BeanFactory beanFactory() {
BDDMockito.given(this.beanFactory.getBean(Tracer.class)).willReturn(this.tracing.tracer());
BDDMockito.given(this.beanFactory.getBean(Tracing.class)).willReturn(this.tracing);
BDDMockito.given(this.beanFactory.getBean(SpanNamer.class)).willReturn(new DefaultSpanNamer());
BDDMockito.given(this.beanFactory.getBean(ErrorParser.class)).willReturn(new ExceptionMessageErrorParser());
return this.beanFactory;
}
}

View File

@@ -21,14 +21,13 @@ import java.util.concurrent.Callable;
import java.util.concurrent.TimeUnit;
import brave.Tracing;
import brave.propagation.CurrentTraceContext;
import brave.propagation.StrictCurrentTraceContext;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.mockito.BDDMockito;
import org.mockito.Mockito;
import org.springframework.cloud.sleuth.DefaultSpanNamer;
import org.springframework.cloud.sleuth.ExceptionMessageErrorParser;
import org.springframework.cloud.sleuth.instrument.async.TraceCallable;
import org.springframework.cloud.sleuth.util.ArrayListSpanReporter;
@@ -52,7 +51,7 @@ public class SleuthHystrixConcurrencyStrategyTest {
ArrayListSpanReporter reporter = new ArrayListSpanReporter();
Tracing tracing = Tracing.newBuilder()
.currentTraceContext(CurrentTraceContext.Default.create())
.currentTraceContext(new StrictCurrentTraceContext())
.spanReporter(this.reporter)
.build();
@@ -70,7 +69,7 @@ public class SleuthHystrixConcurrencyStrategyTest {
HystrixPlugins.getInstance().registerMetricsPublisher(new MyHystrixMetricsPublisher());
HystrixPlugins.getInstance().registerPropertiesStrategy(new MyHystrixPropertiesStrategy());
new SleuthHystrixConcurrencyStrategy(this.tracing.tracer(), new DefaultSpanNamer(), new ExceptionMessageErrorParser());
new SleuthHystrixConcurrencyStrategy(this.tracing, new DefaultSpanNamer());
then(HystrixPlugins
.getInstance().getCommandExecutionHook()).isExactlyInstanceOf(MyHystrixCommandExecutionHook.class);
@@ -87,7 +86,7 @@ public class SleuthHystrixConcurrencyStrategyTest {
throws Exception {
HystrixPlugins.getInstance().registerConcurrencyStrategy(new MyHystrixConcurrencyStrategy());
SleuthHystrixConcurrencyStrategy strategy = new SleuthHystrixConcurrencyStrategy(
this.tracing.tracer(), new DefaultSpanNamer(), new ExceptionMessageErrorParser());
this.tracing, new DefaultSpanNamer());
Callable<String> callable = strategy.wrapCallable(() -> "hello");
@@ -99,7 +98,7 @@ public class SleuthHystrixConcurrencyStrategyTest {
public void should_wrap_callable_in_trace_callable_when_delegate_is_present()
throws Exception {
SleuthHystrixConcurrencyStrategy strategy = new SleuthHystrixConcurrencyStrategy(
this.tracing.tracer(), new DefaultSpanNamer(), new ExceptionMessageErrorParser());
this.tracing, new DefaultSpanNamer());
Callable<String> callable = strategy.wrapCallable(() -> "hello");
@@ -110,7 +109,7 @@ public class SleuthHystrixConcurrencyStrategyTest {
public void should_add_trace_keys_when_span_is_created()
throws Exception {
SleuthHystrixConcurrencyStrategy strategy = new SleuthHystrixConcurrencyStrategy(
this.tracing.tracer(), new DefaultSpanNamer(), new ExceptionMessageErrorParser());
this.tracing, new DefaultSpanNamer());
Callable<String> callable = strategy.wrapCallable(() -> "hello");
callable.call();
@@ -125,7 +124,7 @@ public class SleuthHystrixConcurrencyStrategyTest {
HystrixConcurrencyStrategy strategy = Mockito.mock(HystrixConcurrencyStrategy.class);
HystrixPlugins.getInstance().registerConcurrencyStrategy(strategy);
SleuthHystrixConcurrencyStrategy sleuthStrategy = new SleuthHystrixConcurrencyStrategy(
this.tracing.tracer(), new DefaultSpanNamer(), new ExceptionMessageErrorParser());
this.tracing, new DefaultSpanNamer());
sleuthStrategy.wrapCallable(() -> "foo");
sleuthStrategy.getThreadPool(HystrixThreadPoolKey.Factory.asKey(""), Mockito.mock(

View File

@@ -21,7 +21,7 @@ import java.util.List;
import brave.Span;
import brave.Tracer;
import brave.Tracing;
import brave.propagation.CurrentTraceContext;
import brave.propagation.StrictCurrentTraceContext;
import org.junit.Before;
import org.junit.Test;
import org.springframework.cloud.sleuth.TraceKeys;
@@ -41,7 +41,7 @@ public class TraceCommandTests {
ArrayListSpanReporter reporter = new ArrayListSpanReporter();
Tracing tracing = Tracing.newBuilder()
.currentTraceContext(CurrentTraceContext.Default.create())
.currentTraceContext(new StrictCurrentTraceContext())
.spanReporter(this.reporter)
.build();
Tracer tracer = this.tracing.tracer();

View File

@@ -28,7 +28,7 @@ import java.util.concurrent.ThreadFactory;
import brave.Tracer;
import brave.Tracing;
import brave.propagation.CurrentTraceContext;
import brave.propagation.StrictCurrentTraceContext;
import rx.functions.Action0;
import rx.plugins.RxJavaErrorHandler;
import rx.plugins.RxJavaObservableExecutionHook;
@@ -52,7 +52,7 @@ public class SleuthRxJavaSchedulersHookTests {
TraceKeys traceKeys = new TraceKeys();
ArrayListSpanReporter reporter = new ArrayListSpanReporter();
Tracing tracing = Tracing.newBuilder()
.currentTraceContext(CurrentTraceContext.Default.create())
.currentTraceContext(new StrictCurrentTraceContext())
.spanReporter(this.reporter)
.build();
Tracer tracer = this.tracing.tracer();

View File

@@ -16,9 +16,9 @@
package org.springframework.cloud.sleuth.instrument.web;
import brave.ErrorParser;
import brave.http.HttpClientParser;
import brave.http.HttpServerParser;
import org.springframework.cloud.sleuth.ErrorParser;
import org.springframework.cloud.sleuth.TraceKeys;
/**

View File

@@ -20,17 +20,17 @@ import java.util.concurrent.atomic.AtomicReference;
import java.util.regex.Pattern;
import javax.servlet.Filter;
import brave.ErrorParser;
import brave.Span;
import brave.Tracer;
import brave.Tracing;
import brave.http.HttpTracing;
import brave.propagation.CurrentTraceContext;
import brave.propagation.StrictCurrentTraceContext;
import brave.sampler.Sampler;
import brave.servlet.TracingFilter;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.springframework.cloud.sleuth.ExceptionMessageErrorParser;
import org.springframework.cloud.sleuth.TraceKeys;
import org.springframework.cloud.sleuth.util.ArrayListSpanReporter;
import org.springframework.cloud.sleuth.util.SpanUtil;
@@ -61,7 +61,7 @@ public class TraceFilterTests {
ArrayListSpanReporter reporter = new ArrayListSpanReporter();
Tracing tracing = Tracing.newBuilder()
.currentTraceContext(CurrentTraceContext.Default.create())
.currentTraceContext(new StrictCurrentTraceContext())
.spanReporter(this.reporter)
.build();
Tracer tracer = this.tracing.tracer();
@@ -69,7 +69,7 @@ public class TraceFilterTests {
HttpTracing httpTracing = HttpTracing.newBuilder(this.tracing)
.clientParser(new SleuthHttpClientParser(this.traceKeys))
.serverParser(new SleuthHttpServerParser(this.traceKeys,
new ExceptionMessageErrorParser()))
new ErrorParser()))
.serverSampler(new SleuthHttpSampler(() -> Pattern.compile("")))
.build();
Filter filter = TracingFilter.create(this.httpTracing);
@@ -109,7 +109,7 @@ public class TraceFilterTests {
private Filter neverSampleFilter() {
Tracing tracing = Tracing.newBuilder()
.currentTraceContext(CurrentTraceContext.Default.create())
.currentTraceContext(new StrictCurrentTraceContext())
.spanReporter(this.reporter)
.sampler(Sampler.NEVER_SAMPLE)
.supportsJoin(false)
@@ -117,7 +117,7 @@ public class TraceFilterTests {
HttpTracing httpTracing = HttpTracing.newBuilder(tracing)
.clientParser(new SleuthHttpClientParser(this.traceKeys))
.serverParser(new SleuthHttpServerParser(this.traceKeys,
new ExceptionMessageErrorParser()))
new ErrorParser()))
.serverSampler(new SleuthHttpSampler(() -> Pattern.compile("")))
.build();
return TracingFilter.create(httpTracing);
@@ -236,7 +236,7 @@ public class TraceFilterTests {
@Test
public void createsChildFromHeadersWhenJoinUnsupported() throws Exception {
Tracing tracing = Tracing.newBuilder()
.currentTraceContext(CurrentTraceContext.Default.create())
.currentTraceContext(new StrictCurrentTraceContext())
.spanReporter(this.reporter)
.supportsJoin(false)
.build();

View File

@@ -25,7 +25,7 @@ import brave.Span;
import brave.Tracer;
import brave.Tracing;
import brave.http.HttpTracing;
import brave.propagation.CurrentTraceContext;
import brave.propagation.StrictCurrentTraceContext;
import brave.sampler.Sampler;
import brave.spring.web.TracingClientHttpRequestInterceptor;
import org.apache.commons.lang3.StringUtils;
@@ -61,7 +61,7 @@ public class TraceRestTemplateInterceptorTests {
new MockMvcClientHttpRequestFactory(this.mockMvc));
ArrayListSpanReporter reporter = new ArrayListSpanReporter();
Tracing tracing = Tracing.newBuilder()
.currentTraceContext(CurrentTraceContext.Default.create())
.currentTraceContext(new StrictCurrentTraceContext())
.spanReporter(this.reporter)
.build();
Tracer tracer = this.tracing.tracer();
@@ -137,7 +137,7 @@ public class TraceRestTemplateInterceptorTests {
@Test
public void notSampledHeaderAddedWhenNotExportable() {
Tracing tracing = Tracing.newBuilder()
.currentTraceContext(CurrentTraceContext.Default.create())
.currentTraceContext(new StrictCurrentTraceContext())
.spanReporter(this.reporter)
.sampler(Sampler.NEVER_SAMPLE)
.build();

View File

@@ -36,7 +36,7 @@ import brave.Span;
import brave.Tracer;
import brave.Tracing;
import brave.http.HttpTracing;
import brave.propagation.CurrentTraceContext;
import brave.propagation.StrictCurrentTraceContext;
import brave.spring.web.TracingClientHttpRequestInterceptor;
import okhttp3.mockwebserver.MockResponse;
import okhttp3.mockwebserver.MockWebServer;
@@ -53,7 +53,7 @@ public class TraceRestTemplateInterceptorIntegrationTests {
ArrayListSpanReporter reporter = new ArrayListSpanReporter();
Tracing tracing = Tracing.newBuilder()
.currentTraceContext(CurrentTraceContext.Default.create())
.currentTraceContext(new StrictCurrentTraceContext())
.spanReporter(this.reporter)
.build();
Tracer tracer = this.tracing.tracer();

View File

@@ -23,7 +23,7 @@ import java.util.concurrent.atomic.AtomicInteger;
import brave.Tracing;
import brave.http.HttpTracing;
import brave.propagation.CurrentTraceContext;
import brave.propagation.StrictCurrentTraceContext;
import feign.Client;
import feign.Feign;
import feign.FeignException;
@@ -41,8 +41,6 @@ import org.mockito.BDDMockito;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.cloud.sleuth.ErrorParser;
import org.springframework.cloud.sleuth.ExceptionMessageErrorParser;
import org.springframework.cloud.sleuth.instrument.web.SleuthHttpParserAccessor;
import org.springframework.cloud.sleuth.util.ArrayListSpanReporter;
@@ -62,7 +60,7 @@ public class FeignRetriesTests {
ArrayListSpanReporter reporter = new ArrayListSpanReporter();
Tracing tracing = Tracing.newBuilder()
.currentTraceContext(CurrentTraceContext.Default.create())
.currentTraceContext(new StrictCurrentTraceContext())
.spanReporter(this.reporter)
.build();
org.springframework.cloud.sleuth.TraceKeys traceKeys = new org.springframework.cloud.sleuth.TraceKeys();
@@ -74,7 +72,6 @@ public class FeignRetriesTests {
@After
public void setup() {
BDDMockito.given(this.beanFactory.getBean(HttpTracing.class)).willReturn(this.httpTracing);
BDDMockito.given(this.beanFactory.getBean(ErrorParser.class)).willReturn(new ExceptionMessageErrorParser());
}
@Test

View File

@@ -20,7 +20,7 @@ import java.io.IOException;
import brave.Tracing;
import brave.http.HttpTracing;
import brave.propagation.CurrentTraceContext;
import brave.propagation.StrictCurrentTraceContext;
import feign.Client;
import org.aspectj.lang.ProceedingJoinPoint;
import org.junit.Before;
@@ -47,7 +47,7 @@ public class TraceFeignAspectTests {
@Mock ProceedingJoinPoint pjp;
@Mock TraceLoadBalancerFeignClient traceLoadBalancerFeignClient;
Tracing tracing = Tracing.newBuilder()
.currentTraceContext(CurrentTraceContext.Default.create())
.currentTraceContext(new StrictCurrentTraceContext())
.build();
TraceKeys traceKeys = new TraceKeys();
HttpTracing httpTracing = HttpTracing.newBuilder(this.tracing)

View File

@@ -24,7 +24,7 @@ import brave.Span;
import brave.Tracer;
import brave.Tracing;
import brave.http.HttpTracing;
import brave.propagation.CurrentTraceContext;
import brave.propagation.StrictCurrentTraceContext;
import feign.Client;
import feign.Request;
import org.assertj.core.api.BDDAssertions;
@@ -50,7 +50,7 @@ public class TracingFeignClientTests {
ArrayListSpanReporter reporter = new ArrayListSpanReporter();
@Mock BeanFactory beanFactory;
Tracing tracing = Tracing.newBuilder()
.currentTraceContext(CurrentTraceContext.Default.create())
.currentTraceContext(new StrictCurrentTraceContext())
.spanReporter(this.reporter)
.build();
Tracer tracer = this.tracing.tracer();

View File

@@ -20,11 +20,12 @@ import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import brave.ErrorParser;
import brave.Span;
import brave.Tracer;
import brave.Tracing;
import brave.http.HttpTracing;
import brave.propagation.CurrentTraceContext;
import brave.propagation.StrictCurrentTraceContext;
import com.netflix.zuul.context.RequestContext;
import com.netflix.zuul.monitoring.TracerFactory;
import org.junit.After;
@@ -35,7 +36,6 @@ import org.mockito.BDDMockito;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.springframework.cloud.netflix.zuul.metrics.EmptyTracerFactory;
import org.springframework.cloud.sleuth.ExceptionMessageErrorParser;
import org.springframework.cloud.sleuth.TraceKeys;
import org.springframework.cloud.sleuth.instrument.web.SleuthHttpParserAccessor;
import org.springframework.cloud.sleuth.util.ArrayListSpanReporter;
@@ -54,13 +54,13 @@ public class TracePostZuulFilterTests {
ArrayListSpanReporter reporter = new ArrayListSpanReporter();
Tracing tracing = Tracing.newBuilder()
.currentTraceContext(CurrentTraceContext.Default.create())
.currentTraceContext(new StrictCurrentTraceContext())
.spanReporter(this.reporter)
.build();
TraceKeys traceKeys = new TraceKeys();
HttpTracing httpTracing = HttpTracing.newBuilder(this.tracing)
.clientParser(SleuthHttpParserAccessor.getClient(this.traceKeys))
.serverParser(SleuthHttpParserAccessor.getServer(this.traceKeys, new ExceptionMessageErrorParser()))
.serverParser(SleuthHttpParserAccessor.getServer(this.traceKeys, new ErrorParser()))
.build();
private TracePostZuulFilter filter = new TracePostZuulFilter(this.httpTracing);
RequestContext requestContext = new RequestContext();

View File

@@ -16,17 +16,16 @@
package org.springframework.cloud.sleuth.instrument.zuul;
import brave.ErrorParser;
import brave.Tracing;
import brave.http.HttpTracing;
import brave.propagation.CurrentTraceContext;
import brave.propagation.StrictCurrentTraceContext;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.cloud.netflix.zuul.filters.route.RibbonCommandFactory;
import org.springframework.cloud.sleuth.ExceptionMessageErrorParser;
import org.springframework.cloud.sleuth.TraceKeys;
import org.springframework.cloud.sleuth.instrument.web.SleuthHttpParserAccessor;
import org.springframework.cloud.sleuth.util.ArrayListSpanReporter;
@@ -41,17 +40,16 @@ public class TraceRibbonCommandFactoryBeanPostProcessorTests {
ArrayListSpanReporter reporter = new ArrayListSpanReporter();
Tracing tracing = Tracing.newBuilder()
.currentTraceContext(CurrentTraceContext.Default.create())
.currentTraceContext(new StrictCurrentTraceContext())
.spanReporter(this.reporter)
.build();
TraceKeys traceKeys = new TraceKeys();
HttpTracing httpTracing = HttpTracing.newBuilder(this.tracing)
.clientParser(SleuthHttpParserAccessor.getClient(this.traceKeys))
.serverParser(SleuthHttpParserAccessor.getServer(this.traceKeys, new ExceptionMessageErrorParser()))
.serverParser(SleuthHttpParserAccessor.getServer(this.traceKeys, new ErrorParser()))
.build();
@Mock RibbonCommandFactory ribbonCommandFactory;
@Mock BeanFactory beanFactory;
@InjectMocks TraceRibbonCommandFactoryBeanPostProcessor postProcessor;
@Test

View File

@@ -18,11 +18,12 @@ package org.springframework.cloud.sleuth.instrument.zuul;
import java.util.ArrayList;
import brave.ErrorParser;
import brave.Span;
import brave.Tracer;
import brave.Tracing;
import brave.http.HttpTracing;
import brave.propagation.CurrentTraceContext;
import brave.propagation.StrictCurrentTraceContext;
import com.netflix.zuul.context.RequestContext;
import org.junit.After;
import org.junit.Before;
@@ -35,7 +36,6 @@ import org.springframework.beans.factory.BeanFactory;
import org.springframework.cloud.netflix.ribbon.support.RibbonCommandContext;
import org.springframework.cloud.netflix.zuul.filters.route.RibbonCommand;
import org.springframework.cloud.netflix.zuul.filters.route.RibbonCommandFactory;
import org.springframework.cloud.sleuth.ExceptionMessageErrorParser;
import org.springframework.cloud.sleuth.TraceKeys;
import org.springframework.cloud.sleuth.instrument.web.SleuthHttpParserAccessor;
import org.springframework.cloud.sleuth.util.ArrayListSpanReporter;
@@ -52,13 +52,13 @@ public class TraceRibbonCommandFactoryTest {
ArrayListSpanReporter reporter = new ArrayListSpanReporter();
Tracing tracing = Tracing.newBuilder()
.currentTraceContext(CurrentTraceContext.Default.create())
.currentTraceContext(new StrictCurrentTraceContext())
.spanReporter(this.reporter)
.build();
TraceKeys traceKeys = new TraceKeys();
HttpTracing httpTracing = HttpTracing.newBuilder(this.tracing)
.clientParser(SleuthHttpParserAccessor.getClient(this.traceKeys))
.serverParser(SleuthHttpParserAccessor.getServer(this.traceKeys, new ExceptionMessageErrorParser()))
.serverParser(SleuthHttpParserAccessor.getServer(this.traceKeys, new ErrorParser()))
.build();
@Mock BeanFactory beanFactory;
@Mock RibbonCommandFactory ribbonCommandFactory;

View File

@@ -18,7 +18,8 @@ package org.springframework.cloud.sleuth.log;
import brave.Span;
import brave.Tracing;
import brave.propagation.CurrentTraceContext;
import brave.propagation.CurrentTraceContext.Scope;
import brave.propagation.StrictCurrentTraceContext;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@@ -34,13 +35,13 @@ public class Slf4JSpanLoggerTest {
ArrayListSpanReporter reporter = new ArrayListSpanReporter();
Tracing tracing = Tracing.newBuilder()
.currentTraceContext(CurrentTraceContext.Default.create())
.currentTraceContext(new StrictCurrentTraceContext())
.spanReporter(this.reporter)
.build();
Span span = this.tracing.tracer().nextSpan().name("span").start();
Slf4jCurrentTraceContext slf4jCurrentTraceContext =
new Slf4jCurrentTraceContext(CurrentTraceContext.Default.create());
new Slf4jCurrentTraceContext(new StrictCurrentTraceContext());
@Before
@After
@@ -50,8 +51,7 @@ public class Slf4JSpanLoggerTest {
@Test
public void should_set_entries_to_mdc_from_span() throws Exception {
CurrentTraceContext.Scope scope = this.slf4jCurrentTraceContext
.newScope(this.span.context());
Scope scope = this.slf4jCurrentTraceContext.newScope(this.span.context());
assertThat(MDC.get("X-B3-TraceId")).isEqualTo(span.context().traceIdString());
assertThat(MDC.get("traceId")).isEqualTo(span.context().traceIdString());
@@ -67,7 +67,7 @@ public class Slf4JSpanLoggerTest {
MDC.put("X-B3-TraceId", "A");
MDC.put("traceId", "A");
CurrentTraceContext.Scope scope = this.slf4jCurrentTraceContext
Scope scope = this.slf4jCurrentTraceContext
.newScope(null);
assertThat(MDC.get("X-B3-TraceId")).isNullOrEmpty();