Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sleuth now uses Brave #829

Merged
merged 38 commits into from
Jan 19, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
4689302
Initial work with Brave
marcingrzejszczak Jan 3, 2018
8652d17
Makes runnable and callable pre-emptively create spans
Jan 4, 2018
61a439c
Added exception message error parser to callables / runnables
marcingrzejszczak Jan 4, 2018
b9942fe
Added async support
marcingrzejszczak Jan 4, 2018
365f418
Made the simplest mvc / async case pass - still wondering about Trace…
marcingrzejszczak Jan 4, 2018
eea7276
Added TraceKeys to schedulnig and async
marcingrzejszczak Jan 4, 2018
e55edad
More async stuff added and work on web client started
marcingrzejszczak Jan 4, 2018
f78f435
don't instrument rest template and server with the same bean factory
Jan 5, 2018
afe5765
MAde the tests pass
marcingrzejszczak Jan 6, 2018
bc061d8
Added instrumentation of rest template
marcingrzejszczak Jan 6, 2018
b282b4f
Added Feign support
marcingrzejszczak Jan 6, 2018
0e2243d
Added more Feign tests
marcingrzejszczak Jan 7, 2018
5330d95
Added last Feign tests
marcingrzejszczak Jan 7, 2018
8d442b9
Added Hystrix
marcingrzejszczak Jan 7, 2018
b60a309
Added annotation
marcingrzejszczak Jan 7, 2018
3267c02
Moved to Brave's async client and added docs
marcingrzejszczak Jan 7, 2018
bc452c4
WIP on TraceFilter. Fighting with TraceFilterTests
marcingrzejszczak Jan 7, 2018
64c5f29
MAde TraceFilter work
marcingrzejszczak Jan 8, 2018
419ebfb
in prodress with tracefilter
marcingrzejszczak Jan 8, 2018
a5222be
Made TraceFilter work
marcingrzejszczak Jan 9, 2018
2d6021f
Fixed the supports join broken test
marcingrzejszczak Jan 9, 2018
d9c9f0f
Added spring data and async support for trace filter
marcingrzejszczak Jan 9, 2018
3cbeb6c
Added rxjava
marcingrzejszczak Jan 9, 2018
c6d8b9f
Added reactor
marcingrzejszczak Jan 9, 2018
e92be65
WebClient done
marcingrzejszczak Jan 9, 2018
0ee4d54
Added WebClient and WebFilter support
marcingrzejszczak Jan 9, 2018
0cb2786
Added some zuul instrumentation
marcingrzejszczak Jan 10, 2018
ea2187e
Finished Zuul
marcingrzejszczak Jan 10, 2018
e78448e
WIP on baggage
marcingrzejszczak Jan 10, 2018
59fe4dd
removed sleuth stream
marcingrzejszczak Jan 11, 2018
40c664f
Migrated core to Brave
marcingrzejszczak Jan 11, 2018
de6d1cc
Migrated sleuth zipkin
marcingrzejszczak Jan 11, 2018
e9ded4b
Migrated samples
marcingrzejszczak Jan 11, 2018
11b87d0
Ignored baggage test
marcingrzejszczak Jan 12, 2018
d4f729e
Bumps versions and adds notes about Baggage
Jan 18, 2018
26162c5
Added docs
marcingrzejszczak Jan 19, 2018
7b227b7
Final touches
marcingrzejszczak Jan 19, 2018
a0f6d8c
Updated docs
marcingrzejszczak Jan 19, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
63 changes: 38 additions & 25 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
:github-code: https://github.com/{github-repo}/tree/{github-tag}

image::https://circleci.com/gh/spring-cloud/spring-cloud-sleuth.svg?style=svg["CircleCI", link="https://circleci.com/gh/spring-cloud/spring-cloud-sleuth"]
image::https://codecov.io/gh/spring-cloud/spring-cloud-sleuth/branch/master/graph/badge.svg["codecov", link="https://codecov.io/gh/spring-cloud/spring-cloud-sleuth"]
image::https://codecov.io/gh/spring-cloud/spring-cloud-sleuth/branch/{github-tag}/graph/badge.svg["codecov", link="https://codecov.io/gh/spring-cloud/spring-cloud-sleuth"]
image::https://badges.gitter.im/spring-cloud/spring-cloud-sleuth.svg[Gitter, link="https://gitter.im/spring-cloud/spring-cloud-sleuth?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge"]
== Spring Cloud Sleuth

Expand Down Expand Up @@ -66,8 +66,12 @@ of that span is equal to trace id.
*Trace:* A set of spans forming a tree-like structure. For example, if you are running a distributed
big-data store, a trace might be formed by a put request.

*Annotation:* is used to record existence of an event in time. Some of the core annotations used to define
the start and stop of a request are:
*Annotation:* is used to record existence of an event in time. With
https://github.com/openzipkin/brave[Brave] instrumentation we no longer need to set special events
for https://zipkin.io/[Zipkin] to understand who the client and server are and where
the request started and where it has ended. For learning purposes
however we will mark these events to highlight what kind
of an action took place.

