Make handler Object available to WebMvcTagsProvider.httpRequestTags

Closes gh-11088
pull/10545/merge
Andy Wilkinson 7 years ago
parent 417c98304d
commit 331c7a1c56

@ -45,12 +45,13 @@ public class DefaultWebMvcTagsProvider implements WebMvcTagsProvider {
/**
* Supplies default tags to the Web MVC server programming model.
* @param request The HTTP request.
* @param handler the Spring MVC handler for the request
* @param response The HTTP response.
* @param ex The current exception, if any
* @return A set of tags added to every Spring MVC HTTP request.
*/
@Override
public Iterable<Tag> httpRequestTags(HttpServletRequest request,
public Iterable<Tag> httpRequestTags(HttpServletRequest request, Object handler,
HttpServletResponse response, Throwable ex) {
return Arrays.asList(WebMvcTags.method(request),
WebMvcTags.uri(request, response), WebMvcTags.exception(ex),

@ -45,6 +45,7 @@ import org.springframework.util.ObjectUtils;
import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.method.HandlerMethod;
import org.springframework.web.servlet.mvc.ParameterizableViewController;
import org.springframework.web.servlet.resource.ResourceHttpRequestHandler;
/**
@ -144,16 +145,18 @@ public class WebMvcMetrics {
Throwable thrown) {
// record Timer values
timed(handler).forEach((config) -> {
Timer.Builder builder = getTimerBuilder(request, response, thrown, config);
Timer.Builder builder = getTimerBuilder(request, handler, response, thrown,
config);
long amount = endTime - startTime;
builder.register(this.registry).record(amount, TimeUnit.NANOSECONDS);
});
}
private Timer.Builder getTimerBuilder(HttpServletRequest request,
private Timer.Builder getTimerBuilder(HttpServletRequest request, Object handler,
HttpServletResponse response, Throwable thrown, TimerConfig config) {
Timer.Builder builder = Timer.builder(config.getName())
.tags(this.tagsProvider.httpRequestTags(request, response, thrown))
.tags(this.tagsProvider.httpRequestTags(request, handler, response,
thrown))
.tags(config.getExtraTags()).description("Timer of servlet request")
.publishPercentileHistogram(config.isHistogram());
if (config.getPercentiles().length > 0) {

@ -41,13 +41,14 @@ public interface WebMvcTagsProvider {
/**
* Provides tags to be associated with metrics for the given {@code request} and
* {@code response} exchange.
* {@code response} exchange. The request was handled by the given {@code handler}.
* @param request the request
* @param handler the handler
* @param response the response
* @param ex the current exception, if any
* @return tags to associate with metrics for the request and response exchange
*/
Iterable<Tag> httpRequestTags(HttpServletRequest request,
Iterable<Tag> httpRequestTags(HttpServletRequest request, Object handler,
HttpServletResponse response, Throwable ex);
}

Loading…
Cancel
Save