Skip to content

Commit

Permalink
Added OpenTracing support; fixes #599
Browse files Browse the repository at this point in the history
  • Loading branch information
marcingrzejszczak committed Jan 21, 2018
1 parent 266061f commit 22d91ba
Show file tree
Hide file tree
Showing 9 changed files with 438 additions and 5 deletions.
4 changes: 2 additions & 2 deletions docs/src/main/asciidoc/features.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@ a baggage element then it will be sent downstream either via HTTP or messaging t
* Provides a way to create / continue spans and add tags and logs via annotations.
* Provides simple metrics of accepted / dropped spans.
* If `spring-cloud-sleuth-zipkin` then the app will generate and collect Zipkin-compatible traces.
By default it sends them via HTTP to a Zipkin server on localhost (port 9411).
Configure the location of the service using `spring.zipkin.baseUrl`.
- If you depend on `spring-rabbit` or `spring-kafka` your app will send traces to a broker instead of http.
- Note: `spring-cloud-sleuth-stream` is deprecated and should no longer be used.
* Spring Cloud Sleuth is http://opentracing.io/[OpenTracing] compatible
IMPORTANT: If using Zipkin, configure the percentage of spans exported using `spring.sleuth.sampler.percentage`
(default 0.1, i.e. 10%). *Otherwise you might think that Sleuth is not working cause it's omitting some spans.*

Expand Down
6 changes: 6 additions & 0 deletions docs/src/main/asciidoc/spring-cloud-sleuth.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -931,6 +931,12 @@ on how to create a Stream Zipkin server.

== Integrations

=== OpenTracing

Spring Cloud Sleuth is http://opentracing.io/[OpenTracing] compatible. If you have
OpenTracing on the classpath we will automatically register the OpenTracing
`Tracer` bean. If you wish to disable this just set `spring.sleuth.opentracing.enabled` to `false`

=== Runnable and Callable

If you're wrapping your logic in `Runnable` or `Callable` it's enough to wrap those classes in their Sleuth representative.
Expand Down
5 changes: 5 additions & 0 deletions spring-cloud-sleuth-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,11 @@
<groupId>io.zipkin.brave</groupId>
<artifactId>brave-instrumentation-spring-webmvc</artifactId>
</dependency>
<dependency>
<groupId>io.opentracing.brave</groupId>
<artifactId>brave-opentracing</artifactId>
<optional>true</optional>
</dependency>
<!-- BRAVE -->
<dependency>
<groupId>org.springframework.boot</groupId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package org.springframework.cloud.sleuth.instrument.opentracing;

import brave.Tracing;
import brave.opentracing.BraveTracer;
import io.opentracing.Tracer;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
* {@link org.springframework.boot.autoconfigure.EnableAutoConfiguration Auto-configuration}
* to enable tracing via Opentracing.
*
* @author Spencer Gibb
* @author Marcin Grzejszczak
* @since 2.0.0
*/
@Configuration
@ConditionalOnProperty(value="spring.sleuth.opentracing.enabled", matchIfMissing=true)
@ConditionalOnBean(Tracing.class)
@ConditionalOnClass(Tracer.class)
@EnableConfigurationProperties(SleuthOpentracingProperties.class)
public class OpentracingAutoConfiguration {

@Bean
@ConditionalOnMissingBean
Tracer sleuthOpenTracing(brave.Tracing braveTracing) {
return BraveTracer.create(braveTracing);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Copyright 2013-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

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

import org.springframework.boot.context.properties.ConfigurationProperties;

/**
* Sleuth Opentracing settings
*
* @since 2.0.0
*/
@ConfigurationProperties("spring.sleuth.opentracing")
public class SleuthOpentracingProperties {

private boolean enabled = true;

public boolean isEnabled() {
return this.enabled;
}

public void setEnabled(boolean enabled) {
this.enabled = enabled;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
* @author Marcin Grzejszczak
* @since 2.0.0
*/
public class TraceWebFilter implements WebFilter, Ordered {
public final class TraceWebFilter implements WebFilter, Ordered {

private static final Log log = LogFactory.getLog(TraceWebFilter.class);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ org.springframework.cloud.sleuth.instrument.reactor.TraceReactorAutoConfiguratio
org.springframework.cloud.sleuth.instrument.web.TraceWebFluxAutoConfiguration,\
org.springframework.cloud.sleuth.instrument.zuul.TraceZuulAutoConfiguration,\
org.springframework.cloud.sleuth.instrument.messaging.TraceSpringIntegrationAutoConfiguration,\
org.springframework.cloud.sleuth.instrument.messaging.websocket.TraceWebSocketAutoConfiguration
org.springframework.cloud.sleuth.instrument.messaging.websocket.TraceWebSocketAutoConfiguration,\
org.springframework.cloud.sleuth.instrument.opentracing.OpentracingAutoConfiguration

# Environment Post Processor
org.springframework.boot.env.EnvironmentPostProcessor=\
Expand Down
Loading

0 comments on commit 22d91ba

Please sign in to comment.