Skip to content

Conversation

@lenin-jaganathan
Copy link

The RestClientBeanPostProcessor was always creating a new RestClient bean via mutate().build(), even when the OpenTelemetry interceptor was already present. This resulted in unnecessary bean creation.

Fixes #15545

@lenin-jaganathan lenin-jaganathan requested a review from a team as a code owner December 5, 2025 13:24
@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Dec 5, 2025

CLA Signed

The committers listed above are authorized under a signed CLA.

@github-actions github-actions bot added the test native This label can be applied to PRs to trigger them to run native tests label Dec 5, 2025
@lenin-jaganathan lenin-jaganathan force-pushed the gh-15545-restclient-postprocessing branch 2 times, most recently from 6850089 to c528516 Compare December 5, 2025 13:38
}

private static boolean isInterceptorNotPresent(
java.util.List<ClientHttpRequestInterceptor> interceptors,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you import java.util.List

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, will also do some cleanups improvements once the approach is agreed upon. Created this for discussion, as the issue notes Webclient also suffers from same issue.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I applied this pattern to my PR adding the RestClient for spring boot 4 #15684 , it seems like a fine approach to me.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lenin-jaganathan i think we can consider this approach "agreed upon", in case you were waiting for that to continue.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see this is added as part of another PR. What do you want me to do with this PR, I am make changes to polish this a bit further.

One more thing is We have to consider WebClient as well.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

my PR didn't touch the class you are updating here (for spring boot 3), so your PR is still valid. One thing you can do however, is move the test to an abstract class (do the opposite of this commit). and yea i'd say go ahead and do the same for webclient

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay then. I will update this PR and let you guys know.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have committed the changes.

@laurit laurit added the needs author feedback Waiting for additional feedback from the author label Dec 18, 2025
@lenin-jaganathan lenin-jaganathan force-pushed the gh-15545-restclient-postprocessing branch 2 times, most recently from b418b63 to c7b9736 Compare December 20, 2025 14:03
@lenin-jaganathan lenin-jaganathan changed the title Fix RestClientBeanPostProcessor to avoid creating new bean when interceptor already present Update RestClientBeanPostProcessor/WebClientBeanPostProcessor to create new bean only when adding OTEL Interceptor Dec 20, 2025

@Bean
@Order(Ordered.HIGHEST_PRECEDENCE + 10)
WebClientCustomizer otelWebClientCustomizer(
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the cleaner approach to add instrumentation and is also consistent with what is being done in RestClient.

But doing so would mean we have to add different modules for spring4 where the customizer is moved to the spring-boot-webclient module. What are the thoughts here?

@lenin-jaganathan lenin-jaganathan force-pushed the gh-15545-restclient-postprocessing branch 2 times, most recently from b6e0180 to 0b88f60 Compare December 22, 2025 06:33
…ceptor already present

The RestClientBeanPostProcessor was always creating a new RestClient bean
via mutate().build(), even when the OpenTelemetry interceptor was already
present. This resulted in unnecessary bean creation.

Fixes open-telemetry#15545

Signed-off-by: Lenin Jaganathan<lenin.jaganathan@gmail.com>
Signed-off-by: Lenin Jaganathan <lenin.jaganathan@gmail.com>
Signed-off-by: Lenin Jaganathan <lenin.jaganathan@gmail.com>

Signed-off-by: Lenin Jaganathan <lenin.jaganathan@gmail.com>
@lenin-jaganathan lenin-jaganathan force-pushed the gh-15545-restclient-postprocessing branch from 0b88f60 to 9aa1769 Compare December 22, 2025 10:25
Signed-off-by: Lenin Jaganathan <lenin.jaganathan@gmail.com>
@lenin-jaganathan lenin-jaganathan force-pushed the gh-15545-restclient-postprocessing branch from 9aa1769 to 92119a4 Compare December 22, 2025 12:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs author feedback Waiting for additional feedback from the author test native This label can be applied to PRs to trigger them to run native tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

RestClientBeanPostProcessor always mutates underlying RestClient

3 participants