Delomboking

This commit is contained in:
Marcin Grzejszczak
2016-02-10 19:09:20 +01:00
parent 8f5f553376
commit ee8d7a54c7
68 changed files with 687 additions and 391 deletions

View File

@@ -92,12 +92,6 @@
<artifactId>aspectjrt</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<!-- Only needed at compile time -->
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2013-2015 the original author or authors.
* Copyright 2013-2016 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.
@@ -16,14 +16,9 @@
package org.springframework.cloud.sleuth;
import lombok.Data;
import lombok.RequiredArgsConstructor;
/**
* @author Spencer Gibb
*/
@Data
@RequiredArgsConstructor
public class Log {
/**
* The epoch timestamp of the log record; often set via {@link System#currentTimeMillis()}.
@@ -46,4 +41,17 @@ public class Log {
this.timestamp = 0;
this.event = null;
}
public Log(long timestamp, String event) {
this.timestamp = timestamp;
this.event = event;
}
public long getTimestamp() {
return this.timestamp;
}
public String getEvent() {
return this.event;
}
}

View File

@@ -27,8 +27,6 @@ import java.util.Map;
import org.springframework.util.Assert;
import lombok.Getter;
/**
* Class for gathering and reporting statistics about a block of execution.
* <p/>
@@ -44,7 +42,6 @@ import lombok.Getter;
* like scoped tracers. Sleuth spans are DTOs, whose sole responsibility is the current
* span in the trace tree.
*/
@Getter
public class Span {
public static final String NOT_SAMPLED_NAME = "X-Not-Sampled";
@@ -413,14 +410,22 @@ public class Span {
return span;
}
@Override
public String toString() {
return "org.springframework.cloud.sleuth.Span.SpanBuilder(begin=" + this.begin
+ ", end=" + this.end + ", name=" + this.name + ", traceId="
+ this.traceId + ", parents=" + this.parents + ", spanId="
+ this.spanId + ", remote=" + this.remote + ", exportable="
+ this.exportable + ", processId=" + this.processId + ", logs="
+ this.logs + ", tags=" + this.tags + ", savedSpan=" + this.savedSpan
+ ")";
return "SpanBuilder{" +
"begin=" + this.begin +
", end=" + this.end +
", name=" + this.name +
", traceId=" + this.traceId +
", parents=" + this.parents +
", spanId=" + this.spanId +
", remote=" + this.remote +
", exportable=" + this.exportable +
", processId='" + this.processId + '\'' +
", savedSpan=" + this.savedSpan +
", logs=" + this.logs +
", tags=" + this.tags +
'}';
}
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2013-2015 the original author or authors.
* Copyright 2013-2016 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.
@@ -16,16 +16,14 @@
package org.springframework.cloud.sleuth.event;
import lombok.Value;
import java.util.ArrayList;
import org.springframework.cloud.sleuth.Span;
import org.springframework.context.ApplicationListener;
import java.util.ArrayList;
/**
* @author Spencer Gibb
*/
@Value
public class ArrayListSpanAccumulator implements ApplicationListener<SpanReleasedEvent> {
private final ArrayList<Span> spans = new ArrayList<>();
@@ -33,4 +31,32 @@ public class ArrayListSpanAccumulator implements ApplicationListener<SpanRelease
public void onApplicationEvent(SpanReleasedEvent event) {
this.spans.add(event.getSpan());
}
public ArrayList<Span> getSpans() {
return this.spans;
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
ArrayListSpanAccumulator that = (ArrayListSpanAccumulator) o;
return this.spans.equals(that.spans);
}
@Override
public int hashCode() {
return this.spans.hashCode();
}
@Override
public String toString() {
return "ArrayListSpanAccumulator{" +
"spans=" + this.spans +
'}';
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2013-2015 the original author or authors.
* Copyright 2013-2016 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.
@@ -16,25 +16,17 @@
package org.springframework.cloud.sleuth.event;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.springframework.cloud.sleuth.Span;
import org.springframework.context.ApplicationEvent;
/**
* @author Dave Syer
*
*/
@Data
@EqualsAndHashCode(callSuper = false)
@SuppressWarnings("serial")
public class ClientReceivedEvent extends ApplicationEvent {
private final Span span;
public class ClientReceivedEvent extends SpanContainingEvent {
public ClientReceivedEvent(Object source, Span span) {
super(source);
this.span = span;
super(source, span);
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2013-2015 the original author or authors.
* Copyright 2013-2016 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.
@@ -16,25 +16,17 @@
package org.springframework.cloud.sleuth.event;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.springframework.cloud.sleuth.Span;
import org.springframework.context.ApplicationEvent;
/**
* @author Dave Syer
*
*/
@Data
@EqualsAndHashCode(callSuper = false)
@SuppressWarnings("serial")
public class ClientSentEvent extends ApplicationEvent {
private final Span span;
public class ClientSentEvent extends SpanContainingEvent {
public ClientSentEvent(Object source, Span span) {
super(source);
this.span = span;
super(source, span);
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2013-2015 the original author or authors.
* Copyright 2013-2016 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.
@@ -16,30 +16,19 @@
package org.springframework.cloud.sleuth.event;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.springframework.cloud.sleuth.Span;
import org.springframework.context.ApplicationEvent;
/**
* @author Spencer Gibb
*/
@Data
@EqualsAndHashCode(callSuper=false)
@SuppressWarnings("serial")
public class ServerReceivedEvent extends ApplicationEvent {
private final Span parent;
private final Span span;
public class ServerReceivedEvent extends SpanParentContainingEvent {
public ServerReceivedEvent(Object source, Span span) {
this(source, null, span);
}
public ServerReceivedEvent(Object source, Span parent, Span span) {
super(source);
this.parent = parent;
this.span = span;
super(source, parent, span);
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2013-2015 the original author or authors.
* Copyright 2013-2016 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.
@@ -16,30 +16,19 @@
package org.springframework.cloud.sleuth.event;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.springframework.cloud.sleuth.Span;
import org.springframework.context.ApplicationEvent;
/**
* @author Spencer Gibb
*/
@Data
@EqualsAndHashCode(callSuper=false)
@SuppressWarnings("serial")
public class ServerSentEvent extends ApplicationEvent {
private final Span parent;
private final Span span;
public class ServerSentEvent extends SpanParentContainingEvent {
public ServerSentEvent(Object source, Span span) {
this(source, null, span);
}
public ServerSentEvent(Object source, Span parent, Span span) {
super(source);
this.parent = parent;
this.span = span;
super(source, parent, span);
}
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2013-2015 the original author or authors.
* Copyright 2013-2016 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.
@@ -16,30 +16,19 @@
package org.springframework.cloud.sleuth.event;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.springframework.cloud.sleuth.Span;
import org.springframework.context.ApplicationEvent;
/**
* @author Spencer Gibb
*/
@Data
@EqualsAndHashCode(callSuper=false)
@SuppressWarnings("serial")
public class SpanAcquiredEvent extends ApplicationEvent {
private final Span parent;
private final Span span;
public class SpanAcquiredEvent extends SpanParentContainingEvent {
public SpanAcquiredEvent(Object source, Span span) {
this(source, null, span);
}
public SpanAcquiredEvent(Object source, Span parent, Span span) {
super(source);
this.parent = parent;
this.span = span;
super(source, parent, span);
}
}
}

View File

@@ -0,0 +1,62 @@
/*
* Copyright 2013-2016 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.event;
import java.util.Objects;
import org.springframework.cloud.sleuth.Span;
import org.springframework.context.ApplicationEvent;
/**
* @author Marcin Grzejszczak
*/
class SpanContainingEvent extends ApplicationEvent {
private final Span span;
public SpanContainingEvent(Object source, Span span) {
super(source);
this.span = span;
}
public Span getSpan() {
return this.span;
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
SpanContainingEvent that = (SpanContainingEvent) o;
return Objects.equals(this.span, that.span);
}
@Override
public int hashCode() {
return this.span != null ? this.span.hashCode() : 0;
}
@Override
public String toString() {
return getClass().getSimpleName() + "{" +
"span=" + this.span +
'}';
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2013-2015 the original author or authors.
* Copyright 2013-2016 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.
@@ -16,24 +16,16 @@
package org.springframework.cloud.sleuth.event;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.springframework.cloud.sleuth.Span;
import org.springframework.context.ApplicationEvent;
/**
* @author Spencer Gibb
*/
@Data
@EqualsAndHashCode(callSuper=false)
@SuppressWarnings("serial")
public class SpanContinuedEvent extends ApplicationEvent {
private final Span span;
public class SpanContinuedEvent extends SpanContainingEvent {
public SpanContinuedEvent(Object source, Span span) {
super(source);
this.span = span;
super(source, span);
}
}

View File

@@ -0,0 +1,75 @@
/*
* Copyright 2013-2016 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.event;
import java.util.Objects;
import org.springframework.cloud.sleuth.Span;
import org.springframework.context.ApplicationEvent;
/**
* @author Marcin Grzejszczak
*/
class SpanParentContainingEvent extends ApplicationEvent {
private final Span span;
private final Span parent;
public SpanParentContainingEvent(Object source, Span span) {
this(source, null, span);
}
public SpanParentContainingEvent(Object source, Span parent, Span span) {
super(source);
this.parent = parent;
this.span = span;
}
public Span getParent() {
return this.parent;
}
public Span getSpan() {
return this.span;
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
SpanParentContainingEvent that = (SpanParentContainingEvent) o;
return Objects.equals(this.parent, that.parent) && Objects
.equals(this.span, that.span);
}
@Override
public int hashCode() {
return Objects.hash(this.parent, this.span);
}
@Override
public String toString() {
return getClass().getSimpleName() + "{" +
"span=" + this.span +
", parent=" + this.parent +
'}';
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2013-2015 the original author or authors.
* Copyright 2013-2016 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.
@@ -16,30 +16,19 @@
package org.springframework.cloud.sleuth.event;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.springframework.cloud.sleuth.Span;
import org.springframework.context.ApplicationEvent;
/**
* @author Spencer Gibb
*/
@Data
@EqualsAndHashCode(callSuper=false)
@SuppressWarnings("serial")
public class SpanReleasedEvent extends ApplicationEvent {
private final Span span;
private final Span parent;
public class SpanReleasedEvent extends SpanParentContainingEvent {
public SpanReleasedEvent(Object source, Span span) {
this(source, null, span);
}
public SpanReleasedEvent(Object source, Span parent, Span span) {
super(source);
this.parent = parent;
this.span = span;
super(source, parent, span);
}
}
}

View File

@@ -21,8 +21,6 @@ import java.util.LinkedHashSet;
import org.springframework.boot.context.properties.ConfigurationProperties;
import lombok.Data;
/**
* Well-known {@link org.springframework.cloud.sleuth.Span#tag(String, String) span tag}
* keys.
@@ -49,19 +47,56 @@ import lombok.Data;
* what's you are storing.
*/
@ConfigurationProperties("spring.sleuth.keys")
@Data
public class TraceKeys {
private Http http = new Http();
private Message message = new Message();
@Data
public Http getHttp() {
return this.http;
}
public Message getMessage() {
return this.message;
}
public void setHttp(Http http) {
this.http = http;
}
public void setMessage(Message message) {
this.message = message;
}
public static class Message {
private Payload payload = new Payload();
@Data
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.
@@ -71,6 +106,22 @@ public class TraceKeys {
* 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;
}
}
/**
@@ -87,7 +138,6 @@ public class TraceKeys {
}
@Data
public static class Http {
/**
@@ -160,6 +210,77 @@ public class TraceKeys {
*/
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;
}
}
}

View File

@@ -18,8 +18,6 @@ package org.springframework.cloud.sleuth.instrument.async;
import java.util.concurrent.Executor;
import lombok.RequiredArgsConstructor;
import org.springframework.aop.interceptor.AsyncUncaughtExceptionHandler;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.scheduling.annotation.AsyncConfigurer;
@@ -29,12 +27,16 @@ import org.springframework.scheduling.annotation.AsyncConfigurerSupport;
* @author Dave Syer
*
*/
@RequiredArgsConstructor
public class LazyTraceAsyncCustomizer extends AsyncConfigurerSupport {
private final BeanFactory beanFactory;
private final AsyncConfigurer delegate;
public LazyTraceAsyncCustomizer(BeanFactory beanFactory, AsyncConfigurer delegate) {
this.beanFactory = beanFactory;
this.delegate = delegate;
}
@Override
public Executor getAsyncExecutor() {
return new LazyTraceExecutor(this.beanFactory, this.delegate.getAsyncExecutor());

View File

@@ -22,19 +22,21 @@ import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
import org.springframework.cloud.sleuth.Tracer;
import lombok.RequiredArgsConstructor;
/**
* @author Dave Syer
*
*/
@RequiredArgsConstructor
public class LazyTraceExecutor implements Executor {
private Tracer tracer;
private final BeanFactory beanFactory;
private final Executor delegate;
public LazyTraceExecutor(BeanFactory beanFactory, Executor delegate) {
this.beanFactory = beanFactory;
this.delegate = delegate;
}
@Override
public void execute(Runnable command) {
if (this.tracer == null) {

View File

@@ -18,8 +18,6 @@ package org.springframework.cloud.sleuth.instrument.async;
import java.util.concurrent.Callable;
import lombok.EqualsAndHashCode;
import lombok.Value;
import org.springframework.cloud.sleuth.Span;
import org.springframework.cloud.sleuth.SpanName;
import org.springframework.cloud.sleuth.Tracer;
@@ -27,8 +25,6 @@ import org.springframework.cloud.sleuth.Tracer;
/**
* @author Spencer Gibb
*/
@Value
@EqualsAndHashCode(callSuper = false)
public class TraceCallable<V> extends TraceDelegate<Callable<V>> implements Callable<V> {
public TraceCallable(Tracer tracer, Callable<V> delegate) {

View File

@@ -20,12 +20,9 @@ import org.springframework.cloud.sleuth.Span;
import org.springframework.cloud.sleuth.SpanName;
import org.springframework.cloud.sleuth.Tracer;
import lombok.Getter;
/**
* @author Spencer Gibb
*/
@Getter
public abstract class TraceDelegate<T> {
private static final String ASYNC_COMPONENT = "async";
@@ -60,4 +57,29 @@ public abstract class TraceDelegate<T> {
: this.name;
}
public Tracer getTracer() {
return this.tracer;
}
public T getDelegate() {
return this.delegate;
}
public SpanName getName() {
return this.name;
}
public Span getParent() {
return this.parent;
}
@Override
public String toString() {
return "TraceDelegate{" +
"tracer=" + this.tracer +
", delegate=" + this.delegate +
", name=" + this.name +
", parent=" + this.parent +
'}';
}
}

View File

@@ -16,8 +16,6 @@
package org.springframework.cloud.sleuth.instrument.async;
import lombok.EqualsAndHashCode;
import lombok.Value;
import org.springframework.cloud.sleuth.Span;
import org.springframework.cloud.sleuth.SpanName;
import org.springframework.cloud.sleuth.Tracer;
@@ -25,8 +23,6 @@ import org.springframework.cloud.sleuth.Tracer;
/**
* @author Spencer Gibb
*/
@Value
@EqualsAndHashCode(callSuper = false)
public class TraceRunnable extends TraceDelegate<Runnable> implements Runnable {
public TraceRunnable(Tracer tracer, Runnable delegate) {

View File

@@ -1,19 +1,22 @@
package org.springframework.cloud.sleuth.instrument.hystrix;
import javax.annotation.PreDestroy;
import java.util.concurrent.Callable;
import com.netflix.hystrix.strategy.HystrixPlugins;
import com.netflix.hystrix.strategy.concurrency.HystrixConcurrencyStrategy;
import lombok.extern.slf4j.Slf4j;
import javax.annotation.PreDestroy;
import org.slf4j.Logger;
import org.springframework.cloud.sleuth.Span;
import org.springframework.cloud.sleuth.SpanName;
import org.springframework.cloud.sleuth.Tracer;
@Slf4j
import com.netflix.hystrix.strategy.HystrixPlugins;
import com.netflix.hystrix.strategy.concurrency.HystrixConcurrencyStrategy;
public class SleuthHystrixConcurrencyStrategy extends HystrixConcurrencyStrategy {
private static final String HYSTRIX_COMPONENT = "hystrix";
private static final Logger log = org.slf4j.LoggerFactory
.getLogger(SleuthHystrixConcurrencyStrategy.class);
private final Tracer tracer;

View File

@@ -19,6 +19,7 @@ package org.springframework.cloud.sleuth.instrument.web;
import java.lang.reflect.Field;
import java.util.concurrent.Callable;
import org.apache.commons.logging.Log;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
@@ -29,8 +30,6 @@ import org.springframework.cloud.sleuth.Tracer;
import org.springframework.cloud.sleuth.instrument.async.TraceCallable;
import org.springframework.web.context.request.async.WebAsyncTask;
import lombok.extern.apachecommons.CommonsLog;
/**
* Aspect that adds correlation id to
* <p/>
@@ -60,10 +59,11 @@ import lombok.extern.apachecommons.CommonsLog;
* @author Spencer Gibb
*/
@Aspect
@CommonsLog
public class TraceWebAspect {
private static final String ASYNC_COMPONENT = "async";
private static final Log log = org.apache.commons.logging.LogFactory
.getLog(TraceWebAspect.class);
private final Tracer tracer;
private final SpanAccessor accessor;

View File

@@ -19,6 +19,7 @@ package org.springframework.cloud.sleuth.instrument.zuul;
import java.io.InputStream;
import java.net.URISyntaxException;
import org.slf4j.Logger;
import org.springframework.cloud.netflix.ribbon.SpringClientFactory;
import org.springframework.cloud.netflix.zuul.filters.route.RestClientRibbonCommand;
import org.springframework.cloud.netflix.zuul.filters.route.RestClientRibbonCommandFactory;
@@ -34,14 +35,15 @@ import org.springframework.util.MultiValueMap;
import com.netflix.client.http.HttpRequest;
import com.netflix.niws.client.http.RestClient;
import lombok.SneakyThrows;
/**
* @author Spencer Gibb
*/
public class TraceRestClientRibbonCommandFactory extends RestClientRibbonCommandFactory
implements ApplicationEventPublisherAware {
private static final Logger log = org.slf4j.LoggerFactory
.getLogger(TraceRestClientRibbonCommandFactory.class);
private ApplicationEventPublisher publisher;
private final SpanAccessor accessor;
@@ -58,15 +60,20 @@ public class TraceRestClientRibbonCommandFactory extends RestClientRibbonCommand
}
@Override
@SneakyThrows
@SuppressWarnings("deprecation")
public RestClientRibbonCommand create(RibbonCommandContext context) {
RestClient restClient = getClientFactory().getClient(context.getServiceId(),
RestClient.class);
return new TraceRestClientRibbonCommand(context.getServiceId(), restClient,
getVerb(context.getVerb()), context.getUri(), context.getRetryable(),
context.getHeaders(), context.getParams(), context.getRequestEntity(),
this.publisher, this.accessor);
try {
return new TraceRestClientRibbonCommand(context.getServiceId(), restClient,
getVerb(context.getVerb()), context.getUri(), context.getRetryable(),
context.getHeaders(), context.getParams(), context.getRequestEntity(),
this.publisher, this.accessor);
}
catch (URISyntaxException e) {
log.error("Exception occurred while trying to create the TraceRestClientRibbonCommand", e);
throw new RuntimeException(e);
}
}
class TraceRestClientRibbonCommand extends RestClientRibbonCommand {

View File

@@ -16,7 +16,7 @@
package org.springframework.cloud.sleuth.log;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.MDC;
import org.springframework.cloud.sleuth.Span;
import org.springframework.cloud.sleuth.event.SpanAcquiredEvent;
@@ -29,9 +29,11 @@ import org.springframework.core.annotation.Order;
/**
* @author Spencer Gibb
*/
@Slf4j
public class Slf4jSpanListener {
private static final Logger log = org.slf4j.LoggerFactory
.getLogger(Slf4jSpanListener.class);
@EventListener(SpanAcquiredEvent.class)
@Order(Ordered.LOWEST_PRECEDENCE)
public void start(SpanAcquiredEvent event) {

View File

@@ -2,14 +2,11 @@ package org.springframework.cloud.sleuth.sampler;
import org.springframework.boot.context.properties.ConfigurationProperties;
import lombok.Data;
/**
* @author Marcin Grzejszczak
* @author Adrian Cole
*/
@ConfigurationProperties("spring.sleuth.sampler")
@Data
public class SamplerProperties {
/**
@@ -18,4 +15,12 @@ public class SamplerProperties {
* the traces).
*/
private float percentage = 0.1f;
public float getPercentage() {
return this.percentage;
}
public void setPercentage(float percentage) {
this.percentage = percentage;
}
}

View File

@@ -16,20 +16,20 @@
package org.springframework.cloud.sleuth.trace;
import org.apache.commons.logging.Log;
import org.springframework.cloud.sleuth.Span;
import org.springframework.core.NamedThreadLocal;
import lombok.extern.apachecommons.CommonsLog;
/**
* Utility for managing the thread local state for the {@link DefaultTracer}.
*
* @author Spencer Gibb
* @author Dave Syer
*/
@CommonsLog
class SpanContextHolder {
private static final Log log = org.apache.commons.logging.LogFactory
.getLog(SpanContextHolder.class);
private static final ThreadLocal<SpanContext> CURRENT_SPAN = new NamedThreadLocal<>(
"Trace Context");

View File

@@ -16,14 +16,16 @@
package org.springframework.cloud.sleuth.util;
import lombok.extern.apachecommons.CommonsLog;
import org.apache.commons.logging.Log;
/**
* @author Spencer Gibb
*/
@CommonsLog
public abstract class ExceptionUtils {
private static final Log log = org.apache.commons.logging.LogFactory
.getLog(ExceptionUtils.class);
private static boolean fail = false;
public static void warn(String msg) {
if (fail) {
throw new IllegalStateException(msg);

View File

@@ -1,16 +1,32 @@
/*
* Copyright 2013-2016 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.assertions;
import java.util.Objects;
import org.assertj.core.api.AbstractAssert;
import org.slf4j.Logger;
import org.springframework.cloud.sleuth.Span;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.sleuth.SpanName;
@Slf4j
public class SpanAssert extends AbstractAssert<SpanAssert, Span> {
private static final Logger log = org.slf4j.LoggerFactory.getLogger(SpanAssert.class);
public SpanAssert(Span actual) {
super(actual, SpanAssert.class);
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2013-2015 the original author or authors.
* Copyright 2013-2016 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.
@@ -19,13 +19,14 @@ package org.springframework.cloud.sleuth.assertions;
import java.util.Objects;
import org.assertj.core.api.AbstractAssert;
import org.slf4j.Logger;
import org.springframework.cloud.sleuth.SpanName;
import lombok.extern.slf4j.Slf4j;
@Slf4j
public class SpanNameAssert extends AbstractAssert<SpanNameAssert, SpanName> {
private static final Logger log = org.slf4j.LoggerFactory
.getLogger(SpanNameAssert.class);
public SpanNameAssert(SpanName actual) {
super(actual, SpanNameAssert.class);
}

View File

@@ -9,7 +9,6 @@ import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import lombok.SneakyThrows;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@@ -19,7 +18,6 @@ import org.mockito.runners.MockitoJUnitRunner;
import org.springframework.cloud.sleuth.Span;
import org.springframework.cloud.sleuth.SpanName;
import org.springframework.cloud.sleuth.Tracer;
import org.springframework.cloud.sleuth.instrument.async.TraceableExecutorService;
import org.springframework.cloud.sleuth.sampler.AlwaysSampler;
import org.springframework.cloud.sleuth.trace.DefaultTracer;
import org.springframework.cloud.sleuth.trace.TestSpanContextHolder;
@@ -54,8 +52,8 @@ public class TraceableExecutorServiceTests {
}
@Test
@SneakyThrows
public void should_propagate_trace_id_and_set_new_span_when_traceable_executor_service_is_executed() {
public void should_propagate_trace_id_and_set_new_span_when_traceable_executor_service_is_executed()
throws Exception {
Span span = this.tracer.startTrace(new SpanName("http", "PARENT"));
CompletableFuture.allOf(runnablesExecutedViaTraceManagerableExecutorService()).get();
this.tracer.close(span);

View File

@@ -16,7 +16,8 @@
package org.springframework.cloud.sleuth.instrument.web;
import lombok.SneakyThrows;
import java.util.Random;
import org.junit.Before;
import org.junit.Test;
import org.springframework.cloud.sleuth.Span;
@@ -33,8 +34,6 @@ import org.springframework.mock.web.MockHttpServletResponse;
import org.springframework.mock.web.MockServletContext;
import org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder;
import java.util.Random;
import static org.junit.Assert.assertNull;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
@@ -55,7 +54,6 @@ public class TraceFilterMockChainIntegrationTests {
private MockFilterChain filterChain;
@Before
@SneakyThrows
public void init() {
TestSpanContextHolder.removeCurrentSpan();
this.context.refresh();

View File

@@ -18,7 +18,6 @@ package org.springframework.cloud.sleuth.instrument.web;
import java.util.Random;
import lombok.SneakyThrows;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;
@@ -67,7 +66,6 @@ public class TraceFilterTests {
private Sampler sampler = new AlwaysSampler();
@Before
@SneakyThrows
public void init() {
initMocks(this);
this.tracer = new DefaultTracer(new DelegateSampler(), new Random(),

View File

@@ -1,14 +1,16 @@
package org.springframework.cloud.sleuth.instrument.web.common;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.util.SocketUtils;
@Configuration
@Slf4j
public class MockServerConfiguration {
private static final Logger log = org.slf4j.LoggerFactory
.getLogger(MockServerConfiguration.class);
@Bean(destroyMethod = "shutdownServer")
HttpMockServer httpMockServer() {
return tryToStartMockServer();