Making TraceKeys a deprecated, package scope detail of legacy sleuth parsers; fixes gh-940 (#942)
This commit is contained in:
committed by
GitHub
parent
509929152c
commit
f4081815af
@@ -1,493 +0,0 @@
|
||||
/*
|
||||
* Copyright 2013-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.sleuth;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.LinkedHashSet;
|
||||
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
|
||||
/**
|
||||
* Well-known {@link brave.Span#tag(String, String) span tag}
|
||||
* keys.
|
||||
*
|
||||
* <h3>Overhead of adding Trace Data</h3>
|
||||
*
|
||||
* Overhead is directly related to the size of trace data exported out of process.
|
||||
* Accordingly, it is better to tag what's important for latency troubleshooting, i.e. a
|
||||
* whitelist vs. collecting everything and filtering downstream. The keys listed here are
|
||||
* very common in tracing tools, and are considerate to the issue of overhead.
|
||||
*
|
||||
* <p>
|
||||
* When evaluating new keys, consider how much additional data it implies, and if that
|
||||
* data is critical to classifying, filtering or displaying traces. More data often means
|
||||
* larger systems, less retention, or a lower sample rate.
|
||||
*
|
||||
* <p>
|
||||
* For example, in zipkin, a thrift-encoded span with an "sr" annotation is 82 bytes plus
|
||||
* the size of its name and associated service. The maximum size of an HTTP cookie is 4096
|
||||
* bytes, roughly 50x that. Even if compression helps, if you aren't analyzing based on
|
||||
* cookies, storing them displaces resources that could be used for more traces.
|
||||
* Meanwhile, you have another system storing private data! The takeaway isn't never store
|
||||
* cookies, as there are valid cases for this. The takeaway is to be conscious about
|
||||
* what's you are storing.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @deprecated the Brave's defaults are suggested to be used
|
||||
*/
|
||||
@ConfigurationProperties("spring.sleuth.keys")
|
||||
@Deprecated
|
||||
public class TraceKeys {
|
||||
|
||||
private Http http = new Http();
|
||||
|
||||
private Message message = new Message();
|
||||
|
||||
private Hystrix hystrix = new Hystrix();
|
||||
|
||||
private Async async = new Async();
|
||||
|
||||
private Mvc mvc = new Mvc();
|
||||
|
||||
public Http getHttp() {
|
||||
return this.http;
|
||||
}
|
||||
|
||||
public Message getMessage() {
|
||||
return this.message;
|
||||
}
|
||||
|
||||
public Hystrix getHystrix() {
|
||||
return this.hystrix;
|
||||
}
|
||||
|
||||
public Async getAsync() {
|
||||
return this.async;
|
||||
}
|
||||
|
||||
public Mvc getMvc() {
|
||||
return this.mvc;
|
||||
}
|
||||
|
||||
public void setHttp(Http http) {
|
||||
this.http = http;
|
||||
}
|
||||
|
||||
public void setMessage(Message message) {
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
public void setHystrix(Hystrix hystrix) {
|
||||
this.hystrix = hystrix;
|
||||
}
|
||||
|
||||
public void setAsync(Async async) {
|
||||
this.async = async;
|
||||
}
|
||||
|
||||
public void setMvc(Mvc mvc) {
|
||||
this.mvc = mvc;
|
||||
}
|
||||
|
||||
public static class Message {
|
||||
|
||||
private Payload payload = new Payload();
|
||||
|
||||
public Payload getPayload() {
|
||||
return this.payload;
|
||||
}
|
||||
|
||||
public String getPrefix() {
|
||||
return this.prefix;
|
||||
}
|
||||
|
||||
public Collection<String> getHeaders() {
|
||||
return this.headers;
|
||||
}
|
||||
|
||||
public void setPayload(Payload payload) {
|
||||
this.payload = payload;
|
||||
}
|
||||
|
||||
public void setPrefix(String prefix) {
|
||||
this.prefix = prefix;
|
||||
}
|
||||
|
||||
public void setHeaders(Collection<String> headers) {
|
||||
this.headers = headers;
|
||||
}
|
||||
|
||||
public static class Payload {
|
||||
/**
|
||||
* An estimate of the size of the payload if available.
|
||||
*/
|
||||
private String size = "message/payload-size";
|
||||
/**
|
||||
* The type of the payload.
|
||||
*/
|
||||
private String type = "message/payload-type";
|
||||
|
||||
public String getSize() {
|
||||
return this.size;
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return this.type;
|
||||
}
|
||||
|
||||
public void setSize(String size) {
|
||||
this.size = size;
|
||||
}
|
||||
|
||||
public void setType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Prefix for header names if they are added as tags.
|
||||
*/
|
||||
private String prefix = "message/";
|
||||
|
||||
/**
|
||||
* Additional headers that should be added as tags if they exist. If the header
|
||||
* value is not a String it will be converted to a String using its toString()
|
||||
* method.
|
||||
*/
|
||||
private Collection<String> headers = new LinkedHashSet<String>();
|
||||
|
||||
}
|
||||
|
||||
public static class Http {
|
||||
|
||||
/**
|
||||
* The domain portion of the URL or host header. Example:
|
||||
* "mybucket.s3.amazonaws.com". Used to filter by host as opposed to ip address.
|
||||
*/
|
||||
private String host = "http.host";
|
||||
|
||||
/**
|
||||
* The HTTP method, or verb, such as "GET" or "POST". Used to filter against an
|
||||
* http route.
|
||||
*/
|
||||
private String method = "http.method";
|
||||
|
||||
/**
|
||||
* The absolute http path, without any query parameters. Example:
|
||||
* "/objects/abcd-ff". Used to filter against an http route, portably with zipkin
|
||||
* v1. In zipkin v1, only equals filters are supported. Dropping query parameters
|
||||
* makes the number of distinct URIs less. For example, one can query for the same
|
||||
* resource, regardless of signing parameters encoded in the query line. This does
|
||||
* not reduce cardinality to a HTTP single route. For example, it is common to
|
||||
* express a route as an http URI template like "/resource/{resource_id}". In
|
||||
* systems where only equals queries are available, searching for
|
||||
* {@code http.uri=/resource} won't match if the actual request was
|
||||
* "/resource/abcd-ff". Historical note: This was commonly expressed as "http.uri"
|
||||
* in zipkin, eventhough it was most often just a path.
|
||||
*/
|
||||
private String path = "http.path";
|
||||
|
||||
/**
|
||||
* The entire URL, including the scheme, host and query parameters if available.
|
||||
* Ex.
|
||||
* "https://mybucket.s3.amazonaws.com/objects/abcd-ff?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Algorithm=AWS4-HMAC-SHA256..."
|
||||
* Combined with {@link #method}, you can understand the fully-qualified
|
||||
* request line. This is optional as it may include private data or be of
|
||||
* considerable length.
|
||||
*/
|
||||
private String url = "http.url";
|
||||
|
||||
/**
|
||||
* The HTTP response code, when not in 2xx range. Ex. "503" Used to filter for
|
||||
* error status. 2xx range are not logged as success codes are less interesting
|
||||
* for latency troubleshooting. Omitting saves at least 20 bytes per span.
|
||||
*/
|
||||
private String statusCode = "http.status_code";
|
||||
|
||||
/**
|
||||
* The size of the non-empty HTTP request body, in bytes. Ex. "16384"
|
||||
*
|
||||
* <p>Large uploads can exceed limits or contribute directly to latency.
|
||||
*/
|
||||
private String requestSize = "http.request.size";
|
||||
|
||||
/**
|
||||
* The size of the non-empty HTTP response body, in bytes. Ex. "16384"
|
||||
*
|
||||
* <p>Large downloads can exceed limits or contribute directly to latency.
|
||||
*/
|
||||
private String responseSize = "http.response.size";
|
||||
|
||||
/**
|
||||
* Prefix for header names if they are added as tags.
|
||||
*/
|
||||
private String prefix = "http.";
|
||||
|
||||
/**
|
||||
* Additional headers that should be added as tags if they exist. If the header
|
||||
* value is multi-valued, the tag value will be a comma-separated, single-quoted
|
||||
* list.
|
||||
*/
|
||||
private Collection<String> headers = new LinkedHashSet<String>();
|
||||
|
||||
public String getHost() {
|
||||
return this.host;
|
||||
}
|
||||
|
||||
public String getMethod() {
|
||||
return this.method;
|
||||
}
|
||||
|
||||
public String getPath() {
|
||||
return this.path;
|
||||
}
|
||||
|
||||
public String getUrl() {
|
||||
return this.url;
|
||||
}
|
||||
|
||||
public String getStatusCode() {
|
||||
return this.statusCode;
|
||||
}
|
||||
|
||||
public String getRequestSize() {
|
||||
return this.requestSize;
|
||||
}
|
||||
|
||||
public String getResponseSize() {
|
||||
return this.responseSize;
|
||||
}
|
||||
|
||||
public String getPrefix() {
|
||||
return this.prefix;
|
||||
}
|
||||
|
||||
public Collection<String> getHeaders() {
|
||||
return this.headers;
|
||||
}
|
||||
|
||||
public void setHost(String host) {
|
||||
this.host = host;
|
||||
}
|
||||
|
||||
public void setMethod(String method) {
|
||||
this.method = method;
|
||||
}
|
||||
|
||||
public void setPath(String path) {
|
||||
this.path = path;
|
||||
}
|
||||
|
||||
public void setUrl(String url) {
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
public void setStatusCode(String statusCode) {
|
||||
this.statusCode = statusCode;
|
||||
}
|
||||
|
||||
public void setRequestSize(String requestSize) {
|
||||
this.requestSize = requestSize;
|
||||
}
|
||||
|
||||
public void setResponseSize(String responseSize) {
|
||||
this.responseSize = responseSize;
|
||||
}
|
||||
|
||||
public void setPrefix(String prefix) {
|
||||
this.prefix = prefix;
|
||||
}
|
||||
|
||||
public void setHeaders(Collection<String> headers) {
|
||||
this.headers = headers;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Trace keys related to Hystrix processing
|
||||
*/
|
||||
public static class Hystrix {
|
||||
|
||||
/**
|
||||
* Prefix for header names if they are added as tags.
|
||||
*/
|
||||
private String prefix = "";
|
||||
|
||||
/**
|
||||
* Name of the command key. Describes the name for the given command.
|
||||
* A key to represent a {@link com.netflix.hystrix.HystrixCommand} for
|
||||
* monitoring, circuit-breakers, metrics publishing, caching and other such uses.
|
||||
*
|
||||
* @see com.netflix.hystrix.HystrixCommandKey
|
||||
*/
|
||||
private String commandKey = "commandKey";
|
||||
|
||||
/**
|
||||
* Name of the command group. Hystrix uses the command group key to group
|
||||
* together commands such as for reporting, alerting, dashboards,
|
||||
* or team/library ownership.
|
||||
*
|
||||
* @see com.netflix.hystrix.HystrixCommandGroupKey
|
||||
*/
|
||||
private String commandGroup = "commandGroup";
|
||||
|
||||
/**
|
||||
* Name of the thread pool key. The thread-pool key represents a {@link com.netflix.hystrix.HystrixThreadPool}
|
||||
* for monitoring, metrics publishing, caching, and other such uses. A {@link com.netflix.hystrix.HystrixCommand}
|
||||
* is associated with a single {@link com.netflix.hystrix.HystrixThreadPool} as
|
||||
* retrieved by the {@link com.netflix.hystrix.HystrixThreadPoolKey} injected into it,
|
||||
* or it defaults to one created using the {@link com.netflix.hystrix.HystrixCommandGroupKey}
|
||||
* it is created with.
|
||||
*
|
||||
* @see com.netflix.hystrix.HystrixThreadPoolKey
|
||||
*/
|
||||
private String threadPoolKey = "threadPoolKey";
|
||||
|
||||
public String getPrefix() {
|
||||
return this.prefix;
|
||||
}
|
||||
|
||||
public String getCommandKey() {
|
||||
return this.commandKey;
|
||||
}
|
||||
|
||||
public String getCommandGroup() {
|
||||
return this.commandGroup;
|
||||
}
|
||||
|
||||
public String getThreadPoolKey() {
|
||||
return this.threadPoolKey;
|
||||
}
|
||||
|
||||
public void setPrefix(String prefix) {
|
||||
this.prefix = prefix;
|
||||
}
|
||||
|
||||
public void setCommandKey(String commandKey) {
|
||||
this.commandKey = commandKey;
|
||||
}
|
||||
|
||||
public void setCommandGroup(String commandGroup) {
|
||||
this.commandGroup = commandGroup;
|
||||
}
|
||||
|
||||
public void setThreadPoolKey(String threadPoolKey) {
|
||||
this.threadPoolKey = threadPoolKey;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Trace keys related to async processing
|
||||
*/
|
||||
public static class Async {
|
||||
|
||||
/**
|
||||
* Prefix for header names if they are added as tags.
|
||||
*/
|
||||
private String prefix = "";
|
||||
|
||||
/**
|
||||
* Name of the thread that executed the async method
|
||||
*
|
||||
* @see org.springframework.scheduling.annotation.Async
|
||||
*/
|
||||
private String threadNameKey = "thread";
|
||||
|
||||
/**
|
||||
* Simple name of the class with a method annotated with {@code @Async}
|
||||
* from which the asynchronous process started
|
||||
*
|
||||
* @see org.springframework.scheduling.annotation.Async
|
||||
*/
|
||||
private String classNameKey = "class";
|
||||
|
||||
/**
|
||||
* Name of the method annotated with {@code @Async}
|
||||
*
|
||||
* @see org.springframework.scheduling.annotation.Async
|
||||
*/
|
||||
private String methodNameKey = "method";
|
||||
|
||||
public String getPrefix() {
|
||||
return this.prefix;
|
||||
}
|
||||
|
||||
public String getThreadNameKey() {
|
||||
return this.threadNameKey;
|
||||
}
|
||||
|
||||
public String getClassNameKey() {
|
||||
return this.classNameKey;
|
||||
}
|
||||
|
||||
public String getMethodNameKey() {
|
||||
return this.methodNameKey;
|
||||
}
|
||||
|
||||
public void setPrefix(String prefix) {
|
||||
this.prefix = prefix;
|
||||
}
|
||||
|
||||
public void setThreadNameKey(String threadNameKey) {
|
||||
this.threadNameKey = threadNameKey;
|
||||
}
|
||||
|
||||
public void setClassNameKey(String classNameKey) {
|
||||
this.classNameKey = classNameKey;
|
||||
}
|
||||
|
||||
public void setMethodNameKey(String methodNameKey) {
|
||||
this.methodNameKey = methodNameKey;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Trace keys related to MVC controller tags
|
||||
*/
|
||||
public static class Mvc {
|
||||
|
||||
/**
|
||||
* The lower case, hyphen delimited name of the class that processes the request.
|
||||
* Ex. class named "BookController" will result in "book-controller" tag value.
|
||||
*/
|
||||
private String controllerClass = "mvc.controller.class";
|
||||
|
||||
/**
|
||||
* The lower case, hyphen delimited name of the class that processes the request.
|
||||
* Ex. method named "listOfBooks" will result in "list-of-books" tag value.
|
||||
*/
|
||||
private String controllerMethod = "mvc.controller.method";
|
||||
|
||||
public String getControllerClass() {
|
||||
return this.controllerClass;
|
||||
}
|
||||
|
||||
public void setControllerClass(String controllerClass) {
|
||||
this.controllerClass = controllerClass;
|
||||
}
|
||||
|
||||
public String getControllerMethod() {
|
||||
return this.controllerMethod;
|
||||
}
|
||||
|
||||
public void setControllerMethod(String controllerMethod) {
|
||||
this.controllerMethod = controllerMethod;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -37,7 +37,6 @@ import org.springframework.boot.context.properties.EnableConfigurationProperties
|
||||
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;
|
||||
@@ -53,7 +52,7 @@ import zipkin2.reporter.Reporter;
|
||||
*/
|
||||
@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";
|
||||
|
||||
@@ -27,7 +27,6 @@ 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.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;
|
||||
@@ -66,8 +65,8 @@ public class AsyncDefaultAutoConfiguration {
|
||||
}
|
||||
|
||||
@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
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -42,14 +40,15 @@ import org.springframework.util.ReflectionUtils;
|
||||
@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 * *.*(..))")
|
||||
@@ -61,10 +60,8 @@ public class TraceAsyncAspect {
|
||||
}
|
||||
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();
|
||||
|
||||
@@ -19,7 +19,6 @@ package org.springframework.cloud.sleuth.instrument.hystrix;
|
||||
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
|
||||
@@ -34,14 +33,16 @@ import org.springframework.cloud.sleuth.TraceKeys;
|
||||
*/
|
||||
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();
|
||||
}
|
||||
|
||||
@@ -49,12 +50,9 @@ public abstract class TraceCommand<R> extends HystrixCommand<R> {
|
||||
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();
|
||||
}
|
||||
|
||||
@@ -20,16 +20,15 @@ import java.util.Arrays;
|
||||
|
||||
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
|
||||
@@ -47,9 +46,9 @@ import org.springframework.context.annotation.Configuration;
|
||||
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()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,7 +22,6 @@ import brave.Span;
|
||||
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;
|
||||
@@ -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();
|
||||
@@ -92,22 +88,22 @@ class SleuthRxJavaSchedulersHook extends RxJavaSchedulersHook {
|
||||
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;
|
||||
@@ -135,9 +131,7 @@ class SleuthRxJavaSchedulersHook extends RxJavaSchedulersHook {
|
||||
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)) {
|
||||
|
||||
@@ -24,7 +24,6 @@ import brave.Tracing;
|
||||
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;
|
||||
|
||||
/**
|
||||
@@ -45,15 +44,15 @@ import org.springframework.cloud.sleuth.util.SpanNameUtil;
|
||||
@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 * *.*(..))")
|
||||
@@ -64,10 +63,8 @@ public class TraceSchedulingAspect {
|
||||
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();
|
||||
|
||||
@@ -25,7 +25,6 @@ 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;
|
||||
@@ -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()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,7 +21,6 @@ import java.net.URI;
|
||||
import brave.SpanCustomizer;
|
||||
import brave.http.HttpAdapter;
|
||||
import brave.http.HttpClientParser;
|
||||
import org.springframework.cloud.sleuth.TraceKeys;
|
||||
import org.springframework.cloud.sleuth.util.SpanNameUtil;
|
||||
|
||||
/**
|
||||
@@ -32,9 +31,14 @@ import org.springframework.cloud.sleuth.util.SpanNameUtil;
|
||||
*/
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -74,11 +78,11 @@ class SleuthHttpClientParser extends HttpClientParser {
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
@@ -33,14 +32,14 @@ import org.springframework.cloud.sleuth.TraceKeys;
|
||||
*/
|
||||
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() {
|
||||
@@ -72,13 +71,11 @@ class SleuthHttpServerParser extends HttpServerParser {
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -29,7 +29,6 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
|
||||
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;
|
||||
|
||||
@@ -44,7 +43,7 @@ import org.springframework.context.annotation.Configuration;
|
||||
@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;
|
||||
|
||||
@@ -0,0 +1,77 @@
|
||||
/*
|
||||
* Copyright 2013-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.sleuth.instrument.web;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.LinkedHashSet;
|
||||
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
|
||||
/**
|
||||
* Well-known {@link brave.Span#tag(String, String) span tag} keys.
|
||||
* With the deprecation we only left the option to pass a list of
|
||||
* HTTP request headers that will be set as tags
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @deprecated the Brave's defaults are suggested to be used
|
||||
*/
|
||||
@ConfigurationProperties("spring.sleuth.keys")
|
||||
@Deprecated
|
||||
class TraceKeys {
|
||||
|
||||
private Http http = new Http();
|
||||
|
||||
public Http getHttp() {
|
||||
return this.http;
|
||||
}
|
||||
|
||||
public void setHttp(Http http) {
|
||||
this.http = http;
|
||||
}
|
||||
|
||||
public static class Http {
|
||||
|
||||
/**
|
||||
* Prefix for header names if they are added as tags.
|
||||
*/
|
||||
private String prefix = "http.";
|
||||
|
||||
/**
|
||||
* Additional headers that should be added as tags if they exist. If the header
|
||||
* value is multi-valued, the tag value will be a comma-separated, single-quoted
|
||||
* list.
|
||||
*/
|
||||
private Collection<String> headers = new LinkedHashSet<String>();
|
||||
|
||||
public String getPrefix() {
|
||||
return this.prefix;
|
||||
}
|
||||
|
||||
public Collection<String> getHeaders() {
|
||||
return this.headers;
|
||||
}
|
||||
|
||||
public void setPrefix(String prefix) {
|
||||
this.prefix = prefix;
|
||||
}
|
||||
|
||||
public void setHeaders(Collection<String> headers) {
|
||||
this.headers = headers;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -26,7 +26,6 @@ import brave.propagation.TraceContextOrSamplingFlags;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.beans.factory.BeanFactory;
|
||||
import org.springframework.cloud.sleuth.TraceKeys;
|
||||
import org.springframework.core.Ordered;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.server.reactive.ServerHttpRequest;
|
||||
@@ -50,6 +49,9 @@ import reactor.util.context.Context;
|
||||
public final class TraceWebFilter implements WebFilter, Ordered {
|
||||
|
||||
private static final Log log = LogFactory.getLog(TraceWebFilter.class);
|
||||
private static final String STATUS_CODE_KEY = "http.status_code";
|
||||
static final String MVC_CONTROLLER_CLASS_KEY = "mvc.controller.class";
|
||||
static final String MVC_CONTROLLER_METHOD_KEY = "mvc.controller.method";
|
||||
|
||||
protected static final String TRACE_REQUEST_ATTR = TraceWebFilter.class.getName()
|
||||
+ ".TRACE";
|
||||
@@ -79,7 +81,6 @@ public final class TraceWebFilter implements WebFilter, Ordered {
|
||||
return new TraceWebFilter(beanFactory);
|
||||
}
|
||||
|
||||
TraceKeys traceKeys;
|
||||
Tracer tracer;
|
||||
HttpServerHandler<ServerHttpRequest, ServerHttpResponse> handler;
|
||||
TraceContext.Extractor<HttpHeaders> extractor;
|
||||
@@ -106,13 +107,6 @@ public final class TraceWebFilter implements WebFilter, Ordered {
|
||||
return this.tracer;
|
||||
}
|
||||
|
||||
TraceKeys traceKeys() {
|
||||
if (this.traceKeys == null) {
|
||||
this.traceKeys = this.beanFactory.getBean(TraceKeys.class);
|
||||
}
|
||||
return this.traceKeys;
|
||||
}
|
||||
|
||||
TraceContext.Extractor<HttpHeaders> extractor() {
|
||||
if (this.extractor == null) {
|
||||
this.extractor = this.beanFactory.getBean(HttpTracing.class)
|
||||
@@ -221,8 +215,7 @@ public final class TraceWebFilter implements WebFilter, Ordered {
|
||||
ServerHttpResponse response, Span span) {
|
||||
if (spanWithoutParent(exchange) && response.getStatusCode() != null
|
||||
&& span != null) {
|
||||
span.tag(traceKeys().getHttp().getStatusCode(),
|
||||
String.valueOf(response.getStatusCode().value()));
|
||||
span.tag(STATUS_CODE_KEY, String.valueOf(response.getStatusCode().value()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -237,7 +230,7 @@ public final class TraceWebFilter implements WebFilter, Ordered {
|
||||
private void addClassMethodTag(Object handler, Span span) {
|
||||
if (handler instanceof HandlerMethod) {
|
||||
String methodName = ((HandlerMethod) handler).getMethod().getName();
|
||||
span.tag(traceKeys().getMvc().getControllerMethod(), methodName);
|
||||
span.tag(MVC_CONTROLLER_METHOD_KEY, methodName);
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Adding a method tag with value [" + methodName + "] to a span " + span);
|
||||
}
|
||||
@@ -254,7 +247,7 @@ public final class TraceWebFilter implements WebFilter, Ordered {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Adding a class tag with value [" + className + "] to a span " + span);
|
||||
}
|
||||
span.tag(traceKeys().getMvc().getControllerClass(), className);
|
||||
span.tag(MVC_CONTROLLER_CLASS_KEY, className);
|
||||
}
|
||||
|
||||
@Override public int getOrder() {
|
||||
|
||||
@@ -2,7 +2,6 @@ package org.springframework.cloud.sleuth.instrument.async;
|
||||
|
||||
import brave.Tracing;
|
||||
import brave.propagation.StrictCurrentTraceContext;
|
||||
|
||||
import org.aspectj.lang.ProceedingJoinPoint;
|
||||
import org.aspectj.lang.reflect.MethodSignature;
|
||||
import org.assertj.core.api.BDDAssertions;
|
||||
@@ -11,7 +10,6 @@ import org.junit.Test;
|
||||
import org.mockito.BDDMockito;
|
||||
import org.mockito.Mockito;
|
||||
import org.springframework.cloud.sleuth.DefaultSpanNamer;
|
||||
import org.springframework.cloud.sleuth.TraceKeys;
|
||||
import org.springframework.cloud.sleuth.util.ArrayListSpanReporter;
|
||||
|
||||
/**
|
||||
@@ -38,7 +36,7 @@ public class TraceAsyncAspectTest {
|
||||
//Issue#926
|
||||
@Test public void should_work() throws Throwable {
|
||||
TraceAsyncAspect asyncAspect = new TraceAsyncAspect(this.tracing.tracer(),
|
||||
new DefaultSpanNamer(), new TraceKeys()) {
|
||||
new DefaultSpanNamer()) {
|
||||
@Override String name(ProceedingJoinPoint pjp) {
|
||||
return "foo-bar";
|
||||
}
|
||||
|
||||
@@ -22,16 +22,14 @@ import brave.Span;
|
||||
import brave.Tracer;
|
||||
import brave.Tracing;
|
||||
import brave.propagation.StrictCurrentTraceContext;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.cloud.sleuth.TraceKeys;
|
||||
import org.springframework.cloud.sleuth.util.ArrayListSpanReporter;
|
||||
|
||||
import com.netflix.hystrix.HystrixCommand;
|
||||
import com.netflix.hystrix.HystrixCommandKey;
|
||||
import com.netflix.hystrix.HystrixCommandProperties;
|
||||
import com.netflix.hystrix.HystrixThreadPoolProperties;
|
||||
import com.netflix.hystrix.strategy.HystrixPlugins;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.cloud.sleuth.util.ArrayListSpanReporter;
|
||||
|
||||
import static com.netflix.hystrix.HystrixCommand.Setter.withGroupKey;
|
||||
import static com.netflix.hystrix.HystrixCommandGroupKey.Factory.asKey;
|
||||
@@ -97,7 +95,6 @@ public class TraceCommandTests {
|
||||
@Test
|
||||
public void should_pass_tracing_information_when_using_Hystrix_commands() {
|
||||
Tracer tracer = this.tracer;
|
||||
TraceKeys traceKeys = new TraceKeys();
|
||||
HystrixCommand.Setter setter = withGroupKey(asKey("group"))
|
||||
.andCommandKey(HystrixCommandKey.Factory.asKey("command"));
|
||||
// tag::hystrix_command[]
|
||||
@@ -109,7 +106,7 @@ public class TraceCommandTests {
|
||||
};
|
||||
// end::hystrix_command[]
|
||||
// tag::trace_hystrix_command[]
|
||||
TraceCommand<String> traceCommand = new TraceCommand<String>(tracer, traceKeys, setter) {
|
||||
TraceCommand<String> traceCommand = new TraceCommand<String>(tracer, setter) {
|
||||
@Override
|
||||
public String doRun() throws Exception {
|
||||
return someLogic();
|
||||
@@ -128,7 +125,7 @@ public class TraceCommandTests {
|
||||
}
|
||||
|
||||
private TraceCommand<Span> traceReturningCommand() {
|
||||
return new TraceCommand<Span>(this.tracer, new TraceKeys(),
|
||||
return new TraceCommand<Span>(this.tracer,
|
||||
withGroupKey(asKey("group"))
|
||||
.andThreadPoolPropertiesDefaults(HystrixThreadPoolProperties
|
||||
.Setter().withCoreSize(1).withMaxQueueSize(1))
|
||||
|
||||
@@ -37,7 +37,6 @@ import rx.plugins.RxJavaSchedulersHook;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.cloud.sleuth.TraceKeys;
|
||||
import org.springframework.cloud.sleuth.util.ArrayListSpanReporter;
|
||||
|
||||
import static org.assertj.core.api.BDDAssertions.then;
|
||||
@@ -49,7 +48,6 @@ import static org.assertj.core.api.BDDAssertions.then;
|
||||
public class SleuthRxJavaSchedulersHookTests {
|
||||
|
||||
List<String> threadsToIgnore = new ArrayList<>();
|
||||
TraceKeys traceKeys = new TraceKeys();
|
||||
ArrayListSpanReporter reporter = new ArrayListSpanReporter();
|
||||
Tracing tracing = Tracing.newBuilder()
|
||||
.currentTraceContext(new StrictCurrentTraceContext())
|
||||
@@ -76,7 +74,7 @@ public class SleuthRxJavaSchedulersHookTests {
|
||||
RxJavaPlugins.getInstance().registerErrorHandler(new MyRxJavaErrorHandler());
|
||||
RxJavaPlugins.getInstance().registerObservableExecutionHook(new MyRxJavaObservableExecutionHook());
|
||||
|
||||
new SleuthRxJavaSchedulersHook(this.tracer, this.traceKeys, threadsToIgnore);
|
||||
new SleuthRxJavaSchedulersHook(this.tracer, threadsToIgnore);
|
||||
|
||||
then(RxJavaPlugins.getInstance().getErrorHandler()).isExactlyInstanceOf(MyRxJavaErrorHandler.class);
|
||||
then(RxJavaPlugins.getInstance().getObservableExecutionHook()).isExactlyInstanceOf(MyRxJavaObservableExecutionHook.class);
|
||||
@@ -86,7 +84,7 @@ public class SleuthRxJavaSchedulersHookTests {
|
||||
public void should_wrap_delegates_action_in_wrapped_action_when_delegate_is_present_on_schedule() {
|
||||
RxJavaPlugins.getInstance().registerSchedulersHook(new MyRxJavaSchedulersHook());
|
||||
SleuthRxJavaSchedulersHook schedulersHook = new SleuthRxJavaSchedulersHook(
|
||||
this.tracer, this.traceKeys, threadsToIgnore);
|
||||
this.tracer, this.threadsToIgnore);
|
||||
Action0 action = schedulersHook.onSchedule(() -> {
|
||||
caller = new StringBuilder("hello");
|
||||
});
|
||||
@@ -105,7 +103,7 @@ public class SleuthRxJavaSchedulersHookTests {
|
||||
String threadNameToIgnore = "^MyCustomThread.*$";
|
||||
RxJavaPlugins.getInstance().registerSchedulersHook(new MyRxJavaSchedulersHook());
|
||||
SleuthRxJavaSchedulersHook schedulersHook = new SleuthRxJavaSchedulersHook(
|
||||
this.tracer, this.traceKeys, Collections.singletonList(threadNameToIgnore));
|
||||
this.tracer, Collections.singletonList(threadNameToIgnore));
|
||||
Future<Void> hello = executorService().submit((Callable<Void>) () -> {
|
||||
Action0 action = schedulersHook.onSchedule(() -> {
|
||||
caller = new StringBuilder("hello");
|
||||
|
||||
@@ -19,7 +19,6 @@ package org.springframework.cloud.sleuth.instrument.web;
|
||||
import brave.Tracing;
|
||||
import org.junit.Before;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cloud.sleuth.TraceKeys;
|
||||
import org.springframework.cloud.sleuth.autoconfig.SleuthProperties;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.test.context.web.WebAppConfiguration;
|
||||
@@ -45,7 +44,6 @@ public abstract class AbstractMvcIntegrationTest {
|
||||
protected MockMvc mockMvc;
|
||||
@Autowired protected SleuthProperties properties;
|
||||
@Autowired protected Tracing tracing;
|
||||
@Autowired protected TraceKeys traceKeys;
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
|
||||
@@ -24,7 +24,6 @@ import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.cloud.sleuth.TraceKeys;
|
||||
|
||||
import brave.SpanCustomizer;
|
||||
import brave.http.HttpClientAdapter;
|
||||
|
||||
@@ -19,18 +19,17 @@ package org.springframework.cloud.sleuth.instrument.web;
|
||||
import brave.ErrorParser;
|
||||
import brave.http.HttpClientParser;
|
||||
import brave.http.HttpServerParser;
|
||||
import org.springframework.cloud.sleuth.TraceKeys;
|
||||
|
||||
/**
|
||||
* @author Marcin Grzejszczak
|
||||
* @since
|
||||
*/
|
||||
public class SleuthHttpParserAccessor {
|
||||
public static HttpClientParser getClient(TraceKeys traceKeys) {
|
||||
return new SleuthHttpClientParser(traceKeys);
|
||||
public static HttpClientParser getClient() {
|
||||
return new SleuthHttpClientParser(new TraceKeys());
|
||||
}
|
||||
|
||||
public static HttpServerParser getServer(TraceKeys traceKeys, ErrorParser errorParser) {
|
||||
return new SleuthHttpServerParser(traceKeys, errorParser);
|
||||
public static HttpServerParser getServer(ErrorParser errorParser) {
|
||||
return new SleuthHttpServerParser(new TraceKeys(), errorParser);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,11 +38,9 @@ import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.slf4j.MDC;
|
||||
import org.springframework.beans.factory.BeanFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.actuate.autoconfigure.web.server.ManagementServerProperties;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.cloud.sleuth.TraceKeys;
|
||||
import org.springframework.cloud.sleuth.instrument.DefaultTestAutoConfiguration;
|
||||
import org.springframework.cloud.sleuth.util.ArrayListSpanReporter;
|
||||
import org.springframework.cloud.sleuth.util.SpanUtil;
|
||||
@@ -99,8 +97,8 @@ public class TraceFilterIntegrationTests extends AbstractMvcIntegrationTest {
|
||||
then(this.reporter.getSpans()).hasSize(1);
|
||||
zipkin2.Span span = this.reporter.getSpans().get(0);
|
||||
then(span.tags())
|
||||
.containsKey(new TraceKeys().getMvc().getControllerClass())
|
||||
.containsKey(new TraceKeys().getMvc().getControllerMethod());
|
||||
.containsKey(TraceWebFilter.MVC_CONTROLLER_CLASS_KEY)
|
||||
.containsKey(TraceWebFilter.MVC_CONTROLLER_METHOD_KEY);
|
||||
then(this.tracer.currentSpan()).isNull();
|
||||
}
|
||||
|
||||
|
||||
@@ -31,7 +31,6 @@ import brave.servlet.TracingFilter;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.cloud.sleuth.TraceKeys;
|
||||
import org.springframework.cloud.sleuth.util.ArrayListSpanReporter;
|
||||
import org.springframework.cloud.sleuth.util.SpanUtil;
|
||||
import org.springframework.http.HttpMethod;
|
||||
|
||||
@@ -33,7 +33,6 @@ import org.junit.After;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.cloud.sleuth.TraceKeys;
|
||||
import org.springframework.cloud.sleuth.util.ArrayListSpanReporter;
|
||||
import org.springframework.cloud.sleuth.util.SpanUtil;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
|
||||
@@ -31,7 +31,6 @@ import feign.Request;
|
||||
import feign.RequestLine;
|
||||
import feign.Response;
|
||||
import okhttp3.mockwebserver.MockWebServer;
|
||||
import zipkin2.Span;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
@@ -43,6 +42,7 @@ import org.mockito.junit.MockitoJUnitRunner;
|
||||
import org.springframework.beans.factory.BeanFactory;
|
||||
import org.springframework.cloud.sleuth.instrument.web.SleuthHttpParserAccessor;
|
||||
import org.springframework.cloud.sleuth.util.ArrayListSpanReporter;
|
||||
import zipkin2.Span;
|
||||
|
||||
import static org.assertj.core.api.Assertions.failBecauseExceptionWasNotThrown;
|
||||
import static org.assertj.core.api.BDDAssertions.then;
|
||||
@@ -63,9 +63,8 @@ public class FeignRetriesTests {
|
||||
.currentTraceContext(new StrictCurrentTraceContext())
|
||||
.spanReporter(this.reporter)
|
||||
.build();
|
||||
org.springframework.cloud.sleuth.TraceKeys traceKeys = new org.springframework.cloud.sleuth.TraceKeys();
|
||||
HttpTracing httpTracing = HttpTracing.newBuilder(this.tracing)
|
||||
.clientParser(SleuthHttpParserAccessor.getClient(this.traceKeys))
|
||||
.clientParser(SleuthHttpParserAccessor.getClient())
|
||||
.build();
|
||||
|
||||
@Before
|
||||
|
||||
@@ -29,7 +29,6 @@ import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
import org.springframework.beans.factory.BeanFactory;
|
||||
import org.springframework.cloud.sleuth.TraceKeys;
|
||||
import org.springframework.cloud.sleuth.instrument.web.SleuthHttpParserAccessor;
|
||||
|
||||
import static org.mockito.BDDMockito.given;
|
||||
@@ -49,9 +48,8 @@ public class TraceFeignAspectTests {
|
||||
Tracing tracing = Tracing.newBuilder()
|
||||
.currentTraceContext(new StrictCurrentTraceContext())
|
||||
.build();
|
||||
TraceKeys traceKeys = new TraceKeys();
|
||||
HttpTracing httpTracing = HttpTracing.newBuilder(this.tracing)
|
||||
.clientParser(SleuthHttpParserAccessor.getClient(this.traceKeys))
|
||||
.clientParser(SleuthHttpParserAccessor.getClient())
|
||||
.build();
|
||||
TraceFeignAspect traceFeignAspect;
|
||||
|
||||
|
||||
@@ -35,7 +35,6 @@ import org.mockito.BDDMockito;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
import org.springframework.beans.factory.BeanFactory;
|
||||
import org.springframework.cloud.sleuth.TraceKeys;
|
||||
import org.springframework.cloud.sleuth.instrument.web.SleuthHttpParserAccessor;
|
||||
import org.springframework.cloud.sleuth.util.ArrayListSpanReporter;
|
||||
|
||||
@@ -54,9 +53,8 @@ public class TracingFeignClientTests {
|
||||
.spanReporter(this.reporter)
|
||||
.build();
|
||||
Tracer tracer = this.tracing.tracer();
|
||||
TraceKeys traceKeys = new TraceKeys();
|
||||
HttpTracing httpTracing = HttpTracing.newBuilder(this.tracing)
|
||||
.clientParser(SleuthHttpParserAccessor.getClient(this.traceKeys))
|
||||
.clientParser(SleuthHttpParserAccessor.getClient())
|
||||
.build();
|
||||
@Mock Client client;
|
||||
Client traceFeignClient;
|
||||
|
||||
@@ -33,7 +33,6 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.boot.autoconfigure.jmx.JmxAutoConfiguration;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.boot.web.servlet.context.ServletWebServerInitializedEvent;
|
||||
import org.springframework.cloud.sleuth.TraceKeys;
|
||||
import org.springframework.cloud.sleuth.util.ArrayListSpanReporter;
|
||||
import org.springframework.context.ApplicationListener;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
@@ -63,7 +62,6 @@ import static org.awaitility.Awaitility.await;
|
||||
public class MultipleHopsIntegrationTests {
|
||||
|
||||
@Autowired Tracer tracer;
|
||||
@Autowired TraceKeys traceKeys;
|
||||
@Autowired ArrayListSpanReporter reporter;
|
||||
@Autowired RestTemplate restTemplate;
|
||||
@Autowired Config config;
|
||||
|
||||
@@ -36,7 +36,6 @@ import org.mockito.BDDMockito;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
import org.springframework.cloud.netflix.zuul.metrics.EmptyTracerFactory;
|
||||
import org.springframework.cloud.sleuth.TraceKeys;
|
||||
import org.springframework.cloud.sleuth.instrument.web.SleuthHttpParserAccessor;
|
||||
import org.springframework.cloud.sleuth.util.ArrayListSpanReporter;
|
||||
|
||||
@@ -57,10 +56,9 @@ public class TracePostZuulFilterTests {
|
||||
.currentTraceContext(new StrictCurrentTraceContext())
|
||||
.spanReporter(this.reporter)
|
||||
.build();
|
||||
TraceKeys traceKeys = new TraceKeys();
|
||||
HttpTracing httpTracing = HttpTracing.newBuilder(this.tracing)
|
||||
.clientParser(SleuthHttpParserAccessor.getClient(this.traceKeys))
|
||||
.serverParser(SleuthHttpParserAccessor.getServer(this.traceKeys, new ErrorParser()))
|
||||
.clientParser(SleuthHttpParserAccessor.getClient())
|
||||
.serverParser(SleuthHttpParserAccessor.getServer(new ErrorParser()))
|
||||
.build();
|
||||
private TracePostZuulFilter filter = new TracePostZuulFilter(this.httpTracing);
|
||||
RequestContext requestContext = new RequestContext();
|
||||
|
||||
@@ -16,9 +16,7 @@
|
||||
|
||||
package org.springframework.cloud.sleuth.instrument.zuul;
|
||||
|
||||
import brave.ErrorParser;
|
||||
import brave.Tracing;
|
||||
import brave.http.HttpTracing;
|
||||
import brave.propagation.StrictCurrentTraceContext;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@@ -26,8 +24,6 @@ import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
import org.springframework.cloud.netflix.zuul.filters.route.RibbonCommandFactory;
|
||||
import org.springframework.cloud.sleuth.TraceKeys;
|
||||
import org.springframework.cloud.sleuth.instrument.web.SleuthHttpParserAccessor;
|
||||
import org.springframework.cloud.sleuth.util.ArrayListSpanReporter;
|
||||
|
||||
import static org.assertj.core.api.BDDAssertions.then;
|
||||
@@ -43,11 +39,6 @@ public class TraceRibbonCommandFactoryBeanPostProcessorTests {
|
||||
.currentTraceContext(new StrictCurrentTraceContext())
|
||||
.spanReporter(this.reporter)
|
||||
.build();
|
||||
TraceKeys traceKeys = new TraceKeys();
|
||||
HttpTracing httpTracing = HttpTracing.newBuilder(this.tracing)
|
||||
.clientParser(SleuthHttpParserAccessor.getClient(this.traceKeys))
|
||||
.serverParser(SleuthHttpParserAccessor.getServer(this.traceKeys, new ErrorParser()))
|
||||
.build();
|
||||
|
||||
@Mock RibbonCommandFactory ribbonCommandFactory;
|
||||
@InjectMocks TraceRibbonCommandFactoryBeanPostProcessor postProcessor;
|
||||
|
||||
@@ -36,7 +36,6 @@ import org.springframework.beans.factory.BeanFactory;
|
||||
import org.springframework.cloud.netflix.ribbon.support.RibbonCommandContext;
|
||||
import org.springframework.cloud.netflix.zuul.filters.route.RibbonCommand;
|
||||
import org.springframework.cloud.netflix.zuul.filters.route.RibbonCommandFactory;
|
||||
import org.springframework.cloud.sleuth.TraceKeys;
|
||||
import org.springframework.cloud.sleuth.instrument.web.SleuthHttpParserAccessor;
|
||||
import org.springframework.cloud.sleuth.util.ArrayListSpanReporter;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
@@ -55,10 +54,9 @@ public class TraceRibbonCommandFactoryTest {
|
||||
.currentTraceContext(new StrictCurrentTraceContext())
|
||||
.spanReporter(this.reporter)
|
||||
.build();
|
||||
TraceKeys traceKeys = new TraceKeys();
|
||||
HttpTracing httpTracing = HttpTracing.newBuilder(this.tracing)
|
||||
.clientParser(SleuthHttpParserAccessor.getClient(this.traceKeys))
|
||||
.serverParser(SleuthHttpParserAccessor.getServer(this.traceKeys, new ErrorParser()))
|
||||
.clientParser(SleuthHttpParserAccessor.getClient())
|
||||
.serverParser(SleuthHttpParserAccessor.getServer(new ErrorParser()))
|
||||
.build();
|
||||
@Mock BeanFactory beanFactory;
|
||||
@Mock RibbonCommandFactory ribbonCommandFactory;
|
||||
|
||||
Reference in New Issue
Block a user