From 433e7c301a3f60574768e4c035546fb434efa252 Mon Sep 17 00:00:00 2001 From: Marcin Grzejszczak Date: Wed, 7 Mar 2018 08:43:22 -0500 Subject: [PATCH] Documented how to use spring cloud function; fixes gh-853 --- .../main/asciidoc/spring-cloud-sleuth.adoc | 32 +++++++++++++++++++ .../zipkin2/ZipkinAutoConfiguration.java | 10 ++++-- 2 files changed, 40 insertions(+), 2 deletions(-) diff --git a/docs/src/main/asciidoc/spring-cloud-sleuth.adoc b/docs/src/main/asciidoc/spring-cloud-sleuth.adoc index cd2b06b08..87a4c9c4f 100644 --- a/docs/src/main/asciidoc/spring-cloud-sleuth.adoc +++ b/docs/src/main/asciidoc/spring-cloud-sleuth.adoc @@ -869,6 +869,38 @@ Decorating Spring Integration Executor Channel with `TraceableExecutorService` w We're registering Zuul filters to propagate the tracing information (the request header is enriched with tracing data). 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 find the running examples deployed in the https://run.pivotal.io/[Pivotal Web Services]. Check them out in the following links: 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 2c64bb7f4..81075ecd5 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 @@ -85,11 +85,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(new ReporterMetricsAdapter(spanMetricReporter)) .build(zipkin.getEncoder()); + return new Reporter() { + @Override public void report(Span span) { + reporter.report(span); + reporter.flush(); + } + }; } @Bean