Since Spring Boot 2.7.0 there is no WebMvcMetricsFilter in the context from WebMvcMetricsAutoConfiguration so we lost timing metrics.
Probably we should specify the class in @ConditionalOnMissingBean annotation
@Bean
@ConditionalOnMissingBean
public FilterRegistrationBean<WebMvcMetricsFilter> webMvcMetricsFilter(MeterRegistry registry,
WebMvcTagsProvider tagsProvider) {
ServerRequest request = this.properties.getWeb().getServer().getRequest();
WebMvcMetricsFilter filter = new WebMvcMetricsFilter(registry, tagsProvider, request.getMetricName(),
request.getAutotime());
FilterRegistrationBean<WebMvcMetricsFilter> registration = new FilterRegistrationBean<>(filter);
registration.setOrder(Ordered.HIGHEST_PRECEDENCE + 1);
registration.setDispatcherTypes(DispatcherType.REQUEST, DispatcherType.ASYNC);
return registration;
}
Comment From: wilkinsona
Thanks for the report, @varpa89, and apologies for the inconvenience. You can work around the problem with the following bean declaration in your application:
public FilterRegistrationBean<WebMvcMetricsFilter> webMvcMetricsFilter(MetricsProperties properties,
MeterRegistry registry, WebMvcTagsProvider tagsProvider) {
ServerRequest request = properties.getWeb().getServer().getRequest();
WebMvcMetricsFilter filter = new WebMvcMetricsFilter(registry, tagsProvider, request.getMetricName(),
request.getAutotime());
FilterRegistrationBean<WebMvcMetricsFilter> registration = new FilterRegistrationBean<>(filter);
registration.setOrder(Ordered.HIGHEST_PRECEDENCE + 1);
registration.setDispatcherTypes(DispatcherType.REQUEST, DispatcherType.ASYNC);
return registration;
}
Comment From: rikostave1234
Do I understand correctly that previous behaviour will be restored with v2.7.1 ? The update to v2.7.0 broke our @Timed metrics as well.
Comment From: wilkinsona
Correct. You can confirm that's the case by trying a 2.7.1-SNAPSHOT available from https://repo.spring.io/snapshot or using the workaround above. If you still have a problem with @Timed with the metrics filter in place, there may be another problem that we'll need to investigate.
Comment From: ChristianAnke
Hey,
a workaround with a bit more code reuse:
@Bean
@ConditionalOnMissingFilterBean
public FilterRegistrationBean<WebMvcMetricsFilter> webMvcMetricsFilter(
WebMvcMetricsAutoConfiguration webMvcMetricsAutoConfiguration,
MeterRegistry registry, WebMvcTagsProvider tagsProvider) {
return webMvcMetricsAutoConfiguration.webMvcMetricsFilter(registry, tagsProvider);
}
Comment From: wilkinsona
Thanks for trying to help, @ChristianAnke, but we do not recommend injecting (auto-)configuration classes and calling methods on them. While the workaround above is slightly more verbose, we believe it's more robust and is what we recommend users do until 2.7.1 has been released with a fix.
Comment From: olivergregorius
Thanks @varpa89 for your workaround, saved my day :-) BTW Spring Boot 2.7.1 - including the fix - has been released today.