Spring mvc integration with prometheus Example

In this article ,we will see how we can monitor spring MVC applications using prometheus tool . You wont get much documentation for this setup on web. Prometheus is mostly configured with spring boot easily. But in order to configure it with spring MVC based application , it requires some additional configurations –

Prometheus

Prometheus is a time-series monitoring application written in Go. It can run on a server, in a docker container, or as part of a Kubernetes cluster (or something similar). Prometheus collects, stores, and visualizes time-series data so that you can monitor your systems. You can tell Prometheus exactly where to find metrics by configuring a list of “scrape jobs”. Applications that are being monitored can provide metrics endpoints to Prometheus using any one of the many client libraries available; additionally, separate exporters can gather metrics from applications to make them available in Prometheus. Metrics get stored locally for 15 days, by default, and any Prometheus server can scrape another one for data. Additionally, remote storage is another option for Prometheus data – provided there is a reliable remote storage endpoint.

Benefits:

  • The option of “service discovery” allows Prometheus to keep track of all current endpoints effortlessly.
  • Outages are quickly detected .
  • The PromQL query language is incredibly flexible and Turing-complete.
  • There’s also a very low load on the services monitored (metrics get stored in memory as they get generated), allowing fewer resources to get used.
  • Additionally, Prometheus users can control traffic volumes, access metrics in the browser, and allow for easy reconfiguration.

Step 1 : Spring MVC application pom.xml configuration

Below prometheus dependencies are required in pom.xml for project –

<prometheus.version>0.6.0</prometheus.version>
<dependency>
    <groupid>io.prometheus</groupid>
    <artifactid>simpleclient</artifactid>
    <version>${prometheus.version}</version>
</dependency>
<!-- Hotspot JVM metrics-->
<dependency>
    <groupid>io.prometheus</groupid>
    <artifactid>simpleclient_hotspot</artifactid>
    <version>${prometheus.version}</version>
</dependency>
<!-- Exposition servlet-->
<dependency>
    <groupid>io.prometheus</groupid>
    <artifactid>simpleclient_servlet</artifactid>
    <version>${prometheus.version}</version>
</dependency>
<!-- Pushgateway exposition-->
<dependency>
    <groupid>io.prometheus</groupid>
    <artifactid>simpleclient_pushgateway</artifactid>
    <version>${prometheus.version}</version>
</dependency>
<dependency>
    <groupid>io.prometheus</groupid>
    <artifactid>simpleclient_spring_web</artifactid>
    <version>${prometheus.version}</version>
</dependency>
<dependency>
    <groupid>com.fasterxml.jackson.core</groupid>
    <artifactid>jackson-core</artifactid>
    <version>2.5.2</version>
</dependency>

Step 2 : Spring MVC application web.xml configuration

We need configure MetricsServlet to capture the metrics of our spring mvc application as below –

<servlet>
    <servlet-name>PrometheusServlet</servlet-name>
    <servlet-class>io.prometheus.client.exporter.MetricsServlet</servlet-class>
</servlet>
<servlet-mapping>
    <servlet-name>PrometheusServlet</servlet-name>
    <url-pattern>/metrics</url-pattern>
</servlet-mapping>

Step 3: Add an interceptor class

This will intercept all the requests coming to application and capture the metrics to be exposed to prometheus –

package com.myjavablog.config;

import io.prometheus.client.Counter;
import io.prometheus.client.Gauge;
import io.prometheus.client.Histogram;
import io.prometheus.client.Summary;
import org.apache.log4j.Logger;
import org.springframework.web.method.HandlerMethod;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


/**
 * @author anupb
 */

public class PrometheusMetricsInterceptor extends HandlerInterceptorAdapter {

    private static Logger logger = Logger.getLogger(PrometheusMetricsInterceptor.class);

    private static final Histogram requestLatency = Histogram.build()

            .name("service_requests_latency_seconds")

            .help("Request latency in seconds.")

            .labelNames("systemId", "appId", "type", "name", "method").register();


    private ThreadLocal<Histogram.Timer> timerThreadLocal;


    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {

        return super.preHandle(request, response, handler);

    }

