Skip to content

Commit 1116f81

Browse files
committed
Add HTTP customizers to enable observability with Micrometer.
Closes gh-661
1 parent 0141f4d commit 1116f81

File tree

4 files changed

+113
-1
lines changed

4 files changed

+113
-1
lines changed

spring-cloud-vault-config/pom.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,14 @@
5959
<optional>true</optional>
6060
</dependency>
6161

62+
<!-- Micrometer -->
63+
64+
<dependency>
65+
<groupId>io.micrometer</groupId>
66+
<artifactId>micrometer-tracing</artifactId>
67+
<optional>true</optional>
68+
</dependency>
69+
6270
<!-- HTTP Client Libraries -->
6371
<dependency>
6472
<groupId>org.apache.httpcomponents.client5</groupId>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
* Copyright 2016-2022 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+
* http://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.cloud.vault.config;
18+
19+
import io.micrometer.observation.Observation;
20+
import io.micrometer.observation.ObservationRegistry;
21+
22+
import org.springframework.boot.actuate.metrics.web.client.ObservationRestTemplateCustomizer;
23+
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
24+
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
25+
import org.springframework.boot.autoconfigure.condition.ConditionalOnSingleCandidate;
26+
import org.springframework.context.annotation.Bean;
27+
import org.springframework.context.annotation.Configuration;
28+
import org.springframework.http.client.observation.DefaultClientRequestObservationConvention;
29+
import org.springframework.vault.client.RestTemplateCustomizer;
30+
31+
/**
32+
* {@link org.springframework.boot.autoconfigure.EnableAutoConfiguration
33+
* Auto-configuration} for Observability.
34+
*
35+
* @author Mark Paluch
36+
* @since 3.0
37+
*/
38+
@Configuration(proxyBeanMethods = false)
39+
@ConditionalOnClass(Observation.class)
40+
@AutoConfigureBefore(VaultAutoConfiguration.class)
41+
public class VaultObservationAutoConfiguration {
42+
43+
@Bean
44+
@ConditionalOnSingleCandidate(ObservationRegistry.class)
45+
public RestTemplateCustomizer observationVaultRestTemplateCustomizer(ObservationRegistry observationRegistry) {
46+
return restTemplate -> new ObservationRestTemplateCustomizer(observationRegistry,
47+
new DefaultClientRequestObservationConvention()).customize(restTemplate);
48+
}
49+
50+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
* Copyright 2016-2022 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+
* http://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.cloud.vault.config;
18+
19+
import io.micrometer.observation.Observation;
20+
import io.micrometer.observation.ObservationRegistry;
21+
import reactor.core.publisher.Flux;
22+
23+
import org.springframework.boot.actuate.metrics.web.reactive.client.ObservationWebClientCustomizer;
24+
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
25+
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
26+
import org.springframework.boot.autoconfigure.condition.ConditionalOnSingleCandidate;
27+
import org.springframework.context.annotation.Bean;
28+
import org.springframework.context.annotation.Configuration;
29+
import org.springframework.vault.client.WebClientCustomizer;
30+
import org.springframework.web.reactive.function.client.DefaultClientRequestObservationConvention;
31+
import org.springframework.web.reactive.function.client.WebClient;
32+
33+
/**
34+
* {@link org.springframework.boot.autoconfigure.EnableAutoConfiguration
35+
* Auto-configuration} for Reactive Observability.
36+
*
37+
* @author Mark Paluch
38+
* @since 3.0
39+
*/
40+
@Configuration(proxyBeanMethods = false)
41+
@ConditionalOnClass({ Observation.class, WebClient.class, Flux.class })
42+
@AutoConfigureBefore(VaultReactiveAutoConfiguration.class)
43+
public class VaultReactiveObservationAutoConfiguration {
44+
45+
@Bean
46+
@ConditionalOnSingleCandidate(ObservationRegistry.class)
47+
public WebClientCustomizer observationVaultWebClientCustomizer(ObservationRegistry observationRegistry) {
48+
return webClientBuilder -> new ObservationWebClientCustomizer(observationRegistry,
49+
new DefaultClientRequestObservationConvention()).customize(webClientBuilder);
50+
}
51+
52+
}
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
org.springframework.cloud.vault.config.VaultObservationAutoConfiguration
2+
org.springframework.cloud.vault.config.VaultReactiveObservationAutoConfiguration
13
org.springframework.cloud.vault.config.VaultReactiveAutoConfiguration
24
org.springframework.cloud.vault.config.VaultAutoConfiguration
3-
org.springframework.cloud.vault.config.VaultHealthIndicatorAutoConfiguration
5+
org.springframework.cloud.vault.config.VaultHealthIndicatorAutoConfiguration

0 commit comments

Comments
 (0)