Skip to content

Commit

Permalink
Making TraceKeys a deprecated, package scope detail of legacy sleuth …
Browse files Browse the repository at this point in the history
…parsers; fixes gh-940
  • Loading branch information
marcingrzejszczak committed Apr 13, 2018
1 parent b79e44b commit ba36c7f
Show file tree
Hide file tree
Showing 30 changed files with 158 additions and 634 deletions.

This file was deleted.

Expand Up @@ -37,7 +37,6 @@
import org.springframework.cloud.sleuth.DefaultSpanNamer;
import org.springframework.cloud.sleuth.SpanAdjuster;
import org.springframework.cloud.sleuth.SpanNamer;
import org.springframework.cloud.sleuth.TraceKeys;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import zipkin2.Span;
Expand All @@ -53,7 +52,7 @@
*/
@Configuration
@ConditionalOnProperty(value="spring.sleuth.enabled", matchIfMissing=true)
@EnableConfigurationProperties({ TraceKeys.class, SleuthProperties.class })
@EnableConfigurationProperties(SleuthProperties.class)
public class TraceAutoConfiguration {

public static final String TRACER_BEAN_NAME = "tracer";
Expand Down
Expand Up @@ -27,7 +27,6 @@
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.cloud.sleuth.SpanNamer;
import org.springframework.cloud.sleuth.TraceKeys;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Role;
Expand Down Expand Up @@ -66,8 +65,8 @@ public Executor getAsyncExecutor() {
}

@Bean
public TraceAsyncAspect traceAsyncAspect(Tracer tracer, SpanNamer spanNamer, TraceKeys traceKeys) {
return new TraceAsyncAspect(tracer, spanNamer, traceKeys);
public TraceAsyncAspect traceAsyncAspect(Tracer tracer, SpanNamer spanNamer) {
return new TraceAsyncAspect(tracer, spanNamer);
}

@Bean
Expand Down
Expand Up @@ -16,17 +16,15 @@

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

import brave.Span;
import brave.Tracer;

import java.lang.reflect.Method;

import brave.Span;
import brave.Tracer;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.reflect.MethodSignature;
import org.springframework.cloud.sleuth.SpanNamer;
import org.springframework.cloud.sleuth.TraceKeys;
import org.springframework.cloud.sleuth.util.SpanNameUtil;
import org.springframework.util.ReflectionUtils;

Expand All @@ -42,14 +40,15 @@
@Aspect
public class TraceAsyncAspect {

private static final String CLASS_KEY = "class";
private static final String METHOD_KEY = "method";

private final Tracer tracer;
private final SpanNamer spanNamer;
private final TraceKeys traceKeys;

public TraceAsyncAspect(Tracer tracer, SpanNamer spanNamer, TraceKeys traceKeys) {
public TraceAsyncAspect(Tracer tracer, SpanNamer spanNamer) {
this.tracer = tracer;
this.spanNamer = spanNamer;
this.traceKeys = traceKeys;
}

@Around("execution (@org.springframework.scheduling.annotation.Async * *.*(..))")
Expand All @@ -61,10 +60,8 @@ public Object traceBackgroundThread(final ProceedingJoinPoint pjp) throws Throwa
}
span = span.name(spanName);
try(Tracer.SpanInScope ws = this.tracer.withSpanInScope(span)) {
span.tag(this.traceKeys.getAsync().getPrefix() +
this.traceKeys.getAsync().getClassNameKey(), pjp.getTarget().getClass().getSimpleName());
span.tag(this.traceKeys.getAsync().getPrefix() +
this.traceKeys.getAsync().getMethodNameKey(), pjp.getSignature().getName());
span.tag(CLASS_KEY, pjp.getTarget().getClass().getSimpleName());
span.tag(METHOD_KEY, pjp.getSignature().getName());
return pjp.proceed();
} finally {
span.finish();
Expand Down
Expand Up @@ -19,7 +19,6 @@
import brave.Span;
import brave.Tracer;
import com.netflix.hystrix.HystrixCommand;
import org.springframework.cloud.sleuth.TraceKeys;

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

private static final String COMMAND_KEY = "commandKey";
private static final String COMMAND_GROUP_KEY = "commandGroup";
private static final String THREAD_POOL_KEY = "threadPoolKey";

private final Tracer tracer;
private final TraceKeys traceKeys;
private final Span span;

protected TraceCommand(Tracer tracer, TraceKeys traceKeys, Setter setter) {
protected TraceCommand(Tracer tracer, Setter setter) {
super(setter);
this.tracer = tracer;
this.traceKeys = traceKeys;
this.span = this.tracer.nextSpan();
}

@Override
protected R run() throws Exception {
String commandKeyName = getCommandKey().name();
Span span = this.span.name(commandKeyName);
span.tag(this.traceKeys.getHystrix().getPrefix() +
this.traceKeys.getHystrix().getCommandKey(), commandKeyName);
span.tag(this.traceKeys.getHystrix().getPrefix() +
this.traceKeys.getHystrix().getCommandGroup(), getCommandGroup().name());
span.tag(this.traceKeys.getHystrix().getPrefix() +
this.traceKeys.getHystrix().getThreadPoolKey(), getThreadPoolKey().name());
span.tag(COMMAND_KEY, commandKeyName);
span.tag(COMMAND_GROUP_KEY, getCommandGroup().name());
span.tag(THREAD_POOL_KEY, getThreadPoolKey().name());
try (Tracer.SpanInScope ws = this.tracer.withSpanInScope(span.start())) {
return doRun();
}
Expand Down
Expand Up @@ -20,16 +20,15 @@

import brave.Tracer;
import brave.Tracing;
import rx.plugins.RxJavaSchedulersHook;
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.boot.context.properties.EnableConfigurationProperties;
import org.springframework.cloud.sleuth.TraceKeys;
import org.springframework.cloud.sleuth.autoconfig.TraceAutoConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import rx.plugins.RxJavaSchedulersHook;

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

@Bean
SleuthRxJavaSchedulersHook sleuthRxJavaSchedulersHook(Tracer tracer, TraceKeys traceKeys,
SleuthRxJavaSchedulersHook sleuthRxJavaSchedulersHook(Tracer tracer,
SleuthRxJavaSchedulersProperties sleuthRxJavaSchedulersProperties) {
return new SleuthRxJavaSchedulersHook(tracer, traceKeys,
return new SleuthRxJavaSchedulersHook(tracer,
Arrays.asList(sleuthRxJavaSchedulersProperties.getIgnoredthreads()));
}
}
Expand Up @@ -22,7 +22,6 @@
import brave.Tracer;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.cloud.sleuth.TraceKeys;
import rx.functions.Action0;
import rx.plugins.RxJavaErrorHandler;
import rx.plugins.RxJavaObservableExecutionHook;
Expand All @@ -43,14 +42,11 @@ class SleuthRxJavaSchedulersHook extends RxJavaSchedulersHook {

private static final String RXJAVA_COMPONENT = "rxjava";
private final Tracer tracer;
private final TraceKeys traceKeys;
private final List<String> threadsToSample;
private RxJavaSchedulersHook delegate;

SleuthRxJavaSchedulersHook(Tracer tracer, TraceKeys traceKeys,
List<String> threadsToSample) {
SleuthRxJavaSchedulersHook(Tracer tracer, List<String> threadsToSample) {
this.tracer = tracer;
this.traceKeys = traceKeys;
this.threadsToSample = threadsToSample;
try {
this.delegate = RxJavaPlugins.getInstance().getSchedulersHook();
Expand Down Expand Up @@ -92,22 +88,22 @@ public Action0 onSchedule(Action0 action) {
if (wrappedAction instanceof TraceAction) {
return action;
}
return super.onSchedule(new TraceAction(this.tracer, this.traceKeys, wrappedAction,
return super.onSchedule(new TraceAction(this.tracer, wrappedAction,
this.threadsToSample));
}

static class TraceAction implements Action0 {

private static final String THREAD_NAME_KEY = "thread";

private final Action0 actual;
private final Tracer tracer;
private final TraceKeys traceKeys;
private final Span parent;
private final List<String> threadsToIgnore;

public TraceAction(Tracer tracer, TraceKeys traceKeys, Action0 actual,
public TraceAction(Tracer tracer, Action0 actual,
List<String> threadsToIgnore) {
this.tracer = tracer;
this.traceKeys = traceKeys;
this.threadsToIgnore = threadsToIgnore;
this.parent = this.tracer.currentSpan();
this.actual = actual;
Expand Down Expand Up @@ -135,9 +131,7 @@ public void call() {
span = this.tracer.joinSpan(this.parent.context());
} else {
span = this.tracer.nextSpan().name(RXJAVA_COMPONENT).start();
span.tag(this.traceKeys.getAsync().getPrefix()
+ this.traceKeys.getAsync().getThreadNameKey(),
Thread.currentThread().getName());
span.tag(THREAD_NAME_KEY, Thread.currentThread().getName());
created = true;
}
try (Tracer.SpanInScope ws = this.tracer.withSpanInScope(span)) {
Expand Down
Expand Up @@ -24,7 +24,6 @@
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.cloud.sleuth.TraceKeys;
import org.springframework.cloud.sleuth.util.SpanNameUtil;

/**
Expand All @@ -45,15 +44,15 @@
@Aspect
public class TraceSchedulingAspect {

private static final String CLASS_KEY = "class";
private static final String METHOD_KEY = "method";

private final Tracer tracer;
private final Pattern skipPattern;
private final TraceKeys traceKeys;

public TraceSchedulingAspect(Tracer tracer, Pattern skipPattern,
TraceKeys traceKeys) {
public TraceSchedulingAspect(Tracer tracer, Pattern skipPattern) {
this.tracer = tracer;
this.skipPattern = skipPattern;
this.traceKeys = traceKeys;
}

@Around("execution (@org.springframework.scheduling.annotation.Scheduled * *.*(..))")
Expand All @@ -64,10 +63,8 @@ public Object traceBackgroundThread(final ProceedingJoinPoint pjp) throws Throwa
String spanName = SpanNameUtil.toLowerHyphen(pjp.getSignature().getName());
Span span = startOrContinueRenamedSpan(spanName);
try(Tracer.SpanInScope ws = this.tracer.withSpanInScope(span)) {
span.tag(this.traceKeys.getAsync().getPrefix() +
this.traceKeys.getAsync().getClassNameKey(), pjp.getTarget().getClass().getSimpleName());
span.tag(this.traceKeys.getAsync().getPrefix() +
this.traceKeys.getAsync().getMethodNameKey(), pjp.getSignature().getName());
span.tag(CLASS_KEY, pjp.getTarget().getClass().getSimpleName());
span.tag(METHOD_KEY, pjp.getSignature().getName());
return pjp.proceed();
} finally {
span.finish();
Expand Down
Expand Up @@ -25,7 +25,6 @@
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.cloud.sleuth.TraceKeys;
import org.springframework.cloud.sleuth.autoconfig.TraceAutoConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
Expand All @@ -51,8 +50,8 @@ public class TraceSchedulingAutoConfiguration {
@Bean
@ConditionalOnClass(name = "org.aspectj.lang.ProceedingJoinPoint")
public TraceSchedulingAspect traceSchedulingAspect(Tracer tracer,
SleuthSchedulingProperties sleuthSchedulingProperties, TraceKeys traceKeys) {
SleuthSchedulingProperties sleuthSchedulingProperties) {
return new TraceSchedulingAspect(tracer,
Pattern.compile(sleuthSchedulingProperties.getSkipPattern()), traceKeys);
Pattern.compile(sleuthSchedulingProperties.getSkipPattern()));
}
}
Expand Up @@ -21,7 +21,6 @@
import brave.SpanCustomizer;
import brave.http.HttpAdapter;
import brave.http.HttpClientParser;
import org.springframework.cloud.sleuth.TraceKeys;
import org.springframework.cloud.sleuth.util.SpanNameUtil;

/**
Expand All @@ -32,9 +31,14 @@
*/
class SleuthHttpClientParser extends HttpClientParser {

private static final String HOST_KEY = "http.host";
private static final String METHOD_KEY = "http.method";
private static final String PATH_KEY = "http.path";
private static final String URL_KEY = "http.url";

private final TraceKeys traceKeys;

public SleuthHttpClientParser(TraceKeys traceKeys) {
SleuthHttpClientParser(TraceKeys traceKeys) {
this.traceKeys = traceKeys;
}

Expand Down Expand Up @@ -74,11 +78,11 @@ private String uriScheme(URI uri) {

private void addRequestTags(SpanCustomizer customizer, String url, String host,
String path, String method) {
customizer.tag(this.traceKeys.getHttp().getUrl(), url);
customizer.tag(URL_KEY, url);
if (host != null) {
customizer.tag(this.traceKeys.getHttp().getHost(), host);
customizer.tag(HOST_KEY, host);
}
customizer.tag(this.traceKeys.getHttp().getPath(), path);
customizer.tag(this.traceKeys.getHttp().getMethod(), method);
customizer.tag(PATH_KEY, path);
customizer.tag(METHOD_KEY, method);
}
}
Expand Up @@ -16,14 +16,13 @@

package org.springframework.cloud.sleuth.instrument.web;

import brave.ErrorParser;
import javax.servlet.http.HttpServletResponse;

import brave.ErrorParser;
import brave.SpanCustomizer;
import brave.http.HttpAdapter;
import brave.http.HttpClientParser;
import brave.http.HttpServerParser;
import org.springframework.cloud.sleuth.TraceKeys;

/**
* An {@link HttpClientParser} that behaves like Sleuth in versions 1.x
Expand All @@ -33,14 +32,14 @@
*/
class SleuthHttpServerParser extends HttpServerParser {

private static final String STATUS_CODE_KEY = "http.status_code";

private final SleuthHttpClientParser clientParser;
private final ErrorParser errorParser;
private final TraceKeys traceKeys;

SleuthHttpServerParser(TraceKeys traceKeys, ErrorParser errorParser) {
this.clientParser = new SleuthHttpClientParser(traceKeys);
this.errorParser = errorParser;
this.traceKeys = traceKeys;
}

@Override protected ErrorParser errorParser() {
Expand Down Expand Up @@ -72,13 +71,11 @@ public <Resp> void response(HttpAdapter<?, Resp> adapter, Resp res, Throwable er
if (httpStatus == HttpServletResponse.SC_OK && error != null) {
// Filter chain threw exception but the response status may not have been set
// yet, so we have to guess.
customizer.tag(this.traceKeys.getHttp().getStatusCode(),
String.valueOf(HttpServletResponse.SC_INTERNAL_SERVER_ERROR));
customizer.tag(STATUS_CODE_KEY, String.valueOf(HttpServletResponse.SC_INTERNAL_SERVER_ERROR));
}
// only tag valid http statuses
else if (httpStatus >= 100 && (httpStatus < 200) || (httpStatus > 399)) {
customizer.tag(this.traceKeys.getHttp().getStatusCode(),
String.valueOf(httpStatus));
customizer.tag(STATUS_CODE_KEY, String.valueOf(httpStatus));
}
error(httpStatus, error, customizer);
}
Expand Down
Expand Up @@ -29,7 +29,6 @@
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.cloud.sleuth.TraceKeys;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

Expand All @@ -44,7 +43,7 @@
@ConditionalOnBean(Tracing.class)
@ConditionalOnProperty(name = "spring.sleuth.http.enabled", havingValue = "true", matchIfMissing = true)
@AutoConfigureAfter(TraceWebAutoConfiguration.class)
@EnableConfigurationProperties(SleuthHttpLegacyProperties.class)
@EnableConfigurationProperties({TraceKeys.class, SleuthHttpLegacyProperties.class})
public class TraceHttpAutoConfiguration {

@Autowired HttpClientParser clientParser;
Expand Down

0 comments on commit ba36c7f

Please sign in to comment.