Skip to content

Conversation

@blocha
Copy link

@blocha blocha commented Dec 2, 2025

Problem statement

When using BOAT to generate Rest Template in Java it generates ApiClient class which uses URI object when creating RequestEntity which is then used in rest template itself. The problem is that RestTemplate when URI object is used has access to ONLY full URL of the request with all url/query params already filled out with exact values.

This creates a problem for observability and monitoring using OOTB metrics for rest template from spring which is http.client.requests. How it works in spring-boot 3 is that they are taking the URI TEMPLATE and putting that into uri tag for http.client.requests metric. Full URL is not used in that metric due to high cardinality.

URI Template is available only using specific approaches while using RestTemplate, so not all constructors/method will use that. The current code uses constructor with URI object which does not provide any uri template but a final URL only and we ends up getting the value "none" in uri tag in the metrics all the time (because thats the default value if there is no uri template).

Solution

The solution to a problem is the code added. It is not passing URI object to the RequestEntity and instead it uses a constructor with uri template and a list of variables which is then populated to http.client.requests metric which properly construct uri tag with URI template. The final URI is actually constructed inside a rest template class using the UriTemplateHandler class as a helper method, so to the the final "doExecute" method in RestTemplate we are passing both - final uri with pre-filled variables and the uri template.

The code was tested locally and actually comes from newest version of open api generator templates for Rest Template.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant