TraceManager -> Tracer; startSpan -> startTrace
This commit is contained in:
committed by
Marcin Grzejszczak
parent
da065504a7
commit
6b88e97b9c
@@ -36,20 +36,21 @@ import java.util.concurrent.Callable;
|
||||
* are created. When a TraceScope contains a Span, this span is closed when the scope is
|
||||
* closed.
|
||||
*
|
||||
* The 'startSpan' methods in this class do a few things:
|
||||
* The 'startTrace' methods in this class do a few things:
|
||||
* <ul>
|
||||
* <li>Create a new Span which has this thread's currentSpan as one of its parents.</li>
|
||||
* <li>Set currentSpan to the new Span.</li>
|
||||
* <li>Create a TraceSpan object to manage the new Span.</li>
|
||||
* </ul>
|
||||
*
|
||||
* The 'joinTrace' method creates a new Span which has this thread's currentSpan as one of its parents
|
||||
*
|
||||
* Closing a TraceScope does a few things:
|
||||
* <ul>
|
||||
* <li>It closes the span which the scope was managing.</li>
|
||||
* <li>Set currentSpan to the previous currentSpan (which may be null).</li>
|
||||
* </ul>
|
||||
*/
|
||||
public interface TraceManager extends TraceAccessor {
|
||||
public interface Tracer extends TraceAccessor {
|
||||
|
||||
/**
|
||||
* Creates a trace wrapping a new span.
|
||||
@@ -60,7 +61,7 @@ public interface TraceManager extends TraceAccessor {
|
||||
*
|
||||
* @param name The name field for the new span to create.
|
||||
*/
|
||||
Trace startSpan(String name);
|
||||
Trace startTrace(String name);
|
||||
|
||||
/**
|
||||
* Creates a new trace scope with a specific parent. The parent might be in another
|
||||
@@ -72,7 +73,7 @@ public interface TraceManager extends TraceAccessor {
|
||||
*
|
||||
* @param name The name field for the new span to create.
|
||||
*/
|
||||
Trace startSpan(String name, Span parent);
|
||||
Trace joinTrace(String name, Span parent);
|
||||
|
||||
/**
|
||||
* Start a new span if the sampler allows it or if we are already tracing in this
|
||||
@@ -80,7 +81,7 @@ public interface TraceManager extends TraceAccessor {
|
||||
* @param name the name of the span
|
||||
* @param sampler a sampler to decide whether to create the span or not
|
||||
*/
|
||||
<T> Trace startSpan(String name, Sampler<T> sampler);
|
||||
<T> Trace startTrace(String name, Sampler<T> sampler);
|
||||
|
||||
/**
|
||||
* Pick up an existing span from another thread.
|
||||
@@ -20,7 +20,7 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.cloud.sleuth.Sampler;
|
||||
import org.springframework.cloud.sleuth.sampler.IsTracingSampler;
|
||||
import org.springframework.cloud.sleuth.trace.DefaultTraceManager;
|
||||
import org.springframework.cloud.sleuth.trace.DefaultTracer;
|
||||
import org.springframework.context.ApplicationEventPublisher;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
@@ -47,8 +47,8 @@ public class TraceAutoConfiguration {
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
public DefaultTraceManager traceManager(Sampler<Void> sampler,
|
||||
ApplicationEventPublisher publisher) {
|
||||
return new DefaultTraceManager(sampler, random(), publisher);
|
||||
public DefaultTracer traceManager(Sampler<Void> sampler,
|
||||
ApplicationEventPublisher publisher) {
|
||||
return new DefaultTracer(sampler, random(), publisher);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,7 +19,8 @@ package org.springframework.cloud.sleuth.instrument;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Value;
|
||||
import org.springframework.cloud.sleuth.Trace;
|
||||
import org.springframework.cloud.sleuth.TraceManager;
|
||||
import org.springframework.cloud.sleuth.Tracer;
|
||||
import org.springframework.cloud.sleuth.Tracer;
|
||||
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
@@ -31,12 +32,12 @@ import java.util.concurrent.Callable;
|
||||
public class TraceCallable<V> extends TraceDelegate<Callable<V>> implements Callable<V> {
|
||||
|
||||
|
||||
public TraceCallable(TraceManager traceManager, Callable<V> delegate) {
|
||||
super(traceManager, delegate);
|
||||
public TraceCallable(Tracer tracer, Callable<V> delegate) {
|
||||
super(tracer, delegate);
|
||||
}
|
||||
|
||||
public TraceCallable(TraceManager traceManager, Callable<V> delegate, String name) {
|
||||
super(traceManager, delegate, name);
|
||||
public TraceCallable(Tracer tracer, Callable<V> delegate, String name) {
|
||||
super(tracer, delegate, name);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -18,7 +18,7 @@ package org.springframework.cloud.sleuth.instrument;
|
||||
|
||||
import org.springframework.cloud.sleuth.Span;
|
||||
import org.springframework.cloud.sleuth.Trace;
|
||||
import org.springframework.cloud.sleuth.TraceManager;
|
||||
import org.springframework.cloud.sleuth.Tracer;
|
||||
|
||||
import lombok.Getter;
|
||||
import org.springframework.cloud.sleuth.trace.TraceContextHolder;
|
||||
@@ -29,35 +29,35 @@ import org.springframework.cloud.sleuth.trace.TraceContextHolder;
|
||||
@Getter
|
||||
public abstract class TraceDelegate<T> {
|
||||
|
||||
private final TraceManager traceManager;
|
||||
private final Tracer tracer;
|
||||
private final T delegate;
|
||||
private final String name;
|
||||
private final Span parent;
|
||||
|
||||
public TraceDelegate(TraceManager traceManager, T delegate) {
|
||||
this(traceManager, delegate, null);
|
||||
public TraceDelegate(Tracer tracer, T delegate) {
|
||||
this(tracer, delegate, null);
|
||||
}
|
||||
|
||||
public TraceDelegate(TraceManager traceManager, T delegate, String name) {
|
||||
this.traceManager = traceManager;
|
||||
public TraceDelegate(Tracer tracer, T delegate, String name) {
|
||||
this.tracer = tracer;
|
||||
this.delegate = delegate;
|
||||
this.name = name;
|
||||
this.parent = traceManager.getCurrentSpan();
|
||||
this.parent = tracer.getCurrentSpan();
|
||||
}
|
||||
|
||||
protected void close(Trace trace) {
|
||||
this.traceManager.close(trace);
|
||||
this.tracer.close(trace);
|
||||
}
|
||||
|
||||
protected void closeAll(Trace trace) {
|
||||
trace = this.traceManager.close(trace);
|
||||
trace = this.tracer.close(trace);
|
||||
while (trace != null) {
|
||||
trace = this.traceManager.detach(trace);
|
||||
trace = this.tracer.detach(trace);
|
||||
}
|
||||
}
|
||||
|
||||
protected Trace startSpan() {
|
||||
return this.traceManager.startSpan(getSpanName(), this.parent);
|
||||
return this.tracer.joinTrace(getSpanName(), this.parent);
|
||||
}
|
||||
|
||||
protected String getSpanName() {
|
||||
|
||||
@@ -17,10 +17,11 @@
|
||||
package org.springframework.cloud.sleuth.instrument;
|
||||
|
||||
import org.springframework.cloud.sleuth.Trace;
|
||||
import org.springframework.cloud.sleuth.TraceManager;
|
||||
import org.springframework.cloud.sleuth.Tracer;
|
||||
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Value;
|
||||
import org.springframework.cloud.sleuth.Tracer;
|
||||
|
||||
/**
|
||||
* @author Spencer Gibb
|
||||
@@ -29,12 +30,12 @@ import lombok.Value;
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
public class TraceRunnable extends TraceDelegate<Runnable> implements Runnable {
|
||||
|
||||
public TraceRunnable(TraceManager traceManager, Runnable delegate) {
|
||||
super(traceManager, delegate);
|
||||
public TraceRunnable(Tracer tracer, Runnable delegate) {
|
||||
super(tracer, delegate);
|
||||
}
|
||||
|
||||
public TraceRunnable(TraceManager traceManager, Runnable delegate, String name) {
|
||||
super(traceManager, delegate, name);
|
||||
public TraceRunnable(Tracer tracer, Runnable delegate, String name) {
|
||||
super(tracer, delegate, name);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -24,7 +24,8 @@ import org.springframework.boot.autoconfigure.AutoConfigureAfter;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.cloud.sleuth.TraceManager;
|
||||
import org.springframework.cloud.sleuth.Tracer;
|
||||
import org.springframework.cloud.sleuth.Tracer;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.core.task.SimpleAsyncTaskExecutor;
|
||||
import org.springframework.scheduling.annotation.AsyncConfigurer;
|
||||
@@ -35,7 +36,7 @@ import org.springframework.scheduling.annotation.EnableAsync;
|
||||
@Configuration
|
||||
@ConditionalOnMissingBean(AsyncConfigurer.class)
|
||||
@ConditionalOnProperty(value = "spring.sleuth.async.enabled", matchIfMissing = true)
|
||||
@ConditionalOnBean(TraceManager.class)
|
||||
@ConditionalOnBean(Tracer.class)
|
||||
@AutoConfigureAfter(AsyncCustomAutoConfiguration.class)
|
||||
public class AsyncDefaultAutoConfiguration extends AsyncConfigurerSupport {
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ import java.util.concurrent.Executor;
|
||||
|
||||
import org.springframework.beans.factory.BeanFactory;
|
||||
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
|
||||
import org.springframework.cloud.sleuth.TraceManager;
|
||||
import org.springframework.cloud.sleuth.Tracer;
|
||||
import org.springframework.cloud.sleuth.instrument.TraceRunnable;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
@@ -32,21 +32,21 @@ import lombok.RequiredArgsConstructor;
|
||||
@RequiredArgsConstructor
|
||||
public class LazyTraceExecutor implements Executor {
|
||||
|
||||
private TraceManager traceManager;
|
||||
private Tracer tracer;
|
||||
private final BeanFactory beanFactory;
|
||||
private final Executor delegate;
|
||||
|
||||
@Override
|
||||
public void execute(Runnable command) {
|
||||
if (this.traceManager == null) {
|
||||
if (this.tracer == null) {
|
||||
try {
|
||||
this.traceManager = this.beanFactory.getBean(TraceManager.class);
|
||||
this.tracer = this.beanFactory.getBean(Tracer.class);
|
||||
}
|
||||
catch (NoSuchBeanDefinitionException e) {
|
||||
this.delegate.execute(command);
|
||||
}
|
||||
}
|
||||
this.delegate.execute(new TraceRunnable(this.traceManager, command));
|
||||
this.delegate.execute(new TraceRunnable(this.tracer, command));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -24,7 +24,8 @@ import java.util.concurrent.Future;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
|
||||
import org.springframework.cloud.sleuth.TraceManager;
|
||||
import org.springframework.cloud.sleuth.Tracer;
|
||||
import org.springframework.cloud.sleuth.Tracer;
|
||||
import org.springframework.cloud.sleuth.instrument.TraceCallable;
|
||||
import org.springframework.cloud.sleuth.instrument.TraceRunnable;
|
||||
/**
|
||||
@@ -34,16 +35,16 @@ import org.springframework.cloud.sleuth.instrument.TraceRunnable;
|
||||
*/
|
||||
public class TraceableExecutorService implements ExecutorService {
|
||||
final ExecutorService delegate;
|
||||
final TraceManager traceManager;
|
||||
final Tracer tracer;
|
||||
|
||||
public TraceableExecutorService(final ExecutorService delegate, final TraceManager traceManager) {
|
||||
public TraceableExecutorService(final ExecutorService delegate, final Tracer tracer) {
|
||||
this.delegate = delegate;
|
||||
this.traceManager = traceManager;
|
||||
this.tracer = tracer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(Runnable command) {
|
||||
final Runnable r = new TraceRunnable(this.traceManager, command);
|
||||
final Runnable r = new TraceRunnable(this.tracer, command);
|
||||
this.delegate.execute(r);
|
||||
}
|
||||
|
||||
@@ -74,19 +75,19 @@ public class TraceableExecutorService implements ExecutorService {
|
||||
|
||||
@Override
|
||||
public <T> Future<T> submit(Callable<T> task) {
|
||||
Callable<T> c = new TraceCallable<>(this.traceManager, task);
|
||||
Callable<T> c = new TraceCallable<>(this.tracer, task);
|
||||
return this.delegate.submit(c);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> Future<T> submit(Runnable task, T result) {
|
||||
Runnable r = new TraceRunnable(this.traceManager, task);
|
||||
Runnable r = new TraceRunnable(this.tracer, task);
|
||||
return this.delegate.submit(r, result);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Future<?> submit(Runnable task) {
|
||||
Runnable r = new TraceRunnable(this.traceManager, task);
|
||||
Runnable r = new TraceRunnable(this.tracer, task);
|
||||
return this.delegate.submit(r);
|
||||
}
|
||||
|
||||
|
||||
@@ -21,7 +21,8 @@ import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.ScheduledFuture;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.springframework.cloud.sleuth.TraceManager;
|
||||
import org.springframework.cloud.sleuth.Tracer;
|
||||
import org.springframework.cloud.sleuth.Tracer;
|
||||
import org.springframework.cloud.sleuth.instrument.TraceCallable;
|
||||
import org.springframework.cloud.sleuth.instrument.TraceRunnable;
|
||||
|
||||
@@ -32,8 +33,8 @@ import org.springframework.cloud.sleuth.instrument.TraceRunnable;
|
||||
*/
|
||||
public class TraceableScheduledExecutorService extends TraceableExecutorService implements ScheduledExecutorService {
|
||||
|
||||
public TraceableScheduledExecutorService(final ScheduledExecutorService delegate, final TraceManager traceManager) {
|
||||
super(delegate, traceManager);
|
||||
public TraceableScheduledExecutorService(final ScheduledExecutorService delegate, final Tracer tracer) {
|
||||
super(delegate, tracer);
|
||||
}
|
||||
|
||||
private ScheduledExecutorService getScheduledExecutorService() {
|
||||
@@ -42,7 +43,7 @@ public class TraceableScheduledExecutorService extends TraceableExecutorService
|
||||
|
||||
@Override
|
||||
public ScheduledFuture<?> schedule(Runnable command, long delay, TimeUnit unit) {
|
||||
Runnable r = new TraceRunnable(this.traceManager, command);
|
||||
Runnable r = new TraceRunnable(this.tracer, command);
|
||||
return getScheduledExecutorService().schedule(r, delay, unit);
|
||||
}
|
||||
|
||||
@@ -50,19 +51,19 @@ public class TraceableScheduledExecutorService extends TraceableExecutorService
|
||||
|
||||
@Override
|
||||
public <V> ScheduledFuture<V> schedule(Callable<V> callable, long delay, TimeUnit unit) {
|
||||
Callable<V> c = new TraceCallable<>(this.traceManager,callable);
|
||||
Callable<V> c = new TraceCallable<>(this.tracer,callable);
|
||||
return getScheduledExecutorService().schedule(c, delay, unit);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ScheduledFuture<?> scheduleAtFixedRate(Runnable command, long initialDelay, long period, TimeUnit unit) {
|
||||
Runnable r = new TraceRunnable(this.traceManager, command);
|
||||
Runnable r = new TraceRunnable(this.tracer, command);
|
||||
return getScheduledExecutorService().scheduleAtFixedRate(r, initialDelay, period, unit);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ScheduledFuture<?> scheduleWithFixedDelay(Runnable command, long initialDelay, long delay, TimeUnit unit) {
|
||||
Runnable r = new TraceRunnable(this.traceManager, command);
|
||||
Runnable r = new TraceRunnable(this.tracer, command);
|
||||
return getScheduledExecutorService().scheduleWithFixedDelay(r, initialDelay, delay, unit);
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,8 @@ package org.springframework.cloud.sleuth.instrument.hystrix;
|
||||
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.cloud.sleuth.TraceManager;
|
||||
import org.springframework.cloud.sleuth.Tracer;
|
||||
import org.springframework.cloud.sleuth.Tracer;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@@ -13,7 +14,7 @@ import com.netflix.hystrix.HystrixCommand;
|
||||
@ConditionalOnProperty(value = "spring.sleuth.hystrix.strategy.enabled", matchIfMissing = true)
|
||||
public class SleuthHystrixAutoConfiguration {
|
||||
|
||||
@Bean SleuthHystrixConcurrencyStrategy sleuthHystrixConcurrencyStrategy(TraceManager traceManager) {
|
||||
return new SleuthHystrixConcurrencyStrategy(traceManager);
|
||||
@Bean SleuthHystrixConcurrencyStrategy sleuthHystrixConcurrencyStrategy(Tracer tracer) {
|
||||
return new SleuthHystrixConcurrencyStrategy(tracer);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ package org.springframework.cloud.sleuth.instrument.hystrix;
|
||||
import com.netflix.hystrix.strategy.HystrixPlugins;
|
||||
import com.netflix.hystrix.strategy.concurrency.HystrixConcurrencyStrategy;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.cloud.sleuth.TraceManager;
|
||||
import org.springframework.cloud.sleuth.Tracer;
|
||||
import org.springframework.cloud.sleuth.instrument.TraceCallable;
|
||||
|
||||
import java.util.concurrent.Callable;
|
||||
@@ -11,10 +11,10 @@ import java.util.concurrent.Callable;
|
||||
@Slf4j
|
||||
public class SleuthHystrixConcurrencyStrategy extends HystrixConcurrencyStrategy {
|
||||
|
||||
private final TraceManager traceManager;
|
||||
private final Tracer tracer;
|
||||
|
||||
public SleuthHystrixConcurrencyStrategy(TraceManager traceManager) {
|
||||
this.traceManager = traceManager;
|
||||
public SleuthHystrixConcurrencyStrategy(Tracer tracer) {
|
||||
this.tracer = tracer;
|
||||
try {
|
||||
HystrixPlugins.getInstance().registerConcurrencyStrategy(this);
|
||||
} catch (Exception e) {
|
||||
@@ -25,6 +25,6 @@ public class SleuthHystrixConcurrencyStrategy extends HystrixConcurrencyStrategy
|
||||
|
||||
@Override
|
||||
public <T> Callable<T> wrapCallable(Callable<T> callable) {
|
||||
return new TraceCallable<>(traceManager, callable);
|
||||
return new TraceCallable<>(tracer, callable);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,14 +21,14 @@ import com.netflix.hystrix.HystrixCommandGroupKey;
|
||||
import com.netflix.hystrix.HystrixThreadPoolKey;
|
||||
import org.springframework.cloud.sleuth.Span;
|
||||
import org.springframework.cloud.sleuth.Trace;
|
||||
import org.springframework.cloud.sleuth.TraceManager;
|
||||
import org.springframework.cloud.sleuth.Tracer;
|
||||
import org.springframework.cloud.sleuth.trace.TraceContextHolder;
|
||||
|
||||
/**
|
||||
* Abstraction over {@code HystrixCommand} that wraps command execution with Trace setting
|
||||
*
|
||||
* @see HystrixCommand
|
||||
* @see TraceManager
|
||||
* @see Tracer
|
||||
*
|
||||
* @author Tomasz Nurkiewicz, 4financeIT
|
||||
* @author Marcin Grzejszczak, 4financeIT
|
||||
@@ -36,47 +36,47 @@ import org.springframework.cloud.sleuth.trace.TraceContextHolder;
|
||||
*/
|
||||
public abstract class TraceCommand<R> extends HystrixCommand<R> {
|
||||
|
||||
private final TraceManager traceManager;
|
||||
private final Tracer tracer;
|
||||
private final Span parentSpan;
|
||||
|
||||
protected TraceCommand(TraceManager traceManager, HystrixCommandGroupKey group) {
|
||||
protected TraceCommand(Tracer tracer, HystrixCommandGroupKey group) {
|
||||
super(group);
|
||||
this.traceManager = traceManager;
|
||||
this.parentSpan = traceManager.getCurrentSpan();
|
||||
this.tracer = tracer;
|
||||
this.parentSpan = tracer.getCurrentSpan();
|
||||
}
|
||||
|
||||
protected TraceCommand(TraceManager traceManager, HystrixCommandGroupKey group, HystrixThreadPoolKey threadPool) {
|
||||
protected TraceCommand(Tracer tracer, HystrixCommandGroupKey group, HystrixThreadPoolKey threadPool) {
|
||||
super(group, threadPool);
|
||||
this.traceManager = traceManager;
|
||||
this.parentSpan = traceManager.getCurrentSpan();
|
||||
this.tracer = tracer;
|
||||
this.parentSpan = tracer.getCurrentSpan();
|
||||
}
|
||||
|
||||
protected TraceCommand(TraceManager traceManager, HystrixCommandGroupKey group, int executionIsolationThreadTimeoutInMilliseconds) {
|
||||
protected TraceCommand(Tracer tracer, HystrixCommandGroupKey group, int executionIsolationThreadTimeoutInMilliseconds) {
|
||||
super(group, executionIsolationThreadTimeoutInMilliseconds);
|
||||
this.traceManager = traceManager;
|
||||
this.parentSpan = traceManager.getCurrentSpan();
|
||||
this.tracer = tracer;
|
||||
this.parentSpan = tracer.getCurrentSpan();
|
||||
}
|
||||
|
||||
protected TraceCommand(TraceManager traceManager, HystrixCommandGroupKey group, HystrixThreadPoolKey threadPool, int executionIsolationThreadTimeoutInMilliseconds) {
|
||||
protected TraceCommand(Tracer tracer, HystrixCommandGroupKey group, HystrixThreadPoolKey threadPool, int executionIsolationThreadTimeoutInMilliseconds) {
|
||||
super(group, threadPool, executionIsolationThreadTimeoutInMilliseconds);
|
||||
this.traceManager = traceManager;
|
||||
this.parentSpan = traceManager.getCurrentSpan();
|
||||
this.tracer = tracer;
|
||||
this.parentSpan = tracer.getCurrentSpan();
|
||||
}
|
||||
|
||||
protected TraceCommand(TraceManager traceManager, Setter setter) {
|
||||
protected TraceCommand(Tracer tracer, Setter setter) {
|
||||
super(setter);
|
||||
this.traceManager = traceManager;
|
||||
this.parentSpan = traceManager.getCurrentSpan();
|
||||
this.tracer = tracer;
|
||||
this.parentSpan = tracer.getCurrentSpan();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected R run() throws Exception {
|
||||
enforceThatHystrixThreadIsNotPollutedByPreviousTraces();
|
||||
Trace trace = this.traceManager.startSpan(getCommandKey().name(), parentSpan);
|
||||
Trace trace = this.tracer.joinTrace(getCommandKey().name(), parentSpan);
|
||||
try {
|
||||
return doRun();
|
||||
} finally {
|
||||
this.traceManager.close(trace);
|
||||
this.tracer.close(trace);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ package org.springframework.cloud.sleuth.instrument.integration;
|
||||
import org.springframework.cloud.sleuth.MilliSpan;
|
||||
import org.springframework.cloud.sleuth.Span;
|
||||
import org.springframework.cloud.sleuth.Trace;
|
||||
import org.springframework.cloud.sleuth.TraceManager;
|
||||
import org.springframework.cloud.sleuth.Tracer;
|
||||
import org.springframework.integration.channel.AbstractMessageChannel;
|
||||
import org.springframework.integration.context.IntegrationObjectSupport;
|
||||
import org.springframework.messaging.Message;
|
||||
@@ -19,12 +19,12 @@ import java.util.Random;
|
||||
*/
|
||||
abstract class AbstractTraceChannelInterceptor extends ChannelInterceptorAdapter {
|
||||
|
||||
protected final TraceManager traceManager;
|
||||
protected final Tracer tracer;
|
||||
|
||||
protected final Random random;
|
||||
|
||||
protected AbstractTraceChannelInterceptor(TraceManager traceManager, Random random) {
|
||||
this.traceManager = traceManager;
|
||||
protected AbstractTraceChannelInterceptor(Tracer tracer, Random random) {
|
||||
this.tracer = tracer;
|
||||
this.random = random;
|
||||
}
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ package org.springframework.cloud.sleuth.instrument.integration;
|
||||
|
||||
import org.springframework.cloud.sleuth.Span;
|
||||
import org.springframework.cloud.sleuth.Trace;
|
||||
import org.springframework.cloud.sleuth.TraceManager;
|
||||
import org.springframework.cloud.sleuth.Tracer;
|
||||
import org.springframework.cloud.sleuth.sampler.IsTracingSampler;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.messaging.MessageChannel;
|
||||
@@ -33,23 +33,23 @@ public class TraceChannelInterceptor extends AbstractTraceChannelInterceptor {
|
||||
|
||||
private ThreadLocal<Trace> traceHolder = new ThreadLocal<>();
|
||||
|
||||
public TraceChannelInterceptor(TraceManager traceManager, Random random) {
|
||||
super(traceManager, random);
|
||||
public TraceChannelInterceptor(Tracer tracer, Random random) {
|
||||
super(tracer, random);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postSend(Message<?> message, MessageChannel channel, boolean sent) {
|
||||
Trace trace = this.traceHolder.get();
|
||||
// Double close to clean up the parent (remote span as well)
|
||||
this.traceManager.close(this.traceManager.close(trace));
|
||||
this.tracer.close(this.tracer.close(trace));
|
||||
this.traceHolder.remove();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Message<?> preSend(Message<?> message, MessageChannel channel) {
|
||||
if (this.traceManager.isTracing()) {
|
||||
if (this.tracer.isTracing()) {
|
||||
return SpanMessageHeaders.addSpanHeaders(message,
|
||||
this.traceManager.getCurrentSpan());
|
||||
this.tracer.getCurrentSpan());
|
||||
}
|
||||
String name = getMessageChannelName(channel);
|
||||
Trace trace = startSpan(buildSpan(message), name, message);
|
||||
@@ -59,12 +59,12 @@ public class TraceChannelInterceptor extends AbstractTraceChannelInterceptor {
|
||||
|
||||
private Trace startSpan(Span span, String name, Message message) {
|
||||
if (span != null) {
|
||||
return traceManager.startSpan(name, span);
|
||||
return tracer.joinTrace(name, span);
|
||||
}
|
||||
if (message.getHeaders().containsKey(Trace.NOT_SAMPLED_NAME)) {
|
||||
return traceManager.startSpan(name, IsTracingSampler.INSTANCE);
|
||||
return tracer.startTrace(name, IsTracingSampler.INSTANCE);
|
||||
}
|
||||
return this.traceManager.startSpan(name);
|
||||
return this.tracer.startTrace(name);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ package org.springframework.cloud.sleuth.instrument.integration;
|
||||
import org.springframework.aop.support.AopUtils;
|
||||
import org.springframework.cloud.sleuth.Span;
|
||||
import org.springframework.cloud.sleuth.Trace;
|
||||
import org.springframework.cloud.sleuth.TraceManager;
|
||||
import org.springframework.cloud.sleuth.Tracer;
|
||||
import org.springframework.integration.channel.DirectChannel;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.messaging.MessageChannel;
|
||||
@@ -48,12 +48,12 @@ import java.util.Map;
|
||||
public class TraceContextPropagationChannelInterceptor extends ChannelInterceptorAdapter
|
||||
implements ExecutorChannelInterceptor {
|
||||
|
||||
private final TraceManager traceManager;
|
||||
private final Tracer tracer;
|
||||
|
||||
private final static ThreadLocal<Trace> ORIGINAL_CONTEXT = new ThreadLocal<>();
|
||||
|
||||
public TraceContextPropagationChannelInterceptor(TraceManager traceManager) {
|
||||
this.traceManager = traceManager;
|
||||
public TraceContextPropagationChannelInterceptor(Tracer tracer) {
|
||||
this.tracer = tracer;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -61,7 +61,7 @@ public class TraceContextPropagationChannelInterceptor extends ChannelIntercepto
|
||||
if (DirectChannel.class.isAssignableFrom(AopUtils.getTargetClass(channel))) {
|
||||
return message;
|
||||
}
|
||||
Span span = this.traceManager.getCurrentSpan();
|
||||
Span span = this.tracer.getCurrentSpan();
|
||||
if (span != null) {
|
||||
return new MessageWithSpan(message, span);
|
||||
}
|
||||
@@ -101,13 +101,13 @@ public class TraceContextPropagationChannelInterceptor extends ChannelIntercepto
|
||||
protected void populatePropagatedContext(Span span, Message<?> message,
|
||||
MessageChannel channel) {
|
||||
if (span != null) {
|
||||
ORIGINAL_CONTEXT.set(this.traceManager.continueSpan(span).getSaved());
|
||||
ORIGINAL_CONTEXT.set(this.tracer.continueSpan(span).getSaved());
|
||||
}
|
||||
}
|
||||
|
||||
protected void resetPropagatedContext() {
|
||||
Trace originalContext = ORIGINAL_CONTEXT.get();
|
||||
this.traceManager.detach(originalContext);
|
||||
this.tracer.detach(originalContext);
|
||||
ORIGINAL_CONTEXT.remove();
|
||||
}
|
||||
|
||||
|
||||
@@ -20,7 +20,8 @@ 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.TraceManager;
|
||||
import org.springframework.cloud.sleuth.Tracer;
|
||||
import org.springframework.cloud.sleuth.Tracer;
|
||||
import org.springframework.cloud.sleuth.autoconfig.TraceAutoConfiguration;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
@@ -33,7 +34,7 @@ import java.util.Random;
|
||||
*/
|
||||
@Configuration
|
||||
@ConditionalOnClass(GlobalChannelInterceptor.class)
|
||||
@ConditionalOnBean(TraceManager.class)
|
||||
@ConditionalOnBean(Tracer.class)
|
||||
@AutoConfigureAfter(TraceAutoConfiguration.class)
|
||||
@ConditionalOnProperty(value = "spring.sleuth.integration.enabled", matchIfMissing = true)
|
||||
public class TraceSpringIntegrationAutoConfiguration {
|
||||
@@ -41,25 +42,25 @@ public class TraceSpringIntegrationAutoConfiguration {
|
||||
@Bean
|
||||
@GlobalChannelInterceptor
|
||||
public TraceContextPropagationChannelInterceptor traceContextPropagationChannelInterceptor(
|
||||
TraceManager traceManager) {
|
||||
return new TraceContextPropagationChannelInterceptor(traceManager);
|
||||
Tracer tracer) {
|
||||
return new TraceContextPropagationChannelInterceptor(tracer);
|
||||
}
|
||||
|
||||
@Bean
|
||||
@GlobalChannelInterceptor
|
||||
public TraceChannelInterceptor traceChannelInterceptor(TraceManager traceManager, Random random) {
|
||||
return new TraceChannelInterceptor(traceManager, random);
|
||||
public TraceChannelInterceptor traceChannelInterceptor(Tracer tracer, Random random) {
|
||||
return new TraceChannelInterceptor(tracer, random);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public TraceStompMessageChannelInterceptor traceStompMessageChannelInterceptor(TraceManager traceManager, Random random) {
|
||||
return new TraceStompMessageChannelInterceptor(traceManager, random);
|
||||
public TraceStompMessageChannelInterceptor traceStompMessageChannelInterceptor(Tracer tracer, Random random) {
|
||||
return new TraceStompMessageChannelInterceptor(tracer, random);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public TraceStompMessageContextPropagationChannelInterceptor traceStompMessageContextPropagationChannelInteceptor(
|
||||
TraceManager traceManager) {
|
||||
return new TraceStompMessageContextPropagationChannelInterceptor(traceManager);
|
||||
Tracer tracer) {
|
||||
return new TraceStompMessageContextPropagationChannelInterceptor(tracer);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ package org.springframework.cloud.sleuth.instrument.integration;
|
||||
|
||||
import org.springframework.cloud.sleuth.Span;
|
||||
import org.springframework.cloud.sleuth.Trace;
|
||||
import org.springframework.cloud.sleuth.TraceManager;
|
||||
import org.springframework.cloud.sleuth.Tracer;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.messaging.MessageChannel;
|
||||
import org.springframework.messaging.support.ChannelInterceptor;
|
||||
@@ -34,14 +34,14 @@ import java.util.Random;
|
||||
public class TraceStompMessageChannelInterceptor extends AbstractTraceChannelInterceptor implements ChannelInterceptor {
|
||||
private ThreadLocal<Trace> traceScopeHolder = new ThreadLocal<Trace>();
|
||||
|
||||
public TraceStompMessageChannelInterceptor(TraceManager traceManager, Random random) {
|
||||
super(traceManager, random);
|
||||
public TraceStompMessageChannelInterceptor(Tracer tracer, Random random) {
|
||||
super(tracer, random);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Message<?> preSend(Message<?> message, MessageChannel channel) {
|
||||
if (traceManager.isTracing() || message.getHeaders().containsKey(Trace.NOT_SAMPLED_NAME)) {
|
||||
return StompMessageBuilder.fromMessage(message).setHeadersFromSpan(traceManager.getCurrentSpan()).build();
|
||||
if (tracer.isTracing() || message.getHeaders().containsKey(Trace.NOT_SAMPLED_NAME)) {
|
||||
return StompMessageBuilder.fromMessage(message).setHeadersFromSpan(tracer.getCurrentSpan()).build();
|
||||
}
|
||||
String name = getMessageChannelName(channel);
|
||||
Trace trace = startSpan(buildSpan(message), name);
|
||||
@@ -51,16 +51,16 @@ public class TraceStompMessageChannelInterceptor extends AbstractTraceChannelInt
|
||||
|
||||
private Trace startSpan(Span span, String name) {
|
||||
if (span != null) {
|
||||
return traceManager.startSpan(name, span);
|
||||
return tracer.joinTrace(name, span);
|
||||
}
|
||||
return traceManager.startSpan(name);
|
||||
return tracer.startTrace(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postSend(Message<?> message, MessageChannel channel, boolean sent) {
|
||||
final ThreadLocal<Trace> traceScopeHolder = this.traceScopeHolder;
|
||||
Trace traceInScope = traceScopeHolder.get();
|
||||
this.traceManager.close(traceInScope);
|
||||
this.tracer.close(traceInScope);
|
||||
traceScopeHolder.remove();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,7 +21,8 @@ import java.util.Map;
|
||||
import org.springframework.aop.support.AopUtils;
|
||||
import org.springframework.cloud.sleuth.Span;
|
||||
import org.springframework.cloud.sleuth.Trace;
|
||||
import org.springframework.cloud.sleuth.TraceManager;
|
||||
import org.springframework.cloud.sleuth.Tracer;
|
||||
import org.springframework.cloud.sleuth.Tracer;
|
||||
import org.springframework.integration.channel.DirectChannel;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.messaging.MessageChannel;
|
||||
@@ -40,11 +41,11 @@ import org.springframework.util.Assert;
|
||||
public class TraceStompMessageContextPropagationChannelInterceptor extends ChannelInterceptorAdapter
|
||||
implements ExecutorChannelInterceptor {
|
||||
|
||||
private final TraceManager traceManager;
|
||||
private final Tracer tracer;
|
||||
private final static ThreadLocal<Trace> ORIGINAL_CONTEXT = new ThreadLocal<>();
|
||||
|
||||
public TraceStompMessageContextPropagationChannelInterceptor(TraceManager traceManager) {
|
||||
this.traceManager = traceManager;
|
||||
public TraceStompMessageContextPropagationChannelInterceptor(Tracer tracer) {
|
||||
this.tracer = tracer;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -52,7 +53,7 @@ public class TraceStompMessageContextPropagationChannelInterceptor extends Chann
|
||||
if (DirectChannel.class.isAssignableFrom(AopUtils.getTargetClass(channel))) {
|
||||
return message;
|
||||
}
|
||||
Span span = this.traceManager.getCurrentSpan();
|
||||
Span span = this.tracer.getCurrentSpan();
|
||||
if (span != null) {
|
||||
return new MessageWithSpan(message, span);
|
||||
} else {
|
||||
@@ -82,13 +83,13 @@ public class TraceStompMessageContextPropagationChannelInterceptor extends Chann
|
||||
|
||||
protected void populatePropagatedContext(Span span) {
|
||||
if (span != null) {
|
||||
ORIGINAL_CONTEXT.set(this.traceManager.continueSpan(span).getSaved());
|
||||
ORIGINAL_CONTEXT.set(this.tracer.continueSpan(span).getSaved());
|
||||
}
|
||||
}
|
||||
|
||||
protected void resetPropagatedContext() {
|
||||
Trace originalContext = ORIGINAL_CONTEXT.get();
|
||||
this.traceManager.detach(originalContext);
|
||||
this.tracer.detach(originalContext);
|
||||
ORIGINAL_CONTEXT.remove();
|
||||
}
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ import org.aspectj.lang.ProceedingJoinPoint;
|
||||
import org.aspectj.lang.annotation.Around;
|
||||
import org.aspectj.lang.annotation.Aspect;
|
||||
import org.springframework.cloud.sleuth.Trace;
|
||||
import org.springframework.cloud.sleuth.TraceManager;
|
||||
import org.springframework.cloud.sleuth.Tracer;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
|
||||
/**
|
||||
@@ -33,25 +33,25 @@ import org.springframework.scheduling.annotation.Scheduled;
|
||||
* @author Marcin Grzejszczak, 4financeIT
|
||||
* @author Spencer Gibb
|
||||
*
|
||||
* @see TraceManager
|
||||
* @see Tracer
|
||||
*/
|
||||
@Aspect
|
||||
public class TraceSchedulingAspect {
|
||||
|
||||
private final TraceManager traceManager;
|
||||
private final Tracer tracer;
|
||||
|
||||
public TraceSchedulingAspect(TraceManager traceManager) {
|
||||
this.traceManager = traceManager;
|
||||
public TraceSchedulingAspect(Tracer tracer) {
|
||||
this.tracer = tracer;
|
||||
}
|
||||
|
||||
@Around("execution (@org.springframework.scheduling.annotation.Scheduled * *.*(..))")
|
||||
public Object traceBackgroundThread(final ProceedingJoinPoint pjp) throws Throwable {
|
||||
Trace trace = this.traceManager.startSpan(pjp.toShortString());
|
||||
Trace trace = this.tracer.startTrace(pjp.toShortString());
|
||||
try {
|
||||
return pjp.proceed();
|
||||
}
|
||||
finally {
|
||||
this.traceManager.close(trace);
|
||||
this.tracer.close(trace);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -25,7 +25,8 @@ 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.TraceManager;
|
||||
import org.springframework.cloud.sleuth.Tracer;
|
||||
import org.springframework.cloud.sleuth.Tracer;
|
||||
import org.springframework.cloud.sleuth.autoconfig.TraceAutoConfiguration;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
@@ -42,14 +43,14 @@ import org.springframework.context.annotation.EnableAspectJAutoProxy;
|
||||
@Configuration
|
||||
@EnableAspectJAutoProxy
|
||||
@ConditionalOnProperty(value = "spring.sleuth.schedule.enabled", matchIfMissing = true)
|
||||
@ConditionalOnBean(TraceManager.class)
|
||||
@ConditionalOnBean(Tracer.class)
|
||||
@AutoConfigureAfter(TraceAutoConfiguration.class)
|
||||
public class TraceSchedulingAutoConfiguration {
|
||||
|
||||
@ConditionalOnClass(ProceedingJoinPoint.class)
|
||||
@Bean
|
||||
public TraceSchedulingAspect traceSchedulingAspect(TraceManager traceManager) {
|
||||
return new TraceSchedulingAspect(traceManager);
|
||||
public TraceSchedulingAspect traceSchedulingAspect(Tracer tracer) {
|
||||
return new TraceSchedulingAspect(tracer);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -15,22 +15,8 @@
|
||||
*/
|
||||
package org.springframework.cloud.sleuth.instrument.web;
|
||||
|
||||
import static org.springframework.util.StringUtils.hasText;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Random;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import javax.servlet.FilterChain;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.springframework.cloud.sleuth.MilliSpan;
|
||||
import org.springframework.cloud.sleuth.*;
|
||||
import org.springframework.cloud.sleuth.MilliSpan.MilliSpanBuilder;
|
||||
import org.springframework.cloud.sleuth.Span;
|
||||
import org.springframework.cloud.sleuth.Trace;
|
||||
import org.springframework.cloud.sleuth.TraceManager;
|
||||
import org.springframework.cloud.sleuth.event.ServerReceivedEvent;
|
||||
import org.springframework.cloud.sleuth.event.ServerSentEvent;
|
||||
import org.springframework.cloud.sleuth.instrument.TraceKeys;
|
||||
@@ -45,6 +31,16 @@ import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.filter.OncePerRequestFilter;
|
||||
import org.springframework.web.util.UrlPathHelper;
|
||||
|
||||
import javax.servlet.FilterChain;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.util.Random;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import static org.springframework.util.StringUtils.hasText;
|
||||
|
||||
/**
|
||||
* Filter that takes the value of the {@link Trace#SPAN_ID_NAME} and
|
||||
* {@link Trace#TRACE_ID_NAME} header from either request or response and uses them to
|
||||
@@ -74,7 +70,7 @@ public class TraceFilter extends OncePerRequestFilter
|
||||
public static final Pattern DEFAULT_SKIP_PATTERN = Pattern.compile(
|
||||
"/api-docs.*|/autoconfig|/configprops|/dump|/info|/metrics.*|/mappings|/trace|/swagger.*|.*\\.png|.*\\.css|.*\\.js|.*\\.html|/favicon.ico|/hystrix.stream");
|
||||
|
||||
private final TraceManager traceManager;
|
||||
private final Tracer tracer;
|
||||
private final Pattern skipPattern;
|
||||
private final Random random;
|
||||
|
||||
@@ -82,14 +78,14 @@ public class TraceFilter extends OncePerRequestFilter
|
||||
private ApplicationEventPublisher publisher;
|
||||
|
||||
|
||||
public TraceFilter(TraceManager traceManager) {
|
||||
this.traceManager = traceManager;
|
||||
public TraceFilter(Tracer tracer) {
|
||||
this.tracer = tracer;
|
||||
this.skipPattern = DEFAULT_SKIP_PATTERN;
|
||||
this.random = new Random();
|
||||
}
|
||||
|
||||
public TraceFilter(TraceManager traceManager, Pattern skipPattern, Random random) {
|
||||
this.traceManager = traceManager;
|
||||
public TraceFilter(Tracer tracer, Pattern skipPattern, Random random) {
|
||||
this.tracer = tracer;
|
||||
this.skipPattern = skipPattern;
|
||||
this.random = random;
|
||||
}
|
||||
@@ -111,7 +107,7 @@ public class TraceFilter extends OncePerRequestFilter
|
||||
|
||||
Trace trace = (Trace) request.getAttribute(TRACE_REQUEST_ATTR);
|
||||
if (trace != null) {
|
||||
this.traceManager.continueSpan(trace.getSpan());
|
||||
this.tracer.continueSpan(trace.getSpan());
|
||||
}
|
||||
else if (skip) {
|
||||
addToResponseIfNotPresent(response, Trace.NOT_SAMPLED_NAME, "");
|
||||
@@ -143,18 +139,18 @@ public class TraceFilter extends OncePerRequestFilter
|
||||
span.remote(true);
|
||||
|
||||
Span parent = span.build();
|
||||
trace = this.traceManager.startSpan(name, parent);
|
||||
trace = this.tracer.joinTrace(name, parent);
|
||||
publish(new ServerReceivedEvent(this, parent, trace.getSpan()));
|
||||
request.setAttribute(TRACE_REQUEST_ATTR, trace);
|
||||
|
||||
}
|
||||
else {
|
||||
if (skip) {
|
||||
trace = this.traceManager.startSpan(name, IsTracingSampler.INSTANCE
|
||||
trace = this.tracer.startTrace(name, IsTracingSampler.INSTANCE
|
||||
);
|
||||
}
|
||||
else {
|
||||
trace = this.traceManager.startSpan(name);
|
||||
trace = this.tracer.startTrace(name);
|
||||
}
|
||||
request.setAttribute(TRACE_REQUEST_ATTR, trace);
|
||||
}
|
||||
@@ -186,7 +182,7 @@ public class TraceFilter extends OncePerRequestFilter
|
||||
trace.getSpan()));
|
||||
}
|
||||
// Double close to clean up the parent (remote span as well)
|
||||
this.traceManager.close(this.traceManager.close(trace));
|
||||
this.tracer.close(this.tracer.close(trace));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -207,10 +203,10 @@ public class TraceFilter extends OncePerRequestFilter
|
||||
/** Override to add annotations not defined in {@link TraceKeys}. */
|
||||
protected void addRequestTags(HttpServletRequest request) {
|
||||
String uri = this.urlPathHelper.getPathWithinApplication(request);
|
||||
this.traceManager.addTag(TraceKeys.HTTP_URL, getFullUrl(request));
|
||||
this.traceManager.addTag(TraceKeys.HTTP_HOST, request.getServerName());
|
||||
this.traceManager.addTag(TraceKeys.HTTP_PATH, uri);
|
||||
this.traceManager.addTag(TraceKeys.HTTP_METHOD, request.getMethod());
|
||||
this.tracer.addTag(TraceKeys.HTTP_URL, getFullUrl(request));
|
||||
this.tracer.addTag(TraceKeys.HTTP_HOST, request.getServerName());
|
||||
this.tracer.addTag(TraceKeys.HTTP_PATH, uri);
|
||||
this.tracer.addTag(TraceKeys.HTTP_METHOD, request.getMethod());
|
||||
}
|
||||
|
||||
/** Override to add annotations not defined in {@link TraceKeys}. */
|
||||
@@ -219,11 +215,11 @@ public class TraceFilter extends OncePerRequestFilter
|
||||
if (httpStatus == HttpServletResponse.SC_OK && e != null) {
|
||||
// Filter chain threw exception but the response status may not have been set
|
||||
// yet, so we have to guess.
|
||||
this.traceManager.addTag(TraceKeys.HTTP_STATUS_CODE,
|
||||
this.tracer.addTag(TraceKeys.HTTP_STATUS_CODE,
|
||||
String.valueOf(HttpServletResponse.SC_INTERNAL_SERVER_ERROR));
|
||||
}
|
||||
else if ((httpStatus < 200) || (httpStatus > 299)){
|
||||
this.traceManager.addTag(TraceKeys.HTTP_STATUS_CODE,
|
||||
this.tracer.addTag(TraceKeys.HTTP_STATUS_CODE,
|
||||
String.valueOf(response.getStatus()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.springframework.cloud.sleuth.Trace;
|
||||
import org.springframework.cloud.sleuth.TraceManager;
|
||||
import org.springframework.cloud.sleuth.Tracer;
|
||||
import org.springframework.web.servlet.HandlerInterceptor;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
|
||||
@@ -31,10 +31,10 @@ public class TraceHandlerInterceptor implements HandlerInterceptor {
|
||||
|
||||
private static final String ATTR_NAME = "__CURRENT_TRACE_HANDLER_TRACE_ATTR___";
|
||||
|
||||
private final TraceManager traceManager;
|
||||
private final Tracer tracer;
|
||||
|
||||
public TraceHandlerInterceptor(TraceManager traceManager) {
|
||||
this.traceManager = traceManager;
|
||||
public TraceHandlerInterceptor(Tracer tracer) {
|
||||
this.tracer = tracer;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -42,7 +42,7 @@ public class TraceHandlerInterceptor implements HandlerInterceptor {
|
||||
Object handler) throws Exception {
|
||||
// TODO: get trace data from request?
|
||||
// TODO: what is the description?
|
||||
Trace trace = this.traceManager.startSpan("traceHandlerInterceptor");
|
||||
Trace trace = this.tracer.startTrace("traceHandlerInterceptor");
|
||||
request.setAttribute(ATTR_NAME, trace);
|
||||
return true;
|
||||
}
|
||||
@@ -57,6 +57,6 @@ public class TraceHandlerInterceptor implements HandlerInterceptor {
|
||||
public void afterCompletion(HttpServletRequest request, HttpServletResponse response,
|
||||
Object handler, Exception ex) throws Exception {
|
||||
Trace trace = Trace.class.cast(request.getAttribute(ATTR_NAME));
|
||||
this.traceManager.close(trace);
|
||||
this.tracer.close(trace);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,7 +24,8 @@ import org.aspectj.lang.annotation.Around;
|
||||
import org.aspectj.lang.annotation.Aspect;
|
||||
import org.aspectj.lang.annotation.Pointcut;
|
||||
import org.springframework.cloud.sleuth.TraceAccessor;
|
||||
import org.springframework.cloud.sleuth.TraceManager;
|
||||
import org.springframework.cloud.sleuth.Tracer;
|
||||
import org.springframework.cloud.sleuth.Tracer;
|
||||
import org.springframework.cloud.sleuth.instrument.TraceCallable;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
@@ -50,7 +51,7 @@ import lombok.extern.apachecommons.CommonsLog;
|
||||
* @see Controller
|
||||
* @see RestOperations
|
||||
* @see TraceCallable
|
||||
* @see TraceManager
|
||||
* @see Tracer
|
||||
*
|
||||
* @author Tomasz Nurkewicz, 4financeIT
|
||||
* @author Marcin Grzejszczak, 4financeIT
|
||||
@@ -61,11 +62,11 @@ import lombok.extern.apachecommons.CommonsLog;
|
||||
@CommonsLog
|
||||
public class TraceWebAspect {
|
||||
|
||||
private final TraceManager traceManager;
|
||||
private final Tracer tracer;
|
||||
private final TraceAccessor accessor;
|
||||
|
||||
public TraceWebAspect(TraceManager traceManager, TraceAccessor accessor) {
|
||||
this.traceManager = traceManager;
|
||||
public TraceWebAspect(Tracer tracer, TraceAccessor accessor) {
|
||||
this.tracer = tracer;
|
||||
this.accessor = accessor;
|
||||
}
|
||||
|
||||
@@ -100,7 +101,7 @@ public class TraceWebAspect {
|
||||
if (this.accessor.isTracing()) {
|
||||
log.debug("Wrapping callable with span ["
|
||||
+ this.accessor.getCurrentSpan() + "]");
|
||||
return new TraceCallable<>(this.traceManager, callable);
|
||||
return new TraceCallable<>(this.tracer, callable);
|
||||
}
|
||||
else {
|
||||
return callable;
|
||||
@@ -116,7 +117,7 @@ public class TraceWebAspect {
|
||||
+ this.accessor.getCurrentSpan() + "]");
|
||||
Field callableField = WebAsyncTask.class.getDeclaredField("callable");
|
||||
callableField.setAccessible(true);
|
||||
callableField.set(webAsyncTask, new TraceCallable<>(this.traceManager, webAsyncTask.getCallable()));
|
||||
callableField.set(webAsyncTask, new TraceCallable<>(this.tracer, webAsyncTask.getCallable()));
|
||||
} catch (NoSuchFieldException ex) {
|
||||
log.warn("Cannot wrap webAsyncTask's callable with TraceCallable", ex);
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
|
||||
import org.springframework.boot.context.embedded.FilterRegistrationBean;
|
||||
import org.springframework.cloud.sleuth.TraceAccessor;
|
||||
import org.springframework.cloud.sleuth.TraceManager;
|
||||
import org.springframework.cloud.sleuth.Tracer;
|
||||
import org.springframework.cloud.sleuth.autoconfig.TraceAutoConfiguration;
|
||||
import org.springframework.context.ApplicationEventPublisher;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
@@ -45,7 +45,7 @@ import org.springframework.util.StringUtils;
|
||||
@Configuration
|
||||
@ConditionalOnProperty(value = "spring.sleuth.web.enabled", matchIfMissing = true)
|
||||
@ConditionalOnWebApplication
|
||||
@ConditionalOnBean(TraceManager.class)
|
||||
@ConditionalOnBean(Tracer.class)
|
||||
@AutoConfigureAfter(TraceAutoConfiguration.class)
|
||||
public class TraceWebAutoConfiguration {
|
||||
|
||||
@@ -56,14 +56,14 @@ public class TraceWebAutoConfiguration {
|
||||
private String skipPattern;
|
||||
|
||||
@Autowired
|
||||
private TraceManager traceManager;
|
||||
private Tracer tracer;
|
||||
|
||||
@Autowired
|
||||
private TraceAccessor accessor;
|
||||
|
||||
@Bean
|
||||
public TraceWebAspect traceWebAspect() {
|
||||
return new TraceWebAspect(this.traceManager, this.accessor);
|
||||
return new TraceWebAspect(this.tracer, this.accessor);
|
||||
}
|
||||
|
||||
@Bean
|
||||
@@ -71,7 +71,7 @@ public class TraceWebAutoConfiguration {
|
||||
public TraceFilter traceFilter(ApplicationEventPublisher publisher, Random random) {
|
||||
Pattern pattern = StringUtils.hasText(this.skipPattern) ? Pattern.compile(this.skipPattern)
|
||||
: TraceFilter.DEFAULT_SKIP_PATTERN;
|
||||
TraceFilter filter = new TraceFilter(this.traceManager, pattern, random);
|
||||
TraceFilter filter = new TraceFilter(this.tracer, pattern, random);
|
||||
filter.setApplicationEventPublisher(publisher);
|
||||
return filter;
|
||||
}
|
||||
|
||||
@@ -21,7 +21,8 @@ import java.lang.reflect.InvocationHandler;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.cloud.sleuth.TraceManager;
|
||||
import org.springframework.cloud.sleuth.Tracer;
|
||||
import org.springframework.cloud.sleuth.Tracer;
|
||||
import org.springframework.cloud.sleuth.instrument.hystrix.TraceCommand;
|
||||
|
||||
import com.netflix.hystrix.HystrixCommand;
|
||||
@@ -39,10 +40,10 @@ final class SleuthHystrixInvocationHandler implements InvocationHandler {
|
||||
|
||||
private final Target target;
|
||||
private final Map<Method, MethodHandler> dispatch;
|
||||
private final TraceManager traceManager;
|
||||
private final Tracer tracer;
|
||||
|
||||
SleuthHystrixInvocationHandler(Target target, Map<Method, MethodHandler> dispatch, TraceManager traceManager) {
|
||||
this.traceManager = checkNotNull(traceManager, "traceManager");
|
||||
SleuthHystrixInvocationHandler(Target target, Map<Method, MethodHandler> dispatch, Tracer tracer) {
|
||||
this.tracer = checkNotNull(tracer, "traceManager");
|
||||
this.target = checkNotNull(target, "target");
|
||||
this.dispatch = checkNotNull(dispatch, "dispatch");
|
||||
}
|
||||
@@ -55,7 +56,7 @@ final class SleuthHystrixInvocationHandler implements InvocationHandler {
|
||||
.withGroupKey(HystrixCommandGroupKey.Factory.asKey(groupKey))
|
||||
.andCommandKey(HystrixCommandKey.Factory.asKey(commandKey));
|
||||
|
||||
HystrixCommand<Object> hystrixCommand = new TraceCommand<Object>(traceManager, setter) {
|
||||
HystrixCommand<Object> hystrixCommand = new TraceCommand<Object>(tracer, setter) {
|
||||
@Override
|
||||
public Object doRun() throws Exception {
|
||||
try {
|
||||
@@ -76,15 +77,15 @@ final class SleuthHystrixInvocationHandler implements InvocationHandler {
|
||||
|
||||
static final class Factory implements InvocationHandlerFactory {
|
||||
|
||||
private final TraceManager traceManager;
|
||||
private final Tracer tracer;
|
||||
|
||||
public Factory(TraceManager traceManager) {
|
||||
this.traceManager = traceManager;
|
||||
public Factory(Tracer tracer) {
|
||||
this.tracer = tracer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public InvocationHandler create(Target target, Map<Method, MethodHandler> dispatch) {
|
||||
return new SleuthHystrixInvocationHandler(target, dispatch, traceManager);
|
||||
return new SleuthHystrixInvocationHandler(target, dispatch, tracer);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -34,7 +34,8 @@ import org.springframework.cloud.netflix.feign.support.SpringDecoder;
|
||||
import org.springframework.cloud.sleuth.Span;
|
||||
import org.springframework.cloud.sleuth.Trace;
|
||||
import org.springframework.cloud.sleuth.TraceAccessor;
|
||||
import org.springframework.cloud.sleuth.TraceManager;
|
||||
import org.springframework.cloud.sleuth.Tracer;
|
||||
import org.springframework.cloud.sleuth.Tracer;
|
||||
import org.springframework.cloud.sleuth.event.ClientReceivedEvent;
|
||||
import org.springframework.cloud.sleuth.event.ClientSentEvent;
|
||||
import org.springframework.cloud.sleuth.instrument.hystrix.SleuthHystrixAutoConfiguration;
|
||||
@@ -82,9 +83,9 @@ public class TraceFeignClientAutoConfiguration {
|
||||
@ConditionalOnClass(HystrixCommand.class)
|
||||
@ConditionalOnMissingBean(SleuthHystrixConcurrencyStrategy.class)
|
||||
@ConditionalOnProperty(name = "feign.hystrix.enabled", matchIfMissing = true)
|
||||
public Feign.Builder feignHystrixBuilder(TraceManager traceManager) {
|
||||
public Feign.Builder feignHystrixBuilder(Tracer tracer) {
|
||||
return HystrixFeign.builder()
|
||||
.invocationHandlerFactory(new SleuthHystrixInvocationHandler.Factory(traceManager));
|
||||
.invocationHandlerFactory(new SleuthHystrixInvocationHandler.Factory(tracer));
|
||||
}
|
||||
|
||||
@Bean
|
||||
|
||||
@@ -23,7 +23,7 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
|
||||
import org.springframework.cloud.netflix.ribbon.SpringClientFactory;
|
||||
import org.springframework.cloud.sleuth.TraceAccessor;
|
||||
import org.springframework.cloud.sleuth.TraceManager;
|
||||
import org.springframework.cloud.sleuth.Tracer;
|
||||
import org.springframework.cloud.sleuth.autoconfig.TraceAutoConfiguration;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
@@ -39,7 +39,7 @@ import com.netflix.zuul.ZuulFilter;
|
||||
@ConditionalOnProperty(value = "spring.sleuth.zuul.enabled", matchIfMissing = true)
|
||||
@ConditionalOnWebApplication
|
||||
@ConditionalOnClass(ZuulFilter.class)
|
||||
@ConditionalOnBean(TraceManager.class)
|
||||
@ConditionalOnBean(Tracer.class)
|
||||
@AutoConfigureAfter(TraceAutoConfiguration.class)
|
||||
public class TraceZuulAutoConfiguration {
|
||||
|
||||
|
||||
@@ -22,7 +22,8 @@ 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.TraceManager;
|
||||
import org.springframework.cloud.sleuth.Tracer;
|
||||
import org.springframework.cloud.sleuth.Tracer;
|
||||
import org.springframework.cloud.sleuth.autoconfig.TraceAutoConfiguration;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
@@ -31,7 +32,7 @@ import org.springframework.context.annotation.Configuration;
|
||||
* @author Spencer Gibb
|
||||
*/
|
||||
@Configuration
|
||||
@ConditionalOnBean(TraceManager.class)
|
||||
@ConditionalOnBean(Tracer.class)
|
||||
@AutoConfigureAfter(TraceAutoConfiguration.class)
|
||||
public class SleuthLogAutoConfiguration {
|
||||
|
||||
|
||||
@@ -17,7 +17,8 @@
|
||||
package org.springframework.cloud.sleuth.template;
|
||||
|
||||
import org.springframework.cloud.sleuth.Trace;
|
||||
import org.springframework.cloud.sleuth.TraceManager;
|
||||
import org.springframework.cloud.sleuth.Tracer;
|
||||
import org.springframework.cloud.sleuth.Tracer;
|
||||
import org.springframework.cloud.sleuth.instrument.TraceDelegate;
|
||||
|
||||
/**
|
||||
@@ -25,21 +26,21 @@ import org.springframework.cloud.sleuth.instrument.TraceDelegate;
|
||||
*/
|
||||
public class TraceTemplate implements TraceOperations {
|
||||
|
||||
private final TraceManager traceManager;
|
||||
private final Tracer tracer;
|
||||
|
||||
public TraceTemplate(TraceManager traceManager) {
|
||||
this.traceManager = traceManager;
|
||||
public TraceTemplate(Tracer tracer) {
|
||||
this.tracer = tracer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T trace(final TraceCallback<T> callback) {
|
||||
if (this.traceManager.isTracing()) {
|
||||
DelegateCallback<T> delegate = new DelegateCallback<>(this.traceManager);
|
||||
if (this.tracer.isTracing()) {
|
||||
DelegateCallback<T> delegate = new DelegateCallback<>(this.tracer);
|
||||
Trace trace = delegate.startSpan();
|
||||
try {
|
||||
return callback.doInTrace(trace);
|
||||
} finally {
|
||||
this.traceManager.close(trace);
|
||||
this.tracer.close(trace);
|
||||
}
|
||||
} else {
|
||||
return callback.doInTrace(null);
|
||||
@@ -48,8 +49,8 @@ public class TraceTemplate implements TraceOperations {
|
||||
|
||||
class DelegateCallback<T> extends TraceDelegate<TraceCallback<T>> {
|
||||
|
||||
public DelegateCallback(TraceManager traceManager) {
|
||||
super(traceManager, null);
|
||||
public DelegateCallback(Tracer tracer) {
|
||||
super(tracer, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -25,7 +25,7 @@ import org.springframework.cloud.sleuth.MilliSpan;
|
||||
import org.springframework.cloud.sleuth.Sampler;
|
||||
import org.springframework.cloud.sleuth.Span;
|
||||
import org.springframework.cloud.sleuth.Trace;
|
||||
import org.springframework.cloud.sleuth.TraceManager;
|
||||
import org.springframework.cloud.sleuth.Tracer;
|
||||
import org.springframework.cloud.sleuth.event.SpanAcquiredEvent;
|
||||
import org.springframework.cloud.sleuth.event.SpanContinuedEvent;
|
||||
import org.springframework.cloud.sleuth.event.SpanReleasedEvent;
|
||||
@@ -37,7 +37,7 @@ import org.springframework.context.ApplicationEventPublisher;
|
||||
/**
|
||||
* @author Spencer Gibb
|
||||
*/
|
||||
public class DefaultTraceManager implements TraceManager {
|
||||
public class DefaultTracer implements Tracer {
|
||||
|
||||
private final Sampler<Void> defaultSampler;
|
||||
|
||||
@@ -45,17 +45,17 @@ public class DefaultTraceManager implements TraceManager {
|
||||
|
||||
private final Random random;
|
||||
|
||||
public DefaultTraceManager(Sampler<Void> defaultSampler,
|
||||
Random random, ApplicationEventPublisher publisher) {
|
||||
public DefaultTracer(Sampler<Void> defaultSampler,
|
||||
Random random, ApplicationEventPublisher publisher) {
|
||||
this.defaultSampler = defaultSampler;
|
||||
this.random = random;
|
||||
this.publisher = publisher;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Trace startSpan(String name, Span parent) {
|
||||
public Trace joinTrace(String name, Span parent) {
|
||||
if (parent == null) {
|
||||
return startSpan(name);
|
||||
return startTrace(name);
|
||||
}
|
||||
Span currentSpan = getCurrentSpan();
|
||||
if (currentSpan != null && !parent.equals(currentSpan)) {
|
||||
@@ -67,12 +67,12 @@ public class DefaultTraceManager implements TraceManager {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Trace startSpan(String name) {
|
||||
return this.startSpan(name, this.defaultSampler);
|
||||
public Trace startTrace(String name) {
|
||||
return this.startTrace(name, this.defaultSampler);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> Trace startSpan(String name, Sampler<T> s) {
|
||||
public <T> Trace startTrace(String name, Sampler<T> s) {
|
||||
Span span = null;
|
||||
if (isTracing() || s.next()) {
|
||||
span = createChild(getCurrentSpan(), name);
|
||||
@@ -24,7 +24,7 @@ import org.springframework.cloud.sleuth.event.SpanAcquiredEvent;
|
||||
import org.springframework.cloud.sleuth.event.SpanReleasedEvent;
|
||||
import org.springframework.cloud.sleuth.sampler.AlwaysSampler;
|
||||
import org.springframework.cloud.sleuth.sampler.IsTracingSampler;
|
||||
import org.springframework.cloud.sleuth.trace.DefaultTraceManager;
|
||||
import org.springframework.cloud.sleuth.trace.DefaultTracer;
|
||||
import org.springframework.cloud.sleuth.trace.TraceContextHolder;
|
||||
import org.springframework.context.ApplicationEvent;
|
||||
import org.springframework.context.ApplicationEventPublisher;
|
||||
@@ -65,9 +65,9 @@ public class DefaultTraceManagerTests {
|
||||
public void tracingWorks() {
|
||||
ApplicationEventPublisher publisher = mock(ApplicationEventPublisher.class);
|
||||
|
||||
DefaultTraceManager traceManager = new DefaultTraceManager(new IsTracingSampler(), new Random(), publisher);
|
||||
DefaultTracer traceManager = new DefaultTracer(new IsTracingSampler(), new Random(), publisher);
|
||||
|
||||
Trace trace = traceManager.startSpan(CREATE_SIMPLE_TRACE, new AlwaysSampler());
|
||||
Trace trace = traceManager.startTrace(CREATE_SIMPLE_TRACE, new AlwaysSampler());
|
||||
try {
|
||||
importantWork1(traceManager);
|
||||
}
|
||||
@@ -121,22 +121,22 @@ public class DefaultTraceManagerTests {
|
||||
return found;
|
||||
}
|
||||
|
||||
private void importantWork1(TraceManager traceManager) {
|
||||
Trace cur = traceManager.startSpan(IMPORTANT_WORK_1);
|
||||
private void importantWork1(Tracer tracer) {
|
||||
Trace cur = tracer.startTrace(IMPORTANT_WORK_1);
|
||||
try {
|
||||
Thread.sleep((long) (50 * Math.random()));
|
||||
importantWork2(traceManager);
|
||||
importantWork2(tracer);
|
||||
}
|
||||
catch (InterruptedException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
finally {
|
||||
traceManager.close(cur);
|
||||
tracer.close(cur);
|
||||
}
|
||||
}
|
||||
|
||||
private void importantWork2(TraceManager traceManager) {
|
||||
Trace cur = traceManager.startSpan(IMPORTANT_WORK_2);
|
||||
private void importantWork2(Tracer tracer) {
|
||||
Trace cur = tracer.startTrace(IMPORTANT_WORK_2);
|
||||
try {
|
||||
Thread.sleep((long) (50 * Math.random()));
|
||||
}
|
||||
@@ -144,7 +144,7 @@ public class DefaultTraceManagerTests {
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
finally {
|
||||
traceManager.close(cur);
|
||||
tracer.close(cur);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -6,9 +6,9 @@ import org.junit.runner.RunWith;
|
||||
import org.mockito.Mockito;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
import org.springframework.cloud.sleuth.Trace;
|
||||
import org.springframework.cloud.sleuth.TraceManager;
|
||||
import org.springframework.cloud.sleuth.Tracer;
|
||||
import org.springframework.cloud.sleuth.sampler.AlwaysSampler;
|
||||
import org.springframework.cloud.sleuth.trace.DefaultTraceManager;
|
||||
import org.springframework.cloud.sleuth.trace.DefaultTracer;
|
||||
import org.springframework.cloud.sleuth.trace.TraceContextHolder;
|
||||
import org.springframework.context.ApplicationEventPublisher;
|
||||
|
||||
@@ -23,7 +23,7 @@ import static org.assertj.core.api.BDDAssertions.then;
|
||||
public class TraceCallableTests {
|
||||
|
||||
ExecutorService executor = Executors.newSingleThreadExecutor();
|
||||
TraceManager traceManager = new DefaultTraceManager(new AlwaysSampler(),
|
||||
Tracer tracer = new DefaultTracer(new AlwaysSampler(),
|
||||
new Random(), Mockito.mock(ApplicationEventPublisher.class));
|
||||
|
||||
@After
|
||||
@@ -71,7 +71,7 @@ public class TraceCallableTests {
|
||||
}
|
||||
|
||||
private Trace givenSpanIsAlreadyActive() {
|
||||
return this.traceManager.startSpan("parent");
|
||||
return this.tracer.startTrace("parent");
|
||||
}
|
||||
|
||||
private Callable<Trace> thatRetrievesTraceFromThreadLocal() {
|
||||
@@ -90,7 +90,7 @@ public class TraceCallableTests {
|
||||
|
||||
private Trace whenCallableGetsSubmitted(Callable<Trace> callable)
|
||||
throws InterruptedException, java.util.concurrent.ExecutionException {
|
||||
return this.executor.submit(new TraceCallable<>(this.traceManager, callable))
|
||||
return this.executor.submit(new TraceCallable<>(this.tracer, callable))
|
||||
.get();
|
||||
}
|
||||
|
||||
|
||||
@@ -6,9 +6,11 @@ import org.junit.runner.RunWith;
|
||||
import org.mockito.Mockito;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
import org.springframework.cloud.sleuth.Trace;
|
||||
import org.springframework.cloud.sleuth.TraceManager;
|
||||
import org.springframework.cloud.sleuth.Tracer;
|
||||
import org.springframework.cloud.sleuth.Tracer;
|
||||
import org.springframework.cloud.sleuth.sampler.AlwaysSampler;
|
||||
import org.springframework.cloud.sleuth.trace.DefaultTraceManager;
|
||||
import org.springframework.cloud.sleuth.trace.DefaultTracer;
|
||||
import org.springframework.cloud.sleuth.trace.DefaultTracer;
|
||||
import org.springframework.cloud.sleuth.trace.TraceContextHolder;
|
||||
import org.springframework.context.ApplicationEventPublisher;
|
||||
|
||||
@@ -22,7 +24,7 @@ import static org.assertj.core.api.BDDAssertions.then;
|
||||
public class TraceRunnableTests {
|
||||
|
||||
ExecutorService executor = Executors.newSingleThreadExecutor();
|
||||
TraceManager traceManager = new DefaultTraceManager(new AlwaysSampler(),
|
||||
Tracer tracer = new DefaultTracer(new AlwaysSampler(),
|
||||
new Random(), Mockito.mock(ApplicationEventPublisher.class));
|
||||
|
||||
@After
|
||||
@@ -78,7 +80,7 @@ public class TraceRunnableTests {
|
||||
}
|
||||
|
||||
private void whenRunnableGetsSubmitted(Runnable callable) throws Exception {
|
||||
this.executor.submit(new TraceRunnable(this.traceManager, callable)).get();
|
||||
this.executor.submit(new TraceRunnable(this.tracer, callable)).get();
|
||||
}
|
||||
|
||||
private void whenNonTraceableRunnableGetsSubmitted(Runnable callable)
|
||||
|
||||
@@ -9,9 +9,9 @@ import org.mockito.Mock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
import org.springframework.cloud.sleuth.Span;
|
||||
import org.springframework.cloud.sleuth.Trace;
|
||||
import org.springframework.cloud.sleuth.TraceManager;
|
||||
import org.springframework.cloud.sleuth.Tracer;
|
||||
import org.springframework.cloud.sleuth.sampler.AlwaysSampler;
|
||||
import org.springframework.cloud.sleuth.trace.DefaultTraceManager;
|
||||
import org.springframework.cloud.sleuth.trace.DefaultTracer;
|
||||
import org.springframework.cloud.sleuth.trace.TraceContextHolder;
|
||||
import org.springframework.context.ApplicationEventPublisher;
|
||||
|
||||
@@ -32,21 +32,21 @@ public class TraceableExecutorServiceTests {
|
||||
private static int TOTAL_THREADS = 10;
|
||||
|
||||
@Mock ApplicationEventPublisher publisher;
|
||||
TraceManager traceManager;
|
||||
Tracer tracer;
|
||||
ExecutorService executorService = Executors.newFixedThreadPool(3);
|
||||
ExecutorService traceManagerableExecutorService;
|
||||
SpanVerifyingRunnable spanVerifyingRunnable = new SpanVerifyingRunnable();
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
traceManager = new DefaultTraceManager(new AlwaysSampler(), new Random(), publisher);
|
||||
traceManagerableExecutorService = new TraceableExecutorService(executorService, traceManager);
|
||||
tracer = new DefaultTracer(new AlwaysSampler(), new Random(), publisher);
|
||||
traceManagerableExecutorService = new TraceableExecutorService(executorService, tracer);
|
||||
TraceContextHolder.removeCurrentTrace();
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
traceManager = null;
|
||||
tracer = null;
|
||||
traceManagerableExecutorService.shutdown();
|
||||
executorService.shutdown();
|
||||
TraceContextHolder.removeCurrentTrace();
|
||||
@@ -55,9 +55,9 @@ public class TraceableExecutorServiceTests {
|
||||
@Test
|
||||
@SneakyThrows
|
||||
public void should_propagate_trace_id_and_set_new_span_when_traceable_executor_service_is_executed() {
|
||||
Trace trace = traceManager.startSpan("PARENT");
|
||||
Trace trace = tracer.startTrace("PARENT");
|
||||
CompletableFuture.allOf(runnablesExecutedViaTraceManagerableExecutorService()).get();
|
||||
traceManager.close(trace);
|
||||
tracer.close(trace);
|
||||
|
||||
then(spanVerifyingRunnable.traceIds.stream().distinct().collect(toList())).containsOnly(trace.getSpan().getTraceId());
|
||||
then(spanVerifyingRunnable.spanIds.stream().distinct().collect(toList())).hasSize(TOTAL_THREADS);
|
||||
|
||||
@@ -9,7 +9,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.SpringApplicationConfiguration;
|
||||
import org.springframework.cloud.netflix.hystrix.EnableHystrix;
|
||||
import org.springframework.cloud.sleuth.Span;
|
||||
import org.springframework.cloud.sleuth.TraceManager;
|
||||
import org.springframework.cloud.sleuth.Tracer;
|
||||
import org.springframework.cloud.sleuth.instrument.DefaultTestAutoConfiguration;
|
||||
import org.springframework.cloud.sleuth.trace.TraceContextHolder;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
@@ -26,7 +26,8 @@ import static org.springframework.cloud.sleuth.assertions.SleuthAssertions.then;
|
||||
public class SpanPassingForHystrixViaAnnotationsIntegrationTests {
|
||||
|
||||
@Autowired HystrixCommandInvocationSpanCatcher hystrixCommandInvocationSpanCatcher;
|
||||
@Autowired TraceManager traceManager;
|
||||
@Autowired
|
||||
Tracer tracer;
|
||||
|
||||
@Test
|
||||
public void should_set_span_on_an_hystrix_command_annotated_method() {
|
||||
@@ -38,8 +39,8 @@ public class SpanPassingForHystrixViaAnnotationsIntegrationTests {
|
||||
}
|
||||
|
||||
private Span givenASpanInCurrentThread() {
|
||||
Span span = traceManager.startSpan("existing").getSpan();
|
||||
traceManager.continueSpan(span);
|
||||
Span span = tracer.startTrace("existing").getSpan();
|
||||
tracer.continueSpan(span);
|
||||
return span;
|
||||
}
|
||||
|
||||
|
||||
@@ -8,9 +8,9 @@ import org.junit.Test;
|
||||
import org.mockito.Mockito;
|
||||
import org.springframework.cloud.sleuth.MilliSpan;
|
||||
import org.springframework.cloud.sleuth.Trace;
|
||||
import org.springframework.cloud.sleuth.TraceManager;
|
||||
import org.springframework.cloud.sleuth.Tracer;
|
||||
import org.springframework.cloud.sleuth.sampler.AlwaysSampler;
|
||||
import org.springframework.cloud.sleuth.trace.DefaultTraceManager;
|
||||
import org.springframework.cloud.sleuth.trace.DefaultTracer;
|
||||
import org.springframework.cloud.sleuth.trace.TraceContextHolder;
|
||||
import org.springframework.context.ApplicationEventPublisher;
|
||||
|
||||
@@ -23,7 +23,7 @@ import static org.assertj.core.api.BDDAssertions.then;
|
||||
public class TraceCommandTests {
|
||||
|
||||
static final long EXPECTED_TRACE_ID = 1L;
|
||||
TraceManager traceManager = new DefaultTraceManager(new AlwaysSampler(),
|
||||
Tracer tracer = new DefaultTracer(new AlwaysSampler(),
|
||||
new Random(), Mockito.mock(ApplicationEventPublisher.class));
|
||||
|
||||
@Before
|
||||
@@ -67,11 +67,11 @@ public class TraceCommandTests {
|
||||
}
|
||||
|
||||
private Trace givenATraceIsPresentInTheCurrentThread() {
|
||||
return this.traceManager.startSpan("test", MilliSpan.builder().traceId(EXPECTED_TRACE_ID).build());
|
||||
return this.tracer.joinTrace("test", MilliSpan.builder().traceId(EXPECTED_TRACE_ID).build());
|
||||
}
|
||||
|
||||
private TraceCommand<Trace> traceReturningCommand() {
|
||||
return new TraceCommand<Trace>(this.traceManager, withGroupKey(asKey(""))
|
||||
return new TraceCommand<Trace>(this.tracer, withGroupKey(asKey(""))
|
||||
.andCommandKey(HystrixCommandKey.Factory.asKey("")).andThreadPoolPropertiesDefaults(
|
||||
HystrixThreadPoolProperties.Setter().withMaxQueueSize(1).withCoreSize(1))) {
|
||||
@Override
|
||||
|
||||
@@ -6,7 +6,7 @@ import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.cloud.sleuth.Trace;
|
||||
import org.springframework.cloud.sleuth.TraceManager;
|
||||
import org.springframework.cloud.sleuth.Tracer;
|
||||
import org.springframework.cloud.sleuth.sampler.AlwaysSampler;
|
||||
import org.springframework.cloud.sleuth.trace.TraceContextHolder;
|
||||
import org.springframework.messaging.Message;
|
||||
@@ -22,7 +22,8 @@ abstract class AbstractTraceStompIntegrationTests {
|
||||
@Autowired
|
||||
@Qualifier("executorSubscribableChannel")
|
||||
ExecutorSubscribableChannel channel;
|
||||
@Autowired TraceManager traceManager;
|
||||
@Autowired
|
||||
Tracer tracer;
|
||||
@Autowired StompMessageHandler stompMessageHandler;
|
||||
@Autowired AlwaysSampler sampler;
|
||||
|
||||
@@ -38,7 +39,7 @@ abstract class AbstractTraceStompIntegrationTests {
|
||||
}
|
||||
|
||||
Trace givenALocallyStartedSpan() {
|
||||
return traceManager.startSpan("testSendMessage", sampler);
|
||||
return tracer.startTrace("testSendMessage", sampler);
|
||||
}
|
||||
|
||||
Message<?> givenMessageToBeSampled() {
|
||||
|
||||
@@ -27,7 +27,7 @@ import org.springframework.boot.test.IntegrationTest;
|
||||
import org.springframework.boot.test.SpringApplicationConfiguration;
|
||||
import org.springframework.cloud.sleuth.Span;
|
||||
import org.springframework.cloud.sleuth.Trace;
|
||||
import org.springframework.cloud.sleuth.TraceManager;
|
||||
import org.springframework.cloud.sleuth.Tracer;
|
||||
import org.springframework.cloud.sleuth.event.SpanReleasedEvent;
|
||||
import org.springframework.cloud.sleuth.instrument.integration.TraceChannelInterceptorTests.App;
|
||||
import org.springframework.cloud.sleuth.sampler.AlwaysSampler;
|
||||
@@ -64,7 +64,7 @@ public class TraceChannelInterceptorTests implements MessageHandler {
|
||||
private DirectChannel channel;
|
||||
|
||||
@Autowired
|
||||
private TraceManager traceManager;
|
||||
private Tracer tracer;
|
||||
|
||||
@Autowired
|
||||
private MessagingTemplate messagingTemplate;
|
||||
@@ -136,10 +136,10 @@ public class TraceChannelInterceptorTests implements MessageHandler {
|
||||
|
||||
@Test
|
||||
public void headerCreation() {
|
||||
Trace trace = this.traceManager.startSpan("testSendMessage",
|
||||
Trace trace = this.tracer.startTrace("testSendMessage",
|
||||
new AlwaysSampler());
|
||||
this.channel.send(MessageBuilder.withPayload("hi").build());
|
||||
this.traceManager.close(trace);
|
||||
this.tracer.close(trace);
|
||||
assertNotNull("message was null", this.message);
|
||||
|
||||
String spanId = this.message.getHeaders().get(Trace.SPAN_ID_NAME, String.class);
|
||||
@@ -153,10 +153,10 @@ public class TraceChannelInterceptorTests implements MessageHandler {
|
||||
// TODO: Refactor to parametrized test together with sending messages via channel
|
||||
@Test
|
||||
public void headerCreationViaMessagingTemplate() {
|
||||
Trace trace = this.traceManager.startSpan("testSendMessage",
|
||||
Trace trace = this.tracer.startTrace("testSendMessage",
|
||||
new AlwaysSampler());
|
||||
this.messagingTemplate.send(MessageBuilder.withPayload("hi").build());
|
||||
this.traceManager.close(trace);
|
||||
this.tracer.close(trace);
|
||||
assertNotNull("message was null", this.message);
|
||||
|
||||
String spanId = this.message.getHeaders().get(Trace.SPAN_ID_NAME, String.class);
|
||||
|
||||
@@ -26,7 +26,7 @@ import org.springframework.boot.test.IntegrationTest;
|
||||
import org.springframework.boot.test.SpringApplicationConfiguration;
|
||||
import org.springframework.cloud.sleuth.Span;
|
||||
import org.springframework.cloud.sleuth.Trace;
|
||||
import org.springframework.cloud.sleuth.TraceManager;
|
||||
import org.springframework.cloud.sleuth.Tracer;
|
||||
import org.springframework.cloud.sleuth.instrument.integration.TraceContextPropagationChannelInterceptorTests.App;
|
||||
import org.springframework.cloud.sleuth.sampler.AlwaysSampler;
|
||||
import org.springframework.cloud.sleuth.trace.TraceContextHolder;
|
||||
@@ -56,7 +56,7 @@ public class TraceContextPropagationChannelInterceptorTests {
|
||||
private PollableChannel channel;
|
||||
|
||||
@Autowired
|
||||
private TraceManager traceManager;
|
||||
private Tracer tracer;
|
||||
|
||||
@After
|
||||
public void close() {
|
||||
@@ -66,10 +66,10 @@ public class TraceContextPropagationChannelInterceptorTests {
|
||||
@Test
|
||||
public void testSpanPropagation() {
|
||||
|
||||
Trace trace = this.traceManager.startSpan("testSendMessage", new AlwaysSampler());
|
||||
Trace trace = this.tracer.startTrace("testSendMessage", new AlwaysSampler());
|
||||
this.channel.send(MessageBuilder.withPayload("hi").build());
|
||||
Long expectedSpanId = trace.getSpan().getSpanId();
|
||||
this.traceManager.close(trace);
|
||||
this.tracer.close(trace);
|
||||
|
||||
Message<?> message = this.channel.receive(0);
|
||||
|
||||
|
||||
@@ -53,7 +53,7 @@ public class TraceStompMessageChannelInterceptorTests extends AbstractTraceStomp
|
||||
Message<?> message = givenMessageToBeSampled();
|
||||
|
||||
whenTheMessageWasSent(message);
|
||||
this.traceManager.close(trace);
|
||||
this.tracer.close(trace);
|
||||
|
||||
Long spanId = thenSpanIdFromHeadersIsNotEmpty();
|
||||
long traceId = thenTraceIdFromHeadersIsNotEmpty();
|
||||
|
||||
@@ -33,7 +33,7 @@ public class TraceStompMessageContextPropagationChannelInterceptorTests extends
|
||||
|
||||
whenTheMessageWasSent(m);
|
||||
Long expectedTraceId = trace.getSpan().getTraceId();
|
||||
this.traceManager.close(trace);
|
||||
this.tracer.close(trace);
|
||||
|
||||
thenReceivedMessageIsNotNull();
|
||||
long traceId = thenTraceIdFromHeadersIsNotEmpty();
|
||||
|
||||
@@ -8,7 +8,7 @@ import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.SpringApplicationConfiguration;
|
||||
import org.springframework.cloud.sleuth.Span;
|
||||
import org.springframework.cloud.sleuth.TraceManager;
|
||||
import org.springframework.cloud.sleuth.Tracer;
|
||||
import org.springframework.cloud.sleuth.instrument.DefaultTestAutoConfiguration;
|
||||
import org.springframework.cloud.sleuth.trace.TraceContextHolder;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
@@ -27,7 +27,8 @@ import static org.springframework.cloud.sleuth.assertions.SleuthAssertions.then;
|
||||
public class TraceAsyncIntegrationTests {
|
||||
|
||||
@Autowired ClassPerformingAsyncLogic classPerformingAsyncLogic;
|
||||
@Autowired TraceManager traceManager;
|
||||
@Autowired
|
||||
Tracer tracer;
|
||||
|
||||
@Test
|
||||
public void should_set_span_on_an_async_annotated_method() {
|
||||
@@ -39,8 +40,8 @@ public class TraceAsyncIntegrationTests {
|
||||
}
|
||||
|
||||
private Span givenASpanInCurrentThread() {
|
||||
Span span = traceManager.startSpan("existing").getSpan();
|
||||
traceManager.continueSpan(span);
|
||||
Span span = tracer.startTrace("existing").getSpan();
|
||||
tracer.continueSpan(span);
|
||||
return span;
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.SpringApplicationConfiguration;
|
||||
import org.springframework.cloud.sleuth.Span;
|
||||
import org.springframework.cloud.sleuth.Trace;
|
||||
import org.springframework.cloud.sleuth.TraceManager;
|
||||
import org.springframework.cloud.sleuth.Tracer;
|
||||
import org.springframework.cloud.sleuth.instrument.DefaultTestAutoConfiguration;
|
||||
import org.springframework.cloud.sleuth.instrument.web.common.AbstractMvcIntegrationTest;
|
||||
import org.springframework.http.MediaType;
|
||||
@@ -25,7 +25,7 @@ import static org.assertj.core.api.BDDAssertions.then;
|
||||
public class TraceFilterIntegrationTests extends AbstractMvcIntegrationTest {
|
||||
|
||||
@Autowired
|
||||
TraceManager traceManager;
|
||||
Tracer tracer;
|
||||
|
||||
@Test
|
||||
public void should_create_and_return_trace_in_HTTP_header() throws Exception {
|
||||
@@ -46,7 +46,7 @@ public class TraceFilterIntegrationTests extends AbstractMvcIntegrationTest {
|
||||
|
||||
@Override
|
||||
protected void configureMockMvcBuilder(DefaultMockMvcBuilder mockMvcBuilder) {
|
||||
mockMvcBuilder.addFilters(new TraceFilter(this.traceManager));
|
||||
mockMvcBuilder.addFilters(new TraceFilter(this.tracer));
|
||||
}
|
||||
|
||||
private MvcResult whenSentPingWithoutTracingData() throws Exception {
|
||||
|
||||
@@ -20,9 +20,11 @@ import lombok.SneakyThrows;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.cloud.sleuth.Trace;
|
||||
import org.springframework.cloud.sleuth.TraceManager;
|
||||
import org.springframework.cloud.sleuth.Tracer;
|
||||
import org.springframework.cloud.sleuth.Tracer;
|
||||
import org.springframework.cloud.sleuth.sampler.AlwaysSampler;
|
||||
import org.springframework.cloud.sleuth.trace.DefaultTraceManager;
|
||||
import org.springframework.cloud.sleuth.trace.DefaultTracer;
|
||||
import org.springframework.cloud.sleuth.trace.DefaultTracer;
|
||||
import org.springframework.cloud.sleuth.trace.TraceContextHolder;
|
||||
import org.springframework.context.support.StaticApplicationContext;
|
||||
import org.springframework.http.MediaType;
|
||||
@@ -45,7 +47,7 @@ public class TraceFilterMockChainIntegrationTests {
|
||||
|
||||
private StaticApplicationContext context = new StaticApplicationContext();
|
||||
|
||||
private TraceManager traceManager = new DefaultTraceManager(new AlwaysSampler(),
|
||||
private Tracer tracer = new DefaultTracer(new AlwaysSampler(),
|
||||
new Random(), this.context);
|
||||
|
||||
private MockHttpServletRequest request;
|
||||
@@ -70,7 +72,7 @@ public class TraceFilterMockChainIntegrationTests {
|
||||
|
||||
@Test
|
||||
public void startsNewTrace() throws Exception {
|
||||
TraceFilter filter = new TraceFilter(this.traceManager);
|
||||
TraceFilter filter = new TraceFilter(this.tracer);
|
||||
filter.doFilter(this.request, this.response, this.filterChain);
|
||||
assertNull(TraceContextHolder.getCurrentTrace());
|
||||
}
|
||||
@@ -80,7 +82,7 @@ public class TraceFilterMockChainIntegrationTests {
|
||||
Random generator = new Random();
|
||||
this.request = builder().header(Trace.SPAN_ID_NAME, generator.nextLong())
|
||||
.header(Trace.TRACE_ID_NAME, generator.nextLong()).buildRequest(new MockServletContext());
|
||||
TraceFilter filter = new TraceFilter(this.traceManager);
|
||||
TraceFilter filter = new TraceFilter(this.tracer);
|
||||
filter.doFilter(this.request, this.response, this.filterChain);
|
||||
assertNull(TraceContextHolder.getCurrentSpan());
|
||||
}
|
||||
|
||||
@@ -23,10 +23,10 @@ import org.mockito.Mock;
|
||||
import org.springframework.cloud.sleuth.Sampler;
|
||||
import org.springframework.cloud.sleuth.Span;
|
||||
import org.springframework.cloud.sleuth.Trace;
|
||||
import org.springframework.cloud.sleuth.TraceManager;
|
||||
import org.springframework.cloud.sleuth.Tracer;
|
||||
import org.springframework.cloud.sleuth.sampler.AlwaysSampler;
|
||||
import org.springframework.cloud.sleuth.sampler.IsTracingSampler;
|
||||
import org.springframework.cloud.sleuth.trace.DefaultTraceManager;
|
||||
import org.springframework.cloud.sleuth.trace.DefaultTracer;
|
||||
import org.springframework.cloud.sleuth.trace.TraceContextHolder;
|
||||
import org.springframework.context.ApplicationEventPublisher;
|
||||
import org.springframework.http.HttpStatus;
|
||||
@@ -55,7 +55,7 @@ public class TraceFilterTests {
|
||||
@Mock
|
||||
private ApplicationEventPublisher publisher;
|
||||
|
||||
private TraceManager traceManager;
|
||||
private Tracer tracer;
|
||||
|
||||
private Span span;
|
||||
|
||||
@@ -68,7 +68,7 @@ public class TraceFilterTests {
|
||||
@SneakyThrows
|
||||
public void init() {
|
||||
initMocks(this);
|
||||
this.traceManager = new DefaultTraceManager(new DelegateSampler(), new Random(), this.publisher) {
|
||||
this.tracer = new DefaultTracer(new DelegateSampler(), new Random(), this.publisher) {
|
||||
@Override
|
||||
protected Trace createTrace(Trace trace, Span span) {
|
||||
TraceFilterTests.this.span = span;
|
||||
@@ -89,7 +89,7 @@ public class TraceFilterTests {
|
||||
@Test
|
||||
public void notTraced() throws Exception {
|
||||
this.sampler = new IsTracingSampler();
|
||||
TraceFilter filter = new TraceFilter(this.traceManager);
|
||||
TraceFilter filter = new TraceFilter(this.tracer);
|
||||
|
||||
this.request = get("/favicon.ico").accept(MediaType.ALL)
|
||||
.buildRequest(new MockServletContext());
|
||||
@@ -102,7 +102,7 @@ public class TraceFilterTests {
|
||||
|
||||
@Test
|
||||
public void startsNewTrace() throws Exception {
|
||||
TraceFilter filter = new TraceFilter(this.traceManager);
|
||||
TraceFilter filter = new TraceFilter(this.tracer);
|
||||
filter.doFilter(this.request, this.response, this.filterChain);
|
||||
verifyHttpTags();
|
||||
assertNull(TraceContextHolder.getCurrentTrace());
|
||||
@@ -111,10 +111,10 @@ public class TraceFilterTests {
|
||||
@Test
|
||||
public void continuesSpanInRequestAttr() throws Exception {
|
||||
|
||||
Trace trace = this.traceManager.startSpan("foo");
|
||||
Trace trace = this.tracer.startTrace("foo");
|
||||
this.request.setAttribute(TraceFilter.TRACE_REQUEST_ATTR, trace);
|
||||
|
||||
TraceFilter filter = new TraceFilter(this.traceManager);
|
||||
TraceFilter filter = new TraceFilter(this.tracer);
|
||||
filter.doFilter(this.request, this.response, this.filterChain);
|
||||
|
||||
verifyHttpTags();
|
||||
@@ -128,7 +128,7 @@ public class TraceFilterTests {
|
||||
.header(Trace.TRACE_ID_NAME, 20L)
|
||||
.buildRequest(new MockServletContext());
|
||||
|
||||
TraceFilter filter = new TraceFilter(this.traceManager);
|
||||
TraceFilter filter = new TraceFilter(this.tracer);
|
||||
filter.doFilter(this.request, this.response, this.filterChain);
|
||||
|
||||
verifyHttpTags();
|
||||
@@ -138,7 +138,7 @@ public class TraceFilterTests {
|
||||
|
||||
@Test
|
||||
public void catchesException() throws Exception {
|
||||
TraceFilter filter = new TraceFilter(this.traceManager);
|
||||
TraceFilter filter = new TraceFilter(this.tracer);
|
||||
this.filterChain = new MockFilterChain() {
|
||||
@Override
|
||||
public void doFilter(javax.servlet.ServletRequest request,
|
||||
|
||||
@@ -17,7 +17,8 @@ import org.springframework.cloud.netflix.ribbon.RibbonClient;
|
||||
import org.springframework.cloud.sleuth.MilliSpan;
|
||||
import org.springframework.cloud.sleuth.Span;
|
||||
import org.springframework.cloud.sleuth.Trace;
|
||||
import org.springframework.cloud.sleuth.TraceManager;
|
||||
import org.springframework.cloud.sleuth.Tracer;
|
||||
import org.springframework.cloud.sleuth.Tracer;
|
||||
import org.springframework.cloud.sleuth.event.ClientReceivedEvent;
|
||||
import org.springframework.cloud.sleuth.event.ClientSentEvent;
|
||||
import org.springframework.cloud.sleuth.trace.TraceContextHolder;
|
||||
@@ -54,7 +55,7 @@ public class FeignTraceTests {
|
||||
Listener listener;
|
||||
|
||||
@Autowired
|
||||
TraceManager traceManager;
|
||||
Tracer tracer;
|
||||
|
||||
@After
|
||||
public void close() {
|
||||
@@ -77,7 +78,7 @@ public class FeignTraceTests {
|
||||
// given
|
||||
Long currentTraceId = 1L;
|
||||
Long currentParentId = 2L;
|
||||
this.traceManager.continueSpan(MilliSpan.builder().traceId(currentTraceId)
|
||||
this.tracer.continueSpan(MilliSpan.builder().traceId(currentTraceId)
|
||||
.spanId(generatedId()).parent(currentParentId).build());
|
||||
|
||||
// when
|
||||
|
||||
@@ -22,7 +22,8 @@ import org.junit.Test;
|
||||
import org.springframework.cloud.sleuth.MilliSpan;
|
||||
import org.springframework.cloud.sleuth.Trace;
|
||||
import org.springframework.cloud.sleuth.sampler.AlwaysSampler;
|
||||
import org.springframework.cloud.sleuth.trace.DefaultTraceManager;
|
||||
import org.springframework.cloud.sleuth.trace.DefaultTracer;
|
||||
import org.springframework.cloud.sleuth.trace.DefaultTracer;
|
||||
import org.springframework.cloud.sleuth.trace.TraceContextHolder;
|
||||
import org.springframework.context.support.StaticApplicationContext;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
@@ -55,14 +56,14 @@ public class TraceRestTemplateInterceptorTests {
|
||||
private RestTemplate template = new RestTemplate(
|
||||
new MockMvcClientHttpRequestFactory(this.mockMvc));
|
||||
|
||||
private DefaultTraceManager traces;
|
||||
private DefaultTracer traces;
|
||||
|
||||
private StaticApplicationContext publisher = new StaticApplicationContext();
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
this.publisher.refresh();
|
||||
this.traces = new DefaultTraceManager(new AlwaysSampler(), new Random(), this.publisher);
|
||||
this.traces = new DefaultTracer(new AlwaysSampler(), new Random(), this.publisher);
|
||||
this.template.setInterceptors(Arrays.<ClientHttpRequestInterceptor>asList(
|
||||
new TraceRestTemplateInterceptor(this.traces)));
|
||||
TraceContextHolder.removeCurrentTrace();
|
||||
|
||||
@@ -2,7 +2,8 @@ package org.springframework.cloud.sleuth.instrument.web.common;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cloud.sleuth.TraceManager;
|
||||
import org.springframework.cloud.sleuth.Tracer;
|
||||
import org.springframework.cloud.sleuth.Tracer;
|
||||
import org.springframework.cloud.sleuth.instrument.web.TraceFilter;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.web.servlet.setup.DefaultMockMvcBuilder;
|
||||
@@ -27,7 +28,7 @@ public abstract class AbstractMvcWiremockIntegrationTest extends AbstractMvcInte
|
||||
|
||||
protected WireMock wireMock;
|
||||
@Autowired protected HttpMockServer httpMockServer;
|
||||
@Autowired protected TraceManager traceManager;
|
||||
@Autowired protected Tracer tracer;
|
||||
|
||||
@Override
|
||||
@Before
|
||||
@@ -51,6 +52,6 @@ public abstract class AbstractMvcWiremockIntegrationTest extends AbstractMvcInte
|
||||
|
||||
@Override
|
||||
protected void configureMockMvcBuilder(DefaultMockMvcBuilder mockMvcBuilder) {
|
||||
mockMvcBuilder.addFilters(new TraceFilter(this.traceManager));
|
||||
mockMvcBuilder.addFilters(new TraceFilter(this.tracer));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,9 +3,9 @@ package org.springframework.cloud.sleuth.template;
|
||||
import org.junit.Test;
|
||||
import org.mockito.Mockito;
|
||||
import org.springframework.cloud.sleuth.Trace;
|
||||
import org.springframework.cloud.sleuth.TraceManager;
|
||||
import org.springframework.cloud.sleuth.Tracer;
|
||||
import org.springframework.cloud.sleuth.sampler.AlwaysSampler;
|
||||
import org.springframework.cloud.sleuth.trace.DefaultTraceManager;
|
||||
import org.springframework.cloud.sleuth.trace.DefaultTracer;
|
||||
import org.springframework.cloud.sleuth.trace.TraceContextHolder;
|
||||
import org.springframework.context.ApplicationEventPublisher;
|
||||
|
||||
@@ -15,13 +15,13 @@ import static org.assertj.core.api.BDDAssertions.then;
|
||||
|
||||
public class TraceTemplateTests {
|
||||
|
||||
TraceManager traceManager = new DefaultTraceManager(new AlwaysSampler(),
|
||||
Tracer tracer = new DefaultTracer(new AlwaysSampler(),
|
||||
new Random(), Mockito.mock(ApplicationEventPublisher.class));
|
||||
|
||||
@Test
|
||||
public void should_pass_trace_to_the_callback_if_tracing_is_active() {
|
||||
Trace initialTrace = traceManager.startSpan("test");
|
||||
TraceTemplate traceTemplate = new TraceTemplate(traceManager);
|
||||
Trace initialTrace = tracer.startTrace("test");
|
||||
TraceTemplate traceTemplate = new TraceTemplate(tracer);
|
||||
|
||||
Trace traceFromCallback = whenTraceCallbackReturningCurrentTraceIsExecuted(traceTemplate);
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ package sample;
|
||||
|
||||
import lombok.SneakyThrows;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cloud.sleuth.TraceManager;
|
||||
import org.springframework.cloud.sleuth.Tracer;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@@ -31,7 +31,7 @@ import java.util.Random;
|
||||
public class SampleBackground {
|
||||
|
||||
@Autowired
|
||||
private TraceManager traceManager;
|
||||
private Tracer tracer;
|
||||
@Autowired
|
||||
private Random random;
|
||||
|
||||
@@ -40,7 +40,7 @@ public class SampleBackground {
|
||||
public void background() {
|
||||
int millis = random.nextInt(1000);
|
||||
Thread.sleep(millis);
|
||||
this.traceManager.addTag("background-sleep-millis", String.valueOf(millis));
|
||||
this.tracer.addTag("background-sleep-millis", String.valueOf(millis));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ import java.util.Random;
|
||||
import lombok.SneakyThrows;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cloud.sleuth.TraceManager;
|
||||
import org.springframework.cloud.sleuth.Tracer;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@@ -32,7 +32,7 @@ import org.springframework.stereotype.Component;
|
||||
public class SampleBackground {
|
||||
|
||||
@Autowired
|
||||
private TraceManager traceManager;
|
||||
private Tracer tracer;
|
||||
|
||||
@SneakyThrows
|
||||
@Async
|
||||
@@ -40,7 +40,7 @@ public class SampleBackground {
|
||||
final Random random = new Random();
|
||||
int millis = random.nextInt(1000);
|
||||
Thread.sleep(millis);
|
||||
this.traceManager.addTag("background-sleep-millis", String.valueOf(millis));
|
||||
this.tracer.addTag("background-sleep-millis", String.valueOf(millis));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ import org.springframework.boot.context.embedded.EmbeddedServletContainerInitial
|
||||
import org.springframework.cloud.sleuth.Span;
|
||||
import org.springframework.cloud.sleuth.Trace;
|
||||
import org.springframework.cloud.sleuth.TraceAccessor;
|
||||
import org.springframework.cloud.sleuth.TraceManager;
|
||||
import org.springframework.cloud.sleuth.Tracer;
|
||||
import org.springframework.cloud.sleuth.sampler.AlwaysSampler;
|
||||
import org.springframework.context.ApplicationListener;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
@@ -43,7 +43,7 @@ ApplicationListener<EmbeddedServletContainerInitializedEvent> {
|
||||
@Autowired
|
||||
private RestTemplate restTemplate;
|
||||
@Autowired
|
||||
private TraceManager traceManager;
|
||||
private Tracer tracer;
|
||||
@Autowired
|
||||
private TraceAccessor accessor;
|
||||
@Autowired
|
||||
@@ -69,7 +69,7 @@ ApplicationListener<EmbeddedServletContainerInitializedEvent> {
|
||||
public String call() throws Exception {
|
||||
int millis = random.nextInt(1000);
|
||||
Thread.sleep(millis);
|
||||
SampleController.this.traceManager.addTag("callable-sleep-millis", String.valueOf(millis));
|
||||
SampleController.this.tracer.addTag("callable-sleep-millis", String.valueOf(millis));
|
||||
Span currentSpan = SampleController.this.accessor.getCurrentSpan();
|
||||
return "async hi: " + currentSpan;
|
||||
}
|
||||
@@ -87,23 +87,23 @@ ApplicationListener<EmbeddedServletContainerInitializedEvent> {
|
||||
public String hi2() {
|
||||
int millis = random.nextInt(1000);
|
||||
Thread.sleep(millis);
|
||||
this.traceManager.addTag("random-sleep-millis", String.valueOf(millis));
|
||||
this.tracer.addTag("random-sleep-millis", String.valueOf(millis));
|
||||
return "hi2";
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
@RequestMapping("/traced")
|
||||
public String traced() {
|
||||
Trace trace = this.traceManager.startSpan("customTraceEndpoint",
|
||||
Trace trace = this.tracer.startTrace("customTraceEndpoint",
|
||||
new AlwaysSampler());
|
||||
int millis = random.nextInt(1000);
|
||||
log.info("Sleeping for {} millis", millis);
|
||||
Thread.sleep(millis);
|
||||
this.traceManager.addTag("random-sleep-millis", String.valueOf(millis));
|
||||
this.tracer.addTag("random-sleep-millis", String.valueOf(millis));
|
||||
|
||||
String s = this.restTemplate.getForObject("http://localhost:" + this.port
|
||||
+ "/call", String.class);
|
||||
this.traceManager.close(trace);
|
||||
this.tracer.close(trace);
|
||||
return "traced/" + s;
|
||||
}
|
||||
|
||||
@@ -113,7 +113,7 @@ ApplicationListener<EmbeddedServletContainerInitializedEvent> {
|
||||
int millis = random.nextInt(1000);
|
||||
log.info("Sleeping for {} millis", millis);
|
||||
Thread.sleep(millis);
|
||||
this.traceManager.addTag("random-sleep-millis", String.valueOf(millis));
|
||||
this.tracer.addTag("random-sleep-millis", String.valueOf(millis));
|
||||
|
||||
String s = this.restTemplate.getForObject("http://localhost:" + this.port
|
||||
+ "/call", String.class);
|
||||
|
||||
@@ -18,7 +18,7 @@ package sample;
|
||||
|
||||
import lombok.SneakyThrows;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cloud.sleuth.TraceManager;
|
||||
import org.springframework.cloud.sleuth.Tracer;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@@ -31,7 +31,7 @@ import java.util.Random;
|
||||
public class SampleBackground {
|
||||
|
||||
@Autowired
|
||||
private TraceManager traceManager;
|
||||
private Tracer tracer;
|
||||
@Autowired
|
||||
private Random random;
|
||||
|
||||
@@ -40,7 +40,7 @@ public class SampleBackground {
|
||||
public void background() {
|
||||
int millis = random.nextInt(1000);
|
||||
Thread.sleep(millis);
|
||||
this.traceManager.addTag("background-sleep-millis", String.valueOf(millis));
|
||||
this.tracer.addTag("background-sleep-millis", String.valueOf(millis));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ import org.springframework.boot.context.embedded.EmbeddedServletContainerInitial
|
||||
import org.springframework.cloud.sleuth.Span;
|
||||
import org.springframework.cloud.sleuth.Trace;
|
||||
import org.springframework.cloud.sleuth.TraceAccessor;
|
||||
import org.springframework.cloud.sleuth.TraceManager;
|
||||
import org.springframework.cloud.sleuth.Tracer;
|
||||
import org.springframework.cloud.sleuth.sampler.AlwaysSampler;
|
||||
import org.springframework.context.ApplicationListener;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
@@ -43,7 +43,7 @@ ApplicationListener<EmbeddedServletContainerInitializedEvent> {
|
||||
@Autowired
|
||||
private RestTemplate restTemplate;
|
||||
@Autowired
|
||||
private TraceManager traceManager;
|
||||
private Tracer tracer;
|
||||
@Autowired
|
||||
private TraceAccessor accessor;
|
||||
@Autowired
|
||||
@@ -69,7 +69,7 @@ ApplicationListener<EmbeddedServletContainerInitializedEvent> {
|
||||
public String call() throws Exception {
|
||||
int millis = random.nextInt(1000);
|
||||
Thread.sleep(millis);
|
||||
SampleController.this.traceManager.addTag("callable-sleep-millis", String.valueOf(millis));
|
||||
SampleController.this.tracer.addTag("callable-sleep-millis", String.valueOf(millis));
|
||||
Span currentSpan = SampleController.this.accessor.getCurrentSpan();
|
||||
return "async hi: " + currentSpan;
|
||||
}
|
||||
@@ -87,23 +87,23 @@ ApplicationListener<EmbeddedServletContainerInitializedEvent> {
|
||||
public String hi2() {
|
||||
int millis = random.nextInt(1000);
|
||||
Thread.sleep(millis);
|
||||
this.traceManager.addTag("random-sleep-millis", String.valueOf(millis));
|
||||
this.tracer.addTag("random-sleep-millis", String.valueOf(millis));
|
||||
return "hi2";
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
@RequestMapping("/traced")
|
||||
public String traced() {
|
||||
Trace trace = this.traceManager.startSpan("customTraceEndpoint",
|
||||
Trace trace = this.tracer.startTrace("customTraceEndpoint",
|
||||
new AlwaysSampler());
|
||||
int millis = random.nextInt(1000);
|
||||
log.info("Sleeping for {} millis", millis);
|
||||
Thread.sleep(millis);
|
||||
this.traceManager.addTag("random-sleep-millis", String.valueOf(millis));
|
||||
this.tracer.addTag("random-sleep-millis", String.valueOf(millis));
|
||||
|
||||
String s = this.restTemplate.getForObject("http://localhost:" + this.port
|
||||
+ "/call", String.class);
|
||||
this.traceManager.close(trace);
|
||||
this.tracer.close(trace);
|
||||
return "traced/" + s;
|
||||
}
|
||||
|
||||
@@ -113,7 +113,7 @@ ApplicationListener<EmbeddedServletContainerInitializedEvent> {
|
||||
int millis = random.nextInt(1000);
|
||||
log.info("Sleeping for {} millis", millis);
|
||||
Thread.sleep(millis);
|
||||
this.traceManager.addTag("random-sleep-millis", String.valueOf(millis));
|
||||
this.tracer.addTag("random-sleep-millis", String.valueOf(millis));
|
||||
|
||||
String s = this.restTemplate.getForObject("http://localhost:" + this.port
|
||||
+ "/call", String.class);
|
||||
|
||||
@@ -18,7 +18,7 @@ package sample;
|
||||
|
||||
import lombok.SneakyThrows;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cloud.sleuth.TraceManager;
|
||||
import org.springframework.cloud.sleuth.Tracer;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@@ -31,7 +31,7 @@ import java.util.Random;
|
||||
public class SampleBackground {
|
||||
|
||||
@Autowired
|
||||
private TraceManager traceManager;
|
||||
private Tracer tracer;
|
||||
@Autowired
|
||||
private Random random;
|
||||
|
||||
@@ -40,7 +40,7 @@ public class SampleBackground {
|
||||
public void background() {
|
||||
int millis = random.nextInt(1000);
|
||||
Thread.sleep(millis);
|
||||
this.traceManager.addTag("background-sleep-millis", String.valueOf(millis));
|
||||
this.tracer.addTag("background-sleep-millis", String.valueOf(millis));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ import org.springframework.boot.context.embedded.EmbeddedServletContainerInitial
|
||||
import org.springframework.cloud.sleuth.Span;
|
||||
import org.springframework.cloud.sleuth.Trace;
|
||||
import org.springframework.cloud.sleuth.TraceAccessor;
|
||||
import org.springframework.cloud.sleuth.TraceManager;
|
||||
import org.springframework.cloud.sleuth.Tracer;
|
||||
import org.springframework.cloud.sleuth.sampler.AlwaysSampler;
|
||||
import org.springframework.context.ApplicationListener;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
@@ -43,7 +43,7 @@ ApplicationListener<EmbeddedServletContainerInitializedEvent> {
|
||||
@Autowired
|
||||
private RestTemplate restTemplate;
|
||||
@Autowired
|
||||
private TraceManager traceManager;
|
||||
private Tracer tracer;
|
||||
@Autowired
|
||||
private TraceAccessor accessor;
|
||||
@Autowired
|
||||
@@ -69,7 +69,7 @@ ApplicationListener<EmbeddedServletContainerInitializedEvent> {
|
||||
public String call() throws Exception {
|
||||
int millis = random.nextInt(1000);
|
||||
Thread.sleep(millis);
|
||||
SampleController.this.traceManager.addTag("callable-sleep-millis", String.valueOf(millis));
|
||||
SampleController.this.tracer.addTag("callable-sleep-millis", String.valueOf(millis));
|
||||
Span currentSpan = SampleController.this.accessor.getCurrentSpan();
|
||||
return "async hi: " + currentSpan;
|
||||
}
|
||||
@@ -87,23 +87,23 @@ ApplicationListener<EmbeddedServletContainerInitializedEvent> {
|
||||
public String hi2() {
|
||||
int millis = random.nextInt(1000);
|
||||
Thread.sleep(millis);
|
||||
this.traceManager.addTag("random-sleep-millis", String.valueOf(millis));
|
||||
this.tracer.addTag("random-sleep-millis", String.valueOf(millis));
|
||||
return "hi2";
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
@RequestMapping("/traced")
|
||||
public String traced() {
|
||||
Trace trace = this.traceManager.startSpan("customTraceEndpoint",
|
||||
Trace trace = this.tracer.startTrace("customTraceEndpoint",
|
||||
new AlwaysSampler());
|
||||
int millis = random.nextInt(1000);
|
||||
log.info("Sleeping for {} millis", millis);
|
||||
Thread.sleep(millis);
|
||||
this.traceManager.addTag("random-sleep-millis", String.valueOf(millis));
|
||||
this.tracer.addTag("random-sleep-millis", String.valueOf(millis));
|
||||
|
||||
String s = this.restTemplate.getForObject("http://localhost:" + this.port
|
||||
+ "/call", String.class);
|
||||
this.traceManager.close(trace);
|
||||
this.tracer.close(trace);
|
||||
return "traced/" + s;
|
||||
}
|
||||
|
||||
@@ -113,7 +113,7 @@ ApplicationListener<EmbeddedServletContainerInitializedEvent> {
|
||||
int millis = random.nextInt(1000);
|
||||
log.info("Sleeping for {} millis", millis);
|
||||
Thread.sleep(millis);
|
||||
this.traceManager.addTag("random-sleep-millis", String.valueOf(millis));
|
||||
this.tracer.addTag("random-sleep-millis", String.valueOf(millis));
|
||||
|
||||
String s = this.restTemplate.getForObject("http://localhost:" + this.port
|
||||
+ "/call", String.class);
|
||||
|
||||
@@ -32,7 +32,7 @@ import org.springframework.cloud.sleuth.MilliSpan;
|
||||
import org.springframework.cloud.sleuth.Sampler;
|
||||
import org.springframework.cloud.sleuth.Span;
|
||||
import org.springframework.cloud.sleuth.Trace;
|
||||
import org.springframework.cloud.sleuth.TraceManager;
|
||||
import org.springframework.cloud.sleuth.Tracer;
|
||||
import org.springframework.cloud.sleuth.autoconfig.TraceAutoConfiguration;
|
||||
import org.springframework.cloud.sleuth.event.ClientReceivedEvent;
|
||||
import org.springframework.cloud.sleuth.event.ClientSentEvent;
|
||||
@@ -60,7 +60,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
public class StreamSpanListenerTests {
|
||||
|
||||
@Autowired
|
||||
private TraceManager traceManager;
|
||||
private Tracer tracer;
|
||||
|
||||
@Autowired
|
||||
private ApplicationContext application;
|
||||
@@ -78,8 +78,8 @@ public class StreamSpanListenerTests {
|
||||
|
||||
@Test
|
||||
public void acquireAndRelease() {
|
||||
Trace context = this.traceManager.startSpan("foo");
|
||||
this.traceManager.close(context);
|
||||
Trace context = this.tracer.startTrace("foo");
|
||||
this.tracer.close(context);
|
||||
assertEquals(1, this.test.spans.size());
|
||||
}
|
||||
|
||||
@@ -87,22 +87,22 @@ public class StreamSpanListenerTests {
|
||||
public void rpcAnnotations() {
|
||||
Span parent = MilliSpan.builder().traceId(1L).name("parent").remote(true)
|
||||
.build();
|
||||
Trace context = this.traceManager.startSpan("child", parent);
|
||||
Trace context = this.tracer.joinTrace("child", parent);
|
||||
this.application.publishEvent(new ClientSentEvent(this, context.getSpan()));
|
||||
this.application
|
||||
.publishEvent(new ServerReceivedEvent(this, parent, context.getSpan()));
|
||||
this.application
|
||||
.publishEvent(new ServerSentEvent(this, parent, context.getSpan()));
|
||||
this.application.publishEvent(new ClientReceivedEvent(this, context.getSpan()));
|
||||
this.traceManager.close(context);
|
||||
this.tracer.close(context);
|
||||
assertEquals(2, this.test.spans.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nullSpanName() {
|
||||
Trace context = this.traceManager.startSpan(null, (Sampler) null);
|
||||
Trace context = this.tracer.startTrace(null, (Sampler) null);
|
||||
this.application.publishEvent(new ClientSentEvent(this, context.getSpan()));
|
||||
this.traceManager.close(context);
|
||||
this.tracer.close(context);
|
||||
assertEquals(1, this.test.spans.size());
|
||||
this.listener.poll();
|
||||
assertEquals(0, this.test.spans.size());
|
||||
|
||||
@@ -33,7 +33,7 @@ import org.springframework.cloud.sleuth.MilliSpan;
|
||||
import org.springframework.cloud.sleuth.Sampler;
|
||||
import org.springframework.cloud.sleuth.Span;
|
||||
import org.springframework.cloud.sleuth.Trace;
|
||||
import org.springframework.cloud.sleuth.TraceManager;
|
||||
import org.springframework.cloud.sleuth.Tracer;
|
||||
import org.springframework.cloud.sleuth.autoconfig.TraceAutoConfiguration;
|
||||
import org.springframework.cloud.sleuth.event.ClientReceivedEvent;
|
||||
import org.springframework.cloud.sleuth.event.ClientSentEvent;
|
||||
@@ -56,7 +56,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
public class ZipkinSpanListenerTests {
|
||||
|
||||
@Autowired
|
||||
private TraceManager traceManager;
|
||||
private Tracer tracer;
|
||||
|
||||
@Autowired
|
||||
private ApplicationContext application;
|
||||
@@ -119,8 +119,8 @@ public class ZipkinSpanListenerTests {
|
||||
*/
|
||||
@Test
|
||||
public void spanWithoutAnnotationsLogsComponent() {
|
||||
Trace context = this.traceManager.startSpan("foo");
|
||||
this.traceManager.close(context);
|
||||
Trace context = this.tracer.startTrace("foo");
|
||||
this.tracer.close(context);
|
||||
assertEquals(1, this.test.spans.size());
|
||||
assertThat(this.test.spans.get(0).binaryAnnotations.get(0).endpoint.serviceName)
|
||||
.isEqualTo("unknown"); // TODO: "unknown" bc process id, documented as not nullable, is null.
|
||||
@@ -128,12 +128,12 @@ public class ZipkinSpanListenerTests {
|
||||
|
||||
@Test
|
||||
public void rpcAnnotations() {
|
||||
Trace context = this.traceManager.startSpan("child", parent);
|
||||
Trace context = this.tracer.joinTrace("child", parent);
|
||||
this.application.publishEvent(new ClientSentEvent(this, context.getSpan()));
|
||||
this.application.publishEvent(new ServerReceivedEvent(this, parent, context.getSpan()));
|
||||
this.application.publishEvent(new ServerSentEvent(this, parent, context.getSpan()));
|
||||
this.application.publishEvent(new ClientReceivedEvent(this, context.getSpan()));
|
||||
this.traceManager.close(context);
|
||||
this.tracer.close(context);
|
||||
assertEquals(2, this.test.spans.size());
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user