Diego
Diego

Reputation: 11

JPetShop and Azure Application Insight

I would like to to test the Application Insight tool of Microsoft Azure. For this reason, I took a Spring application, jpetshop (https://github.com/mybatis/jpetstore-6), and I am trying to set up the Application Insight on top of it following this guide: https://learn.microsoft.com/en-us/azure/application-insights/app-insights-java-get-started

I added the Maven dependency and repository and, thanks to Eclipse, I created the ApplicationInsights.xml file with my InstrumentationKey. The only thing that I am not sure about is how to add is the HTTP filter on this application.

I modified the web.xml in this way:

    <?xml version="1.0" encoding="UTF-8" standalone="no"?>

<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
    version="2.5">
    <display-name>JPetStore</display-name>
    <description>Online Pet Store Sample Application</description>
    <context-param>
        <param-name>javax.servlet.jsp.jstl.fmt.localizationContext</param-name>
        <param-value>StripesResources</param-value>
    </context-param>
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
    <filter>
        <display-name>Stripes Filter</display-name>
        <filter-name>StripesFilter</filter-name>
        <filter-class>net.sourceforge.stripes.controller.StripesFilter</filter-class>
        <init-param>
            <param-name>ActionResolver.Packages</param-name>
            <param-value>org.mybatis.jpetstore.web</param-value>
        </init-param>
        <init-param>
            <param-name>Extension.Packages</param-name>
            <param-value>net.sourceforge.stripes.integration.spring</param-value>
        </init-param>

        <init-param>
            <param-name>ApplicationInsightsRequestNameInterceptor</param-name>
            <param-value>com.microsoft.applicationinsights.web.struts.RequestNameInterceptor</param-value>
        </init-param>     

    </filter>
    <filter-mapping>
        <filter-name>StripesFilter</filter-name>
        <servlet-name>StripesDispatcher</servlet-name>
        <dispatcher>REQUEST</dispatcher>
    </filter-mapping>
    <servlet>
        <servlet-name>StripesDispatcher</servlet-name>
        <servlet-class>net.sourceforge.stripes.controller.DispatcherServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>StripesDispatcher</servlet-name>
        <url-pattern>*.action</url-pattern>
    </servlet-mapping>
</web-app>

However, if I change the filter-mapper field as shown in the guide, the application doesn't work anymore.

Since the jpetshop application uses the Spring framework I also though to modify the *-servlet.xml file. However, this file is not present in this project.

Do you know how can I make the Azure Application Insight work on this application? Thank you

Upvotes: 1

Views: 127

Answers (1)

user3129358
user3129358

Reputation: 56

I think you missed the section where you need to define ApplicationInsights's filter:

<filter>
  <filter-name>ApplicationInsightsWebFilter</filter-name>
  <filter-class>
    com.microsoft.applicationinsights.web.internal.WebRequestTrackingFilter
  </filter-class>
</filter>
<filter-mapping>
   <filter-name>ApplicationInsightsWebFilter</filter-name>
   <url-pattern>/*</url-pattern>
</filter-mapping>

Upvotes: 1

Related Questions