- *cs* - Client Sent - The client has made a request. This annotation depicts the start of the span.
- *sr* - Server Received - The server side got the request and will start processing it.
Expand All @@ -90,8 +94,8 @@ Trace Id = X
Span Id = D
Client Sent

That means that the current span has *Trace-Id* set to *X*, *Span-Id* set to *D*. It also has emitted
*Client Sent* event.
That means that the current span has *Trace-Id* set to *X*, *Span-Id* set to *D*. Also, the
*Client Sent* event took place.

This is how the visualization of the parent / child relationship of spans would look like:

Expand All @@ -118,14 +122,14 @@ annotations then they will presented as a single span.
Why is there a difference between the 7 and 4 spans in this case?

- 2 spans come from `http:/start` span. It has the Server Received (SR) and Server Sent (SS) annotations.
- 2 spans come from the RPC call from `service1` to `service2` to the `http:/foo` endpoint. It has the Client Sent (CS)
and Client Received (CR) annotations on `service1` side. It also has Server Received (SR) and Server Sent (SS) annotations
- 2 spans come from the RPC call from `service1` to `service2` to the `http:/foo` endpoint. The Client Sent (CS)
and Client Received (CR) events took place on `service1` side. Server Received (SR) and Server Sent (SS) events took place
on the `service2` side. Physically there are 2 spans but they form 1 logical span related to an RPC call.
- 2 spans come from the RPC call from `service2` to `service3` to the `http:/bar` endpoint. It has the Client Sent (CS)
and Client Received (CR) annotations on `service2` side. It also has Server Received (SR) and Server Sent (SS) annotations
- 2 spans come from the RPC call from `service2` to `service3` to the `http:/bar` endpoint. The Client Sent (CS)
and Client Received (CR) events took place on `service2` side. Server Received (SR) and Server Sent (SS) events took place
on the `service3` side. Physically there are 2 spans but they form 1 logical span related to an RPC call.
- 2 spans come from the RPC call from `service2` to `service4` to the `http:/baz` endpoint. It has the Client Sent (CS)
and Client Received (CR) annotations on `service2` side. It also has Server Received (SR) and Server Sent (SS) annotations
- 2 spans come from the RPC call from `service2` to `service4` to the `http:/baz` endpoint. The Client Sent (CS)
and Client Received (CR) events took place on `service2` side. Server Received (SR) and Server Sent (SS) events took place
on the `service4` side. Physically there are 2 spans but they form 1 logical span related to an RPC call.

So if we count the physical spans we have *1* from `http:/start`, *2* from `service1` calling `service2`, *2* form `service2`
Expand All @@ -150,11 +154,25 @@ image::https://raw.githubusercontent.com/spring-cloud/spring-cloud-sleuth/{branc

As you can see you can easily see the reason for an error and the whole stacktrace related to it.

==== Distributed tracing with Brave

Starting with version `2.0.0`, Spring Cloud Sleuth uses
https://github.com/openzipkin/brave[Brave] as the tracing library. That means
that Sleuth no longer takes care of storing the context but it delegates
that work to Brave.

Due to the fact that Sleuth had different naming / tagging
conventions than Brave, we've decided to follow the Brave's
conventions from now on. However, if you want to use the legacy
Sleuth approaches, it's enough to set the `spring.sleuth.http.legacy.enabled` property
to `true`.

==== Live examples

.Click Pivotal Web Services icon to see it live!
[caption="Click Pivotal Web Services icon to see it live!"]
image::https://raw.githubusercontent.com/spring-cloud/spring-cloud-sleuth/{branch}/docs/src/main/asciidoc/images/pws.png["Zipkin deployed on Pivotal Web Services", link="http://docssleuth-zipkin-server.cfapps.io/", width=150, height=74]
http://docssleuth-zipkin-server.cfapps.io/[Click here to see it live!]

The dependency graph in Zipkin would look like this:

Expand All @@ -163,7 +181,7 @@ image::https://raw.githubusercontent.com/spring-cloud/spring-cloud-sleuth/{branc
.Click Pivotal Web Services icon to see it live!
[caption="Click Pivotal Web Services icon to see it live!"]
image::https://raw.githubusercontent.com/spring-cloud/spring-cloud-sleuth/{branch}/docs/src/main/asciidoc/images/pws.png["Zipkin deployed on Pivotal Web Services", link="http://docssleuth-zipkin-server.cfapps.io/dependency", width=150, height=74]

http://docssleuth-zipkin-server.cfapps.io/dependency[Click here to see it live!]

==== Log correlation

Expand Down Expand Up @@ -322,9 +340,8 @@ Example of setting baggage on a span:

[source,java]
----
Span initialSpan = this.tracer.createSpan("span");
initialSpan.setBaggageItem("foo", "bar");
initialSpan.setBaggageItem("UPPER_CASE", "someValue");
Unresolved directive in intro.adoc - include::https://raw.githubusercontent.com/spring-cloud/spring-cloud-sleuth/master/spring-cloud-sleuth-core/src/test/java/org/springframework/cloud/brave/instrument/web/multiple/MultipleHopsIntegrationTests.java[tags=baggage,indent=0]
}
----

===== Baggage vs. Span Tags
Expand All @@ -337,15 +354,11 @@ can search by tag to find the trace, where there exists a span having the search

If you want to be able to lookup a span based on baggage, you should add corresponding entry as a tag in the root span.

IMPORTANT: Remember that the span needs to be in scope!

[source,java]
----
@Autowired Tracer tracer;

Span span = tracer.getCurrentSpan();
String baggageKey = "key";
String baggageValue = "foo";
span.setBaggageItem(baggageKey, baggageValue);
tracer.addTag(baggageKey, baggageValue);
Unresolved directive in intro.adoc - include::https://raw.githubusercontent.com/spring-cloud/spring-cloud-sleuth/master/spring-cloud-sleuth-core/src/test/java/org/springframework/cloud/brave/instrument/web/multiple/MultipleHopsIntegrationTests.java[tags=baggage_tag,indent=0]
----

=== Adding to the project
Expand All @@ -361,7 +374,7 @@ the `spring-cloud-starter-sleuth` module to your project.
[source,xml,indent=0,subs="verbatim,attributes",role="primary"]
.Maven
----
<dependencyManagement> <1>
<dependencyManagement> <1>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
Expand Down Expand Up @@ -406,7 +419,7 @@ If you want both Sleuth and Zipkin just add the `spring-cloud-starter-zipkin` de
[source,xml,indent=0,subs="verbatim,attributes",role="primary"]
.Maven
----
<dependencyManagement> <1>
<dependencyManagement> <1>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
Expand Down Expand Up @@ -457,7 +470,7 @@ dependencies.
[source,xml,indent=0,subs="verbatim,attributes",role="primary"]
.Maven
----
<dependencyManagement> <1>
<dependencyManagement> <1>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2013-2017 the original author or authors.
* Copyright 2013-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -21,7 +21,6 @@
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

import javax.annotation.PreDestroy;

import org.apache.commons.logging.Log;
Expand All @@ -30,19 +29,17 @@
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.embedded.EmbeddedServletContainerFactory;
import org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory;
import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory;
import org.springframework.boot.web.servlet.context.ServletWebServerInitializedEvent;
import org.springframework.boot.web.servlet.server.ServletWebServerFactory;
import org.springframework.cloud.sleuth.Sampler;
import org.springframework.cloud.sleuth.Span;
import org.springframework.cloud.sleuth.Tracer;
import org.springframework.cloud.sleuth.annotation.ContinueSpan;
import org.springframework.cloud.sleuth.annotation.NewSpan;
import org.springframework.cloud.sleuth.annotation.SpanTag;
import org.springframework.cloud.sleuth.sampler.AlwaysSampler;
import org.springframework.cloud.sleuth.util.ArrayListSpanAccumulator;
import org.springframework.context.ApplicationListener;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.EnableAsync;
Expand Down Expand Up @@ -102,9 +99,9 @@ public void onApplicationEvent(ServletWebServerInitializedEvent event) {
}

@Bean
public EmbeddedServletContainerFactory servletContainer(@Value("${server.port:0}") int serverPort) {
public ServletWebServerFactory servletContainer(@Value("${server.port:0}") int serverPort) {
log.info("Starting container at port [" + serverPort + "]");
return new TomcatEmbeddedServletContainerFactory(serverPort == 0 ? SocketUtils.findAvailableTcpPort() : serverPort);
return new TomcatServletWebServerFactory(serverPort == 0 ? SocketUtils.findAvailableTcpPort() : serverPort);
}

@PreDestroy
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2013-2016 the original author or authors.
* Copyright 2013-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2013-2017 the original author or authors.
* Copyright 2013-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2013-2017 the original author or authors.
* Copyright 2013-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2013-2017 the original author or authors.
* Copyright 2013-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2013-2017 the original author or authors.
* Copyright 2013-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/src/test/jmeter/jmeter.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright 2013-2017 the original author or authors.
# Copyright 2013-2018 the original author or authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion docs/src/main/asciidoc/README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
:github-code: https://github.com/{github-repo}/tree/{github-tag}

image::https://circleci.com/gh/spring-cloud/spring-cloud-sleuth.svg?style=svg["CircleCI", link="https://circleci.com/gh/spring-cloud/spring-cloud-sleuth"]
image::https://codecov.io/gh/spring-cloud/spring-cloud-sleuth/branch/master/graph/badge.svg["codecov", link="https://codecov.io/gh/spring-cloud/spring-cloud-sleuth"]
image::https://codecov.io/gh/spring-cloud/spring-cloud-sleuth/branch/{github-tag}/graph/badge.svg["codecov", link="https://codecov.io/gh/spring-cloud/spring-cloud-sleuth"]
image::https://badges.gitter.im/spring-cloud/spring-cloud-sleuth.svg[Gitter, link="https://gitter.im/spring-cloud/spring-cloud-sleuth?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge"]
== Spring Cloud Sleuth

Expand Down
Loading