Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
nilsga opened this issue Dec 1, 2023 · 1 comment · Fixed by #9990
Labels
bug Something isn't working needs triage New issue that requires triage spring boot starter

Comments

@nilsga
Copy link
Contributor

nilsga commented Dec 1, 2023

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

@nilsga nilsga added bug Something isn't working needs triage New issue that requires triage labels Dec 1, 2023
@trask
Copy link
Member

trask commented Dec 1, 2023

hi @nilsga! if you'd like to send a PR to fix that would be great

cc @jeanbisutti

nilsga added a commit to nilsga/opentelemetry-java-instrumentation that referenced this issue Dec 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working needs triage New issue that requires triage spring boot starter
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants