microsoft / ApplicationInsights-Java

Application Insights for Java
http://aka.ms/application-insights
Other
296 stars 199 forks source link

I am unable to see spring boot multimodule app logs in appinsight #814

Closed githubpratibha closed 5 years ago

githubpratibha commented 5 years ago

Expected behavior

logs should be captured in azure app insight for all the modules Following document for Configure Springboot Application to send log4j logs to Application Insights

Actual behavior

unable to see spring boot app logs in appinsight while using different spring modules

To Reproduce

@dhaval24 I have two separate spring boot java modules. One is added as dependency in another. I am not able to push spring boot logs to app insight.Kindly help please

==============log4j2.xml in app module resources folder===============

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

%d{yyyy-MM-dd HH:mm:ss.SSS} %5p ${hostName} --- [%15.15t] %-40.40c{1.} : %m%n%ex

===========application.properties in app module==========

azure.application-insights.instrumentation-key=XXXXXX

spring.application.name=preferencecenter-app

azure.application-insights.enabled=true

azure.application-insights.logger.type=console

azure.application-insights.logger.level=trace

===============pom.xml for core module================

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

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

<modelVersion>4.0.0</modelVersion>

<groupId>com.sams.preferencecenter</groupId>
<artifactId>PreferenceCenter-core</artifactId>
<packaging>jar</packaging>
<version>0.0.7-SNAPSHOT</version>
<name>PreferenceCenter-core</name>
<description>Sam's Preference Center Core</description>

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.1.3.RELEASE</version>
    <relativePath/> <!-- lookup parent from repository -->
</parent>

<properties>
    <java.version>1.8</java.version>
    <azure.version>2.0.5</azure.version>
</properties>

<dependencies>
   <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
        <exclusions>
            <exclusion>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-logging</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>org.testng</groupId>
        <artifactId>testng</artifactId>
        <version>6.14.3</version>
    </dependency>
    <dependency>
        <groupId>commons-beanutils</groupId>
        <artifactId>commons-beanutils</artifactId>
        <version>1.8.2</version>
        <exclusions>
            <exclusion>
                <groupId>commons-logging</groupId>
                <artifactId>commons-logging</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>org.hibernate.javax.persistence</groupId>
        <artifactId>hibernate-jpa-2.1-api</artifactId>
        <version>1.0.0.Final</version>
    </dependency>

    <dependency>
        <groupId>com.microsoft.azure</groupId>
        <artifactId>spring-data-cosmosdb</artifactId>
        <version>2.0.3</version>
    </dependency>
    <dependency>
        <groupId>javax.ws.rs</groupId>
        <artifactId>javax.ws.rs-api</artifactId>
        <version>2.0-m10</version>
    </dependency>
    <dependency>
        <groupId>org.codehaus.jackson</groupId>
        <artifactId>jackson-mapper-asl</artifactId>
        <version>1.9.13</version>
    </dependency>
    <dependency>
        <groupId>io.springfox</groupId>
        <artifactId>springfox-swagger2</artifactId>
        <version>2.9.2</version>
    </dependency>
    <dependency>
        <groupId>io.springfox</groupId>
        <artifactId>springfox-swagger-ui</artifactId>
        <version>2.9.2</version>
    </dependency>
    <dependency>
        <groupId>com.microsoft.azure</groupId>
        <artifactId>azure-keyvault-secrets-spring-boot-starter</artifactId>
        <version>2.0.7</version>
        <exclusions>
            <exclusion>
                <groupId>commons-logging</groupId>
                <artifactId>commons-logging</artifactId>
            </exclusion>
            <exclusion>
                <groupId>com.squareup.okhttp3</groupId>
                <artifactId>logging-interceptor</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>com.google.auto.value</groupId>
        <artifactId>auto-value-annotations</artifactId>
        <version>1.6.2</version>
    </dependency>
    <dependency>
        <groupId>com.google.auto.value</groupId>
        <artifactId>auto-value</artifactId>
        <version>1.6.2</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>org.projectlombok</groupId>
        <artifactId>lombok</artifactId>
        <version>1.16.22</version>
    </dependency>
</dependencies>

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>com.microsoft.azure</groupId>
            <artifactId>azure-spring-boot-bom</artifactId>
            <version>${azure.version}</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.7.0</version>
            <configuration>
                <source>${java.version}</source>
                <target>${java.version}</target>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-release-plugin</artifactId>
            <version>2.5.2</version>
            <configuration>
                <localCheckout>true</localCheckout>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.22.0</version>
            <configuration>
                <trimStackTrace>false</trimStackTrace>
                <systemPropertyVariables>
                    <jacoco-agent.destfile>${project.build.directory}/coverage-reports/jacoco.exec</jacoco-agent.destfile>
                </systemPropertyVariables>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.jacoco</groupId>
            <artifactId>jacoco-maven-plugin</artifactId>
            <version>0.8.1</version>
            <executions>
                <execution>
                    <id>default-prepare-agent</id>
                    <goals>
                        <goal>prepare-agent</goal>
                    </goals>
                    <configuration>
                        <destFile>${project.build.directory}/coverage-reports/jacoco.exec</destFile>
                    </configuration>
                </execution>
                <execution>
                    <id>default-report</id>
                    <phase>prepare-package</phase>
                    <goals>
                        <goal>report</goal>
                    </goals>
                    <configuration>
                        <dataFile>${project.build.directory}/coverage-reports/jacoco.exec</dataFile>
                        <!-- Sets the output directory for the code coverage report. -->
                        <outputDirectory>${project.reporting.outputDirectory}/jacoco</outputDirectory>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

========pom.xml for app module in which core module is added as dependency====

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

<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

     xmlns="http://maven.apache.org/POM/4.0.0"

     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

<modelVersion>4.0.0</modelVersion>
<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.1.3.RELEASE</version>
    <relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.walmart.sams.preferencecenter</groupId>
<artifactId>preferencecenter-app</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>preferencecenter-app</name>
<description>preferencecenter-app</description>

<properties>
    <java.version>1.8</java.version>
    <preference.core.version>0.0.6-SNAPSHOT</preference.core.version>
</properties>

<dependencies>

    <dependency>
        <groupId>com.walmart.sams.preferencecenter</groupId>
        <artifactId>PreferenceCenter-core</artifactId>
        <version>${preference.core.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
        <exclusions>
            <exclusion>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-logging</artifactId>
            </exclusion>
        </exclusions>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-log4j2</artifactId>
    </dependency>

    <dependency>
        <groupId>com.microsoft.azure</groupId>
        <artifactId>applicationinsights-spring-boot-starter</artifactId>
        <version>1.1.1</version>
    </dependency>

    <dependency>
        <groupId>com.microsoft.azure</groupId>
        <artifactId>applicationinsights-logging-log4j2</artifactId>
        <version>2.1.1</version>
    </dependency>
</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>

System information

Please provide the following information:

dhaval24 commented 5 years ago

@githubpratibha thanks for creating a new ticket. First of all : you do not need:

azure.application-insights.logger.type=console

azure.application-insights.logger.level=trace

These properties have nothing to do with configuring logging appender. Instead these are meant to enable debug logs for Application Insight Java SDK. (nonetheless its good that you have kept it enabled. Do you see any wired exceptions etc that come out of Application Insights SDK in your stack trace? They should be prefixed with AI: ).

Some clarification questions that will help me. Do you see, any logs at all on your AI resource?

If yes, do you only see the logs for the module in which the AI dependencies are added but not for the transitive module you depend on?

Also where is your log4j config file placed? Is it configured in the main application?

The easiest and most quick way to debug might also be if you can possibly upload a sample dummy application to test the behavior.

githubpratibha commented 5 years ago

Thanks @dhaval24 for looking into this I just fixed it by updating pom.xml for core module.Just excluded the unnecessary dependencies specially the ones which have logging dependencies included in their dependency tree. Because we are already providing appinsights log4j2 dependency in app module pom.xml we should exclude all other dependencies which have logging dependencies included in their dependency tree. Otherwise, they clash and no logs are sent to app-insight.

===============pom.xml for core module================

com.microsoft.azure azure-spring-boot org.springframework.boot spring-boot-autoconfigure org.slf4j slf4j-api org.springframework.boot spring-boot-starter-web org.springframework.boot spring-boot-starter-logging org.testng testng 6.14.3 test commons-beanutils commons-beanutils 1.8.2 commons-logging commons-logging org.hibernate.javax.persistence hibernate-jpa-2.1-api 1.0.0.Final com.microsoft.azure spring-data-cosmosdb 2.0.3 javax.ws.rs javax.ws.rs-api 2.0-m10 org.codehaus.jackson jackson-mapper-asl 1.9.13 io.springfox springfox-swagger2 2.9.2 io.springfox springfox-swagger-ui 2.9.2 com.microsoft.azure azure-keyvault-secrets-spring-boot-starter 2.0.7 org.springframework.boot spring-boot-starter-validation commons-logging commons-logging com.microsoft.azure azure-spring-boot com.google.code.findbugs annotations com.squareup.okhttp3 logging-interceptor com.microsoft.azure azure-spring-boot-starter org.projectlombok lombok 1.16.22 com.microsoft.azure azure-cosmosdb 2.2.0 com.microsoft.azure applicationinsights-core 2.3.0
dhaval24 commented 5 years ago

Awesome @githubpratibha that is great! Thanks for updating. Please feel free to open any issues on Github if you face further problems.