diff --git a/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/TraceManager.java b/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/Tracer.java
similarity index 92%
rename from spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/TraceManager.java
rename to spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/Tracer.java
index 6872c6565..7e353b316 100644
--- a/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/TraceManager.java
+++ b/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/Tracer.java
@@ -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:
*
- *
Create a new Span which has this thread's currentSpan as one of its parents.
*
Set currentSpan to the new Span.
*
Create a TraceSpan object to manage the new Span.
*
*
+ * 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:
*
*
It closes the span which the scope was managing.
*
Set currentSpan to the previous currentSpan (which may be null).
*
*/
-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
*/
- Trace startSpan(String name, Sampler sampler);
+ Trace startTrace(String name, Sampler sampler);
/**
* Pick up an existing span from another thread.
diff --git a/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/autoconfig/TraceAutoConfiguration.java b/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/autoconfig/TraceAutoConfiguration.java
index fd051f6e3..237a2821d 100644
--- a/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/autoconfig/TraceAutoConfiguration.java
+++ b/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/autoconfig/TraceAutoConfiguration.java
@@ -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 sampler,
- ApplicationEventPublisher publisher) {
- return new DefaultTraceManager(sampler, random(), publisher);
+ public DefaultTracer traceManager(Sampler sampler,
+ ApplicationEventPublisher publisher) {
+ return new DefaultTracer(sampler, random(), publisher);
}
}
diff --git a/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/instrument/TraceCallable.java b/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/instrument/TraceCallable.java
index 8d37a4055..e09f11302 100644
--- a/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/instrument/TraceCallable.java
+++ b/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/instrument/TraceCallable.java
@@ -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 extends TraceDelegate> implements Callable {
- public TraceCallable(TraceManager traceManager, Callable delegate) {
- super(traceManager, delegate);
+ public TraceCallable(Tracer tracer, Callable delegate) {
+ super(tracer, delegate);
}
- public TraceCallable(TraceManager traceManager, Callable delegate, String name) {
- super(traceManager, delegate, name);
+ public TraceCallable(Tracer tracer, Callable delegate, String name) {
+ super(tracer, delegate, name);
}
@Override
diff --git a/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/instrument/TraceDelegate.java b/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/instrument/TraceDelegate.java
index c50e0d2e6..4c9bc2faf 100644
--- a/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/instrument/TraceDelegate.java
+++ b/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/instrument/TraceDelegate.java
@@ -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 {
- 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() {
diff --git a/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/instrument/TraceRunnable.java b/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/instrument/TraceRunnable.java
index a4695adfd..ba75b7bc6 100644
--- a/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/instrument/TraceRunnable.java
+++ b/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/instrument/TraceRunnable.java
@@ -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 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
diff --git a/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/instrument/async/AsyncDefaultAutoConfiguration.java b/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/instrument/async/AsyncDefaultAutoConfiguration.java
index 3591b73e1..c3911bd59 100644
--- a/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/instrument/async/AsyncDefaultAutoConfiguration.java
+++ b/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/instrument/async/AsyncDefaultAutoConfiguration.java
@@ -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 {
diff --git a/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/instrument/async/LazyTraceExecutor.java b/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/instrument/async/LazyTraceExecutor.java
index 8a4fd5f37..6f894d210 100644
--- a/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/instrument/async/LazyTraceExecutor.java
+++ b/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/instrument/async/LazyTraceExecutor.java
@@ -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));
}
}
diff --git a/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/instrument/executor/TraceableExecutorService.java b/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/instrument/executor/TraceableExecutorService.java
index 530f1bf7e..b22914673 100644
--- a/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/instrument/executor/TraceableExecutorService.java
+++ b/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/instrument/executor/TraceableExecutorService.java
@@ -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 Future submit(Callable task) {
- Callable c = new TraceCallable<>(this.traceManager, task);
+ Callable c = new TraceCallable<>(this.tracer, task);
return this.delegate.submit(c);
}
@Override
public Future 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);
}
diff --git a/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/instrument/executor/TraceableScheduledExecutorService.java b/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/instrument/executor/TraceableScheduledExecutorService.java
index 5a81da162..ee3fccfba 100644
--- a/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/instrument/executor/TraceableScheduledExecutorService.java
+++ b/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/instrument/executor/TraceableScheduledExecutorService.java
@@ -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 ScheduledFuture schedule(Callable callable, long delay, TimeUnit unit) {
- Callable c = new TraceCallable<>(this.traceManager,callable);
+ Callable 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);
}
diff --git a/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/instrument/hystrix/SleuthHystrixAutoConfiguration.java b/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/instrument/hystrix/SleuthHystrixAutoConfiguration.java
index dd3d27978..e843abf1a 100644
--- a/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/instrument/hystrix/SleuthHystrixAutoConfiguration.java
+++ b/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/instrument/hystrix/SleuthHystrixAutoConfiguration.java
@@ -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);
}
}
diff --git a/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/instrument/hystrix/SleuthHystrixConcurrencyStrategy.java b/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/instrument/hystrix/SleuthHystrixConcurrencyStrategy.java
index 9063b2be5..7e2a7b4f6 100644
--- a/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/instrument/hystrix/SleuthHystrixConcurrencyStrategy.java
+++ b/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/instrument/hystrix/SleuthHystrixConcurrencyStrategy.java
@@ -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 Callable wrapCallable(Callable callable) {
- return new TraceCallable<>(traceManager, callable);
+ return new TraceCallable<>(tracer, callable);
}
}
diff --git a/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/instrument/hystrix/TraceCommand.java b/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/instrument/hystrix/TraceCommand.java
index 7a77664da..455ade803 100644
--- a/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/instrument/hystrix/TraceCommand.java
+++ b/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/instrument/hystrix/TraceCommand.java
@@ -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 extends HystrixCommand {
- 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);
}
}
diff --git a/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/instrument/integration/AbstractTraceChannelInterceptor.java b/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/instrument/integration/AbstractTraceChannelInterceptor.java
index 42d7e121b..ea5123eb3 100644
--- a/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/instrument/integration/AbstractTraceChannelInterceptor.java
+++ b/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/instrument/integration/AbstractTraceChannelInterceptor.java
@@ -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;
}
diff --git a/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/instrument/integration/TraceChannelInterceptor.java b/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/instrument/integration/TraceChannelInterceptor.java
index 50fa660ea..25dc1aed7 100644
--- a/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/instrument/integration/TraceChannelInterceptor.java
+++ b/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/instrument/integration/TraceChannelInterceptor.java
@@ -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 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);
}
}
diff --git a/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/instrument/integration/TraceContextPropagationChannelInterceptor.java b/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/instrument/integration/TraceContextPropagationChannelInterceptor.java
index e463bd027..d96e6509d 100644
--- a/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/instrument/integration/TraceContextPropagationChannelInterceptor.java
+++ b/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/instrument/integration/TraceContextPropagationChannelInterceptor.java
@@ -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 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();
}
diff --git a/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/instrument/integration/TraceSpringIntegrationAutoConfiguration.java b/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/instrument/integration/TraceSpringIntegrationAutoConfiguration.java
index 757336fae..7b09a71d2 100644
--- a/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/instrument/integration/TraceSpringIntegrationAutoConfiguration.java
+++ b/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/instrument/integration/TraceSpringIntegrationAutoConfiguration.java
@@ -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);
}
}
diff --git a/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/instrument/integration/TraceStompMessageChannelInterceptor.java b/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/instrument/integration/TraceStompMessageChannelInterceptor.java
index 1a59b528a..96c99adce 100644
--- a/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/instrument/integration/TraceStompMessageChannelInterceptor.java
+++ b/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/instrument/integration/TraceStompMessageChannelInterceptor.java
@@ -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 traceScopeHolder = new ThreadLocal();
- 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 traceScopeHolder = this.traceScopeHolder;
Trace traceInScope = traceScopeHolder.get();
- this.traceManager.close(traceInScope);
+ this.tracer.close(traceInScope);
traceScopeHolder.remove();
}
}
diff --git a/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/instrument/integration/TraceStompMessageContextPropagationChannelInterceptor.java b/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/instrument/integration/TraceStompMessageContextPropagationChannelInterceptor.java
index 7848cda57..6a593b45e 100644
--- a/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/instrument/integration/TraceStompMessageContextPropagationChannelInterceptor.java
+++ b/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/instrument/integration/TraceStompMessageContextPropagationChannelInterceptor.java
@@ -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 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();
}
diff --git a/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/instrument/scheduling/TraceSchedulingAspect.java b/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/instrument/scheduling/TraceSchedulingAspect.java
index 5188f7f3d..ec51cfd4d 100644
--- a/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/instrument/scheduling/TraceSchedulingAspect.java
+++ b/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/instrument/scheduling/TraceSchedulingAspect.java
@@ -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);
}
}
diff --git a/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/instrument/scheduling/TraceSchedulingAutoConfiguration.java b/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/instrument/scheduling/TraceSchedulingAutoConfiguration.java
index f6b9da8ea..b06de63b0 100644
--- a/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/instrument/scheduling/TraceSchedulingAutoConfiguration.java
+++ b/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/instrument/scheduling/TraceSchedulingAutoConfiguration.java
@@ -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);
}
}
diff --git a/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/instrument/web/TraceFilter.java b/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/instrument/web/TraceFilter.java
index 49d11dd10..181e4b4fa 100644
--- a/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/instrument/web/TraceFilter.java
+++ b/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/instrument/web/TraceFilter.java
@@ -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()));
}
}
diff --git a/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/instrument/web/TraceHandlerInterceptor.java b/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/instrument/web/TraceHandlerInterceptor.java
index a1c2a6d14..ae17295b6 100644
--- a/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/instrument/web/TraceHandlerInterceptor.java
+++ b/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/instrument/web/TraceHandlerInterceptor.java
@@ -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);
}
}
diff --git a/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/instrument/web/TraceWebAspect.java b/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/instrument/web/TraceWebAspect.java
index c10f09257..89f950660 100644
--- a/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/instrument/web/TraceWebAspect.java
+++ b/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/instrument/web/TraceWebAspect.java
@@ -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);
}
diff --git a/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/instrument/web/TraceWebAutoConfiguration.java b/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/instrument/web/TraceWebAutoConfiguration.java
index b6775dea4..47d398c84 100644
--- a/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/instrument/web/TraceWebAutoConfiguration.java
+++ b/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/instrument/web/TraceWebAutoConfiguration.java
@@ -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;
}
diff --git a/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/instrument/web/client/SleuthHystrixInvocationHandler.java b/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/instrument/web/client/SleuthHystrixInvocationHandler.java
index ed51922b2..7803d339f 100644
--- a/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/instrument/web/client/SleuthHystrixInvocationHandler.java
+++ b/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/instrument/web/client/SleuthHystrixInvocationHandler.java
@@ -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 dispatch;
- private final TraceManager traceManager;
+ private final Tracer tracer;
- SleuthHystrixInvocationHandler(Target target, Map dispatch, TraceManager traceManager) {
- this.traceManager = checkNotNull(traceManager, "traceManager");
+ SleuthHystrixInvocationHandler(Target target, Map 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