diff --git a/docs/src/main/asciidoc/spring-cloud-sleuth.adoc b/docs/src/main/asciidoc/spring-cloud-sleuth.adoc index 2021a92eb..31de43228 100644 --- a/docs/src/main/asciidoc/spring-cloud-sleuth.adoc +++ b/docs/src/main/asciidoc/spring-cloud-sleuth.adoc @@ -1147,6 +1147,38 @@ To block this feature, set `spring.sleuth.messaging.enabled` to `false`. We instrument the Zuul Ribbon integration by enriching the Ribbon requests with tracing information. To disable Zuul support, set the `spring.sleuth.zuul.enabled` property to `false`. +=== Spring Cloud Function + +Sleuth works out of the box with Spring Cloud Function. Since functions +might be short living, it's best to make the Zipkin span reporting synchronous. +Just define a `Reporter` bean as presented below: + +[source,java] +---- +@Configuration +class ReporterConfiguration { + @Bean + public Reporter reporter( + SpanMetricReporter spanMetricReporter, + ZipkinProperties zipkin, + Sender sender + ) { + final AsyncReporter reporter = AsyncReporter.builder(sender) + .queuedMaxSpans(1000) + .messageTimeout(zipkin.getMessageTimeout(), TimeUnit.SECONDS) + .metrics(new ReporterMetricsAdapter(spanMetricReporter)) + .build(zipkin.getEncoder()); + return new Reporter() { + @Override public void report(Span span) { + reporter.report(span); + // make the reporter synchronous + reporter.flush(); + } + }; + } +} +---- + == Running examples You can see the running examples deployed in the https://run.pivotal.io/[Pivotal Web Services]. diff --git a/spring-cloud-sleuth-zipkin/src/main/java/org/springframework/cloud/sleuth/zipkin2/ZipkinAutoConfiguration.java b/spring-cloud-sleuth-zipkin/src/main/java/org/springframework/cloud/sleuth/zipkin2/ZipkinAutoConfiguration.java index 1943918c5..e6c37b4dd 100644 --- a/spring-cloud-sleuth-zipkin/src/main/java/org/springframework/cloud/sleuth/zipkin2/ZipkinAutoConfiguration.java +++ b/spring-cloud-sleuth-zipkin/src/main/java/org/springframework/cloud/sleuth/zipkin2/ZipkinAutoConfiguration.java @@ -80,11 +80,17 @@ public class ZipkinAutoConfiguration { ZipkinProperties zipkin, Sender sender ) { - return AsyncReporter.builder(sender) - .queuedMaxSpans(1000) // historical constraint. Note: AsyncReporter supports memory bounds + final AsyncReporter reporter = AsyncReporter.builder(sender).queuedMaxSpans( + 1000) // historical constraint. Note: AsyncReporter supports memory bounds .messageTimeout(zipkin.getMessageTimeout(), TimeUnit.SECONDS) .metrics(reporterMetrics) .build(zipkin.getEncoder()); + return new Reporter() { + @Override public void report(Span span) { + reporter.report(span); + reporter.flush(); + } + }; } @Bean