Skip to content

RestClientBeanPostProcessor always mutates underlying RestClient #15545

@lenin-jaganathan

Description

@lenin-jaganathan

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

  1. Create a Spring Boot 3.2+ application with OpenTelemetry autoconfiguration
  2. Define a RestClient bean with the OTel interceptor already configured
  3. Observe that a new RestClient instance 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingneeds triageNew issue that requires triage

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions