Skip to content

Update RestClientBeanPostProcessor/WebClientBeanPostProcessor to create new bean only when adding OTEL Interceptor#15546

Merged
trask merged 11 commits intoopen-telemetry:mainfrom
lenin-jaganathan:gh-15545-restclient-postprocessing
Apr 17, 2026
Merged

Update RestClientBeanPostProcessor/WebClientBeanPostProcessor to create new bean only when adding OTEL Interceptor#15546
trask merged 11 commits intoopen-telemetry:mainfrom
lenin-jaganathan:gh-15545-restclient-postprocessing

Conversation

@lenin-jaganathan
Copy link
Copy Markdown
Contributor

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
Copy Markdown

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
@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
@lenin-jaganathan lenin-jaganathan force-pushed the gh-15545-restclient-postprocessing branch 4 times, most recently from 9aa1769 to 92119a4 Compare December 22, 2025 12:40
@github-actions
Copy link
Copy Markdown
Contributor

This PR has been labeled as stale due to lack of activity and needing author feedback. It will be automatically closed if there is no further activity over the next 7 days.

@github-actions github-actions Bot added the stale label Dec 29, 2025
@jaydeluca jaydeluca removed the stale label Dec 29, 2025
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jan 5, 2026

This PR has been labeled as stale due to lack of activity and needing author feedback. It will be automatically closed if there is no further activity over the next 7 days.

@github-actions github-actions Bot added the stale label Jan 5, 2026
@jaydeluca
Copy link
Copy Markdown
Member

@lenin-jaganathan in case you might not have noticed, there are some merge conflicts that need to be resolved

@jaydeluca jaydeluca removed the stale label Jan 5, 2026
@lenin-jaganathan lenin-jaganathan force-pushed the gh-15545-restclient-postprocessing branch 2 times, most recently from 933565b to 69a6c45 Compare January 5, 2026 16:08
@lenin-jaganathan
Copy link
Copy Markdown
Contributor Author

@lenin-jaganathan in case you might not have noticed, there are some merge conflicts that need to be resolved

Just now coming off a break and saw it. I have fixed it and pushed changes.

@github-actions github-actions Bot removed the needs author feedback Waiting for additional feedback from the author label Jan 5, 2026
@Override
public Object postProcessAfterInitialization(Object bean, String beanName) {
if (bean instanceof WebClient) {
WebClient webClient = (WebClient) bean;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Do I understand correctly that the intention here is that the interceptor will be added here when the WebClient wasn't created by spring. For example when there is something like

@Bean
WebClient webClient() {
  return WebClient.create();
}

I'd guess the WebClientCustomizer won't run then. What if there is

@Bean
WebClient.Builder webClientBuilder() {
  return WebClient.builder();
}

I'd guess the WebClientCustomizer won't run then either. Should we handle that? Should this be aligned with RestClientBeanPostProcessor (cc @zeitlinger, do you remember why you wrote RestClientBeanPostProcessor the way it is).
Assuming that the intent is to add the interceptor in post processor when the customizer didn't run do we have any tests for this?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

My goal was to make sure that we add the interceptor in every possible way that you can do it - either by creating a builder or the client bean directly.

I did add unit and smoke tests - but maybe I missed a case: #11038

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Sorry for not getting back here.

I'd guess the WebClientCustomizer won't run then either. Should we handle that? Should this be aligned with RestClientBeanPostProcessor

The existing behaviour was RestClient.Builder was not processed by a BPP but by WebClient.Builder was. The current state was that neither builder was handled in that case. I think this is an expected pattern in Spring Boot when a Builder bean is created; the choice to apply customizer beans lies with the creator, consistent with how other customizers would be treated in the Spring Boot world.

Open to discuss otherwise, too.

…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<[email protected]>
Signed-off-by: Lenin Jaganathan <[email protected]>
Signed-off-by: Lenin Jaganathan <[email protected]>

Signed-off-by: Lenin Jaganathan <[email protected]>
Signed-off-by: Lenin Jaganathan <[email protected]>
Signed-off-by: Lenin Jaganathan <[email protected]>
@lenin-jaganathan lenin-jaganathan force-pushed the gh-15545-restclient-postprocessing branch from 79ec6d8 to 047841e Compare April 8, 2026 15:18
@laurit laurit added this to the v2.27.0 milestone Apr 16, 2026
@trask trask merged commit 77a26cd into open-telemetry:main Apr 17, 2026
95 checks passed
@otelbot
Copy link
Copy Markdown
Contributor

otelbot Bot commented Apr 17, 2026

Thank you for your contribution @lenin-jaganathan! 🎉 We would like to hear from you about your experience contributing to OpenTelemetry by taking a few minutes to fill out this survey.

@lenin-jaganathan lenin-jaganathan deleted the gh-15545-restclient-postprocessing branch April 22, 2026 07:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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

5 participants