WebMvcMetricsFilter
record all requests, but I want to record the request which I need.
can WebMvcMetricsFilter
support customization just like WebMvcTagsProvider
?
@Bean
@ConditionalOnMissingBean(WebMvcTagsProvider.class)
public DefaultWebMvcTagsProvider webMvcTagsProvider(ObjectProvider<WebMvcTagsContributor> contributors) {
return new DefaultWebMvcTagsProvider(this.properties.getWeb().getServer().getRequest().isIgnoreTrailingSlash(),
contributors.orderedStream().collect(Collectors.toList()));
}
@Bean
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
@Razor0719, can you please expand a bit on what you mean by "and I want to record the request which I needed"? Would you like to be able to define your own FilterRegistrationBean<WebMvcMetricsFilter>
bean so that you can configure it to only filter specific paths, dispatcher types, etc.?
Comment From: Razor0719
@Razor0719, can you please expand a bit on what you mean by "and I want to record the request which I needed"? Would you like to be able to define your own
FilterRegistrationBean<WebMvcMetricsFilter>
bean so that you can configure it to only filter specific paths, dispatcher types, etc.?
@wilkinsona yes, I want to configure WebMvcMetricsFilter
to only filter specific paths, dispatcher types, etc.
I tried to code my own implementation, but can not find a great way to load it into the spring container up till now.
I update the issue and sorry for my bad English.
Comment From: wilkinsona
Thanks.
We could do that by making the registration bean @ConditionalOnMissingBean
. Alternatively, we could offer some properties to control the dispatcher types, filtered paths, etc. I'll flag this one for a forthcoming team meeting so that we can discuss our options.
Comment From: wilkinsona
We're going to make registration of the bean conditional. In the meantime, @Razor0719, I think you could use a BeanPostProcessor
to change the auto-configured registration bean to meet your needs. Something like this:
@Bean
static BeanPostProcessor webMvcMetricsFilterRegistrationCustomizer() {
return new BeanPostProcessor() {
@Override
@SuppressWarnings("unchecked")
public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
if (beanName.equals("webMvcMetricsFilter")) {
FilterRegistrationBean<WebMvcMetricsFilter> registration = ((FilterRegistrationBean<WebMvcMetricsFilter>) bean);
registration.setUrlPatterns(Arrays.asList("one/", "two/"));
}
return bean;
}
};
}
Comment From: Razor0719
Thanks.
We could do that by making the registration bean
@ConditionalOnMissingBean
. Alternatively, we could offer some properties to control the dispatcher types, filtered paths, etc. I'll flag this one for a forthcoming team meeting so that we can discuss our options.
@wilkinsona Thanks, and I'll wait for it and use the BeanPostProcessor
temporarily