Updated documentation

This commit is contained in:
Tim Ysewyn
2019-01-16 12:42:37 +01:00
parent 7c31475422
commit 8327ecbb4d
2 changed files with 94 additions and 4 deletions

View File

@@ -417,6 +417,18 @@ dependencies {
<2> Add the dependency to `spring-cloud-starter-zipkin`. That way, all nested dependencies get downloaded.
<3> To automatically configure RabbitMQ, add the `spring-rabbit` dependency.
=== Overriding the auto-configuration of Zipkin
Spring Cloud Sleuth supports sending traces to multiple tracing systems as of version 2.1.0.
In order to get this to work, every tracing system needs to have a `Reporter<Span>` and `Sender`.
If you want to override the provided beans you need to give them a specific name.
To do this you can use respectively `ZipkinAutoConfiguration.REPORTER_BEAN_NAME` and `ZipkinAutoConfiguration.SENDER_BEAN_NAME`.
[source,java]
----
include::../../../../spring-cloud-sleuth-zipkin/src/test/java/org/springframework/cloud/sleuth/zipkin2/ZipkinAutoConfigurationTests.java[tags=override_default_beans,indent=0]
----
== Additional Resources
You can watch a video of https://twitter.com/reshmi9k[Reshmi Krishna] and https://twitter.com/mgrzejszczak[Marcin Grzejszczak] talking about Spring Cloud

View File

@@ -203,12 +203,12 @@ public class ZipkinAutoConfigurationTests {
this.context.refresh();
then(this.context.getBeansOfType(Sender.class)).hasSize(2);
then(this.context.getBeansOfType(Sender.class)).containsKeys("zipkinSender",
"otherSender");
then(this.context.getBeansOfType(Sender.class))
.containsKeys(ZipkinAutoConfiguration.SENDER_BEAN_NAME, "otherSender");
then(this.context.getBeansOfType(Reporter.class)).hasSize(2);
then(this.context.getBeansOfType(Reporter.class)).containsKeys("zipkinReporter",
"otherReporter");
then(this.context.getBeansOfType(Reporter.class)).containsKeys(
ZipkinAutoConfiguration.REPORTER_BEAN_NAME, "otherReporter");
Span span = this.context.getBean(Tracing.class).tracer().nextSpan().name("foo")
.tag("foo", "bar").start();
@@ -226,6 +226,34 @@ public class ZipkinAutoConfigurationTests {
Awaitility.await().untilAsserted(() -> then(sender.isSpanSent()).isTrue());
}
@Test
public void shouldOverrideDefaultBeans() {
this.context = new AnnotationConfigApplicationContext();
this.context.register(ZipkinAutoConfiguration.class,
PropertyPlaceholderAutoConfiguration.class, TraceAutoConfiguration.class,
Config.class, MyConfig.class);
this.context.refresh();
then(this.context.getBeansOfType(Sender.class)).hasSize(1);
then(this.context.getBeansOfType(Sender.class))
.containsKeys(ZipkinAutoConfiguration.SENDER_BEAN_NAME);
then(this.context.getBeansOfType(Reporter.class)).hasSize(1);
then(this.context.getBeansOfType(Reporter.class))
.containsKeys(ZipkinAutoConfiguration.REPORTER_BEAN_NAME);
Span span = this.context.getBean(Tracing.class).tracer().nextSpan().name("foo")
.tag("foo", "bar").start();
span.finish();
Awaitility.await()
.untilAsserted(() -> then(this.server.getRequestCount()).isEqualTo(0));
MyConfig.MySender sender = this.context.getBean(MyConfig.MySender.class);
Awaitility.await().untilAsserted(() -> then(sender.isSpanSent()).isTrue());
}
@Configuration
protected static class Config {
@@ -309,4 +337,54 @@ public class ZipkinAutoConfigurationTests {
}
// tag::override_default_beans[]
@Configuration
protected static class MyConfig {
@Bean(ZipkinAutoConfiguration.REPORTER_BEAN_NAME)
Reporter<zipkin2.Span> myReporter() {
return AsyncReporter.create(mySender());
}
@Bean(ZipkinAutoConfiguration.SENDER_BEAN_NAME)
MySender mySender() {
return new MySender();
}
static class MySender extends Sender {
private boolean spanSent = false;
boolean isSpanSent() {
return this.spanSent;
}
@Override
public Encoding encoding() {
return Encoding.JSON;
}
@Override
public int messageMaxBytes() {
return Integer.MAX_VALUE;
}
@Override
public int messageSizeInBytes(List<byte[]> encodedSpans) {
return encoding().listSizeInBytes(encodedSpans);
}
@Override
public Call<Void> sendSpans(List<byte[]> encodedSpans) {
this.spanSent = true;
return Call.create(null);
}
}
}
// end::override_default_beans[]
}