Updated zipkin config to support multiple span reporters/senders
This commit is contained in:
@@ -27,6 +27,7 @@ import zipkin2.reporter.ReporterMetrics;
|
||||
import zipkin2.reporter.Sender;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
|
||||
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||
@@ -72,10 +73,11 @@ public class ZipkinAutoConfiguration {
|
||||
* Accepts a sender so you can plug-in any standard one. Returns a Reporter so you can
|
||||
* also replace with a standard one.
|
||||
*/
|
||||
@Bean
|
||||
@Bean("zipkinReporter")
|
||||
@ConditionalOnMissingBean
|
||||
public Reporter<Span> reporter(ReporterMetrics reporterMetrics,
|
||||
ZipkinProperties zipkin, Sender sender, BytesEncoder<Span> spanBytesEncoder) {
|
||||
ZipkinProperties zipkin, @Qualifier("zipkinSender") Sender sender,
|
||||
BytesEncoder<Span> spanBytesEncoder) {
|
||||
return AsyncReporter.builder(sender).queuedMaxSpans(1000) // historical
|
||||
// constraint. Note:
|
||||
// AsyncReporter
|
||||
|
||||
@@ -42,7 +42,7 @@ class ZipkinKafkaSenderConfiguration {
|
||||
@Value("${spring.zipkin.kafka.topic:zipkin}")
|
||||
private String topic;
|
||||
|
||||
@Bean
|
||||
@Bean("zipkinSender")
|
||||
Sender kafkaSender(KafkaProperties config) {
|
||||
Map<String, Object> properties = config.buildProducerProperties();
|
||||
properties.put("key.serializer", ByteArraySerializer.class.getName());
|
||||
|
||||
@@ -36,7 +36,7 @@ class ZipkinRabbitSenderConfiguration {
|
||||
@Value("${spring.zipkin.rabbitmq.queue:zipkin}")
|
||||
private String queue;
|
||||
|
||||
@Bean
|
||||
@Bean("zipkinSender")
|
||||
Sender rabbitSender(CachingConnectionFactory connectionFactory,
|
||||
RabbitProperties config) {
|
||||
return RabbitMQSender.newBuilder()
|
||||
|
||||
@@ -50,7 +50,7 @@ class ZipkinRestTemplateSenderConfiguration {
|
||||
@Autowired
|
||||
ZipkinUrlExtractor extractor;
|
||||
|
||||
@Bean
|
||||
@Bean("zipkinSender")
|
||||
@ConditionalOnMissingBean
|
||||
public Sender restTemplateSender(ZipkinProperties zipkin,
|
||||
ZipkinRestTemplateCustomizer zipkinRestTemplateCustomizer) {
|
||||
|
||||
@@ -16,6 +16,8 @@
|
||||
|
||||
package org.springframework.cloud.sleuth.zipkin2;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import brave.Span;
|
||||
import brave.Tracing;
|
||||
import brave.handler.FinishedSpanHandler;
|
||||
@@ -38,6 +40,9 @@ import org.springframework.context.annotation.AnnotationConfigApplicationContext
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.mock.env.MockEnvironment;
|
||||
import zipkin2.Call;
|
||||
import zipkin2.codec.Encoding;
|
||||
import zipkin2.reporter.Reporter;
|
||||
import zipkin2.reporter.Sender;
|
||||
import zipkin2.reporter.amqp.RabbitMQSender;
|
||||
import zipkin2.reporter.kafka11.KafkaSender;
|
||||
@@ -184,6 +189,25 @@ public class ZipkinAutoConfigurationTests {
|
||||
this.context.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void supportsMultipleReporters() {
|
||||
this.context = new AnnotationConfigApplicationContext();
|
||||
environment().setProperty("spring.zipkin.base-url",
|
||||
this.server.url("/").toString());
|
||||
this.context.register(ZipkinAutoConfiguration.class,
|
||||
PropertyPlaceholderAutoConfiguration.class, TraceAutoConfiguration.class,
|
||||
MultipleReportersConfig.class);
|
||||
this.context.refresh();
|
||||
|
||||
then(this.context.getBeansOfType(Sender.class)).hasSize(2);
|
||||
then(this.context.getBeansOfType(Sender.class)).containsKeys("zipkinSender", "otherSender");
|
||||
|
||||
then(this.context.getBeansOfType(Reporter.class)).hasSize(2);
|
||||
then(this.context.getBeansOfType(Reporter.class)).containsKeys("zipkinReporter", "otherReporter");
|
||||
|
||||
this.context.close();
|
||||
}
|
||||
|
||||
@Configuration
|
||||
protected static class Config {
|
||||
|
||||
@@ -221,4 +245,41 @@ public class ZipkinAutoConfigurationTests {
|
||||
|
||||
}
|
||||
|
||||
@Configuration
|
||||
protected static class MultipleReportersConfig {
|
||||
|
||||
@Bean
|
||||
Reporter<zipkin2.Span> otherReporter() {
|
||||
return span -> {
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
@Bean
|
||||
Sender otherSender() {
|
||||
return new Sender() {
|
||||
@Override
|
||||
public Encoding encoding() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int messageMaxBytes() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int messageSizeInBytes(List<byte[]> encodedSpans) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Call<Void> sendSpans(List<byte[]> encodedSpans) {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user