Skip to content

Auto-configure observations for RestClients #38500

@atrepczik

Description

@atrepczik

I was trying out Spring Boot 3.2.0-RC2 and was quite surprised that a RestClient created via RestClient.builder().build() is not auto-instrumented like RestTemplate and WebClient currently are. If I create a RestClientCustomizer in a similar fashion to RestTemplateObservationConfiguration, then observations are properly created for HTTP requests as one could expect:

	@Bean
	RestClientCustomizer observationRestClientCustomizer(
			ObservationRegistry observationRegistry,
			ObjectProvider<ClientRequestObservationConvention> customConvention,
			ObservationProperties properties) {
		String name = properties.getHttp().getClient().getRequests().getName();
		ClientRequestObservationConvention observationConvention = customConvention
			.getIfAvailable(() -> new DefaultClientRequestObservationConvention(name));
		return builder -> builder
				.observationRegistry(observationRegistry)
				.observationConvention(observationConvention);
	}

Adding this as an auto configuration would improve the out-of-the-box experience for the new RestClient.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions