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);
|
||||
Reference in New Issue
Block a user