From 6f43c675510e8be55bc90e1011c3e8f136a7ae75 Mon Sep 17 00:00:00 2001 From: Marcin Grzejszczak Date: Thu, 18 Aug 2022 12:32:34 +0200 Subject: [PATCH] Updated the docs to use tests; fixes gh-2187 --- docs/src/main/asciidoc/project-features.adoc | 20 ++++--------------- .../ZipkinHttpSenderConfigurationTests.java | 8 ++++++++ 2 files changed, 12 insertions(+), 16 deletions(-) diff --git a/docs/src/main/asciidoc/project-features.adoc b/docs/src/main/asciidoc/project-features.adoc index ba7bcc6f7..de59b7c44 100644 --- a/docs/src/main/asciidoc/project-features.adoc +++ b/docs/src/main/asciidoc/project-features.adoc @@ -288,21 +288,12 @@ spring.zipkin.sender.type: web If you're running a non-reactive application we will use a `RestTemplate` based span sender. Otherwise a `WebClient` based span sender will be chosen. -To customize the `RestTemplate` that sends spans to Zipkin via HTTP, you can register the `ZipkinRestTemplateCustomizer` bean. +To customize the `RestTemplate` that sends spans to Zipkin via HTTP, you can register the `ZipkinRestTemplateCustomizer` bean in your `@Configuration` annotated Spring configuration class. [source,java,indent=0] ---- -@Configuration(proxyBeanMethods = false) - class MyConfig { - @Bean ZipkinRestTemplateCustomizer myCustomizer() { - return new ZipkinRestTemplateCustomizer() { - @Override - void customize(RestTemplate restTemplate) { - // customize the RestTemplate - } - }; - } -} +include::{autoconfig_path}/src/test/java/org/springframework/cloud/sleuth/autoconfig/zipkin2/ZipkinHttpSenderConfigurationTests.java[tags=customizer_1,indent=0] +include::{autoconfig_path}/src/test/java/org/springframework/cloud/sleuth/autoconfig/zipkin2/ZipkinHttpSenderConfigurationTests.java[tags=customizer_2,indent=0] ---- If, however, you would like to control the full process of creating the `RestTemplate` @@ -310,10 +301,7 @@ object, you will have to create a bean of `ZipkinRestTemplateProvider` type. [source,java,indent=0] ---- - @Bean - ZipkinRestTemplateProvider myZipkinRestTemplateProvider() { - return MyRestTemplate::new; - } +include::{autoconfig_path}/src/test/java/org/springframework/cloud/sleuth/autoconfig/zipkin2/ZipkinHttpSenderConfigurationTests.java[tags=provider,indent=0] ---- By default, api path will be set to `api/v2/spans` or `api/v1/spans` depending on the encoder version. If you want to use a custom api path, you can configure it using the following property (empty case, set ""): diff --git a/spring-cloud-sleuth-autoconfigure/src/test/java/org/springframework/cloud/sleuth/autoconfig/zipkin2/ZipkinHttpSenderConfigurationTests.java b/spring-cloud-sleuth-autoconfigure/src/test/java/org/springframework/cloud/sleuth/autoconfig/zipkin2/ZipkinHttpSenderConfigurationTests.java index 5b9715b26..f7d693741 100644 --- a/spring-cloud-sleuth-autoconfigure/src/test/java/org/springframework/cloud/sleuth/autoconfig/zipkin2/ZipkinHttpSenderConfigurationTests.java +++ b/spring-cloud-sleuth-autoconfigure/src/test/java/org/springframework/cloud/sleuth/autoconfig/zipkin2/ZipkinHttpSenderConfigurationTests.java @@ -47,22 +47,30 @@ class ZipkinHttpSenderConfigurationTests { boolean customizerCalled; + + // tag::provider[] @Bean ZipkinRestTemplateProvider myZipkinRestTemplateProvider() { return MyRestTemplate::new; } + // end::provider[] + // tag::customizer_1[] @Bean ZipkinRestTemplateCustomizer myZipkinRestTemplateCustomizer() { return new ZipkinRestTemplateCustomizer() { @Override public RestTemplate customizeTemplate(RestTemplate restTemplate) { + // end::customizer_1[] customizerCalled = true; BDDAssertions.then(restTemplate).isInstanceOf(MyRestTemplate.class); + // tag::customizer_2[] + // customize the RestTemplate return restTemplate; } }; } + // end::customizer_2[] }