Deepak Shrivastava
Deepak Shrivastava

Reputation: 67

Unable to push logs to application insights using logback appenders

I have a java web app (springboot app) where in I want to push the logs to the application insights in azure. I am using logback as my logging framework as it is natively supported by Springboot. I followed the following blog for the integration of the applicationInsights for my web app.

https://github.com/AzureCAT-GSI/DevCamp/tree/master/HOL/java/06-appinsights

As per this blog I have created the following:

  1. created the application insights resource in azure
  2. created the filter in my java web app to capture the http requests
  3. created ApplicationInsights.xml
  4. created logback.xml which will have the AI appender provided by Azure.

here are the snippets from my web app

1) ApplicationInsight filter class is as follows:-

@Configuration

public class AppInsightsConfig {

    @Bean
    public String telemetryConfig() {
        String telemetryKey = System.getenv("APPLICATION_INSIGHTS_IKEY");
        if (telemetryKey != null) {
            TelemetryConfiguration.getActive().setInstrumentationKey(telemetryKey);
        }
        return telemetryKey;
    }

    @Bean
    @Order(1)
    public org.springframework.boot.web.servlet.FilterRegistrationBean aiFilterRegistration() {
        FilterRegistrationBean registration = new FilterRegistrationBean();
        registration.setFilter(new WebRequestTrackingFilter());
        registration.addUrlPatterns("/**");
        registration.setOrder(1);
        return registration;
    } 

    @Bean(name = "WebRequestTrackingFilter")
    public Filter WebRequestTrackingFilter() {
        return new WebRequestTrackingFilter();
    }   
}

2) ApplicationInsights.xml (src/main/resources folder)

<?xml version="1.0" encoding="UTF-8"?>
<ApplicationInsights xmlns="http://schemas.microsoft.com/ApplicationInsights/2013/Settings" schemaVersion="2014-05-30">


    <!-- The key from the portal: -->

    <InstrumentationKey>my app key</InstrumentationKey>


    <!-- HTTP request component (not required for bare API) -->

    <TelemetryModules>
        <Add type="com.microsoft.applicationinsights.web.extensibility.modules.WebRequestTrackingTelemetryModule"/>
        <Add type="com.microsoft.applicationinsights.web.extensibility.modules.WebSessionTrackingTelemetryModule"/>
        <Add type="com.microsoft.applicationinsights.web.extensibility.modules.WebUserTrackingTelemetryModule"/>
    </TelemetryModules>

    <!-- Events correlation (not required for bare API) -->
    <!-- These initializers add context data to each event -->

    <TelemetryInitializers>
        <Add   type="com.microsoft.applicationinsights.web.extensibility.initializers.WebOperationIdTelemetryInitializer"/>
        <Add type="com.microsoft.applicationinsights.web.extensibility.initializers.WebOperationNameTelemetryInitializer"/>
        <Add type="com.microsoft.applicationinsights.web.extensibility.initializers.WebSessionTelemetryInitializer"/>
        <Add type="com.microsoft.applicationinsights.web.extensibility.initializers.WebUserTelemetryInitializer"/>
        <Add type="com.microsoft.applicationinsights.web.extensibility.initializers.WebUserAgentTelemetryInitializer"/>

    </TelemetryInitializers>
    </ApplicationInsights>  

3) Logback.xml is as follows:-

<configuration>
    <appender name="aiAppender" 
        class="com.microsoft.applicationinsights.logback.ApplicationInsightsAppender">
    </appender>
    <root level="trace">
        <appender-ref ref="aiAppender" />
    </root>

    <logger name="org.springframework.web" level="INFO"/>
</configuration>

The issue is that I am not able to push the logs to the app insights. However I am able to get the telemetries in the app insights.

Note: I am using the latest versions of appinsights libraries (core and web)

Upvotes: 2

Views: 1807

Answers (3)

Dhaval Doshi
Dhaval Doshi

Reputation: 129

A new version of Application Insights Java SDK v2.0.0-BETA is now out. Please upgrade to this version. The issue is now fixed.

Upvotes: 0

fanfanta
fanfanta

Reputation: 181

I had the same issue and I've downgraded the library version from 1.0.10 to 1.0.9 as you advised. it's resolved! Thank you.

Upvotes: 0

Deepak Shrivastava
Deepak Shrivastava

Reputation: 67

There seems to be a bug in azure library version 1.0.10. The fix is there in the next version 1.0.11. So to fix this, i downgraded the azure libraries to 1.0.9 and everything worked like a charm. The libraries application insights core/web/logback appender were down graded to 1.0.9 from 1.0.10.

The issue was only with logback appender. Log4j versions were behaving correctly with version 1.0.10.

Upvotes: 4

Related Questions