Delomboking
This commit is contained in:
23
README.adoc
23
README.adoc
@@ -177,15 +177,6 @@ following command:
|
||||
The generated eclipse projects can be imported by selecting `import existing projects`
|
||||
from the `file` menu.
|
||||
|
||||
==== Adding Project Lombok Agent
|
||||
|
||||
Spring Cloud uses http://projectlombok.org/features/index.html[Project Lombok]
|
||||
to generate getters and setters etc. Compiling from the command line this
|
||||
shouldn't cause any problems, but in an IDE you need to add an agent
|
||||
to the JVM. Full instructions can be found in the Lombok website. The
|
||||
sign that you need to do this is a lot of compiler errors to do with
|
||||
missing methods and fields, e.g.
|
||||
|
||||
[indent=0]
|
||||
----
|
||||
The method getInitialStatus() is undefined for the type EurekaInstanceConfigBean EurekaDiscoveryClientConfiguration.java /spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/eureka line 120 Java Problem
|
||||
@@ -197,21 +188,17 @@ The method getLocation() is undefined for the type ProxyRouteLocator.ProxyRouteS
|
||||
----
|
||||
|
||||
==== Importing into Intellij
|
||||
Spring Cloud projects use annotation processing, particularly Lombok, which requires configuration
|
||||
or you will encounter compile problems. It also needs a specific version of maven and a profile
|
||||
Spring Cloud needs a specific version of maven and a profile
|
||||
enabled. Intellij 14.1+ requires some configuration to ensure these are setup properly.
|
||||
|
||||
1. Click Preferences, Plugins. *Ensure Lombok is installed*
|
||||
2. Click New, Project from Existing Sources, choose your spring-cloud-sleuth directory
|
||||
3. Choose Maven, and select Environment Settings. *Ensure you are using Maven 3.3.3*
|
||||
4. In the next screen, *Select the profile `spring`* click Next until Finish.
|
||||
5. Click Preferences, "Build, Execution, Deployment", Compiler, Annotation Processors. *Click Enable Annotation Processing*
|
||||
6. Click Build, Rebuild Project, and you are ready to go!
|
||||
1. Click New, Project from Existing Sources, choose your spring-cloud-sleuth directory
|
||||
2. Choose Maven, and select Environment Settings. *Ensure you are using Maven 3.3.3*
|
||||
3. In the next screen, *Select the profile `spring`* click Next until Finish.
|
||||
4. Click Build, Rebuild Project, and you are ready to go!
|
||||
|
||||
==== Importing into other IDEs
|
||||
Maven is well supported by most Java IDEs. Refer to you vendor documentation.
|
||||
|
||||
|
||||
== Contributing
|
||||
|
||||
Spring Cloud is released under the non-restrictive Apache 2.0 license,
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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 +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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 +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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());
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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 +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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");
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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(),
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -76,10 +76,6 @@
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-actuator</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.github.kristofa</groupId>
|
||||
<artifactId>brave-core</artifactId>
|
||||
|
||||
@@ -16,14 +16,13 @@
|
||||
|
||||
package sample;
|
||||
|
||||
import lombok.SneakyThrows;
|
||||
import java.util.Random;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cloud.sleuth.Tracer;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
/**
|
||||
* @author Spencer Gibb
|
||||
*/
|
||||
@@ -35,9 +34,8 @@ public class SampleBackground {
|
||||
@Autowired
|
||||
private Random random;
|
||||
|
||||
@SneakyThrows
|
||||
@Async
|
||||
public void background() {
|
||||
public void background() throws InterruptedException {
|
||||
int millis = this.random.nextInt(1000);
|
||||
Thread.sleep(millis);
|
||||
this.tracer.addTag("background-sleep-millis", String.valueOf(millis));
|
||||
|
||||
@@ -16,8 +16,7 @@
|
||||
|
||||
package sample;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.context.embedded.EmbeddedServletContainerInitializedEvent;
|
||||
import org.springframework.context.ApplicationListener;
|
||||
@@ -30,10 +29,11 @@ import org.springframework.web.client.RestTemplate;
|
||||
* @author Dave Syer
|
||||
*
|
||||
*/
|
||||
@MessageEndpoint
|
||||
@Slf4j
|
||||
public class SampleService implements
|
||||
@MessageEndpoint public class SampleService implements
|
||||
ApplicationListener<EmbeddedServletContainerInitializedEvent> {
|
||||
private static final Logger log = org.slf4j.LoggerFactory
|
||||
.getLogger(SampleService.class);
|
||||
|
||||
@Autowired private RestTemplate restTemplate;
|
||||
private int port;
|
||||
|
||||
|
||||
@@ -16,8 +16,7 @@
|
||||
|
||||
package sample;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.integration.annotation.MessageEndpoint;
|
||||
import org.springframework.integration.annotation.ServiceActivator;
|
||||
@@ -28,14 +27,16 @@ import org.springframework.messaging.Message;
|
||||
*
|
||||
*/
|
||||
@MessageEndpoint
|
||||
@Slf4j
|
||||
public class SampleTransformer {
|
||||
|
||||
private static final Logger log = org.slf4j.LoggerFactory
|
||||
.getLogger(SampleTransformer.class);
|
||||
|
||||
@Autowired
|
||||
SampleBackground background;
|
||||
|
||||
@ServiceActivator(inputChannel="xform")
|
||||
public String log(Message<?> message) {
|
||||
public String log(Message<?> message) throws InterruptedException {
|
||||
log.info("Received: " + message);
|
||||
this.background.background();
|
||||
return message.getPayload().toString().toUpperCase();
|
||||
|
||||
@@ -15,22 +15,25 @@
|
||||
*/
|
||||
package integration;
|
||||
|
||||
import lombok.extern.apachecommons.CommonsLog;
|
||||
import org.springframework.cloud.sleuth.zipkin.ZipkinSpanReporter;
|
||||
import zipkin.Span;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.springframework.cloud.sleuth.zipkin.ZipkinSpanReporter;
|
||||
|
||||
import zipkin.Span;
|
||||
|
||||
/**
|
||||
* Span Collector that logs spans and adds Spans to a list
|
||||
*
|
||||
* @author Marcin Grzejszczak
|
||||
*/
|
||||
@CommonsLog
|
||||
public class IntegrationTestZipkinSpanReporter implements ZipkinSpanReporter {
|
||||
|
||||
private static final Log log = org.apache.commons.logging.LogFactory
|
||||
.getLog(IntegrationTestZipkinSpanReporter.class);
|
||||
|
||||
public List<Span> hashedSpans = Collections.synchronizedList(new LinkedList<>());
|
||||
|
||||
@Override
|
||||
|
||||
@@ -60,10 +60,6 @@
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-actuator</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
|
||||
@@ -16,14 +16,13 @@
|
||||
|
||||
package sample;
|
||||
|
||||
import lombok.SneakyThrows;
|
||||
import java.util.Random;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
/**
|
||||
* @author Spencer Gibb
|
||||
* @author Dave Syer
|
||||
@@ -36,15 +35,13 @@ public class SampleController {
|
||||
@Autowired
|
||||
private Random random;
|
||||
|
||||
@SneakyThrows
|
||||
@RequestMapping("/")
|
||||
public String hi() {
|
||||
public String hi() throws InterruptedException {
|
||||
Thread.sleep(this.random.nextInt(1000));
|
||||
String s = this.restTemplate.getForObject("http://zipkin/hi2", String.class);
|
||||
return "hi/" + s;
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
@RequestMapping("/call")
|
||||
public String traced() {
|
||||
String s = this.restTemplate.getForObject("http://zipkin/call", String.class);
|
||||
|
||||
@@ -64,10 +64,6 @@
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-actuator</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
|
||||
@@ -18,8 +18,6 @@ package sample;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
import lombok.SneakyThrows;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cloud.sleuth.Tracer;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
@@ -34,9 +32,8 @@ public class SampleBackground {
|
||||
@Autowired
|
||||
private Tracer tracer;
|
||||
|
||||
@SneakyThrows
|
||||
@Async
|
||||
public void background() {
|
||||
public void background() throws InterruptedException {
|
||||
final Random random = new Random();
|
||||
int millis = random.nextInt(1000);
|
||||
Thread.sleep(millis);
|
||||
|
||||
@@ -19,8 +19,7 @@ package sample;
|
||||
import java.util.Random;
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
import lombok.SneakyThrows;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.slf4j.Logger;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.context.embedded.EmbeddedServletContainerInitializedEvent;
|
||||
import org.springframework.cloud.sleuth.Span;
|
||||
@@ -36,10 +35,12 @@ import org.springframework.web.client.RestTemplate;
|
||||
/**
|
||||
* @author Spencer Gibb
|
||||
*/
|
||||
@Slf4j
|
||||
@RestController
|
||||
public class SampleController implements
|
||||
ApplicationListener<EmbeddedServletContainerInitializedEvent> {
|
||||
private static final Logger log = org.slf4j.LoggerFactory
|
||||
.getLogger(SampleController.class);
|
||||
|
||||
@Autowired
|
||||
private RestTemplate restTemplate;
|
||||
@Autowired
|
||||
@@ -52,9 +53,8 @@ ApplicationListener<EmbeddedServletContainerInitializedEvent> {
|
||||
private Random random;
|
||||
private int port;
|
||||
|
||||
@SneakyThrows
|
||||
@RequestMapping("/")
|
||||
public String hi() {
|
||||
public String hi() throws InterruptedException {
|
||||
Thread.sleep(this.random.nextInt(1000));
|
||||
|
||||
String s = this.restTemplate.getForObject("http://localhost:" + this.port
|
||||
@@ -77,23 +77,21 @@ ApplicationListener<EmbeddedServletContainerInitializedEvent> {
|
||||
}
|
||||
|
||||
@RequestMapping("/async")
|
||||
public String async() {
|
||||
public String async() throws InterruptedException {
|
||||
this.controller.background();
|
||||
return "ho";
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
@RequestMapping("/hi2")
|
||||
public String hi2() {
|
||||
public String hi2() throws InterruptedException {
|
||||
int millis = this.random.nextInt(1000);
|
||||
Thread.sleep(millis);
|
||||
this.tracer.addTag("random-sleep-millis", String.valueOf(millis));
|
||||
return "hi2";
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
@RequestMapping("/traced")
|
||||
public String traced() {
|
||||
public String traced() throws InterruptedException {
|
||||
Span span = this.tracer.startTrace(new SpanName("http", "customTraceEndpoint"),
|
||||
new AlwaysSampler());
|
||||
int millis = this.random.nextInt(1000);
|
||||
@@ -107,9 +105,8 @@ ApplicationListener<EmbeddedServletContainerInitializedEvent> {
|
||||
return "traced/" + s;
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
@RequestMapping("/start")
|
||||
public String start() {
|
||||
public String start() throws InterruptedException {
|
||||
int millis = this.random.nextInt(1000);
|
||||
log.info("Sleeping for {} millis", millis);
|
||||
Thread.sleep(millis);
|
||||
|
||||
@@ -67,10 +67,6 @@
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-actuator</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
|
||||
@@ -15,9 +15,6 @@
|
||||
*/
|
||||
package tools;
|
||||
|
||||
import static java.util.concurrent.TimeUnit.SECONDS;
|
||||
import static org.assertj.core.api.BDDAssertions.then;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
@@ -28,6 +25,7 @@ import java.util.stream.Collectors;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.slf4j.Logger;
|
||||
import org.springframework.cloud.sleuth.trace.IntegrationTestSpanContextHolder;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpMethod;
|
||||
@@ -39,16 +37,20 @@ import org.springframework.web.client.RestTemplate;
|
||||
import com.jayway.awaitility.Awaitility;
|
||||
import com.jayway.awaitility.core.ConditionFactory;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import zipkin.Codec;
|
||||
import zipkin.Span;
|
||||
|
||||
import static java.util.concurrent.TimeUnit.SECONDS;
|
||||
import static org.assertj.core.api.BDDAssertions.then;
|
||||
|
||||
/**
|
||||
* @author Marcin Grzejszczak
|
||||
*/
|
||||
@Slf4j
|
||||
public abstract class AbstractIntegrationTest {
|
||||
|
||||
private static final Logger log = org.slf4j.LoggerFactory
|
||||
.getLogger(AbstractIntegrationTest.class);
|
||||
|
||||
protected static int pollInterval = 1;
|
||||
protected static int timeout = 20;
|
||||
protected RestTemplate restTemplate = new AssertingRestTemplate();
|
||||
|
||||
@@ -15,23 +15,29 @@
|
||||
*/
|
||||
package tools;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.http.client.ClientHttpResponse;
|
||||
import org.springframework.web.client.*;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.http.client.ClientHttpResponse;
|
||||
import org.springframework.web.client.DefaultResponseErrorHandler;
|
||||
import org.springframework.web.client.RequestCallback;
|
||||
import org.springframework.web.client.ResponseExtractor;
|
||||
import org.springframework.web.client.RestClientException;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
/**
|
||||
*
|
||||
* RestTemplate that logs erroneous responses and throws AssertionsError on any connection issues
|
||||
*
|
||||
* @author Marcin Grzejszczak
|
||||
*/
|
||||
@Slf4j
|
||||
public class AssertingRestTemplate extends RestTemplate {
|
||||
|
||||
private static final Logger log = org.slf4j.LoggerFactory
|
||||
.getLogger(AssertingRestTemplate.class);
|
||||
|
||||
public AssertingRestTemplate() {
|
||||
setErrorHandler(new DefaultResponseErrorHandler() {
|
||||
@Override
|
||||
|
||||
@@ -15,11 +15,10 @@
|
||||
*/
|
||||
package tools;
|
||||
|
||||
import static org.assertj.core.api.BDDAssertions.then;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.Random;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.springframework.cloud.sleuth.Span;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpMethod;
|
||||
@@ -28,7 +27,7 @@ import org.springframework.http.RequestEntity;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import static org.assertj.core.api.BDDAssertions.then;
|
||||
|
||||
/**
|
||||
* Runnable that will send a request via the provide rest template to the
|
||||
@@ -36,8 +35,11 @@ import lombok.extern.slf4j.Slf4j;
|
||||
*
|
||||
* @author Marcin Grzejszczak
|
||||
*/
|
||||
@Slf4j
|
||||
public class RequestSendingRunnable implements Runnable {
|
||||
|
||||
private static final Logger log = org.slf4j.LoggerFactory
|
||||
.getLogger(RequestSendingRunnable.class);
|
||||
|
||||
private final RestTemplate restTemplate;
|
||||
private final String url;
|
||||
private final long traceId;
|
||||
|
||||
@@ -54,12 +54,6 @@
|
||||
<artifactId>mysql-connector-java</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-stream-test-support</artifactId>
|
||||
|
||||
@@ -67,10 +67,6 @@
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-actuator</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
|
||||
@@ -16,14 +16,13 @@
|
||||
|
||||
package sample;
|
||||
|
||||
import lombok.SneakyThrows;
|
||||
import java.util.Random;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cloud.sleuth.Tracer;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
/**
|
||||
* @author Spencer Gibb
|
||||
*/
|
||||
@@ -35,9 +34,8 @@ public class SampleBackground {
|
||||
@Autowired
|
||||
private Random random;
|
||||
|
||||
@SneakyThrows
|
||||
@Async
|
||||
public void background() {
|
||||
public void background() throws InterruptedException {
|
||||
int millis = this.random.nextInt(1000);
|
||||
Thread.sleep(millis);
|
||||
this.tracer.addTag("background-sleep-millis", String.valueOf(millis));
|
||||
|
||||
@@ -19,6 +19,7 @@ package sample;
|
||||
import java.util.Random;
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.context.embedded.EmbeddedServletContainerInitializedEvent;
|
||||
import org.springframework.cloud.sleuth.Span;
|
||||
@@ -31,16 +32,16 @@ import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
import lombok.SneakyThrows;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
* @author Spencer Gibb
|
||||
*/
|
||||
@Slf4j
|
||||
@RestController
|
||||
public class SampleController implements
|
||||
ApplicationListener<EmbeddedServletContainerInitializedEvent> {
|
||||
|
||||
private static final Logger log = org.slf4j.LoggerFactory
|
||||
.getLogger(SampleController.class);
|
||||
|
||||
@Autowired
|
||||
private RestTemplate restTemplate;
|
||||
@Autowired
|
||||
@@ -53,9 +54,8 @@ ApplicationListener<EmbeddedServletContainerInitializedEvent> {
|
||||
private Random random;
|
||||
private int port;
|
||||
|
||||
@SneakyThrows
|
||||
@RequestMapping("/")
|
||||
public String hi() {
|
||||
public String hi() throws InterruptedException {
|
||||
Thread.sleep(this.random.nextInt(1000));
|
||||
log.info("Home page");
|
||||
String s = this.restTemplate.getForObject("http://localhost:" + this.port
|
||||
@@ -78,15 +78,14 @@ ApplicationListener<EmbeddedServletContainerInitializedEvent> {
|
||||
}
|
||||
|
||||
@RequestMapping("/async")
|
||||
public String async() {
|
||||
public String async() throws InterruptedException {
|
||||
log.info("async");
|
||||
this.controller.background();
|
||||
return "ho";
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
@RequestMapping("/hi2")
|
||||
public String hi2() {
|
||||
public String hi2() throws InterruptedException {
|
||||
log.info("hi2");
|
||||
int millis = this.random.nextInt(1000);
|
||||
Thread.sleep(millis);
|
||||
@@ -94,9 +93,8 @@ ApplicationListener<EmbeddedServletContainerInitializedEvent> {
|
||||
return "hi2";
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
@RequestMapping("/traced")
|
||||
public String traced() {
|
||||
public String traced() throws InterruptedException {
|
||||
Span span = this.tracer.startTrace(new SpanName("http", "customTraceEndpoint"),
|
||||
new AlwaysSampler());
|
||||
int millis = this.random.nextInt(1000);
|
||||
@@ -110,9 +108,8 @@ ApplicationListener<EmbeddedServletContainerInitializedEvent> {
|
||||
return "traced/" + s;
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
@RequestMapping("/start")
|
||||
public String start() {
|
||||
public String start() throws InterruptedException {
|
||||
int millis = this.random.nextInt(1000);
|
||||
log.info("Sleeping for {} millis", millis);
|
||||
Thread.sleep(millis);
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package sample;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
@@ -24,17 +25,17 @@ import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.EnableAspectJAutoProxy;
|
||||
import org.springframework.scheduling.annotation.EnableAsync;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
* @author Spencer Gibb
|
||||
*/
|
||||
@SpringBootApplication
|
||||
@EnableAspectJAutoProxy(proxyTargetClass = true)
|
||||
@EnableAsync
|
||||
@Slf4j
|
||||
public class SampleZipkinApplication {
|
||||
|
||||
private static final Logger log = org.slf4j.LoggerFactory
|
||||
.getLogger(SampleZipkinApplication.class);
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(SampleZipkinApplication.class, args);
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@ import java.util.Random;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.slf4j.Logger;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.boot.test.SpringApplicationConfiguration;
|
||||
import org.springframework.boot.test.WebIntegrationTest;
|
||||
@@ -33,8 +34,6 @@ import org.springframework.test.context.TestPropertySource;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import integration.ZipkinTests.WaitUntilZipkinIsUpConfig;
|
||||
import lombok.SneakyThrows;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import sample.SampleZipkinApplication;
|
||||
import tools.AbstractIntegrationTest;
|
||||
import zipkin.server.ZipkinServer;
|
||||
@@ -73,10 +72,12 @@ public class ZipkinTests extends AbstractIntegrationTest {
|
||||
}
|
||||
|
||||
@Configuration
|
||||
@Slf4j
|
||||
public static class WaitUntilZipkinIsUpConfig {
|
||||
|
||||
private static final Logger log = org.slf4j.LoggerFactory
|
||||
.getLogger(WaitUntilZipkinIsUpConfig.class);
|
||||
|
||||
@Bean
|
||||
@SneakyThrows
|
||||
public ZipkinSpanReporter spanCollector(final ZipkinProperties zipkin,
|
||||
final SpanReporterService spanReporterService) {
|
||||
await().until(new Runnable() {
|
||||
|
||||
@@ -52,10 +52,6 @@
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-aop</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
|
||||
@@ -16,14 +16,13 @@
|
||||
|
||||
package sample;
|
||||
|
||||
import lombok.SneakyThrows;
|
||||
import java.util.Random;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cloud.sleuth.Tracer;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
/**
|
||||
* @author Spencer Gibb
|
||||
*/
|
||||
@@ -35,9 +34,8 @@ public class SampleBackground {
|
||||
@Autowired
|
||||
private Random random;
|
||||
|
||||
@SneakyThrows
|
||||
@Async
|
||||
public void background() {
|
||||
public void background() throws InterruptedException {
|
||||
int millis = this.random.nextInt(1000);
|
||||
Thread.sleep(millis);
|
||||
this.tracer.addTag("background-sleep-millis", String.valueOf(millis));
|
||||
|
||||
@@ -19,8 +19,7 @@ package sample;
|
||||
import java.util.Random;
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
import lombok.SneakyThrows;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.slf4j.Logger;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.context.embedded.EmbeddedServletContainerInitializedEvent;
|
||||
import org.springframework.cloud.sleuth.Span;
|
||||
@@ -36,10 +35,11 @@ import org.springframework.web.client.RestTemplate;
|
||||
/**
|
||||
* @author Spencer Gibb
|
||||
*/
|
||||
@Slf4j
|
||||
@RestController
|
||||
public class SampleController implements
|
||||
ApplicationListener<EmbeddedServletContainerInitializedEvent> {
|
||||
private static final Logger log = org.slf4j.LoggerFactory
|
||||
.getLogger(SampleController.class);
|
||||
@Autowired
|
||||
private RestTemplate restTemplate;
|
||||
@Autowired
|
||||
@@ -52,9 +52,8 @@ ApplicationListener<EmbeddedServletContainerInitializedEvent> {
|
||||
private Random random;
|
||||
private int port;
|
||||
|
||||
@SneakyThrows
|
||||
@RequestMapping("/")
|
||||
public String hi() {
|
||||
public String hi() throws InterruptedException {
|
||||
Thread.sleep(this.random.nextInt(1000));
|
||||
|
||||
String s = this.restTemplate.getForObject("http://localhost:" + this.port
|
||||
@@ -77,23 +76,21 @@ ApplicationListener<EmbeddedServletContainerInitializedEvent> {
|
||||
}
|
||||
|
||||
@RequestMapping("/async")
|
||||
public String async() {
|
||||
public String async() throws InterruptedException {
|
||||
this.controller.background();
|
||||
return "ho";
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
@RequestMapping("/hi2")
|
||||
public String hi2() {
|
||||
public String hi2() throws InterruptedException {
|
||||
int millis = this.random.nextInt(1000);
|
||||
Thread.sleep(millis);
|
||||
this.tracer.addTag("random-sleep-millis", String.valueOf(millis));
|
||||
return "hi2";
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
@RequestMapping("/traced")
|
||||
public String traced() {
|
||||
public String traced() throws InterruptedException {
|
||||
Span span = this.tracer.startTrace(new SpanName("http", "customTraceEndpoint"),
|
||||
new AlwaysSampler());
|
||||
int millis = this.random.nextInt(1000);
|
||||
@@ -107,9 +104,8 @@ ApplicationListener<EmbeddedServletContainerInitializedEvent> {
|
||||
return "traced/" + s;
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
@RequestMapping("/start")
|
||||
public String start() {
|
||||
public String start() throws InterruptedException {
|
||||
int millis = this.random.nextInt(1000);
|
||||
log.info("Sleeping for {} millis", millis);
|
||||
Thread.sleep(millis);
|
||||
|
||||
@@ -44,12 +44,6 @@
|
||||
<artifactId>spring-boot-configuration-processor</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.assertj</groupId>
|
||||
<artifactId>assertj-core</artifactId>
|
||||
|
||||
@@ -22,22 +22,23 @@ import java.nio.ByteBuffer;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @author Dave Syer
|
||||
*
|
||||
*/
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
public class Host {
|
||||
|
||||
private String serviceName;
|
||||
private String address;
|
||||
private Integer port;
|
||||
|
||||
public Host(String serviceName, String address, Integer port) {
|
||||
this.serviceName = serviceName;
|
||||
this.address = address;
|
||||
this.port = port;
|
||||
}
|
||||
|
||||
public int getIpv4() {
|
||||
InetAddress inetAddress = null;
|
||||
try {
|
||||
@@ -49,4 +50,27 @@ public class Host {
|
||||
return ByteBuffer.wrap(inetAddress.getAddress()).getInt();
|
||||
}
|
||||
|
||||
public String getServiceName() {
|
||||
return this.serviceName;
|
||||
}
|
||||
|
||||
public String getAddress() {
|
||||
return this.address;
|
||||
}
|
||||
|
||||
public Integer getPort() {
|
||||
return this.port;
|
||||
}
|
||||
|
||||
public void setServiceName(String serviceName) {
|
||||
this.serviceName = serviceName;
|
||||
}
|
||||
|
||||
public void setAddress(String address) {
|
||||
this.address = address;
|
||||
}
|
||||
|
||||
public void setPort(Integer port) {
|
||||
this.port = port;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,14 +18,27 @@ package org.springframework.cloud.sleuth.stream;
|
||||
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @author Dave Syer
|
||||
*/
|
||||
@ConfigurationProperties("spring.sleuth.stream")
|
||||
@Data
|
||||
public class SleuthStreamProperties {
|
||||
private boolean enabled = true;
|
||||
private String group = SleuthSink.INPUT;
|
||||
|
||||
public boolean isEnabled() {
|
||||
return this.enabled;
|
||||
}
|
||||
|
||||
public String getGroup() {
|
||||
return this.group;
|
||||
}
|
||||
|
||||
public void setEnabled(boolean enabled) {
|
||||
this.enabled = enabled;
|
||||
}
|
||||
|
||||
public void setGroup(String group) {
|
||||
this.group = group;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,9 +23,6 @@ import org.springframework.cloud.sleuth.Span;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* Data transfer object for a collection of spans from a given host.
|
||||
*
|
||||
@@ -33,11 +30,29 @@ import lombok.Data;
|
||||
*
|
||||
*/
|
||||
@JsonInclude(JsonInclude.Include.NON_DEFAULT)
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
public class Spans {
|
||||
|
||||
private Host host;
|
||||
private List<Span> spans = Collections.emptyList();
|
||||
|
||||
public Spans(Host host, List<Span> spans) {
|
||||
this.host = host;
|
||||
this.spans = spans;
|
||||
}
|
||||
|
||||
public Host getHost() {
|
||||
return this.host;
|
||||
}
|
||||
|
||||
public List<Span> getSpans() {
|
||||
return this.spans;
|
||||
}
|
||||
|
||||
public void setHost(Host host) {
|
||||
this.host = host;
|
||||
}
|
||||
|
||||
public void setSpans(List<Span> spans) {
|
||||
this.spans = spans;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -75,12 +75,6 @@
|
||||
<artifactId>mysql-connector-java</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.assertj</groupId>
|
||||
<artifactId>assertj-core</artifactId>
|
||||
|
||||
@@ -18,12 +18,13 @@ package org.springframework.cloud.sleuth.zipkin.stream;
|
||||
import java.util.Iterator;
|
||||
import java.util.NoSuchElementException;
|
||||
|
||||
import lombok.extern.apachecommons.CommonsLog;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.springframework.cloud.sleuth.Span;
|
||||
import org.springframework.cloud.sleuth.SpanName;
|
||||
import org.springframework.cloud.sleuth.stream.Host;
|
||||
import org.springframework.cloud.sleuth.stream.SleuthSink;
|
||||
import org.springframework.cloud.sleuth.stream.Spans;
|
||||
|
||||
import zipkin.BinaryAnnotation;
|
||||
import zipkin.Constants;
|
||||
import zipkin.Endpoint;
|
||||
@@ -33,9 +34,10 @@ import zipkin.Span.Builder;
|
||||
/**
|
||||
* This converts sleuth spans to zipkin ones, skipping invalid or unsampled.
|
||||
*/
|
||||
@CommonsLog
|
||||
final class SamplingZipkinSpanIterator implements Iterator<zipkin.Span> {
|
||||
|
||||
private static final Log log = org.apache.commons.logging.LogFactory
|
||||
.getLog(SamplingZipkinSpanIterator.class);
|
||||
private static final String MESSAGE_COMPONENT = "message";
|
||||
|
||||
private final Sampler sampler;
|
||||
|
||||
@@ -1,6 +1,12 @@
|
||||
package org.springframework.cloud.sleuth.zipkin.stream;
|
||||
|
||||
import lombok.extern.apachecommons.CommonsLog;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionOutcome;
|
||||
@@ -14,7 +20,11 @@ import org.springframework.cloud.sleuth.Span;
|
||||
import org.springframework.cloud.sleuth.stream.SleuthSink;
|
||||
import org.springframework.cloud.sleuth.stream.Spans;
|
||||
import org.springframework.cloud.sleuth.zipkin.stream.ZipkinMessageListener.NotSleuthStreamClient;
|
||||
import org.springframework.context.annotation.*;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.ConditionContext;
|
||||
import org.springframework.context.annotation.Conditional;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Profile;
|
||||
import org.springframework.core.env.ConfigurableEnvironment;
|
||||
import org.springframework.core.env.Environment;
|
||||
import org.springframework.core.env.MapPropertySource;
|
||||
@@ -22,21 +32,20 @@ import org.springframework.core.type.AnnotatedTypeMetadata;
|
||||
import org.springframework.integration.annotation.MessageEndpoint;
|
||||
import org.springframework.integration.annotation.ServiceActivator;
|
||||
|
||||
import zipkin.*;
|
||||
import zipkin.Annotation;
|
||||
import zipkin.BinaryAnnotation;
|
||||
import zipkin.BinaryAnnotation.Type;
|
||||
import zipkin.Endpoint;
|
||||
import zipkin.Sampler;
|
||||
import zipkin.Span.Builder;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import zipkin.SpanStore;
|
||||
|
||||
@MessageEndpoint
|
||||
@CommonsLog
|
||||
@Conditional(NotSleuthStreamClient.class)
|
||||
public class ZipkinMessageListener {
|
||||
|
||||
private static final org.apache.commons.logging.Log log = org.apache.commons.logging.LogFactory
|
||||
.getLog(ZipkinMessageListener.class);
|
||||
static final String UNKNOWN_PROCESS_ID = "unknown";
|
||||
|
||||
@Autowired
|
||||
|
||||
@@ -45,12 +45,6 @@
|
||||
<groupId>io.zipkin.java</groupId>
|
||||
<artifactId>zipkin</artifactId>
|
||||
</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>
|
||||
|
||||
@@ -1,15 +1,18 @@
|
||||
package org.springframework.cloud.sleuth.zipkin;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.slf4j.Logger;
|
||||
|
||||
import zipkin.Endpoint;
|
||||
|
||||
/**
|
||||
* Endpoint locator that will try to call an endpoint via Discovery Client
|
||||
* and will fallback to Server Properties if an exception is thrown
|
||||
*/
|
||||
@Slf4j
|
||||
public class FallbackHavingEndpointLocator implements EndpointLocator {
|
||||
|
||||
private static final Logger log = org.slf4j.LoggerFactory
|
||||
.getLogger(FallbackHavingEndpointLocator.class);
|
||||
|
||||
private final DiscoveryClientEndpointLocator discoveryClientEndpointLocator;
|
||||
private final ServerPropertiesEndpointLocator serverPropertiesEndpointLocator;
|
||||
|
||||
|
||||
@@ -1,10 +1,5 @@
|
||||
package org.springframework.cloud.sleuth.zipkin;
|
||||
|
||||
import lombok.extern.apachecommons.CommonsLog;
|
||||
import org.springframework.cloud.sleuth.metric.SpanReporterService;
|
||||
import zipkin.Codec;
|
||||
import zipkin.Span;
|
||||
|
||||
import java.io.Closeable;
|
||||
import java.io.Flushable;
|
||||
import java.io.IOException;
|
||||
@@ -20,14 +15,21 @@ import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.springframework.cloud.sleuth.metric.SpanReporterService;
|
||||
|
||||
import zipkin.Codec;
|
||||
import zipkin.Span;
|
||||
|
||||
import static java.util.concurrent.TimeUnit.SECONDS;
|
||||
|
||||
/**
|
||||
* Submits spans using Zipkin's {@code POST /spans} endpoint.
|
||||
*/
|
||||
@CommonsLog
|
||||
public final class HttpZipkinSpanReporter
|
||||
implements ZipkinSpanReporter, Flushable, Closeable {
|
||||
private static final Log log = org.apache.commons.logging.LogFactory
|
||||
.getLog(HttpZipkinSpanReporter.class);
|
||||
private static final Charset UTF_8 = Charset.forName("UTF-8");
|
||||
|
||||
private final String url;
|
||||
|
||||
@@ -18,16 +18,37 @@ package org.springframework.cloud.sleuth.zipkin;
|
||||
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @author Spencer Gibb
|
||||
*/
|
||||
@ConfigurationProperties("spring.zipkin")
|
||||
@Data
|
||||
public class ZipkinProperties {
|
||||
/** URL of the zipkin query server instance. */
|
||||
private String baseUrl = "http://localhost:9411/";
|
||||
private boolean enabled = true;
|
||||
private int flushInterval = 1;
|
||||
|
||||
public String getBaseUrl() {
|
||||
return this.baseUrl;
|
||||
}
|
||||
|
||||
public boolean isEnabled() {
|
||||
return this.enabled;
|
||||
}
|
||||
|
||||
public int getFlushInterval() {
|
||||
return this.flushInterval;
|
||||
}
|
||||
|
||||
public void setBaseUrl(String baseUrl) {
|
||||
this.baseUrl = baseUrl;
|
||||
}
|
||||
|
||||
public void setEnabled(boolean enabled) {
|
||||
this.enabled = enabled;
|
||||
}
|
||||
|
||||
public void setFlushInterval(int flushInterval) {
|
||||
this.flushInterval = flushInterval;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,7 +19,6 @@ package org.springframework.cloud.sleuth.zipkin;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.Map;
|
||||
|
||||
import lombok.extern.apachecommons.CommonsLog;
|
||||
import org.springframework.cloud.sleuth.Log;
|
||||
import org.springframework.cloud.sleuth.Span;
|
||||
import org.springframework.cloud.sleuth.SpanName;
|
||||
@@ -31,6 +30,7 @@ import org.springframework.cloud.sleuth.event.SpanAcquiredEvent;
|
||||
import org.springframework.cloud.sleuth.event.SpanReleasedEvent;
|
||||
import org.springframework.context.event.EventListener;
|
||||
import org.springframework.core.annotation.Order;
|
||||
|
||||
import zipkin.Annotation;
|
||||
import zipkin.BinaryAnnotation;
|
||||
import zipkin.Constants;
|
||||
@@ -39,8 +39,9 @@ import zipkin.Endpoint;
|
||||
/**
|
||||
* @author Spencer Gibb
|
||||
*/
|
||||
@CommonsLog
|
||||
public class ZipkinSpanListener {
|
||||
private static final org.apache.commons.logging.Log log = org.apache.commons.logging.LogFactory
|
||||
.getLog(ZipkinSpanListener.class);
|
||||
private static final Charset UTF_8 = Charset.forName("UTF-8");
|
||||
private static final byte[] UNKNOWN_BYTES = "unknown".getBytes(UTF_8);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user