    @Override
    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {

        String name = this.getName(request, handler).toLowerCase();
        String method = request.getMethod().toUpperCase();

        timerThreadLocal = new ThreadLocal<>();
        timerThreadLocal.set(requestLatency.labels(name, method).startTimer());
        super.postHandle(request, response, handler, modelAndView);
    }

    @Override
    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {

        super.afterCompletion(request, response, handler, ex);

        if (timerThreadLocal.get() != null) {
            timerThreadLocal.get().observeDuration();
        }
    }

    @Override
    public void afterConcurrentHandlingStarted(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {

        super.afterConcurrentHandlingStarted(request, response, handler);
    }

    private String getName(HttpServletRequest request, Object handler) {
        String name = "";

        try {
            if (handler != null && handler instanceof HandlerMethod) {

                HandlerMethod method = (HandlerMethod) handler;
                String className = ((HandlerMethod) handler).getBeanType().getName();
                name = className + "." + method.getMethod().getName();
            } else {
                name = request.getRequestURI();
            }

        } catch (Exception ex) {
            logger.error("getName", ex);
        } finally {
            return name;
        }
    }
}

Step 4: Add prometheus initialization configuration

This will expose the metrics to prometheus server –

package com.myjavablog.config;
 public class PrometheusConfig {

private static Logger logger = Logger.getLogger(PrometheusConfig.class);

 

@PostConstruct

public void initialize() {

logger.info("prometheus init...");

DefaultExports.initialize();

logger.info("prometheus has been initialized...");

}

}

Step 5: Add an interceptor to spring-mvc.xml

You need to first add the schema location as below –

http://www.springframework.org/schema/mvc

http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd

Then you need to add below tag –

<mvc:interceptors>

<bean class="com.xx.config.PrometheusMetricsInterceptor"/>

</mvc:interceptors>

Step 6: Add configuration to applicationcontext.xml

<bean id="prometheusConfig" class="com.myjavablog.config.PrometheusConfig" init-method="initialize" />

Once all this configuration is done , you can add the application URL in prometheus.

These parameters are useful to monitor your spring MVC application.

6 thoughts on “Spring mvc integration with prometheus Example”

  1. Hi,

    It did not work for Spring MVC 5. I got exception in the interceptor’s requestLatency.labels(name, method) code, line 49. It gives error because the method passes two arguments while the labelNames of the class has 5 element.

    Can you help me with that?

    Best regards,

    Reply
      • The stack trace is:

        javax.servlet.ServletException: org.springframework.web.util.NestedServletException: Request processing failed; nested exception is java.lang.IllegalArgumentException: Incorrect number of labels.
        at org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.java:146) ~[jetty-server-9.4.14.v20181114.jar:9.4.14.v20181114]
        at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:548) ~[jetty-security-9.4.14.v20181114.jar:9.4.14.v20181114]
        at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:132) ~[jetty-server-9.4.14.v20181114.jar:9.4.14.v20181114]
        at org.eclipse.jetty.server.Server.handle(Server.java:502) ~[jetty-server-9.4.14.v20181114.jar:9.4.14.v20181114]
        at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:364) [jetty-server-9.4.14.v20181114.jar:9.4.14.v20181114]
        at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:260) [jetty-server-9.4.14.v20181114.jar:9.4.14.v20181114]
        at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:305) [jetty-io-9.4.14.v20181114.jar:9.4.14.v20181114]
        at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:103) [jetty-io-9.4.14.v20181114.jar:9.4.14.v20181114]
        at org.eclipse.jetty.io.ChannelEndPoint$2.run(ChannelEndPoint.java:118) [jetty-io-9.4.14.v20181114.jar:9.4.14.v20181114]
        at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:765) [jetty-util-9.4.14.v20181114.jar:9.4.14.v20181114]
        at org.eclipse.jetty.util.thread.QueuedThreadPool$2.run(QueuedThreadPool.java:683) [jetty-util-9.4.14.v20181114.jar:9.4.14.v20181114]
        at java.lang.Thread.run(Thread.java:834) [?:?]
        Caused by: org.springframework.web.util.NestedServletException: Request processing failed; nested exception is java.lang.IllegalArgumentException: Incorrect number of labels.
        at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006) ~[?:?]
        at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:890) ~[?:?]
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:687) ~[javax.servlet-api-3.1.0.jar:3.1.0]
        at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:875) ~[?:?]
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:790) ~[javax.servlet-api-3.1.0.jar:3.1.0]
        at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:867) ~[jetty-servlet-9.4.14.v20181114.jar:9.4.14.v20181114]
        at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1623) ~[jetty-servlet-9.4.14.v20181114.jar:9.4.14.v20181114]
        at se.app.struts.filter.UTF8Filter.doFilter(UTF8Filter.java:33) ~[?:?]
        at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1610) ~[jetty-servlet-9.4.14.v20181114.jar:9.4.14.v20181114]
        at se.app.struts.filter.StrutsSecurityFilter.doFilter(StrutsSecurityFilter.java:56) ~[?:?]
        at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1610) ~[jetty-servlet-9.4.14.v20181114.jar:9.4.14.v20181114]
        at se.app.struts.filter.IdleTimeoutFilter.doFilter(IdleTimeoutFilter.java:85) ~[?:?]
        at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1610) ~[jetty-servlet-9.4.14.v20181114.jar:9.4.14.v20181114]
        at org.eclipse.jetty.websocket.server.WebSocketUpgradeFilter.doFilter(WebSocketUpgradeFilter.java:214) ~[websocket-server-9.4.14.v20181114.jar:9.4.14.v20181114]
        at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1610) ~[jetty-servlet-9.4.14.v20181114.jar:9.4.14.v20181114]
        at se.app.struts.filter.NoCacheFilter.doFilter(NoCacheFilter.java:31) ~[?:?]
        at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1610) ~[jetty-servlet-9.4.14.v20181114.jar:9.4.14.v20181114]
        at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:317) ~[?:?]
        at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:127) ~[?:?]
        at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:91) ~[?:?]
        at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331) ~[?:?]
        at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:114) ~[?:?]
        at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331) ~[?:?]
        at org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:137) ~[?:?]
        at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331) ~[?:?]
        at org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:111) ~[?:?]
        at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331) ~[?:?]
        at org.springframework.security.web.authentication.rememberme.RememberMeAuthenticationFilter.doFilter(RememberMeAuthenticationFilter.java:150) ~[?:?]
        at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331) ~[?:?]
        at org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:170) ~[?:?]
        at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331) ~[?:?]
        at org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:63) ~[?:?]
        at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331) ~[?:?]
        at org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:200) ~[?:?]
        at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331) ~[?:?]
        at se.app.web.security.appJwtAuthenticationFilter.doFilterInternal(appJwtAuthenticationFilter.java:95) ~[?:?]
        at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-5.1.2.RELEASE.jar:5.1.2.RELEASE]
        at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331) ~[?:?]
        at org.springframework.security.web.header.HeaderWriterFilter.doFilterInternal(HeaderWriterFilter.java:64) ~[?:?]
        at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-5.1.2.RELEASE.jar:5.1.2.RELEASE]
        at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331) ~[?:?]
        at org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter.doFilterInternal(WebAsyncManagerIntegrationFilter.java:56) ~[?:?]
        at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-5.1.2.RELEASE.jar:5.1.2.RELEASE]
        at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331) ~[?:?]
        at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:105) ~[?:?]
        at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331) ~[?:?]
        at org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:214) ~[?:?]
        at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:177) ~[?:?]
        at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:357) ~[spring-web-5.1.2.RELEASE.jar:5.1.2.RELEASE]
        at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:270) ~[spring-web-5.1.2.RELEASE.jar:5.1.2.RELEASE]
        at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1610) ~[jetty-servlet-9.4.14.v20181114.jar:9.4.14.v20181114]
        at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:540) ~[jetty-servlet-9.4.14.v20181114.jar:9.4.14.v20181114]
        at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:146) ~[jetty-server-9.4.14.v20181114.jar:9.4.14.v20181114]
        at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:548) ~[jetty-security-9.4.14.v20181114.jar:9.4.14.v20181114]
        at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:132) ~[jetty-server-9.4.14.v20181114.jar:9.4.14.v20181114]
        at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:257) ~[jetty-server-9.4.14.v20181114.jar:9.4.14.v20181114]
        at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:1588) ~[jetty-server-9.4.14.v20181114.jar:9.4.14.v20181114]
        at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:255) ~[jetty-server-9.4.14.v20181114.jar:9.4.14.v20181114]
        at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1345) ~[jetty-server-9.4.14.v20181114.jar:9.4.14.v20181114]
        at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:203) ~[jetty-server-9.4.14.v20181114.jar:9.4.14.v20181114]
        at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:480) ~[jetty-servlet-9.4.14.v20181114.jar:9.4.14.v20181114]
        at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:1557) ~[jetty-server-9.4.14.v20181114.jar:9.4.14.v20181114]
        at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:201) ~[jetty-server-9.4.14.v20181114.jar:9.4.14.v20181114]
        at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1247) ~[jetty-server-9.4.14.v20181114.jar:9.4.14.v20181114]
        at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:144) ~[jetty-server-9.4.14.v20181114.jar:9.4.14.v20181114]
        at org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:220) ~[jetty-server-9.4.14.v20181114.jar:9.4.14.v20181114]
        at org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.java:126) ~[jetty-server-9.4.14.v20181114.jar:9.4.14.v20181114]
        … 11 more
        Caused by: java.lang.IllegalArgumentException: Incorrect number of labels.
        at io.prometheus.client.SimpleCollector.labels(SimpleCollector.java:64) ~[?:?]
        at se.app.web.prometheus.PrometheusMetricsInterceptor.postHandle(PrometheusMetricsInterceptor.java:37) ~[?:?]
        at org.springframework.web.servlet.HandlerExecutionChain.applyPostHandle(HandlerExecutionChain.java:156) ~[?:?]
        at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1045) ~[?:?]
        at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:942) ~[?:?]
        at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:998) ~[?:?]
        at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:890) ~[?:?]
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:687) ~[javax.servlet-api-3.1.0.jar:3.1.0]
        at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:875) ~[?:?]
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:790) ~[javax.servlet-api-3.1.0.jar:3.1.0]
        at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:867) ~[jetty-servlet-9.4.14.v20181114.jar:9.4.14.v20181114]
        at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1623) ~[jetty-servlet-9.4.14.v20181114.jar:9.4.14.v20181114]
        at se.app.struts.filter.UTF8Filter.doFilter(UTF8Filter.java:33) ~[?:?]
        at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1610) ~[jetty-servlet-9.4.14.v20181114.jar:9.4.14.v20181114]
        at se.app.struts.filter.StrutsSecurityFilter.doFilter(StrutsSecurityFilter.java:56) ~[?:?]
        at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1610) ~[jetty-servlet-9.4.14.v20181114.jar:9.4.14.v20181114]
        at se.app.struts.filter.IdleTimeoutFilter.doFilter(IdleTimeoutFilter.java:85) ~[?:?]
        at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1610) ~[jetty-servlet-9.4.14.v20181114.jar:9.4.14.v20181114]
        at org.eclipse.jetty.websocket.server.WebSocketUpgradeFilter.doFilter(WebSocketUpgradeFilter.java:214) ~[websocket-server-9.4.14.v20181114.jar:9.4.14.v20181114]
        at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1610) ~[jetty-servlet-9.4.14.v20181114.jar:9.4.14.v20181114]
        at se.app.struts.filter.NoCacheFilter.doFilter(NoCacheFilter.java:31) ~[?:?]
        at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1610) ~[jetty-servlet-9.4.14.v20181114.jar:9.4.14.v20181114]
        at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:317) ~[?:?]
        at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:127) ~[?:?]
        at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:91) ~[?:?]
        at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331) ~[?:?]
        at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:114) ~[?:?]
        at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331) ~[?:?]
        at org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:137) ~[?:?]
        at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331) ~[?:?]
        at org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:111) ~[?:?]
        at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331) ~[?:?]
        at org.springframework.security.web.authentication.rememberme.RememberMeAuthenticationFilter.doFilter(RememberMeAuthenticationFilter.java:150) ~[?:?]
        at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331) ~[?:?]
        at org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:170) ~[?:?]
        at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331) ~[?:?]
        at org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:63) ~[?:?]
        at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331) ~[?:?]
        at org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:200) ~[?:?]
        at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331) ~[?:?]
        at se.app.web.security.appJwtAuthenticationFilter.doFilterInternal(AppJwtAuthenticationFilter.java:95) ~[?:?]
        at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-5.1.2.RELEASE.jar:5.1.2.RELEASE]
        at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331) ~[?:?]
        at org.springframework.security.web.header.HeaderWriterFilter.doFilterInternal(HeaderWriterFilter.java:64) ~[?:?]
        at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-5.1.2.RELEASE.jar:5.1.2.RELEASE]
        at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331) ~[?:?]
        at org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter.doFilterInternal(WebAsyncManagerIntegrationFilter.java:56) ~[?:?]
        at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-5.1.2.RELEASE.jar:5.1.2.RELEASE]
        at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331) ~[?:?]
        at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:105) ~[?:?]
        at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331) ~[?:?]
        at org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:214) ~[?:?]
        at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:177) ~[?:?]
        at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:357) ~[spring-web-5.1.2.RELEASE.jar:5.1.2.RELEASE]
        at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:270) ~[spring-web-5.1.2.RELEASE.jar:5.1.2.RELEASE]
        at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1610) ~[jetty-servlet-9.4.14.v20181114.jar:9.4.14.v20181114]
        at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:540) ~[jetty-servlet-9.4.14.v20181114.jar:9.4.14.v20181114]
        at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:146) ~[jetty-server-9.4.14.v20181114.jar:9.4.14.v20181114]
        at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:548) ~[jetty-security-9.4.14.v20181114.jar:9.4.14.v20181114]
        at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:132) ~[jetty-server-9.4.14.v20181114.jar:9.4.14.v20181114]
        at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:257) ~[jetty-server-9.4.14.v20181114.jar:9.4.14.v20181114]
        at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:1588) ~[jetty-server-9.4.14.v20181114.jar:9.4.14.v20181114]
        at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:255) ~[jetty-server-9.4.14.v20181114.jar:9.4.14.v20181114]
        at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1345) ~[jetty-server-9.4.14.v20181114.jar:9.4.14.v20181114]
        at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:203) ~[jetty-server-9.4.14.v20181114.jar:9.4.14.v20181114]
        at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:480) ~[jetty-servlet-9.4.14.v20181114.jar:9.4.14.v20181114]
        at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:1557) ~[jetty-server-9.4.14.v20181114.jar:9.4.14.v20181114]
        at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:201) ~[jetty-server-9.4.14.v20181114.jar:9.4.14.v20181114]
        at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1247) ~[jetty-server-9.4.14.v20181114.jar:9.4.14.v20181114]
        at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:144) ~[jetty-server-9.4.14.v20181114.jar:9.4.14.v20181114]
        at org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:220) ~[jetty-server-9.4.14.v20181114.jar:9.4.14.v20181114]
        at org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.java:126) ~[jetty-server-9.4.14.v20181114.jar:9.4.14.v20181114]
        … 11 more

        Reply
  2. For the demo purpose, i have used 3.1.2.RELEASE version.May i know which version of spring you are using here?

    Also you an try passing blank String parameter for remaining 3 fields as below on line #49-

    requestLatency.labels(name, method,””,””,””).startTimer()

    Reply
    • Since you have:
      .labelNames(“systemId”, “appId”, “type”, “name”, “method”)

      I think it is better to set those values instead of blank strings
      timerThreadLocal.set(requestLatency.labels(“mySystemId”, “myAppId”, “myType”, name, method).startTimer());

      Reply

Leave a Comment

Bitnami