-
Notifications
You must be signed in to change notification settings - Fork 1k
Description
Describe the bug
The RestClientBeanPostProcessor in the Spring Boot auto-configuration module created a new RestClient bean every time it processed a bean, even when the OpenTelemetry interceptor was already present. This resulted in unnecessary bean creation.
The primary reason I am here is that though this tries to create a mutated bean, it doesn't really go well when the client bean is some kind of proxy/delegates, which hides them and creates a default rest client. Even though the bean is created using an injected RestClient.Builder that would have added RequestInterceptor already.
Steps to reproduce
- Create a Spring Boot 3.2+ application with OpenTelemetry autoconfiguration
- Define a
RestClientbean with the OTel interceptor already configured - Observe that a new
RestClientinstance is created even though the interceptor is already present and nothing really changed.
Expected behavior
The RestClientBeanPostProcessor should:
- Check if the OTel interceptor is already present in the
RestClient - Return the original bean instance if the interceptor already exists
- Only create a new bean instance when actually adding the interceptor
Actual behavior
The bean post-processor always calls restClient.mutate().build(), creating a new bean instance regardless of whether the interceptor was already present.
Javaagent or library instrumentation version
v2.21.0
Environment
JDK: 25
Additional context
No response
Tip
React with 👍 to help prioritize this issue. Please use comments to provide useful context, avoiding +1 or me too, to help us triage it. Learn more here.