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

RestTemplate instrumentation doesn't capture URI when calling restTemplate with a URI object instead of a URL string #98

Closed
breun opened this issue Aug 21, 2017 · 2 comments
Milestone

Comments

@breun
Copy link

breun commented Aug 21, 2017

I was testing the client-side HTTP instrumentation for Spring's RestTemplate as described at http://micrometer.io/docs/prometheus#_client_side_http_instrumentation using this REST controller method:

@GetMapping
public String get() throws Exception {
    return restTemplate.getForObject(new URI("https://jsonplaceholder.typicode.com/posts/1"), String.class);
}

I get metrics for this, but the uri isn't being captured by Micrometer:

# HELP http_client_requests_duration_seconds  
# TYPE http_client_requests_duration_seconds summary
http_client_requests_duration_seconds_count{clientName="jsonplaceholder.typicode.com",method="GET",status="200",uri="none",} 1.0
http_client_requests_duration_seconds_sum{clientName="jsonplaceholder.typicode.com",method="GET",status="200",uri="none",} 0.164180339

I guess this is because io.micrometer.spring.RestTemplateUrlTemplateCapturingAspect only executes for RestOperations calls that have a String as their first argument, but calls using a URI object are also supported by RestTemplate (and RestOperations), so I guess those should also be intercepted?

@jkschneider
Copy link
Contributor

Interesting, thanks!

@jkschneider jkschneider added this to the 0.11.0.RELEASE milestone Aug 21, 2017
@jkschneider
Copy link
Contributor

jkschneider commented Aug 22, 2017

I added support for capturing URI's for this signature, but I want to caution you that it should only be used when the URI is not parameterizable. What you have right now would cause dimensional explosion on the backend.

// BAD - will result in dimensional explosion with enough requests
restTemplate.getForObject(new URI("https://jsonplaceholder.typicode.com/posts/1"), String.class);
// GOOD - will result in one URI dimension regardless of the number of requests
restTemplate.getForObject("https://jsonplaceholder.typicode.com/posts/{id}", String.class, 1);

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

No branches or pull requests

2 participants