Azure Application Insights Integration with my component

Avatar

Avatar

archanar9327882

Avatar

archanar9327882

archanar9327882

01-11-2018

  • In  my pom.xml , I have added the below lines of code:

<dependency>

<groupId>com.microsoft.azure</groupId>

<artifactId>applicationinsights-web</artifactId>

<version>2.2.0</version>

     </dependency>

……………………………………………………………………………..

<Export-Package>  com.microsoft.applicationinsights.*,

</Export-Package>

  • Sample code Snippet: In my @component/@service/ Servlet class(all these are felix scr annotations) used in AEM 6.2 , I have given below lines of code.

import com.microsoft.applicationinsights.TelemetryClient;

import com.microsoft.applicationinsights.TelemetryConfiguration;

import com.microsoft.applicationinsights.telemetry.TelemetryContext;

………………………………………….

…………………………………….

private static TelemetryClient telemetry = new TelemetryClient();

…………………….

By some means I m setting the instrumentation key also.

…………………

Inside a method,

try {

       My custom logic………………………..

} catch (Exception e) {

telemetry.trackException(e);

LOGGER.error(e.getMessage());

}

So whenever i instantiate the TelemetryClient , the component/service/servlet  in which i do this, goes to "satisfied" state instead of "active" state. Fo example, i have used the above client in component - i get following error:

01.11.2018 07:16:46.773 *ERROR* [FelixDispatchQueue] org.apache.sling.auth.core FrameworkEvent ERROR (org.osgi.framework.ServiceException: Service factory returned null. (Component: Project.package.CustomHandler (id of the component: 12360)))

org.osgi.framework.ServiceException: Service factory returned null. (Component: Project.package.CustomHandler  (12360))

at org.apache.felix.framework.ServiceRegistrationImpl.getFactoryUnchecked(ServiceRegistrationImpl.java:380)

at org.apache.felix.framework.ServiceRegistrationImpl.getService(ServiceRegistrationImpl.java:247)

at org.apache.felix.framework.ServiceRegistry.getService(ServiceRegistry.java:344)

at org.apache.felix.framework.Felix.getService(Felix.java:3699)

at org.apache.felix.framework.BundleContextImpl.getService(BundleContextImpl.java:470)

at org.osgi.util.tracker.ServiceTracker.addingService(ServiceTracker.java:414)

at org.apache.sling.auth.core.impl.SlingAuthenticator$AuthenticationHandlerTracker.addingService(SlingAuthenticator.java:1634)

at org.osgi.util.tracker.ServiceTracker$Tracked.customizerAdding(ServiceTracker.java:941)

at org.osgi.util.tracker.ServiceTracker$Tracked.customizerAdding(ServiceTracker.java:870)

at org.osgi.util.tracker.AbstractTracked.trackAdding(AbstractTracked.java:256)

at org.osgi.util.tracker.AbstractTracked.track(AbstractTracked.java:229)

at org.osgi.util.tracker.ServiceTracker$Tracked.serviceChanged(ServiceTracker.java:901)

at org.apache.felix.framework.util.EventDispatcher.invokeServiceListenerCallback(EventDispatcher.java:991)

at org.apache.felix.framework.util.EventDispatcher.fireEventImmediately(EventDispatcher.java:839)

at org.apache.felix.framework.util.EventDispatcher.fireServiceEvent(EventDispatcher.java:546)

at org.apache.felix.framework.Felix.fireServiceEvent(Felix.java:4557)

at org.apache.felix.framework.Felix.registerService(Felix.java:3549)

at org.apache.felix.framework.BundleContextImpl.registerService(BundleContextImpl.java:348)

at org.apache.felix.scr.impl.manager.AbstractComponentManager$3.register(AbstractComponentManager.java:869)

at org.apache.felix.scr.impl.manager.AbstractComponentManager$3.register(AbstractComponentManager.java:857)

at org.apache.felix.scr.impl.manager.RegistrationManager.changeRegistration(RegistrationManager.java:133)

at org.apache.felix.scr.impl.manager.AbstractComponentManager.registerService(AbstractComponentManager.java:915)

at org.apache.felix.scr.impl.manager.AbstractComponentManager.activateInternal(AbstractComponentManager.java:715)

at org.apache.felix.scr.impl.manager.DependencyManager$SingleStaticCustomizer.addedService(DependencyManager.java:954)

at org.apache.felix.scr.impl.manager.DependencyManager$SingleStaticCustomizer.addedService(DependencyManager.java:915)

at org.apache.felix.scr.impl.manager.ServiceTracker$Tracked.customizerAdded(ServiceTracker.java:1215)

at org.apache.felix.scr.impl.manager.ServiceTracker$Tracked.customizerAdded(ServiceTracker.java:1136)

at org.apache.felix.scr.impl.manager.ServiceTracker$AbstractTracked.trackAdding(ServiceTracker.java:945)

at org.apache.felix.scr.impl.manager.ServiceTracker$AbstractTracked.track(ServiceTracker.java:881)

at org.apache.felix.scr.impl.manager.ServiceTracker$Tracked.serviceChanged(ServiceTracker.java:1167)

at org.apache.felix.scr.impl.BundleComponentActivator$ListenerInfo.serviceChanged(BundleComponentActivator.java:120)

at org.apache.felix.framework.util.EventDispatcher.invokeServiceListenerCallback(EventDispatcher.java:991)

at org.apache.felix.framework.util.EventDispatcher.fireEventImmediately(EventDispatcher.java:839)

at org.apache.felix.framework.util.EventDispatcher.fireServiceEvent(EventDispatcher.java:546)

at org.apache.felix.framework.Felix.fireServiceEvent(Felix.java:4557)

at org.apache.felix.framework.Felix.registerService(Felix.java:3549)

at org.apache.felix.framework.BundleContextImpl.registerService(BundleContextImpl.java:348)

at org.apache.felix.scr.impl.manager.AbstractComponentManager$3.register(AbstractComponentManager.java:869)

at org.apache.felix.scr.impl.manager.AbstractComponentManager$3.register(AbstractComponentManager.java:857)

at org.apache.felix.scr.impl.manager.RegistrationManager.changeRegistration(RegistrationManager.java:133)

at org.apache.felix.scr.impl.manager.AbstractComponentManager.registerService(AbstractComponentManager.java:915)

at org.apache.felix.scr.impl.manager.AbstractComponentManager.activateInternal(AbstractComponentManager.java:715)

at org.apache.felix.scr.impl.manager.AbstractComponentManager.enable(AbstractComponentManager.java:399)

at org.apache.felix.scr.impl.config.ConfigurableComponentHolder.enableComponents(ConfigurableComponentHolder.java:676)

at org.apache.felix.scr.impl.BundleComponentActivator.initialEnable(BundleComponentActivator.java:339)

at org.apache.felix.scr.impl.Activator.loadComponents(Activator.java:360)

at org.apache.felix.scr.impl.Activator.access$000(Activator.java:53)

at org.apache.felix.scr.impl.Activator$ScrExtension.start(Activator.java:260)

at org.apache.felix.utils.extender.AbstractExtender.createExtension(AbstractExtender.java:259)

at org.apache.felix.utils.extender.AbstractExtender.modifiedBundle(AbstractExtender.java:232)

at org.osgi.util.tracker.BundleTracker$Tracked.customizerModified(BundleTracker.java:482)

at org.osgi.util.tracker.BundleTracker$Tracked.customizerModified(BundleTracker.java:415)

at org.osgi.util.tracker.AbstractTracked.track(AbstractTracked.java:232)

at org.osgi.util.tracker.BundleTracker$Tracked.bundleChanged(BundleTracker.java:444)

at org.apache.felix.framework.util.EventDispatcher.invokeBundleListenerCallback(EventDispatcher.java:916)

at org.apache.felix.framework.util.EventDispatcher.fireEventImmediately(EventDispatcher.java:835)

at org.apache.felix.framework.util.EventDispatcher.fireBundleEvent(EventDispatcher.java:517)

at org.apache.felix.framework.Felix.fireBundleEvent(Felix.java:4541)

at org.apache.felix.framework.Felix.startBundle(Felix.java:2172)

at org.apache.felix.framework.Felix$RefreshHelper.restart(Felix.java:5063)

at org.apache.felix.framework.Felix.refreshPackages(Felix.java:4253)

at org.apache.felix.framework.FrameworkWiringImpl.run(FrameworkWiringImpl.java:188)

at java.lang.Thread.run(Unknown Source)

Someone kindly guide me how i could resolve this.

Thanks in advance.

Replies

Avatar

Avatar

vivekanand-mishra

Employee

Avatar

vivekanand-mishra

Employee

vivekanand-mishra
Employee

15-10-2019

Hi Abhay,

I hope you are following this article- Performance monitoring for Java web apps in Azure Application Insights | Microsoft Docs

I have not tried this. But I suggest modify your AEM start up script and change this line to include java-agent:

if not defined CQ_JVM_OPTS set CQ_JVM_OPTS=-Xmx1024m -XX:MaxPermSize=256M -Djava.awt.headless=true -Xdebug -Xrunjdwp:transport=dt_socket,server=y,address=8080,suspend=n -javaagent:<full path to agent JAR file>

Are you facing any issue while setting up agent?

Thanks.

Avatar

Avatar

abhay_kumarm728

Avatar

abhay_kumarm728

abhay_kumarm728

15-10-2019

Hi Vivekanand,

       I am following the same above link for Java Agent set up in AEM. But somehow AppInsights Java Agent  is NOT capturing "Dependency calls" on it's own for AEM server side code. Ideally Java Agent must be able to track HTTP requests (server side tracking, not the client side), dependencies and exceptions.

Using sample example web app (not AEM app) deployed in Azure Tomcat - ApplicationInsights-Java/samples/app-services at master · microsoft/ApplicationInsights-Java · GitH... , I am able to capture HTTP requests (server side tracking, not the client side), dependencies and exceptions.

Now I need your help to make Java Agent working in AEM 6.4.2.0. Please be informed that as per documentation, I am putting java agent jar & AI-Agent.xml in the same folder but somehow dependency calls are NOT being tracked. Using your earlier provided Web Filter, I was able to track Server Side Web request and Unhandled exception. Request you to guide us on making "AppInsights Java Agent"  working with AEM. Thanks for the help.

Regards,

Abhay

Avatar

Avatar

vivekanand-mishra

Employee

Avatar

vivekanand-mishra

Employee

vivekanand-mishra
Employee

21-10-2019

Hi Abhay,

There was some embed-dependency issue with the repo that I shared. I have updated the code at - GitHub - vivekanand-mishra/app-insights . Now, It should be running fine and request tracking should work properly with AEM just make sure to provide correct instrumentation key. Can you try out this in your AEM app and confirm back. I am looking for contributions in this repo to make this robust for any future AEM-App Insight Integration. If interested, please share your git user details, I will add you to it.

Regarding java agent - it has 3 simple steps to configure with AEM:

1. Deploy web tracking filter code to AEM (Reference code- GitHub - vivekanand-mishra/app-insights ) and ensure that the request tracking is working fine

2. Modify start.bat script to add javaagent parameter as below:

if not defined CQ_JVM_OPTS set CQ_JVM_OPTS=-Xmx1024m -XX:MaxPermSize=256M -Djava.awt.headless=true -Xdebug -Xrunjdwp:transport=dt_socket,server=y,address=8080,suspend=n -javaagent:<full path to agent JAR file>

3. Check AEM error log and the app insight logs (Location: C:\Users\<usrid>\AppData\Local\Temp) for any issue.

In case if this does not work please contact Microsoft Azure team through their support center, they should be able to guide further on this topic.

Thanks!

Avatar

Avatar

varuns69729001

Avatar

varuns69729001

varuns69729001

16-04-2020

There is a configurationPid = "com.insights.sample.core.filters.AppInsightsConfigFilter in the AppInsightsTestFilter but I am not able to find this above class. Can you help on that?