Skip to content

Commit 8721c0e

Browse files
wilkinsonamhalbritterphilwebb
committed
Add ConnectionDetail support to Zipkin auto-configuration
Update Zipkin auto-configuration so that `ZipkinConnectionDetails` beans may be optionally used to provide connection details. See gh-34657 Co-Authored-By: Mortitz Halbritter <[email protected]> Co-Authored-By: Phillip Webb <[email protected]>
1 parent ac55caa commit 8721c0e

File tree

3 files changed

+89
-6
lines changed

3 files changed

+89
-6
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* Copyright 2012-2023 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.boot.actuate.autoconfigure.tracing.zipkin;
18+
19+
/**
20+
* Adapts {@link ZipkinProperties} to {@link ZipkinConnectionDetails}.
21+
*
22+
* @author Moritz Halbritter
23+
* @author Andy Wilkinson
24+
* @author Phillip Webb
25+
*/
26+
class PropertiesZipkinConnectionDetails implements ZipkinConnectionDetails {
27+
28+
private final ZipkinProperties properties;
29+
30+
PropertiesZipkinConnectionDetails(ZipkinProperties properties) {
31+
this.properties = properties;
32+
}
33+
34+
@Override
35+
public String getSpanEndpoint() {
36+
return this.properties.getEndpoint();
37+
}
38+
39+
}

spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/tracing/zipkin/ZipkinConfigurations.java

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,14 @@ static class UrlConnectionSenderConfiguration {
5959

6060
@Bean
6161
@ConditionalOnMissingBean(Sender.class)
62-
URLConnectionSender urlConnectionSender(ZipkinProperties properties) {
62+
URLConnectionSender urlConnectionSender(ZipkinProperties properties,
63+
ObjectProvider<ZipkinConnectionDetails> connectionDetailsProvider) {
64+
ZipkinConnectionDetails connectionDetails = connectionDetailsProvider
65+
.getIfAvailable(() -> new PropertiesZipkinConnectionDetails(properties));
6366
URLConnectionSender.Builder builder = URLConnectionSender.newBuilder();
6467
builder.connectTimeout((int) properties.getConnectTimeout().toMillis());
6568
builder.readTimeout((int) properties.getReadTimeout().toMillis());
66-
builder.endpoint(properties.getEndpoint());
69+
builder.endpoint(connectionDetails.getSpanEndpoint());
6770
return builder.build();
6871
}
6972

@@ -77,12 +80,15 @@ static class RestTemplateSenderConfiguration {
7780
@Bean
7881
@ConditionalOnMissingBean(Sender.class)
7982
ZipkinRestTemplateSender restTemplateSender(ZipkinProperties properties,
80-
ObjectProvider<ZipkinRestTemplateBuilderCustomizer> customizers) {
83+
ObjectProvider<ZipkinRestTemplateBuilderCustomizer> customizers,
84+
ObjectProvider<ZipkinConnectionDetails> connectionDetailsProvider) {
85+
ZipkinConnectionDetails connectionDetails = connectionDetailsProvider
86+
.getIfAvailable(() -> new PropertiesZipkinConnectionDetails(properties));
8187
RestTemplateBuilder restTemplateBuilder = new RestTemplateBuilder()
8288
.setConnectTimeout(properties.getConnectTimeout())
8389
.setReadTimeout(properties.getReadTimeout());
8490
restTemplateBuilder = applyCustomizers(restTemplateBuilder, customizers);
85-
return new ZipkinRestTemplateSender(properties.getEndpoint(), restTemplateBuilder.build());
91+
return new ZipkinRestTemplateSender(connectionDetails.getSpanEndpoint(), restTemplateBuilder.build());
8692
}
8793

8894
private RestTemplateBuilder applyCustomizers(RestTemplateBuilder restTemplateBuilder,
@@ -106,10 +112,13 @@ static class WebClientSenderConfiguration {
106112
@Bean
107113
@ConditionalOnMissingBean(Sender.class)
108114
ZipkinWebClientSender webClientSender(ZipkinProperties properties,
109-
ObjectProvider<ZipkinWebClientBuilderCustomizer> customizers) {
115+
ObjectProvider<ZipkinWebClientBuilderCustomizer> customizers,
116+
ObjectProvider<ZipkinConnectionDetails> connectionDetailsProvider) {
117+
ZipkinConnectionDetails connectionDetails = connectionDetailsProvider
118+
.getIfAvailable(() -> new PropertiesZipkinConnectionDetails(properties));
110119
WebClient.Builder builder = WebClient.builder();
111120
customizers.orderedStream().forEach((customizer) -> customizer.customize(builder));
112-
return new ZipkinWebClientSender(properties.getEndpoint(), builder.build());
121+
return new ZipkinWebClientSender(connectionDetails.getSpanEndpoint(), builder.build());
113122
}
114123

115124
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* Copyright 2012-2023 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.boot.actuate.autoconfigure.tracing.zipkin;
18+
19+
import org.springframework.boot.autoconfigure.service.connection.ConnectionDetails;
20+
21+
/**
22+
* Details required to establish a connection to a Zipkin server.
23+
*
24+
* @author Moritz Halbritter
25+
* @since 3.1.0
26+
*/
27+
public interface ZipkinConnectionDetails extends ConnectionDetails {
28+
29+
/**
30+
* The endpoint for the span reporting.
31+
* @return the endpoint
32+
*/
33+
String getSpanEndpoint();
34+
35+
}

0 commit comments

Comments
 (0)