Hi Mamon,
You can override the "protected String getRequestName(HttpServletRequest request)" method of the javamelody MonitoringFilter.
For example:
public class MultiTenantMonitoringFilter extends MonitoringFilter {
@Override
protected String getRequestName(HttpServletRequest request){
return "tenant-" + getCurrentTenantId() + ' ' + super.getRequestName(request);
}
}
If you use the javamelody spring boot starter, you can use your MultiTenantMonitoringFilter instead of the MonitoringFilter by adding a method like the following in your application configuration:
@Bean(name = JavaMelodyAutoConfiguration.REGISTRATION_BEAN_NAME)
public FilterRegistrationBean<MonitoringFilter> monitoringFilter(
JavaMelodyConfigurationProperties properties, ServletContext servletContext) {
final FilterRegistrationBean<MonitoringFilter> registrationBean = new FilterRegistrationBean<>();
// Create the monitoring filter and set its configuration parameters.
final MonitoringFilter filter;
if (properties.isManagementEndpointMonitoringEnabled()) {
// if the management endpoint is enabled, disable the /monitoring reports on the application port
filter = new MultiTenantMonitoringFilter() {
@Override
protected boolean isAllowed(HttpServletRequest request,
HttpServletResponse response) throws IOException {
response.sendError(HttpServletResponse.SC_FORBIDDEN, "Forbidden access");
return false;
}
};
} else {
// use your multi-tenant MonitoringFilter
filter = new
MultiTenantMonitoringFilter();
}
filter.setApplicationType("Spring Boot");
// Wrap the monitoring filter in the registration bean.
registrationBean.setFilter(filter);
registrationBean.setAsyncSupported(true);
registrationBean.setName("javamelody");
registrationBean.setDispatcherTypes(DispatcherType.REQUEST, DispatcherType.ASYNC);
// Set the initialization parameter for the monitoring filter.
for (final Entry<String, String> parameter : properties.getInitParameters().entrySet()) {
registrationBean.addInitParameter(parameter.getKey(), parameter.getValue());
}
// Set the URL patterns to activate the monitoring filter for.
registrationBean.addUrlPatterns("/*");
final FilterRegistration filterRegistration = servletContext
.getFilterRegistration("javamelody");
if (filterRegistration != null) {
// if webapp deployed as war in a container with MonitoringFilter already added by web-fragment.xml,
// do not try to add it again
registrationBean.setEnabled(false);
for (final Map.Entry<String, String> entry : registrationBean.getInitParameters()
.entrySet()) {
filterRegistration.setInitParameter(entry.getKey(), entry.getValue());
}
}
return registrationBean;
}
bye,
Emeric