diff --git a/reference/html/README.html b/reference/html/README.html index 86f3f149b..e0846819f 100644 --- a/reference/html/README.html +++ b/reference/html/README.html @@ -139,7 +139,7 @@ $(addBlockSwitches);
Unresolved directive in intro.adoc - include::https://raw.githubusercontent.com/spring-cloud/spring-cloud-sleuth/origin/master/spring-cloud-sleuth-core/src/test/java/org/springframework/cloud/sleuth/instrument/multiple/MultipleHopsIntegrationTests.java[tags=baggage,indent=0]
+Span initialSpan = this.tracer.nextSpan().name("span").start();
+ExtraFieldPropagation.set(initialSpan.context(), "foo", "bar");
+ExtraFieldPropagation.set(initialSpan.context(), "UPPER_CASE", "someValue");
Unresolved directive in intro.adoc - include::https://raw.githubusercontent.com/spring-cloud/spring-cloud-sleuth/origin/master/spring-cloud-sleuth-core/src/test/resources/application-baggage.yml[indent=0]
+spring.sleuth:
+ baggage-keys:
+ - baz
+ - bizarrecase
+ propagation-keys:
+ - foo
+ - upper_case
Unresolved directive in intro.adoc - include::https://raw.githubusercontent.com/spring-cloud/spring-cloud-sleuth/origin/master/spring-cloud-sleuth-core/src/test/java/org/springframework/cloud/sleuth/instrument/multiple/MultipleHopsIntegrationTests.java[tags=baggage_tag,indent=0]
+initialSpan.tag("foo",
+ ExtraFieldPropagation.get(initialSpan.context(), "foo"));
+initialSpan.tag("UPPER_CASE",
+ ExtraFieldPropagation.get(initialSpan.context(), "UPPER_CASE"));
ZipkinAutoConfiguration.REPORTER_BEAN_
-Unresolved directive in intro.adoc - include::https://raw.githubusercontent.com/spring-cloud/spring-cloud-sleuth/origin/master/spring-cloud-sleuth-zipkin/src/test/java/org/springframework/cloud/sleuth/zipkin2/ZipkinAutoConfigurationTests.java[tags=override_default_beans,indent=0]
+@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);
+ }
+
+ }
+
+}
diff --git a/reference/html/index.html b/reference/html/index.html
index 60af4bd9c..ee57a28be 100644
--- a/reference/html/index.html
+++ b/reference/html/index.html
@@ -762,7 +762,9 @@ In extreme cases, too much baggage can crash the application, due to exceeding t
-Unresolved directive in intro.adoc - include::https://raw.githubusercontent.com/spring-cloud/spring-cloud-sleuth/origin/master/spring-cloud-sleuth-core/src/test/java/org/springframework/cloud/sleuth/instrument/multiple/MultipleHopsIntegrationTests.java[tags=baggage,indent=0]
+Span initialSpan = this.tracer.nextSpan().name("span").start();
+ExtraFieldPropagation.set(initialSpan.context(), "foo", "bar");
+ExtraFieldPropagation.set(initialSpan.context(), "UPPER_CASE", "someValue");
@@ -809,13 +811,22 @@ The span must be in scope.
The setup
-Unresolved directive in intro.adoc - include::https://raw.githubusercontent.com/spring-cloud/spring-cloud-sleuth/origin/master/spring-cloud-sleuth-core/src/test/resources/application-baggage.yml[indent=0]
+spring.sleuth:
+ baggage-keys:
+ - baz
+ - bizarrecase
+ propagation-keys:
+ - foo
+ - upper_case
The code
-Unresolved directive in intro.adoc - include::https://raw.githubusercontent.com/spring-cloud/spring-cloud-sleuth/origin/master/spring-cloud-sleuth-core/src/test/java/org/springframework/cloud/sleuth/instrument/multiple/MultipleHopsIntegrationTests.java[tags=baggage_tag,indent=0]
+initialSpan.tag("foo",
+ ExtraFieldPropagation.get(initialSpan.context(), "foo"));
+initialSpan.tag("UPPER_CASE",
+ ExtraFieldPropagation.get(initialSpan.context(), "UPPER_CASE"));
@@ -1097,7 +1108,51 @@ To do this you can use respectively ZipkinAutoConfiguration.REPORTER_BEAN_
-Unresolved directive in intro.adoc - include::https://raw.githubusercontent.com/spring-cloud/spring-cloud-sleuth/origin/master/spring-cloud-sleuth-zipkin/src/test/java/org/springframework/cloud/sleuth/zipkin2/ZipkinAutoConfigurationTests.java[tags=override_default_beans,indent=0]
+@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);
+ }
+
+ }
+
+}
@@ -1656,7 +1711,10 @@ You can configure the rate limit by setting spring.sleuth.sampler.rate
-Unresolved directive in index.adoc - include::https://raw.githubusercontent.com/spring-cloud/spring-cloud-sleuth/origin/master/spring-cloud-sleuth-core/src/test/java/org/springframework/cloud/sleuth/documentation/SpringCloudSleuthDocTests.java[tags=always_sampler,indent=0]
+@Bean
+public Sampler defaultSampler() {
+ return Sampler.ALWAYS_SAMPLE;
+}
@@ -2091,7 +2149,22 @@ Spring Cloud Sleuth creates an instance of Tracer for you. In order
-Unresolved directive in index.adoc - include::https://raw.githubusercontent.com/spring-cloud/spring-cloud-sleuth/origin/master/spring-cloud-sleuth-core/src/test/java/org/springframework/cloud/sleuth/documentation/SpringCloudSleuthDocTests.java[tags=manual_span_creation,indent=0]
+// Start a span. If there was a span present in this thread it will become
+// the `newSpan`'s parent.
+Span newSpan = this.tracer.nextSpan().name("calculateTax");
+try (Tracer.SpanInScope ws = this.tracer.withSpanInScope(newSpan.start())) {
+ // ...
+ // You can tag a span
+ newSpan.tag("taxValue", taxValue);
+ // ...
+ // You can log an event on a span
+ newSpan.annotate("taxCalculated");
+}
+finally {
+ // Once done remember to finish the span. This will allow collecting
+ // the span to send it to Zipkin
+ newSpan.finish();
+}
@@ -2146,7 +2219,22 @@ It is in fact merely a technical implementation detail that you would not necess
-Unresolved directive in index.adoc - include::https://raw.githubusercontent.com/spring-cloud/spring-cloud-sleuth/origin/master/spring-cloud-sleuth-core/src/test/java/org/springframework/cloud/sleuth/documentation/SpringCloudSleuthDocTests.java[tags=manual_span_continuation,indent=0]
+// let's assume that we're in a thread Y and we've received
+// the `initialSpan` from thread X
+Span continuedSpan = this.tracer.toSpan(newSpan.context());
+try {
+ // ...
+ // You can tag a span
+ continuedSpan.tag("taxValue", taxValue);
+ // ...
+ // You can log an event on a span
+ continuedSpan.annotate("taxCalculated");
+}
+finally {
+ // Once done remember to flush the span. That means that
+ // it will get reported but the span itself is not yet finished
+ continuedSpan.flush();
+}
@@ -2160,7 +2248,27 @@ You can put the span in scope and then call nextSpan(), as shown in
-Unresolved directive in index.adoc - include::https://raw.githubusercontent.com/spring-cloud/spring-cloud-sleuth/origin/master/spring-cloud-sleuth-core/src/test/java/org/springframework/cloud/sleuth/documentation/SpringCloudSleuthDocTests.java[tags=manual_span_joining,indent=0]
+// let's assume that we're in a thread Y and we've received
+// the `initialSpan` from thread X. `initialSpan` will be the parent
+// of the `newSpan`
+Span newSpan = null;
+try (Tracer.SpanInScope ws = this.tracer.withSpanInScope(initialSpan)) {
+ newSpan = this.tracer.nextSpan().name("calculateCommission");
+ // ...
+ // You can tag a span
+ newSpan.tag("commissionValue", commissionValue);
+ // ...
+ // You can log an event on a span
+ newSpan.annotate("commissionCalculated");
+}
+finally {
+ // Once done remember to finish the span. This will allow collecting
+ // the span to send it to Zipkin. The tags and events set on the
+ // newSpan will not be present on the parent
+ if (newSpan != null) {
+ newSpan.finish();
+ }
+}
@@ -2211,7 +2319,17 @@ The name should be low cardinality, so it should not include identifiers.
-Unresolved directive in index.adoc - include::https://raw.githubusercontent.com/spring-cloud/spring-cloud-sleuth/origin/master/spring-cloud-sleuth-core/src/test/java/org/springframework/cloud/sleuth/documentation/SpringCloudSleuthDocTests.java[tags=span_name_annotation,indent=0]
+ @SpanName("calculateTax")
+ class TaxCountingRunnable implements Runnable {
+
+ @Override
+ public void run() {
+ // perform logic
+ }
+
+ }
+
+}
@@ -2219,7 +2337,11 @@ The name should be low cardinality, so it should not include identifiers.
-Unresolved directive in index.adoc - include::https://raw.githubusercontent.com/spring-cloud/spring-cloud-sleuth/origin/master/spring-cloud-sleuth-core/src/test/java/org/springframework/cloud/sleuth/documentation/SpringCloudSleuthDocTests.java[tags=span_name_annotated_runnable_execution,indent=0]
+Runnable runnable = new TraceRunnable(this.tracing, spanNamer,
+ new TaxCountingRunnable());
+Future<?> future = executorService.submit(runnable);
+// ... some additional logic ...
+future.get();
@@ -2236,7 +2358,20 @@ To overcome that limitation, if there is no @SpanName annotation pr
-Unresolved directive in index.adoc - include::https://raw.githubusercontent.com/spring-cloud/spring-cloud-sleuth/origin/master/spring-cloud-sleuth-core/src/test/java/org/springframework/cloud/sleuth/documentation/SpringCloudSleuthDocTests.java[tags=span_name_to_string_runnable_execution,indent=0]
+Runnable runnable = new TraceRunnable(this.tracing, spanNamer, new Runnable() {
+ @Override
+ public void run() {
+ // perform logic
+ }
+
+ @Override
+ public String toString() {
+ return "calculateTax";
+ }
+});
+Future<?> future = executorService.submit(runnable);
+// ... some additional logic ...
+future.get();
@@ -2282,7 +2417,8 @@ Also, we provide the @SpanTag annotation to add tags in an automate
-Unresolved directive in index.adoc - include::https://raw.githubusercontent.com/spring-cloud/spring-cloud-sleuth/origin/master/spring-cloud-sleuth-core/src/test/java/org/springframework/cloud/sleuth/annotation/SleuthSpanCreatorAspectTests.java[tags=annotated_method,indent=0]
+@NewSpan
+void testMethod();
@@ -2290,7 +2426,8 @@ Also, we provide the @SpanTag annotation to add tags in an automate
-Unresolved directive in index.adoc - include::https://raw.githubusercontent.com/spring-cloud/spring-cloud-sleuth/origin/master/spring-cloud-sleuth-core/src/test/java/org/springframework/cloud/sleuth/annotation/SleuthSpanCreatorAspectTests.java[tags=custom_name_on_annotated_method,indent=0]
+@NewSpan("customNameOnTestMethod4")
+void testMethod4();
@@ -2299,10 +2436,11 @@ Also, we provide the @SpanTag annotation to add tags in an automate
// method declaration
-Unresolved directive in index.adoc - include::https://raw.githubusercontent.com/spring-cloud/spring-cloud-sleuth/origin/master/spring-cloud-sleuth-core/src/test/java/org/springframework/cloud/sleuth/annotation/SleuthSpanCreatorAspectTests.java[tags=custom_name_and_tag_on_annotated_method,indent=0]
+@NewSpan(name = "customNameOnTestMethod5")
+void testMethod5(@SpanTag("testTag") String param);
// and method execution
-Unresolved directive in index.adoc - include::https://raw.githubusercontent.com/spring-cloud/spring-cloud-sleuth/origin/master/spring-cloud-sleuth-core/src/test/java/org/springframework/cloud/sleuth/annotation/SleuthSpanCreatorAspectTests.java[tags=execution,indent=0]
+this.testBean.testMethod5("test");
@@ -2312,7 +2450,10 @@ In our sample, the tag key is testTag, and the tag value is t
-Unresolved directive in index.adoc - include::https://raw.githubusercontent.com/spring-cloud/spring-cloud-sleuth/origin/master/spring-cloud-sleuth-core/src/test/java/org/springframework/cloud/sleuth/annotation/SleuthSpanCreatorAspectTests.java[tags=name_on_implementation,indent=0]
+@NewSpan(name = "customNameOnTestMethod3")
+@Override
+public void testMethod3() {
+}
@@ -2329,10 +2470,12 @@ concrete one wins (in this case customNameOnTestMethod3 is set).
// method declaration
-Unresolved directive in index.adoc - include::https://raw.githubusercontent.com/spring-cloud/spring-cloud-sleuth/origin/master/spring-cloud-sleuth-core/src/test/java/org/springframework/cloud/sleuth/annotation/SleuthSpanCreatorAspectTests.java[tags=continue_span,indent=0]
+@ContinueSpan(log = "testMethod11")
+void testMethod11(@SpanTag("testTag11") String param);
// method execution
-Unresolved directive in index.adoc - include::https://raw.githubusercontent.com/spring-cloud/spring-cloud-sleuth/origin/master/spring-cloud-sleuth-core/src/test/java/org/springframework/cloud/sleuth/annotation/SleuthSpanCreatorAspectTests.java[tags=continue_span_execution,indent=0]
+this.testBean.testMethod11("test");
+this.testBean.testMethod13();
@@ -2388,7 +2531,10 @@ Its class name has to be passed as the value of the resolver attrib
-Unresolved directive in index.adoc - include::https://raw.githubusercontent.com/spring-cloud/spring-cloud-sleuth/origin/master/spring-cloud-sleuth-core/src/test/java/org/springframework/cloud/sleuth/annotation/SpanTagAnnotationHandlerTests.java[tags=resolver_bean,indent=0]
+@NewSpan
+public void getAnnotationForTagValueResolver(
+ @SpanTag(key = "test", resolver = TagValueResolver.class) String test) {
+}
@@ -2396,7 +2542,10 @@ Its class name has to be passed as the value of the resolver attrib
-Unresolved directive in index.adoc - include::https://raw.githubusercontent.com/spring-cloud/spring-cloud-sleuth/origin/master/spring-cloud-sleuth-core/src/test/java/org/springframework/cloud/sleuth/annotation/SpanTagAnnotationHandlerTests.java[tags=custom_resolver,indent=0]
+@Bean(name = "myCustomTagValueResolver")
+public TagValueResolver tagValueResolver() {
+ return parameter -> "Value from myCustomTagValueResolver";
+}
@@ -2410,7 +2559,10 @@ Its class name has to be passed as the value of the resolver attrib
-Unresolved directive in index.adoc - include::https://raw.githubusercontent.com/spring-cloud/spring-cloud-sleuth/origin/master/spring-cloud-sleuth-core/src/test/java/org/springframework/cloud/sleuth/annotation/SpanTagAnnotationHandlerTests.java[tags=spel,indent=0]
+@NewSpan
+public void getAnnotationForTagValueExpression(@SpanTag(key = "test",
+ expression = "'hello' + ' characters'") String test) {
+}
@@ -2425,7 +2577,9 @@ If you want to use some other expression resolution mechanism, you can create yo
-Unresolved directive in index.adoc - include::https://raw.githubusercontent.com/spring-cloud/spring-cloud-sleuth/origin/master/spring-cloud-sleuth-core/src/test/java/org/springframework/cloud/sleuth/annotation/SpanTagAnnotationHandlerTests.java[tags=toString,indent=0]
+@NewSpan
+public void getAnnotationForArgumentToString(@SpanTag("test") Long param) {
+}
@@ -2463,7 +2617,22 @@ an example of usage of SkipPatternProvider inside a server side,
@Configuration
class Config {
-Unresolved directive in index.adoc - include::https://raw.githubusercontent.com/spring-cloud/spring-cloud-sleuth/origin/master/tests/spring-cloud-sleuth-instrumentation-mvc-tests/src/test/java/org/springframework/cloud/sleuth/instrument/web/TraceFilterWebIntegrationTests.java[tags=custom_server_sampler,indent=2]
+ @Bean(name = ServerSampler.NAME)
+ HttpSampler myHttpSampler(SkipPatternProvider provider) {
+ Pattern pattern = provider.skipPattern();
+ return new HttpSampler() {
+
+ @Override
+ public <Req> Boolean trySample(HttpAdapter<Req, ?> adapter, Req request) {
+ String url = adapter.path(request);
+ boolean shouldSkip = pattern.matcher(url).matches();
+ if (shouldSkip) {
+ return false;
+ }
+ return null;
+ }
+ };
+ }
}
@@ -2479,7 +2648,33 @@ You can customize the tags or modify the response headers by registering your ow
-Unresolved directive in index.adoc - include::https://raw.githubusercontent.com/spring-cloud/spring-cloud-sleuth/origin/master/tests/spring-cloud-sleuth-instrumentation-mvc-tests/src/test/java/org/springframework/cloud/sleuth/instrument/web/TraceFilterIntegrationTests.java[tags=response_headers,indent=0]
+@Component
+@Order(TraceWebServletAutoConfiguration.TRACING_FILTER_ORDER + 1)
+class MyFilter extends GenericFilterBean {
+
+ private final Tracer tracer;
+
+ MyFilter(Tracer tracer) {
+ this.tracer = tracer;
+ }
+
+ @Override
+ public void doFilter(ServletRequest request, ServletResponse response,
+ FilterChain chain) throws IOException, ServletException {
+ Span currentSpan = this.tracer.currentSpan();
+ if (currentSpan == null) {
+ chain.doFilter(request, response);
+ return;
+ }
+ // for readability we're returning trace id in a hex form
+ ((HttpServletResponse) response).addHeader("ZIPKIN-TRACE-ID",
+ currentSpan.context().traceIdString());
+ // we can also add some custom tags
+ currentSpan.tag("custom", "tag");
+ chain.doFilter(request, response);
+ }
+
+}
@@ -2513,7 +2708,27 @@ You can implement the FinishedSpanHandler interface to alter that n
-Unresolved directive in index.adoc - include::https://raw.githubusercontent.com/spring-cloud/spring-cloud-sleuth/origin/master//spring-cloud-sleuth-core/src/test/java/org/springframework/cloud/sleuth/FinishedSpanHandlerTests.java[tags=finishedSpanHandler,indent=0]
+@Bean
+FinishedSpanHandler handlerOne() {
+ return new FinishedSpanHandler() {
+ @Override
+ public boolean handle(TraceContext traceContext, MutableSpan span) {
+ span.name("foo");
+ return true; // keep this span
+ }
+ };
+}
+
+@Bean
+FinishedSpanHandler handlerTwo() {
+ return new FinishedSpanHandler() {
+ @Override
+ public boolean handle(TraceContext traceContext, MutableSpan span) {
+ span.name(span.name() + " bar");
+ return true; // keep this span
+ }
+ };
+}
@@ -2672,7 +2887,24 @@ If you wish to disable this, set spring.sleuth.opentracing.enabled
-Unresolved directive in index.adoc - include::https://raw.githubusercontent.com/spring-cloud/spring-cloud-sleuth/origin/master/spring-cloud-sleuth-core/src/test/java/org/springframework/cloud/sleuth/documentation/SpringCloudSleuthDocTests.java[tags=trace_runnable,indent=0]
+Runnable runnable = new Runnable() {
+ @Override
+ public void run() {
+ // do some work
+ }
+
+ @Override
+ public String toString() {
+ return "spanNameFromToStringMethod";
+ }
+};
+// Manual `TraceRunnable` creation with explicit "calculateTax" Span name
+Runnable traceRunnable = new TraceRunnable(this.tracing, spanNamer, runnable,
+ "calculateTax");
+// Wrapping `Runnable` with `Tracing`. That way the current span will be available
+// in the thread of `Runnable`
+Runnable traceRunnableFromTracer = this.tracing.currentTraceContext()
+ .wrap(runnable);
@@ -2680,7 +2912,24 @@ If you wish to disable this, set spring.sleuth.opentracing.enabled
-Unresolved directive in index.adoc - include::https://raw.githubusercontent.com/spring-cloud/spring-cloud-sleuth/origin/master/spring-cloud-sleuth-core/src/test/java/org/springframework/cloud/sleuth/documentation/SpringCloudSleuthDocTests.java[tags=trace_callable,indent=0]
+Callable<String> callable = new Callable<String>() {
+ @Override
+ public String call() throws Exception {
+ return someLogic();
+ }
+
+ @Override
+ public String toString() {
+ return "spanNameFromToStringMethod";
+ }
+};
+// Manual `TraceCallable` creation with explicit "calculateTax" Span name
+Callable<String> traceCallable = new TraceCallable<>(this.tracing, spanNamer,
+ callable, "calculateTax");
+// Wrapping `Callable` with `Tracing`. That way the current span will be available
+// in the thread of `Callable`
+Callable<String> traceCallableFromTracer = this.tracing.currentTraceContext()
+ .wrap(callable);
@@ -2704,7 +2953,12 @@ To disable the custom Hystrix Concurrency Strategy, set the spring.sleuth.
-Unresolved directive in index.adoc - include::https://raw.githubusercontent.com/spring-cloud/spring-cloud-sleuth/origin/master/spring-cloud-sleuth-core/src/test/java/org/springframework/cloud/sleuth/instrument/hystrix/TraceCommandTests.java[tags=hystrix_command,indent=0]
+HystrixCommand<String> hystrixCommand = new HystrixCommand<String>(setter) {
+ @Override
+ protected String run() throws Exception {
+ return someLogic();
+ }
+};
@@ -2713,7 +2967,12 @@ To disable the custom Hystrix Concurrency Strategy, set the spring.sleuth.
-Unresolved directive in index.adoc - include::https://raw.githubusercontent.com/spring-cloud/spring-cloud-sleuth/origin/master/spring-cloud-sleuth-core/src/test/java/org/springframework/cloud/sleuth/instrument/hystrix/TraceCommandTests.java[tags=trace_hystrix_command,indent=0]
+TraceCommand<String> traceCommand = new TraceCommand<String>(tracer, setter) {
+ @Override
+ public String doRun() throws Exception {
+ return someLogic();
+ }
+};
@@ -2886,7 +3145,29 @@ In the following snippet, you can see an example of how to set up such a custom
-Unresolved directive in index.adoc - include::https://raw.githubusercontent.com/spring-cloud/spring-cloud-sleuth/origin/master/spring-cloud-sleuth-core/src/test/java/org/springframework/cloud/sleuth/instrument/web/client/MultipleAsyncRestTemplateTests.java[tags=custom_async_rest_template,indent=0]
+@Configuration
+@EnableAutoConfiguration
+static class Config {
+
+ @Bean(name = "customAsyncRestTemplate")
+ public AsyncRestTemplate traceAsyncRestTemplate() {
+ return new AsyncRestTemplate(asyncClientFactory(),
+ clientHttpRequestFactory());
+ }
+
+ private ClientHttpRequestFactory clientHttpRequestFactory() {
+ ClientHttpRequestFactory clientHttpRequestFactory = new CustomClientHttpRequestFactory();
+ // CUSTOMIZE HERE
+ return clientHttpRequestFactory;
+ }
+
+ private AsyncClientHttpRequestFactory asyncClientFactory() {
+ AsyncClientHttpRequestFactory factory = new CustomAsyncClientHttpRequestFactory();
+ // CUSTOMIZE HERE
+ return factory;
+ }
+
+}
@@ -3127,7 +3408,12 @@ This behavior may be annoying. That’s why, by default, spring.sleuth
-Unresolved directive in index.adoc - include::https://raw.githubusercontent.com/spring-cloud/spring-cloud-sleuth/origin/master/spring-cloud-sleuth-core/src/test/java/org/springframework/cloud/sleuth/instrument/async/TraceableExecutorServiceTests.java[tags=completablefuture,indent=0]
+CompletableFuture<Long> completableFuture = CompletableFuture.supplyAsync(() -> {
+ // perform some logic
+ return 1_000_000L;
+}, new TraceableExecutorService(beanFactory, executorService,
+ // 'calculateTax' explicitly names the span - this param is optional
+ "calculateTax"));
@@ -3156,7 +3442,30 @@ The following example shows how to set up such a custom Executor:
-Unresolved directive in index.adoc - include::https://raw.githubusercontent.com/spring-cloud/spring-cloud-sleuth/origin/master/spring-cloud-sleuth-core/src/test/java/org/springframework/cloud/sleuth/instrument/web/client/MultipleAsyncRestTemplateTests.java[tags=custom_executor,indent=0]
+@Configuration
+@EnableAutoConfiguration
+@EnableAsync
+// add the infrastructure role to ensure that the bean gets auto-proxied
+@Role(BeanDefinition.ROLE_INFRASTRUCTURE)
+static class CustomExecutorConfig extends AsyncConfigurerSupport {
+
+ @Autowired
+ BeanFactory beanFactory;
+
+ @Override
+ public Executor getAsyncExecutor() {
+ ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
+ // CUSTOMIZE HERE
+ executor.setCorePoolSize(7);
+ executor.setMaxPoolSize(42);
+ executor.setQueueCapacity(11);
+ executor.setThreadNamePrefix("MyExecutor-");
+ // DON'T FORGET TO INITIALIZE
+ executor.initialize();
+ return new LazyTraceExecutor(this.beanFactory, executor);
+ }
+
+}
diff --git a/reference/html/intro.html b/reference/html/intro.html
index 3d3a90124..d49b6878f 100644
--- a/reference/html/intro.html
+++ b/reference/html/intro.html
@@ -573,7 +573,9 @@ In extreme cases, too much baggage can crash the application, due to exceeding t
-Unresolved directive in intro.adoc - include::https://raw.githubusercontent.com/spring-cloud/spring-cloud-sleuth/origin/master/spring-cloud-sleuth-core/src/test/java/org/springframework/cloud/sleuth/instrument/multiple/MultipleHopsIntegrationTests.java[tags=baggage,indent=0]
+Span initialSpan = this.tracer.nextSpan().name("span").start();
+ExtraFieldPropagation.set(initialSpan.context(), "foo", "bar");
+ExtraFieldPropagation.set(initialSpan.context(), "UPPER_CASE", "someValue");
@@ -620,13 +622,22 @@ The span must be in scope.
The setup
-Unresolved directive in intro.adoc - include::https://raw.githubusercontent.com/spring-cloud/spring-cloud-sleuth/origin/master/spring-cloud-sleuth-core/src/test/resources/application-baggage.yml[indent=0]
+spring.sleuth:
+ baggage-keys:
+ - baz
+ - bizarrecase
+ propagation-keys:
+ - foo
+ - upper_case
The code
-Unresolved directive in intro.adoc - include::https://raw.githubusercontent.com/spring-cloud/spring-cloud-sleuth/origin/master/spring-cloud-sleuth-core/src/test/java/org/springframework/cloud/sleuth/instrument/multiple/MultipleHopsIntegrationTests.java[tags=baggage_tag,indent=0]
+initialSpan.tag("foo",
+ ExtraFieldPropagation.get(initialSpan.context(), "foo"));
+initialSpan.tag("UPPER_CASE",
+ ExtraFieldPropagation.get(initialSpan.context(), "UPPER_CASE"));
@@ -908,7 +919,51 @@ To do this you can use respectively ZipkinAutoConfiguration.REPORTER_BEAN_
-Unresolved directive in intro.adoc - include::https://raw.githubusercontent.com/spring-cloud/spring-cloud-sleuth/origin/master/spring-cloud-sleuth-zipkin/src/test/java/org/springframework/cloud/sleuth/zipkin2/ZipkinAutoConfigurationTests.java[tags=override_default_beans,indent=0]
+@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);
+ }
+
+ }
+
+}
diff --git a/reference/html/spring-cloud-sleuth.html b/reference/html/spring-cloud-sleuth.html
index cf19e30cc..ee57a28be 100644
--- a/reference/html/spring-cloud-sleuth.html
+++ b/reference/html/spring-cloud-sleuth.html
@@ -762,7 +762,9 @@ In extreme cases, too much baggage can crash the application, due to exceeding t
-Unresolved directive in intro.adoc - include::https://raw.githubusercontent.com/spring-cloud/spring-cloud-sleuth/origin/master/spring-cloud-sleuth-core/src/test/java/org/springframework/cloud/sleuth/instrument/multiple/MultipleHopsIntegrationTests.java[tags=baggage,indent=0]
+Span initialSpan = this.tracer.nextSpan().name("span").start();
+ExtraFieldPropagation.set(initialSpan.context(), "foo", "bar");
+ExtraFieldPropagation.set(initialSpan.context(), "UPPER_CASE", "someValue");
@@ -809,13 +811,22 @@ The span must be in scope.
The setup
-Unresolved directive in intro.adoc - include::https://raw.githubusercontent.com/spring-cloud/spring-cloud-sleuth/origin/master/spring-cloud-sleuth-core/src/test/resources/application-baggage.yml[indent=0]
+spring.sleuth:
+ baggage-keys:
+ - baz
+ - bizarrecase
+ propagation-keys:
+ - foo
+ - upper_case
The code
-Unresolved directive in intro.adoc - include::https://raw.githubusercontent.com/spring-cloud/spring-cloud-sleuth/origin/master/spring-cloud-sleuth-core/src/test/java/org/springframework/cloud/sleuth/instrument/multiple/MultipleHopsIntegrationTests.java[tags=baggage_tag,indent=0]
+initialSpan.tag("foo",
+ ExtraFieldPropagation.get(initialSpan.context(), "foo"));
+initialSpan.tag("UPPER_CASE",
+ ExtraFieldPropagation.get(initialSpan.context(), "UPPER_CASE"));
@@ -1097,7 +1108,51 @@ To do this you can use respectively ZipkinAutoConfiguration.REPORTER_BEAN_
-Unresolved directive in intro.adoc - include::https://raw.githubusercontent.com/spring-cloud/spring-cloud-sleuth/origin/master/spring-cloud-sleuth-zipkin/src/test/java/org/springframework/cloud/sleuth/zipkin2/ZipkinAutoConfigurationTests.java[tags=override_default_beans,indent=0]
+@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);
+ }
+
+ }
+
+}
@@ -1656,7 +1711,10 @@ You can configure the rate limit by setting spring.sleuth.sampler.rate
-Unresolved directive in spring-cloud-sleuth.adoc - include::https://raw.githubusercontent.com/spring-cloud/spring-cloud-sleuth/origin/master/spring-cloud-sleuth-core/src/test/java/org/springframework/cloud/sleuth/documentation/SpringCloudSleuthDocTests.java[tags=always_sampler,indent=0]
+@Bean
+public Sampler defaultSampler() {
+ return Sampler.ALWAYS_SAMPLE;
+}
@@ -2091,7 +2149,22 @@ Spring Cloud Sleuth creates an instance of Tracer for you. In order
-Unresolved directive in spring-cloud-sleuth.adoc - include::https://raw.githubusercontent.com/spring-cloud/spring-cloud-sleuth/origin/master/spring-cloud-sleuth-core/src/test/java/org/springframework/cloud/sleuth/documentation/SpringCloudSleuthDocTests.java[tags=manual_span_creation,indent=0]
+// Start a span. If there was a span present in this thread it will become
+// the `newSpan`'s parent.
+Span newSpan = this.tracer.nextSpan().name("calculateTax");
+try (Tracer.SpanInScope ws = this.tracer.withSpanInScope(newSpan.start())) {
+ // ...
+ // You can tag a span
+ newSpan.tag("taxValue", taxValue);
+ // ...
+ // You can log an event on a span
+ newSpan.annotate("taxCalculated");
+}
+finally {
+ // Once done remember to finish the span. This will allow collecting
+ // the span to send it to Zipkin
+ newSpan.finish();
+}
@@ -2146,7 +2219,22 @@ It is in fact merely a technical implementation detail that you would not necess
-Unresolved directive in spring-cloud-sleuth.adoc - include::https://raw.githubusercontent.com/spring-cloud/spring-cloud-sleuth/origin/master/spring-cloud-sleuth-core/src/test/java/org/springframework/cloud/sleuth/documentation/SpringCloudSleuthDocTests.java[tags=manual_span_continuation,indent=0]
+// let's assume that we're in a thread Y and we've received
+// the `initialSpan` from thread X
+Span continuedSpan = this.tracer.toSpan(newSpan.context());
+try {
+ // ...
+ // You can tag a span
+ continuedSpan.tag("taxValue", taxValue);
+ // ...
+ // You can log an event on a span
+ continuedSpan.annotate("taxCalculated");
+}
+finally {
+ // Once done remember to flush the span. That means that
+ // it will get reported but the span itself is not yet finished
+ continuedSpan.flush();
+}
@@ -2160,7 +2248,27 @@ You can put the span in scope and then call nextSpan(), as shown in
-Unresolved directive in spring-cloud-sleuth.adoc - include::https://raw.githubusercontent.com/spring-cloud/spring-cloud-sleuth/origin/master/spring-cloud-sleuth-core/src/test/java/org/springframework/cloud/sleuth/documentation/SpringCloudSleuthDocTests.java[tags=manual_span_joining,indent=0]
+// let's assume that we're in a thread Y and we've received
+// the `initialSpan` from thread X. `initialSpan` will be the parent
+// of the `newSpan`
+Span newSpan = null;
+try (Tracer.SpanInScope ws = this.tracer.withSpanInScope(initialSpan)) {
+ newSpan = this.tracer.nextSpan().name("calculateCommission");
+ // ...
+ // You can tag a span
+ newSpan.tag("commissionValue", commissionValue);
+ // ...
+ // You can log an event on a span
+ newSpan.annotate("commissionCalculated");
+}
+finally {
+ // Once done remember to finish the span. This will allow collecting
+ // the span to send it to Zipkin. The tags and events set on the
+ // newSpan will not be present on the parent
+ if (newSpan != null) {
+ newSpan.finish();
+ }
+}
@@ -2211,7 +2319,17 @@ The name should be low cardinality, so it should not include identifiers.
-Unresolved directive in spring-cloud-sleuth.adoc - include::https://raw.githubusercontent.com/spring-cloud/spring-cloud-sleuth/origin/master/spring-cloud-sleuth-core/src/test/java/org/springframework/cloud/sleuth/documentation/SpringCloudSleuthDocTests.java[tags=span_name_annotation,indent=0]
+ @SpanName("calculateTax")
+ class TaxCountingRunnable implements Runnable {
+
+ @Override
+ public void run() {
+ // perform logic
+ }
+
+ }
+
+}
@@ -2219,7 +2337,11 @@ The name should be low cardinality, so it should not include identifiers.
-Unresolved directive in spring-cloud-sleuth.adoc - include::https://raw.githubusercontent.com/spring-cloud/spring-cloud-sleuth/origin/master/spring-cloud-sleuth-core/src/test/java/org/springframework/cloud/sleuth/documentation/SpringCloudSleuthDocTests.java[tags=span_name_annotated_runnable_execution,indent=0]
+Runnable runnable = new TraceRunnable(this.tracing, spanNamer,
+ new TaxCountingRunnable());
+Future<?> future = executorService.submit(runnable);
+// ... some additional logic ...
+future.get();
@@ -2236,7 +2358,20 @@ To overcome that limitation, if there is no @SpanName annotation pr
-Unresolved directive in spring-cloud-sleuth.adoc - include::https://raw.githubusercontent.com/spring-cloud/spring-cloud-sleuth/origin/master/spring-cloud-sleuth-core/src/test/java/org/springframework/cloud/sleuth/documentation/SpringCloudSleuthDocTests.java[tags=span_name_to_string_runnable_execution,indent=0]
+Runnable runnable = new TraceRunnable(this.tracing, spanNamer, new Runnable() {
+ @Override
+ public void run() {
+ // perform logic
+ }
+
+ @Override
+ public String toString() {
+ return "calculateTax";
+ }
+});
+Future<?> future = executorService.submit(runnable);
+// ... some additional logic ...
+future.get();
@@ -2282,7 +2417,8 @@ Also, we provide the @SpanTag annotation to add tags in an automate
-Unresolved directive in spring-cloud-sleuth.adoc - include::https://raw.githubusercontent.com/spring-cloud/spring-cloud-sleuth/origin/master/spring-cloud-sleuth-core/src/test/java/org/springframework/cloud/sleuth/annotation/SleuthSpanCreatorAspectTests.java[tags=annotated_method,indent=0]
+@NewSpan
+void testMethod();
@@ -2290,7 +2426,8 @@ Also, we provide the @SpanTag annotation to add tags in an automate
-Unresolved directive in spring-cloud-sleuth.adoc - include::https://raw.githubusercontent.com/spring-cloud/spring-cloud-sleuth/origin/master/spring-cloud-sleuth-core/src/test/java/org/springframework/cloud/sleuth/annotation/SleuthSpanCreatorAspectTests.java[tags=custom_name_on_annotated_method,indent=0]
+@NewSpan("customNameOnTestMethod4")
+void testMethod4();
@@ -2299,10 +2436,11 @@ Also, we provide the @SpanTag annotation to add tags in an automate
// method declaration
-Unresolved directive in spring-cloud-sleuth.adoc - include::https://raw.githubusercontent.com/spring-cloud/spring-cloud-sleuth/origin/master/spring-cloud-sleuth-core/src/test/java/org/springframework/cloud/sleuth/annotation/SleuthSpanCreatorAspectTests.java[tags=custom_name_and_tag_on_annotated_method,indent=0]
+@NewSpan(name = "customNameOnTestMethod5")
+void testMethod5(@SpanTag("testTag") String param);
// and method execution
-Unresolved directive in spring-cloud-sleuth.adoc - include::https://raw.githubusercontent.com/spring-cloud/spring-cloud-sleuth/origin/master/spring-cloud-sleuth-core/src/test/java/org/springframework/cloud/sleuth/annotation/SleuthSpanCreatorAspectTests.java[tags=execution,indent=0]
+this.testBean.testMethod5("test");
@@ -2312,7 +2450,10 @@ In our sample, the tag key is testTag, and the tag value is t
-Unresolved directive in spring-cloud-sleuth.adoc - include::https://raw.githubusercontent.com/spring-cloud/spring-cloud-sleuth/origin/master/spring-cloud-sleuth-core/src/test/java/org/springframework/cloud/sleuth/annotation/SleuthSpanCreatorAspectTests.java[tags=name_on_implementation,indent=0]
+@NewSpan(name = "customNameOnTestMethod3")
+@Override
+public void testMethod3() {
+}
@@ -2329,10 +2470,12 @@ concrete one wins (in this case customNameOnTestMethod3 is set).
// method declaration
-Unresolved directive in spring-cloud-sleuth.adoc - include::https://raw.githubusercontent.com/spring-cloud/spring-cloud-sleuth/origin/master/spring-cloud-sleuth-core/src/test/java/org/springframework/cloud/sleuth/annotation/SleuthSpanCreatorAspectTests.java[tags=continue_span,indent=0]
+@ContinueSpan(log = "testMethod11")
+void testMethod11(@SpanTag("testTag11") String param);
// method execution
-Unresolved directive in spring-cloud-sleuth.adoc - include::https://raw.githubusercontent.com/spring-cloud/spring-cloud-sleuth/origin/master/spring-cloud-sleuth-core/src/test/java/org/springframework/cloud/sleuth/annotation/SleuthSpanCreatorAspectTests.java[tags=continue_span_execution,indent=0]
+this.testBean.testMethod11("test");
+this.testBean.testMethod13();
@@ -2388,7 +2531,10 @@ Its class name has to be passed as the value of the resolver attrib
-Unresolved directive in spring-cloud-sleuth.adoc - include::https://raw.githubusercontent.com/spring-cloud/spring-cloud-sleuth/origin/master/spring-cloud-sleuth-core/src/test/java/org/springframework/cloud/sleuth/annotation/SpanTagAnnotationHandlerTests.java[tags=resolver_bean,indent=0]
+@NewSpan
+public void getAnnotationForTagValueResolver(
+ @SpanTag(key = "test", resolver = TagValueResolver.class) String test) {
+}
@@ -2396,7 +2542,10 @@ Its class name has to be passed as the value of the resolver attrib
-Unresolved directive in spring-cloud-sleuth.adoc - include::https://raw.githubusercontent.com/spring-cloud/spring-cloud-sleuth/origin/master/spring-cloud-sleuth-core/src/test/java/org/springframework/cloud/sleuth/annotation/SpanTagAnnotationHandlerTests.java[tags=custom_resolver,indent=0]
+@Bean(name = "myCustomTagValueResolver")
+public TagValueResolver tagValueResolver() {
+ return parameter -> "Value from myCustomTagValueResolver";
+}
@@ -2410,7 +2559,10 @@ Its class name has to be passed as the value of the resolver attrib
-Unresolved directive in spring-cloud-sleuth.adoc - include::https://raw.githubusercontent.com/spring-cloud/spring-cloud-sleuth/origin/master/spring-cloud-sleuth-core/src/test/java/org/springframework/cloud/sleuth/annotation/SpanTagAnnotationHandlerTests.java[tags=spel,indent=0]
+@NewSpan
+public void getAnnotationForTagValueExpression(@SpanTag(key = "test",
+ expression = "'hello' + ' characters'") String test) {
+}
@@ -2425,7 +2577,9 @@ If you want to use some other expression resolution mechanism, you can create yo
-Unresolved directive in spring-cloud-sleuth.adoc - include::https://raw.githubusercontent.com/spring-cloud/spring-cloud-sleuth/origin/master/spring-cloud-sleuth-core/src/test/java/org/springframework/cloud/sleuth/annotation/SpanTagAnnotationHandlerTests.java[tags=toString,indent=0]
+@NewSpan
+public void getAnnotationForArgumentToString(@SpanTag("test") Long param) {
+}
@@ -2463,7 +2617,22 @@ an example of usage of SkipPatternProvider inside a server side,
@Configuration
class Config {
-Unresolved directive in spring-cloud-sleuth.adoc - include::https://raw.githubusercontent.com/spring-cloud/spring-cloud-sleuth/origin/master/tests/spring-cloud-sleuth-instrumentation-mvc-tests/src/test/java/org/springframework/cloud/sleuth/instrument/web/TraceFilterWebIntegrationTests.java[tags=custom_server_sampler,indent=2]
+ @Bean(name = ServerSampler.NAME)
+ HttpSampler myHttpSampler(SkipPatternProvider provider) {
+ Pattern pattern = provider.skipPattern();
+ return new HttpSampler() {
+
+ @Override
+ public <Req> Boolean trySample(HttpAdapter<Req, ?> adapter, Req request) {
+ String url = adapter.path(request);
+ boolean shouldSkip = pattern.matcher(url).matches();
+ if (shouldSkip) {
+ return false;
+ }
+ return null;
+ }
+ };
+ }
}
@@ -2479,7 +2648,33 @@ You can customize the tags or modify the response headers by registering your ow
-Unresolved directive in spring-cloud-sleuth.adoc - include::https://raw.githubusercontent.com/spring-cloud/spring-cloud-sleuth/origin/master/tests/spring-cloud-sleuth-instrumentation-mvc-tests/src/test/java/org/springframework/cloud/sleuth/instrument/web/TraceFilterIntegrationTests.java[tags=response_headers,indent=0]
+@Component
+@Order(TraceWebServletAutoConfiguration.TRACING_FILTER_ORDER + 1)
+class MyFilter extends GenericFilterBean {
+
+ private final Tracer tracer;
+
+ MyFilter(Tracer tracer) {
+ this.tracer = tracer;
+ }
+
+ @Override
+ public void doFilter(ServletRequest request, ServletResponse response,
+ FilterChain chain) throws IOException, ServletException {
+ Span currentSpan = this.tracer.currentSpan();
+ if (currentSpan == null) {
+ chain.doFilter(request, response);
+ return;
+ }
+ // for readability we're returning trace id in a hex form
+ ((HttpServletResponse) response).addHeader("ZIPKIN-TRACE-ID",
+ currentSpan.context().traceIdString());
+ // we can also add some custom tags
+ currentSpan.tag("custom", "tag");
+ chain.doFilter(request, response);
+ }
+
+}
@@ -2513,7 +2708,27 @@ You can implement the FinishedSpanHandler interface to alter that n
-Unresolved directive in spring-cloud-sleuth.adoc - include::https://raw.githubusercontent.com/spring-cloud/spring-cloud-sleuth/origin/master//spring-cloud-sleuth-core/src/test/java/org/springframework/cloud/sleuth/FinishedSpanHandlerTests.java[tags=finishedSpanHandler,indent=0]
+@Bean
+FinishedSpanHandler handlerOne() {
+ return new FinishedSpanHandler() {
+ @Override
+ public boolean handle(TraceContext traceContext, MutableSpan span) {
+ span.name("foo");
+ return true; // keep this span
+ }
+ };
+}
+
+@Bean
+FinishedSpanHandler handlerTwo() {
+ return new FinishedSpanHandler() {
+ @Override
+ public boolean handle(TraceContext traceContext, MutableSpan span) {
+ span.name(span.name() + " bar");
+ return true; // keep this span
+ }
+ };
+}
@@ -2672,7 +2887,24 @@ If you wish to disable this, set spring.sleuth.opentracing.enabled
-Unresolved directive in spring-cloud-sleuth.adoc - include::https://raw.githubusercontent.com/spring-cloud/spring-cloud-sleuth/origin/master/spring-cloud-sleuth-core/src/test/java/org/springframework/cloud/sleuth/documentation/SpringCloudSleuthDocTests.java[tags=trace_runnable,indent=0]
+Runnable runnable = new Runnable() {
+ @Override
+ public void run() {
+ // do some work
+ }
+
+ @Override
+ public String toString() {
+ return "spanNameFromToStringMethod";
+ }
+};
+// Manual `TraceRunnable` creation with explicit "calculateTax" Span name
+Runnable traceRunnable = new TraceRunnable(this.tracing, spanNamer, runnable,
+ "calculateTax");
+// Wrapping `Runnable` with `Tracing`. That way the current span will be available
+// in the thread of `Runnable`
+Runnable traceRunnableFromTracer = this.tracing.currentTraceContext()
+ .wrap(runnable);
@@ -2680,7 +2912,24 @@ If you wish to disable this, set spring.sleuth.opentracing.enabled
-Unresolved directive in spring-cloud-sleuth.adoc - include::https://raw.githubusercontent.com/spring-cloud/spring-cloud-sleuth/origin/master/spring-cloud-sleuth-core/src/test/java/org/springframework/cloud/sleuth/documentation/SpringCloudSleuthDocTests.java[tags=trace_callable,indent=0]
+Callable<String> callable = new Callable<String>() {
+ @Override
+ public String call() throws Exception {
+ return someLogic();
+ }
+
+ @Override
+ public String toString() {
+ return "spanNameFromToStringMethod";
+ }
+};
+// Manual `TraceCallable` creation with explicit "calculateTax" Span name
+Callable<String> traceCallable = new TraceCallable<>(this.tracing, spanNamer,
+ callable, "calculateTax");
+// Wrapping `Callable` with `Tracing`. That way the current span will be available
+// in the thread of `Callable`
+Callable<String> traceCallableFromTracer = this.tracing.currentTraceContext()
+ .wrap(callable);
@@ -2704,7 +2953,12 @@ To disable the custom Hystrix Concurrency Strategy, set the spring.sleuth.
-Unresolved directive in spring-cloud-sleuth.adoc - include::https://raw.githubusercontent.com/spring-cloud/spring-cloud-sleuth/origin/master/spring-cloud-sleuth-core/src/test/java/org/springframework/cloud/sleuth/instrument/hystrix/TraceCommandTests.java[tags=hystrix_command,indent=0]
+HystrixCommand<String> hystrixCommand = new HystrixCommand<String>(setter) {
+ @Override
+ protected String run() throws Exception {
+ return someLogic();
+ }
+};
@@ -2713,7 +2967,12 @@ To disable the custom Hystrix Concurrency Strategy, set the spring.sleuth.
-Unresolved directive in spring-cloud-sleuth.adoc - include::https://raw.githubusercontent.com/spring-cloud/spring-cloud-sleuth/origin/master/spring-cloud-sleuth-core/src/test/java/org/springframework/cloud/sleuth/instrument/hystrix/TraceCommandTests.java[tags=trace_hystrix_command,indent=0]
+TraceCommand<String> traceCommand = new TraceCommand<String>(tracer, setter) {
+ @Override
+ public String doRun() throws Exception {
+ return someLogic();
+ }
+};
@@ -2886,7 +3145,29 @@ In the following snippet, you can see an example of how to set up such a custom
-Unresolved directive in spring-cloud-sleuth.adoc - include::https://raw.githubusercontent.com/spring-cloud/spring-cloud-sleuth/origin/master/spring-cloud-sleuth-core/src/test/java/org/springframework/cloud/sleuth/instrument/web/client/MultipleAsyncRestTemplateTests.java[tags=custom_async_rest_template,indent=0]
+@Configuration
+@EnableAutoConfiguration
+static class Config {
+
+ @Bean(name = "customAsyncRestTemplate")
+ public AsyncRestTemplate traceAsyncRestTemplate() {
+ return new AsyncRestTemplate(asyncClientFactory(),
+ clientHttpRequestFactory());
+ }
+
+ private ClientHttpRequestFactory clientHttpRequestFactory() {
+ ClientHttpRequestFactory clientHttpRequestFactory = new CustomClientHttpRequestFactory();
+ // CUSTOMIZE HERE
+ return clientHttpRequestFactory;
+ }
+
+ private AsyncClientHttpRequestFactory asyncClientFactory() {
+ AsyncClientHttpRequestFactory factory = new CustomAsyncClientHttpRequestFactory();
+ // CUSTOMIZE HERE
+ return factory;
+ }
+
+}
@@ -3127,7 +3408,12 @@ This behavior may be annoying. That’s why, by default, spring.sleuth
-Unresolved directive in spring-cloud-sleuth.adoc - include::https://raw.githubusercontent.com/spring-cloud/spring-cloud-sleuth/origin/master/spring-cloud-sleuth-core/src/test/java/org/springframework/cloud/sleuth/instrument/async/TraceableExecutorServiceTests.java[tags=completablefuture,indent=0]
+CompletableFuture<Long> completableFuture = CompletableFuture.supplyAsync(() -> {
+ // perform some logic
+ return 1_000_000L;
+}, new TraceableExecutorService(beanFactory, executorService,
+ // 'calculateTax' explicitly names the span - this param is optional
+ "calculateTax"));
@@ -3156,7 +3442,30 @@ The following example shows how to set up such a custom Executor:
-Unresolved directive in spring-cloud-sleuth.adoc - include::https://raw.githubusercontent.com/spring-cloud/spring-cloud-sleuth/origin/master/spring-cloud-sleuth-core/src/test/java/org/springframework/cloud/sleuth/instrument/web/client/MultipleAsyncRestTemplateTests.java[tags=custom_executor,indent=0]
+@Configuration
+@EnableAutoConfiguration
+@EnableAsync
+// add the infrastructure role to ensure that the bean gets auto-proxied
+@Role(BeanDefinition.ROLE_INFRASTRUCTURE)
+static class CustomExecutorConfig extends AsyncConfigurerSupport {
+
+ @Autowired
+ BeanFactory beanFactory;
+
+ @Override
+ public Executor getAsyncExecutor() {
+ ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
+ // CUSTOMIZE HERE
+ executor.setCorePoolSize(7);
+ executor.setMaxPoolSize(42);
+ executor.setQueueCapacity(11);
+ executor.setThreadNamePrefix("MyExecutor-");
+ // DON'T FORGET TO INITIALIZE
+ executor.initialize();
+ return new LazyTraceExecutor(this.beanFactory, executor);
+ }
+
+}