Skip to content

Auto instrumentation of RestTemplate/RestClient/WebClient does not work with Spring Boot 3.2.0Β #9987

@nilsga

Description

@nilsga

Describe the bug

When upgrading our applications to Spring Boot 3.2.0, we noticed that we stopped getting spans from http client invocations. After some digging, we think the reason is that the http request factory has changed: https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-3.2-Release-Notes#resttemplate-http-clients

If we opt in to JdkClientHttpRequestFactory, as described, tracing works. However, Apache HttpClient 5 request factory, or the jetty 12 client factory, does not seem to work. For Apache Http Client 5, the problem seem to be that Spring send null as HttpHost here: https://github.com/spring-projects/spring-framework/blob/main/spring-web/src/main/java/org/springframework/http/client/HttpComponentsClientHttpRequest.java#L95

which results in a NullPointerException in RequestWithHost:

public RequestWithHost(HttpHost httpHost, ClassicHttpRequest httpRequest) {
    super(httpRequest);
    this.scheme = httpHost.getSchemeName();
    this.authority = new URIAuthority(httpHost.getHostName(), httpHost.getPort());
  }

Intuitive fix is to fetch URIAuthority and scheme from httpRequest:

this.scheme = httpRequest.getScheme();
this.authority = httpRequest.getAuthority();

but perhaps there is a reason this is not done in the first place.

For Jetty 12 http client, it seems that support just does not exist.

Steps to reproduce

  • Create a new Spring Boot 3.2.0 application
  • Add Apache HttpClient 5 or Jetty 12 Http Client to classpath.
  • Create endpoint using RestClient to invoke a http service

Expected behavior

Span is created for the RestClient call

Actual behavior

No span is created

Javaagent or library instrumentation version

1.32.0

Environment

JDK: Azul 17
OS: MacOS

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions