Skip to content
This repository has been archived by the owner on Jul 22, 2024. It is now read-only.

Added AI #35

Open
wants to merge 2 commits into
base: ai
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>applicationinsights-web</artifactId>
<version>[1.0,)</version>

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update version to 2.0.0-BETA for now and later to [2.0.,) once stable version is out.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nicolehaugen79 I still see the dependency version as [1.0,). Did you missed changing to 2.0.0-BETA ?

</dependency>
</dependencies>

<build>
Expand Down
32 changes: 32 additions & 0 deletions src/main/java/com/microsoft/azure/sample/AppInsightsConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/**
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See LICENSE in the project root for
* license information.
*/
package com.microsoft.azure.sample;

import javax.servlet.Filter;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import com.microsoft.applicationinsights.TelemetryConfiguration;
import com.microsoft.applicationinsights.web.internal.WebRequestTrackingFilter;;


@Configuration
public class AppInsightsConfig {

@Bean
public FilterRegistrationBean aiFilterRegistration() {
final FilterRegistrationBean registration = new FilterRegistrationBean();
registration.setFilter(new WebRequestTrackingFilter());
registration.addUrlPatterns("/**");
registration.setOrder(1);
return registration;
}

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well have you tried to instrument Application Insights Agent to collect dependencies in this application? Probably if you would like to collect the calls to documentDB (unfortunately not autocollected now) or other dependencies like HTTP outgoing via Apache HTTP, Redis etc. you would need to put a "name of type string representing application name" as a parameter to WebRequestTrackingFilter() . Feel free to ask for more details

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As we discussed, there is a bug that is blocking this - I logged an issue to add dependency tracking when the bug is fixed: #36

}
}
34 changes: 34 additions & 0 deletions src/main/resources/ApplicationInsights.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?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>put-your-instrumentation-key-here</InstrumentationKey>

<!-- Turn on logging in the IDE console windows to view Application Insights logging -->

<SDKLogger>
<Level>ALL</Level>
</SDKLogger>

<!-- 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>

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggest adding Tag so customers can see AI logs also in-case SDK behaves in a funky way.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it necessary to add a switch so that user could disable ai data collecting?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The intention of this version of the sample is to show collecting AI data, so I don't feel that is necessary.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yungez I don't think adding a switch would make sense as the purpose of the demo app as Nicole said is to show the use case of multiple azure services in java with azure monitoring capabilities with AI.

</ApplicationInsights>