Skip to content

Commit 0cede81

Browse files
Making TraceKeys a deprecated, package scope detail of legacy sleuth parsers; fixes gh-940
1 parent 62b6f62 commit 0cede81

30 files changed

+158
-634
lines changed

spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/TraceKeys.java

Lines changed: 0 additions & 493 deletions
This file was deleted.

spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/autoconfig/TraceAutoConfiguration.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
import org.springframework.cloud.sleuth.DefaultSpanNamer;
3838
import org.springframework.cloud.sleuth.SpanAdjuster;
3939
import org.springframework.cloud.sleuth.SpanNamer;
40-
import org.springframework.cloud.sleuth.TraceKeys;
4140
import org.springframework.context.annotation.Bean;
4241
import org.springframework.context.annotation.Configuration;
4342
import zipkin2.Span;
@@ -53,7 +52,7 @@
5352
*/
5453
@Configuration
5554
@ConditionalOnProperty(value="spring.sleuth.enabled", matchIfMissing=true)
56-
@EnableConfigurationProperties({ TraceKeys.class, SleuthProperties.class })
55+
@EnableConfigurationProperties(SleuthProperties.class)
5756
public class TraceAutoConfiguration {
5857

5958
public static final String TRACER_BEAN_NAME = "tracer";

spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/instrument/async/AsyncDefaultAutoConfiguration.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
2828
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
2929
import org.springframework.cloud.sleuth.SpanNamer;
30-
import org.springframework.cloud.sleuth.TraceKeys;
3130
import org.springframework.context.annotation.Bean;
3231
import org.springframework.context.annotation.Configuration;
3332
import org.springframework.context.annotation.Role;
@@ -66,8 +65,8 @@ public Executor getAsyncExecutor() {
6665
}
6766

6867
@Bean
69-
public TraceAsyncAspect traceAsyncAspect(Tracer tracer, SpanNamer spanNamer, TraceKeys traceKeys) {
70-
return new TraceAsyncAspect(tracer, spanNamer, traceKeys);
68+
public TraceAsyncAspect traceAsyncAspect(Tracer tracer, SpanNamer spanNamer) {
69+
return new TraceAsyncAspect(tracer, spanNamer);
7170
}
7271

7372
@Bean

spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/instrument/async/TraceAsyncAspect.java

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,15 @@
1616

1717
package org.springframework.cloud.sleuth.instrument.async;
1818

19-
import brave.Span;
20-
import brave.Tracer;
21-
2219
import java.lang.reflect.Method;
2320

21+
import brave.Span;
22+
import brave.Tracer;
2423
import org.aspectj.lang.ProceedingJoinPoint;
2524
import org.aspectj.lang.annotation.Around;
2625
import org.aspectj.lang.annotation.Aspect;
2726
import org.aspectj.lang.reflect.MethodSignature;
2827
import org.springframework.cloud.sleuth.SpanNamer;
29-
import org.springframework.cloud.sleuth.TraceKeys;
3028
import org.springframework.cloud.sleuth.util.SpanNameUtil;
3129
import org.springframework.util.ReflectionUtils;
3230

@@ -42,14 +40,15 @@
4240
@Aspect
4341
public class TraceAsyncAspect {
4442

43+
private static final String CLASS_KEY = "class";
44+
private static final String METHOD_KEY = "method";
45+
4546
private final Tracer tracer;
4647
private final SpanNamer spanNamer;
47-
private final TraceKeys traceKeys;
4848

49-
public TraceAsyncAspect(Tracer tracer, SpanNamer spanNamer, TraceKeys traceKeys) {
49+
public TraceAsyncAspect(Tracer tracer, SpanNamer spanNamer) {
5050
this.tracer = tracer;
5151
this.spanNamer = spanNamer;
52-
this.traceKeys = traceKeys;
5352
}
5453

5554
@Around("execution (@org.springframework.scheduling.annotation.Async * *.*(..))")
@@ -61,10 +60,8 @@ public Object traceBackgroundThread(final ProceedingJoinPoint pjp) throws Throwa
6160
}
6261
span = span.name(spanName);
6362
try(Tracer.SpanInScope ws = this.tracer.withSpanInScope(span)) {
64-
span.tag(this.traceKeys.getAsync().getPrefix() +
65-
this.traceKeys.getAsync().getClassNameKey(), pjp.getTarget().getClass().getSimpleName());
66-
span.tag(this.traceKeys.getAsync().getPrefix() +
67-
this.traceKeys.getAsync().getMethodNameKey(), pjp.getSignature().getName());
63+
span.tag(CLASS_KEY, pjp.getTarget().getClass().getSimpleName());
64+
span.tag(METHOD_KEY, pjp.getSignature().getName());
6865
return pjp.proceed();
6966
} finally {
7067
span.finish();

spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/instrument/hystrix/TraceCommand.java

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import brave.Span;
2020
import brave.Tracer;
2121
import com.netflix.hystrix.HystrixCommand;
22-
import org.springframework.cloud.sleuth.TraceKeys;
2322

2423
/**
2524
* Abstraction over {@code HystrixCommand} that wraps command execution with Trace setting
@@ -34,27 +33,26 @@
3433
*/
3534
public abstract class TraceCommand<R> extends HystrixCommand<R> {
3635

36+
private static final String COMMAND_KEY = "commandKey";
37+
private static final String COMMAND_GROUP_KEY = "commandGroup";
38+
private static final String THREAD_POOL_KEY = "threadPoolKey";
39+
3740
private final Tracer tracer;
38-
private final TraceKeys traceKeys;
3941
private final Span span;
4042

41-
protected TraceCommand(Tracer tracer, TraceKeys traceKeys, Setter setter) {
43+
protected TraceCommand(Tracer tracer, Setter setter) {
4244
super(setter);
4345
this.tracer = tracer;
44-
this.traceKeys = traceKeys;
4546
this.span = this.tracer.nextSpan();
4647
}
4748

4849
@Override
4950
protected R run() throws Exception {
5051
String commandKeyName = getCommandKey().name();
5152
Span span = this.span.name(commandKeyName);
52-
span.tag(this.traceKeys.getHystrix().getPrefix() +
53-
this.traceKeys.getHystrix().getCommandKey(), commandKeyName);
54-
span.tag(this.traceKeys.getHystrix().getPrefix() +
55-
this.traceKeys.getHystrix().getCommandGroup(), getCommandGroup().name());
56-
span.tag(this.traceKeys.getHystrix().getPrefix() +
57-
this.traceKeys.getHystrix().getThreadPoolKey(), getThreadPoolKey().name());
53+
span.tag(COMMAND_KEY, commandKeyName);
54+
span.tag(COMMAND_GROUP_KEY, getCommandGroup().name());
55+
span.tag(THREAD_POOL_KEY, getThreadPoolKey().name());
5856
try (Tracer.SpanInScope ws = this.tracer.withSpanInScope(span.start())) {
5957
return doRun();
6058
}

spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/instrument/rxjava/RxJavaAutoConfiguration.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,15 @@
2020

2121
import brave.Tracer;
2222
import brave.Tracing;
23-
import rx.plugins.RxJavaSchedulersHook;
2423
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
2524
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
2625
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
2726
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
2827
import org.springframework.boot.context.properties.EnableConfigurationProperties;
29-
import org.springframework.cloud.sleuth.TraceKeys;
3028
import org.springframework.cloud.sleuth.autoconfig.TraceAutoConfiguration;
3129
import org.springframework.context.annotation.Bean;
3230
import org.springframework.context.annotation.Configuration;
31+
import rx.plugins.RxJavaSchedulersHook;
3332

3433
/**
3534
* {@link org.springframework.boot.autoconfigure.EnableAutoConfiguration Auto-configuration} that
@@ -47,9 +46,9 @@
4746
public class RxJavaAutoConfiguration {
4847

4948
@Bean
50-
SleuthRxJavaSchedulersHook sleuthRxJavaSchedulersHook(Tracer tracer, TraceKeys traceKeys,
49+
SleuthRxJavaSchedulersHook sleuthRxJavaSchedulersHook(Tracer tracer,
5150
SleuthRxJavaSchedulersProperties sleuthRxJavaSchedulersProperties) {
52-
return new SleuthRxJavaSchedulersHook(tracer, traceKeys,
51+
return new SleuthRxJavaSchedulersHook(tracer,
5352
Arrays.asList(sleuthRxJavaSchedulersProperties.getIgnoredthreads()));
5453
}
5554
}

spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/instrument/rxjava/SleuthRxJavaSchedulersHook.java

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import brave.Tracer;
2323
import org.apache.commons.logging.Log;
2424
import org.apache.commons.logging.LogFactory;
25-
import org.springframework.cloud.sleuth.TraceKeys;
2625
import rx.functions.Action0;
2726
import rx.plugins.RxJavaErrorHandler;
2827
import rx.plugins.RxJavaObservableExecutionHook;
@@ -43,14 +42,11 @@ class SleuthRxJavaSchedulersHook extends RxJavaSchedulersHook {
4342

4443
private static final String RXJAVA_COMPONENT = "rxjava";
4544
private final Tracer tracer;
46-
private final TraceKeys traceKeys;
4745
private final List<String> threadsToSample;
4846
private RxJavaSchedulersHook delegate;
4947

50-
SleuthRxJavaSchedulersHook(Tracer tracer, TraceKeys traceKeys,
51-
List<String> threadsToSample) {
48+
SleuthRxJavaSchedulersHook(Tracer tracer, List<String> threadsToSample) {
5249
this.tracer = tracer;
53-
this.traceKeys = traceKeys;
5450
this.threadsToSample = threadsToSample;
5551
try {
5652
this.delegate = RxJavaPlugins.getInstance().getSchedulersHook();
@@ -92,22 +88,22 @@ public Action0 onSchedule(Action0 action) {
9288
if (wrappedAction instanceof TraceAction) {
9389
return action;
9490
}
95-
return super.onSchedule(new TraceAction(this.tracer, this.traceKeys, wrappedAction,
91+
return super.onSchedule(new TraceAction(this.tracer, wrappedAction,
9692
this.threadsToSample));
9793
}
9894

9995
static class TraceAction implements Action0 {
10096

97+
private static final String THREAD_NAME_KEY = "thread";
98+
10199
private final Action0 actual;
102100
private final Tracer tracer;
103-
private final TraceKeys traceKeys;
104101
private final Span parent;
105102
private final List<String> threadsToIgnore;
106103

107-
public TraceAction(Tracer tracer, TraceKeys traceKeys, Action0 actual,
104+
public TraceAction(Tracer tracer, Action0 actual,
108105
List<String> threadsToIgnore) {
109106
this.tracer = tracer;
110-
this.traceKeys = traceKeys;
111107
this.threadsToIgnore = threadsToIgnore;
112108
this.parent = this.tracer.currentSpan();
113109
this.actual = actual;
@@ -135,9 +131,7 @@ public void call() {
135131
span = this.tracer.joinSpan(this.parent.context());
136132
} else {
137133
span = this.tracer.nextSpan().name(RXJAVA_COMPONENT).start();
138-
span.tag(this.traceKeys.getAsync().getPrefix()
139-
+ this.traceKeys.getAsync().getThreadNameKey(),
140-
Thread.currentThread().getName());
134+
span.tag(THREAD_NAME_KEY, Thread.currentThread().getName());
141135
created = true;
142136
}
143137
try (Tracer.SpanInScope ws = this.tracer.withSpanInScope(span)) {

spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/instrument/scheduling/TraceSchedulingAspect.java

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
import org.aspectj.lang.ProceedingJoinPoint;
2525
import org.aspectj.lang.annotation.Around;
2626
import org.aspectj.lang.annotation.Aspect;
27-
import org.springframework.cloud.sleuth.TraceKeys;
2827
import org.springframework.cloud.sleuth.util.SpanNameUtil;
2928

3029
/**
@@ -45,15 +44,15 @@
4544
@Aspect
4645
public class TraceSchedulingAspect {
4746

47+
private static final String CLASS_KEY = "class";
48+
private static final String METHOD_KEY = "method";
49+
4850
private final Tracer tracer;
4951
private final Pattern skipPattern;
50-
private final TraceKeys traceKeys;
5152

52-
public TraceSchedulingAspect(Tracer tracer, Pattern skipPattern,
53-
TraceKeys traceKeys) {
53+
public TraceSchedulingAspect(Tracer tracer, Pattern skipPattern) {
5454
this.tracer = tracer;
5555
this.skipPattern = skipPattern;
56-
this.traceKeys = traceKeys;
5756
}
5857

5958
@Around("execution (@org.springframework.scheduling.annotation.Scheduled * *.*(..))")
@@ -64,10 +63,8 @@ public Object traceBackgroundThread(final ProceedingJoinPoint pjp) throws Throwa
6463
String spanName = SpanNameUtil.toLowerHyphen(pjp.getSignature().getName());
6564
Span span = startOrContinueRenamedSpan(spanName);
6665
try(Tracer.SpanInScope ws = this.tracer.withSpanInScope(span)) {
67-
span.tag(this.traceKeys.getAsync().getPrefix() +
68-
this.traceKeys.getAsync().getClassNameKey(), pjp.getTarget().getClass().getSimpleName());
69-
span.tag(this.traceKeys.getAsync().getPrefix() +
70-
this.traceKeys.getAsync().getMethodNameKey(), pjp.getSignature().getName());
66+
span.tag(CLASS_KEY, pjp.getTarget().getClass().getSimpleName());
67+
span.tag(METHOD_KEY, pjp.getSignature().getName());
7168
return pjp.proceed();
7269
} finally {
7370
span.finish();

spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/instrument/scheduling/TraceSchedulingAutoConfiguration.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
2626
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
2727
import org.springframework.boot.context.properties.EnableConfigurationProperties;
28-
import org.springframework.cloud.sleuth.TraceKeys;
2928
import org.springframework.cloud.sleuth.autoconfig.TraceAutoConfiguration;
3029
import org.springframework.context.annotation.Bean;
3130
import org.springframework.context.annotation.Configuration;
@@ -51,8 +50,8 @@ public class TraceSchedulingAutoConfiguration {
5150
@Bean
5251
@ConditionalOnClass(name = "org.aspectj.lang.ProceedingJoinPoint")
5352
public TraceSchedulingAspect traceSchedulingAspect(Tracer tracer,
54-
SleuthSchedulingProperties sleuthSchedulingProperties, TraceKeys traceKeys) {
53+
SleuthSchedulingProperties sleuthSchedulingProperties) {
5554
return new TraceSchedulingAspect(tracer,
56-
Pattern.compile(sleuthSchedulingProperties.getSkipPattern()), traceKeys);
55+
Pattern.compile(sleuthSchedulingProperties.getSkipPattern()));
5756
}
5857
}

spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/instrument/web/SleuthHttpClientParser.java

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import brave.SpanCustomizer;
2222
import brave.http.HttpAdapter;
2323
import brave.http.HttpClientParser;
24-
import org.springframework.cloud.sleuth.TraceKeys;
2524
import org.springframework.cloud.sleuth.util.SpanNameUtil;
2625

2726
/**
@@ -32,9 +31,14 @@
3231
*/
3332
class SleuthHttpClientParser extends HttpClientParser {
3433

34+
private static final String HOST_KEY = "http.host";
35+
private static final String METHOD_KEY = "http.method";
36+
private static final String PATH_KEY = "http.path";
37+
private static final String URL_KEY = "http.url";
38+
3539
private final TraceKeys traceKeys;
3640

37-
public SleuthHttpClientParser(TraceKeys traceKeys) {
41+
SleuthHttpClientParser(TraceKeys traceKeys) {
3842
this.traceKeys = traceKeys;
3943
}
4044

@@ -74,11 +78,11 @@ private String uriScheme(URI uri) {
7478

7579
private void addRequestTags(SpanCustomizer customizer, String url, String host,
7680
String path, String method) {
77-
customizer.tag(this.traceKeys.getHttp().getUrl(), url);
81+
customizer.tag(URL_KEY, url);
7882
if (host != null) {
79-
customizer.tag(this.traceKeys.getHttp().getHost(), host);
83+
customizer.tag(HOST_KEY, host);
8084
}
81-
customizer.tag(this.traceKeys.getHttp().getPath(), path);
82-
customizer.tag(this.traceKeys.getHttp().getMethod(), method);
85+
customizer.tag(PATH_KEY, path);
86+
customizer.tag(METHOD_KEY, method);
8387
}
8488
}

0 commit comments

Comments
 (0)