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

Inconsistent inclusion of base URL in WebClient URI template attribute since Spring WebFlux 6.1.2 #31882

Closed
breun opened this issue Dec 21, 2023 · 2 comments
Assignees
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: bug A general bug
Milestone

Comments

@breun
Copy link

breun commented Dec 21, 2023

Consider this code:

String URI_TEMPLATE_ATTRIBUTE = WebClient.class.getName() + ".uriTemplate";

WebClient webClient = WebClient.builder()
        .baseUrl("http://example.com")
        .build();

webClient.get()
        .uri("/foo/{id}", Map.of("id", 1))
        .attributes(attributes ->
                System.out.println("URI template when using a Map: " + attributes.get(URI_TEMPLATE_ATTRIBUTE))
        );

webClient.get()
        .uri("/foo/{id}", 1)
        .attributes(attributes ->
                System.out.println("URI template when using varargs: " + attributes.get(URI_TEMPLATE_ATTRIBUTE))
        );

With Spring Framework 6.1.1 this prints the following:

URI template when using a Map: /foo/{id}
URI template when using varargs: /foo/{id}

However, with Spring Framework 6.1.2 the output is this:

URI template when using a Map: /foo/{id}
URI template when using varargs: http://example.com/foo/{id}

So, when using varargs the baseUrl is now included in the URI template, but when using a Map it isn't.

It seems the change to include the base URL in the URI template was made via #30027. I personally have doubts about whether the base URL should be included in the URI template. I'd like to have access to the URI template as it was passed to the client and I'd prefer the base URL not to be included, because it clutters our distributed tracing output. The base URL could be passed via a separate attribute maybe?

But if this change to suddenly include the base URL in the URI template attribute is indeed intentional, it seems it was at least not consistently implemented.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Dec 21, 2023
@jhoeller jhoeller added the in: web Issues in web modules (web, webmvc, webflux, websocket) label Jan 3, 2024
@poutsma
Copy link
Contributor

poutsma commented Jan 9, 2024

FYA @rstoyanchev

@sbrannen sbrannen changed the title Inconsistent inclusion of base URL in WebClient URI template attribute since Spring WebFlux 6.1.2 Inconsistent inclusion of base URL in WebClient URI template attribute since Spring WebFlux 6.1.2 Jan 10, 2024
@rstoyanchev rstoyanchev self-assigned this Jan 10, 2024
@rstoyanchev rstoyanchev added type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Jan 10, 2024
@rstoyanchev rstoyanchev added this to the 6.1.3 milestone Jan 10, 2024
@rstoyanchev
Copy link
Contributor

The change is intentional as per #30027. The baseUrl makes the URL complete and potentially unique if there is more than one WebClient, but I do understand sometimes the baseUrl is not of interest. A separate attribute wouldn't help much as the built-in observation support would still need to decide whether to include it or not. We would need a config option to control the behavior if necessary.

You're right the change wasn't applied consistently. I'll fix that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: bug A general bug
Projects
None yet
Development

No branches or pull requests

5 participants