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

ClientObservationConventionAdapter overwrites WebClient request attributes #40330

Closed
HaloFour opened this issue Apr 12, 2024 · 2 comments
Closed
Assignees
Labels
theme: observability Issues related to observability type: bug A general bug
Milestone

Comments

@HaloFour
Copy link

Spring Boot version: 3.0.13

I have noticed that when using WebClient metrics with the built-in convention for adapting WebClientExchangeTagsProvider that the URI template is being stripped from the attributes of the ClientRequest. This is caused by the ClientObservationConventionAdapter trying to overwrite the attribute to ClientRequestObservationContext.getUriTemplate() before ClientRequestObservationContext.setUriTemplate(String) has been called.

Reproduction:

var clazz = Class.forName("org.springframework.boot.actuate.autoconfigure.observation.web.client.ClientObservationConventionAdapter");
var constructor = clazz.getDeclaredConstructors()[0];
constructor.setAccessible(true);
var adapter = (ClientRequestObservationConvention) constructor.newInstance("http.client.requests", new DefaultWebClientExchangeTagsProvider());

var registry = TestObservationRegistry.create();
var client = WebClient.builder()
        .observationRegistry(registry)
        .observationConvention(adapter)
        .build();

client.get()
        .uri("https://httpbin.org/{method}", "get")
        .retrieve()
        .bodyToMono(String.class)
        .block();


TestObservationRegistryAssert.assertThat(registry)
        .hasObservationWithNameEqualTo("http.client.requests")
        .that()
        .hasLowCardinalityKeyValue("uri", "/get"); // should be "/{method}"

I have worked around this by providing my own adapter convention which avoids overwriting the request attribute. Given this adapter convention has already been removed from Spring Boot 3.2 it might not be worth addressing, but I thought I would report it.

@bclozel
Copy link
Member

bclozel commented Apr 12, 2024

Thanks for the report.

Spring Boot 3.1.x is almost out of OSS supported, scheduled in roughly a month (2024-05-18). While I do see similarities and inconsistencies (see spring-projects/spring-framework#29885), I believe this behavior has been this way for a long time now and I don't think we should change this right before cutting the OSS support. This is likely to break existing dashboards - arguably, they will break anyway when applications will move to the observation conventions in 3.2.x, since this adapter has been removed in that generation.

I'll discuss that with the team.

@bclozel bclozel added the for: team-meeting An issue we'd like to discuss as a team to make progress label Apr 12, 2024
@HaloFour HaloFour changed the title WebClient request contributes full URI to meter tag when using WebClient request contributes full URI to meter tag when using WebClientExchangeTagsProvider Apr 12, 2024
@bclozel bclozel self-assigned this Apr 12, 2024
@bclozel bclozel added type: bug A general bug theme: observability Issues related to observability and removed status: waiting-for-triage An issue we've not yet triaged for: team-meeting An issue we'd like to discuss as a team to make progress labels Apr 12, 2024
@bclozel bclozel added this to the 3.1.11 milestone Apr 12, 2024
@bclozel bclozel changed the title WebClient request contributes full URI to meter tag when using WebClientExchangeTagsProvider ClientObservationConventionAdapter overwrites WebClient request attributes Apr 12, 2024
@bclozel
Copy link
Member

bclozel commented Apr 12, 2024

I've had another look and it's definitely invalid behavior. I'm pushing a fix for 3.1.x as the existing implementation only breaks expectations. Thanks for your report!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
theme: observability Issues related to observability type: bug A general bug
Projects
None yet
Development

No branches or pull requests

3 participants