Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Failed to scan packages 'com.microsoft.applicationinsights' (When AI libraries are part of Uber SpringBoot Jar) #553

Closed
maciejkopecpl opened this issue Feb 9, 2018 · 21 comments
Assignees
Labels

Comments

@maciejkopecpl
Copy link

Hey,

I trying to use Application Insights with Spring Boot, packed as a single jar. I encounter a problem during startup, here is my log:

AI: INFO 09-02-2018 12:14, 24: Registering WebApp with name 'webapp'
AI: INFO 09-02-2018 12:14, 24: Configuration file has been successfully found as resource
AI: INFO 09-02-2018 12:14, 24: 'MaxTelemetryBufferCapacity': null value is replaced with '500'
AI: INFO 09-02-2018 12:14, 24: 'FlushIntervalInSeconds': null value is replaced with '5'
AI: TRACE 09-02-2018 12:14, 24: Using Http Client version 4.3+
AI: INFO 09-02-2018 12:14, 24: 'Channel.MaxTransmissionStorageCapacityInMB': null value is replaced with '10'
AI: ERROR 09-02-2018 12:14, 24: Failed to scan packages 'com.microsoft.applicationinsights': exception: 'URI is not hierarchical'
AI: TRACE 09-02-2018 12:14, 24: Default performance counters will be automatically loaded.
AI: TRACE 09-02-2018 12:14, 24: ****\AISDK\native\1.0.10 folder exists
AI: TRACE 09-02-2018 12:14, 24: Java process name is set to 'java#1'
AI: TRACE 09-02-2018 12:14, 24: Successfully loaded library 'applicationinsights-core-native-win64.dll'
AI: INFO 09-02-2018 12:14, 24: Configuration file has been successfully found as resource
AI: INFO 09-02-2018 12:14, 24: 'MaxTelemetryBufferCapacity': null value is replaced with '500'
AI: INFO 09-02-2018 12:14, 24: 'FlushIntervalInSeconds': null value is replaced with '5'
AI: INFO 09-02-2018 12:14, 24: 'Channel.MaxTransmissionStorageCapacityInMB': null value is replaced with '10'
AI: ERROR 09-02-2018 12:14, 24: Failed to scan packages 'com.microsoft.applicationinsights': exception: 'URI is not hierarchical'
AI: TRACE 09-02-2018 12:14, 24: Default performance counters will be automatically loaded.
AI: TRACE 09-02-2018 12:14, 24: ****\AISDK\native\1.0.10 folder exists
AI: TRACE 09-02-2018 12:14, 24: Java process name is set to 'java#1'
AI: TRACE 09-02-2018 12:14, 24: Successfully loaded library 'applicationinsights-core-native-win64.dll'
AI: TRACE 09-02-2018 12:14, 24: Registering PC 'JSDK_ProcessMemoryPerformanceCounter'
AI: TRACE 09-02-2018 12:14, 24: Registering PC 'JSDK_ProcessCpuPerformanceCounter'
AI: TRACE 09-02-2018 12:14, 24: Registering PC 'JSDK_WindowsPerformanceCounterAsPC'
AI: ERROR 09-02-2018 12:14, 24: Failed to create WindowsPerformanceCounterAsPC: 'Failed to register all built-in Windows performance counters.'
AI: TRACE 09-02-2018 12:14, 24: Registering PC 'JSDK_ProcessMemoryPerformanceCounter'
AI: TRACE 09-02-2018 12:14, 24: Failed to store performance counter 'JSDK_ProcessMemoryPerformanceCounter', since there is already one
AI: TRACE 09-02-2018 12:14, 24: Registering PC 'JSDK_ProcessCpuPerformanceCounter'
AI: TRACE 09-02-2018 12:14, 24: Failed to store performance counter 'JSDK_ProcessCpuPerformanceCounter', since there is already one
AI: INFO 09-02-2018 12:14, 24: Registered WebApp 'webapp' key='webapp'
AI: INFO 09-02-2018 12:14, 24: Successfully registered the filter 'ApplicationInsightsWebFilter'

I tried to use 2.0.0-BETA version too, but I get very similar results:

AI: INFO 09-02-2018 11:26, 20: Agent was not found. Skipping the agent registration
AI: INFO 09-02-2018 11:26, 20: Configuration file has been successfully found as resource
AI: INFO 09-02-2018 11:26, 20: 'MaxTelemetryBufferCapacity': null value is replaced with '500'
AI: INFO 09-02-2018 11:26, 20: 'FlushIntervalInSeconds': null value is replaced with '5'
AI: TRACE 09-02-2018 11:26, 20: Using Http Client version 4.3+
AI: INFO 09-02-2018 11:26, 20: 'Channel.MaxTransmissionStorageCapacityInMB': null value is replaced with '10'
**AI: ERROR 09-02-2018 11:26, 20: Failed to scan packages 'com.microsoft.applicationinsights': exception: 'null'**
AI: TRACE 09-02-2018 11:26, 20: Stack trace generated is java.lang.NullPointerException
        at java.io.File.<init>(File.java:277)
        at com.microsoft.applicationinsights.core.dependencies.annotation.AnnotationDetector.toFile(AnnotationDetector.java:334)
        at com.microsoft.applicationinsights.core.dependencies.annotation.AnnotationDetector.detect(AnnotationDetector.java:287)
        at com.microsoft.applicationinsights.internal.annotation.AnnotationPackageScanner.scanForClassAnnotations(AnnotationPackageScanner.java:58)
        at com.microsoft.applicationinsights.internal.config.TelemetryConfigurationFactory.getPerformanceModules(TelemetryConfigurationFactory.java:283)
        at com.microsoft.applicationinsights.internal.config.TelemetryConfigurationFactory.setTelemetryModules(TelemetryConfigurationFactory.java:175)
        at com.microsoft.applicationinsights.internal.config.TelemetryConfigurationFactory.initialize(TelemetryConfigurationFactory.java:107)
        at com.microsoft.applicationinsights.TelemetryConfiguration.getActive(TelemetryConfiguration.java:70)
        at com.microsoft.applicationinsights.web.internal.WebRequestTrackingFilter.init(WebRequestTrackingFilter.java:133)
        at org.apache.catalina.core.ApplicationFilterConfig.initFilter(ApplicationFilterConfig.java:285)
        at org.apache.catalina.core.ApplicationFilterConfig.<init>(ApplicationFilterConfig.java:112)
        at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:4590)
        at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5233)
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
        at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1419)
        at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1409)
        at java.util.concurrent.FutureTask.run(FutureTask.java:266)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
        at java.lang.Thread.run(Thread.java:745)

AI: TRACE 09-02-2018 11:26, 20: Default performance counters will be automatically loaded.
AI: TRACE 09-02-2018 11:26, 20: ****\AISDK\native\2.0.0-BETA folder exists
AI: TRACE 09-02-2018 11:26, 20: Java process name is set to 'java'
AI: TRACE 09-02-2018 11:26, 20: Successfully loaded library 'applicationinsights-core-native-win32.dll'
AI: INFO 09-02-2018 11:26, 20: Configuration file has been successfully found as resource
AI: INFO 09-02-2018 11:26, 20: 'MaxTelemetryBufferCapacity': null value is replaced with '500'
AI: INFO 09-02-2018 11:26, 20: 'FlushIntervalInSeconds': null value is replaced with '5'
AI: INFO 09-02-2018 11:26, 20: 'Channel.MaxTransmissionStorageCapacityInMB': null value is replaced with '10'
**AI: ERROR 09-02-2018 11:26, 20: Failed to scan packages 'com.microsoft.applicationinsights': exception: 'null'**
AI: TRACE 09-02-2018 11:26, 20: Stack trace generated is java.lang.NullPointerException
        at java.io.File.<init>(File.java:277)
        at com.microsoft.applicationinsights.core.dependencies.annotation.AnnotationDetector.toFile(AnnotationDetector.java:334)
        at com.microsoft.applicationinsights.core.dependencies.annotation.AnnotationDetector.detect(AnnotationDetector.java:287)
        at com.microsoft.applicationinsights.internal.annotation.AnnotationPackageScanner.scanForClassAnnotations(AnnotationPackageScanner.java:58)
        at com.microsoft.applicationinsights.internal.config.TelemetryConfigurationFactory.getPerformanceModules(TelemetryConfigurationFactory.java:283)
        at com.microsoft.applicationinsights.internal.config.TelemetryConfigurationFactory.setTelemetryModules(TelemetryConfigurationFactory.java:175)
        at com.microsoft.applicationinsights.internal.config.TelemetryConfigurationFactory.initialize(TelemetryConfigurationFactory.java:107)
        at com.microsoft.applicationinsights.TelemetryConfiguration.getActive(TelemetryConfiguration.java:70)
        at com.microsoft.applicationinsights.internal.quickpulse.QuickPulse.initialize(QuickPulse.java:69)
        at com.microsoft.applicationinsights.internal.config.TelemetryConfigurationFactory.setQuickPulse(TelemetryConfigurationFactory.java:158)
        at com.microsoft.applicationinsights.internal.config.TelemetryConfigurationFactory.initialize(TelemetryConfigurationFactory.java:110)
        at com.microsoft.applicationinsights.TelemetryConfiguration.getActive(TelemetryConfiguration.java:70)
        at com.microsoft.applicationinsights.web.internal.WebRequestTrackingFilter.init(WebRequestTrackingFilter.java:133)
        at org.apache.catalina.core.ApplicationFilterConfig.initFilter(ApplicationFilterConfig.java:285)
        at org.apache.catalina.core.ApplicationFilterConfig.<init>(ApplicationFilterConfig.java:112)
        at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:4590)
        at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5233)
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
        at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1419)
        at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1409)
        at java.util.concurrent.FutureTask.run(FutureTask.java:266)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
        at java.lang.Thread.run(Thread.java:745)

AI: TRACE 09-02-2018 11:26, 20: Default performance counters will be automatically loaded.
AI: TRACE 09-02-2018 11:26, 20: ****\AISDK\native\2.0.0-BETA folder exists
AI: TRACE 09-02-2018 11:26, 20: Java process name is set to 'java'
AI: TRACE 09-02-2018 11:26, 20: Successfully loaded library 'applicationinsights-core-native-win32.dll'
AI: TRACE 09-02-2018 11:26, 20: InstrumentationKeyResolver - pending resolution of instrumentation key: 6bc524ed-0359-4b9f-a4cb-43720a52239a
AI: TRACE 09-02-2018 11:26, 20: Registering PC 'JSDK_ProcessMemoryPerformanceCounter'
AI: TRACE 09-02-2018 11:26, 20: Registering PC 'JSDK_ProcessCpuPerformanceCounter'
AI: TRACE 09-02-2018 11:26, 20: Registering PC 'JSDK_WindowsPerformanceCounterAsPC'
AI: TRACE 09-02-2018 11:26, 20: InstrumentationKeyResolver - pending resolution of instrumentation key: 6bc524ed-0359-4b9f-a4cb-43720a52239a
AI: ERROR 09-02-2018 11:26, 20: Failed to create WindowsPerformanceCounterAsPC: 'Failed to register all built-in Windows performance counters.'
AI: TRACE 09-02-2018 11:26, 20: Registering PC 'JSDK_ProcessMemoryPerformanceCounter'
AI: TRACE 09-02-2018 11:26, 20: Failed to store performance counter 'JSDK_ProcessMemoryPerformanceCounter', since there is already one
AI: TRACE 09-02-2018 11:26, 20: Registering PC 'JSDK_ProcessCpuPerformanceCounter'
AI: TRACE 09-02-2018 11:26, 20: Failed to store performance counter 'JSDK_ProcessCpuPerformanceCounter', since there is already one

I debuged it a little, and problem lies in library that is used to scan for annotations. It doesn't support opening files that are inside jar, that's the path where applicationinsights jar is stored when packed as a single jar:
jar:file:/C:/my-app.jar!/BOOT-INF/lib/applicationinsights-core-2.0.0-BETA.jar!/com/microsoft/applicationinsights/

So it's jar inside jar :) Any ideas how to fix that?

Best regards

@dhaval24
Copy link
Contributor

dhaval24 commented Feb 9, 2018

@MicNeo thank you for reporting the issue. Could you please update the thread with instructions on how to reproduce the issue? Also just a sanity check are you having both Application Insights core and Web jars inside the same uber spring boot jar? (i.e did you make sure you are not missing anyone). Also I believe annotation detector is commonly used library to detect annotations I believe. Correct me if I am wrong here.

@dhaval24 dhaval24 changed the title Failed to scan packages 'com.microsoft.applicationinsights' Failed to scan packages 'com.microsoft.applicationinsights' (When AI libraries are part of Uber SpringBoot Jar) Feb 9, 2018
@dhaval24
Copy link
Contributor

@MicNeo I tried to reproduce this issue by creating a spring boot application and packaged it into single jar using mvn package. I then executed the jar and I cannot find the same exception. I have placed followed the maven organization of packages.(https://maven.apache.org/guides/introduction/introduction-to-the-standard-directory-layout.html) Please let me know if you followed these guidelines for packaging or else provide us with the steps to reproduce the issue. FYI my Application Insights jars are residing in the same location in UberSpringBoot Jar

@dhaval24 dhaval24 self-assigned this Feb 11, 2018
@maciejkopecpl
Copy link
Author

@dhaval24 yes, of course both AI jars are in place, in that uber jar :) About reproduction steps of this one, really nothing fancy. It's simple spring boot app with configured AI via filter. How do you launch your test app? Directly from some IDE or in terminal, like java -jar UberSpringBoot.jar ?

@maciejkopecpl
Copy link
Author

Here you have project which reproduces that error. It's minimal setup of spring boot with AI. Pleace notice that I replaced instrumentation key to XXXX for security reasons :) To reproduce this bug, simply download that zip, extract, run mvn install, and then in your terminal run: java -jar target/demo-0.0.1-SNAPSHOT.jar

demo.zip

@dhaval24
Copy link
Contributor

@MicNeo I am using from the command line : like java -jar DemoApp.jar and it works fine.

@dhaval24
Copy link
Contributor

dhaval24 commented Feb 12, 2018

@Configuration
@ComponentScan("com.dhaval.springboot.studentservices")
public class AppInsightsConfig {
    

    @Bean
    public String telemetryConfig() {
        String telemetryKey = "XXXX";
        //System.out.println(appName);
        if (telemetryKey != null) {
            TelemetryConfiguration.getActive().setInstrumentationKey(telemetryKey);
        }
        return telemetryKey;
    }

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

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

You are basically providing the wrong base package in component scan - it should be the root package of your application. This is the possible culprit. Also your configuration misses one of the beans.

@maciejkopecpl
Copy link
Author

@dhaval24 I tried root package without success. Have you tried my sample project I have uploaded? Can you upload your working example? Maybe this is problem related with some JVM settings.

@dhaval24
Copy link
Contributor

@MicNeo sure, I would trim and upload it this evening. I have it in another machine.

@maciejkopecpl
Copy link
Author

@dhaval24 would you find some time to post your sample app which works for you? :)

@dhaval24
Copy link
Contributor

@MicNeo apologies got really caught up. I will try to upload something as soon as possible. Thanks for your patience.

@maciejkopecpl
Copy link
Author

@dhaval24 any news on that topic? sorry for rushing you but it's very important to me to have it working. If you got working example I could try to find out by my own what is wrong with my setup.

@dhaval24
Copy link
Contributor

SpringBootTestApp.zip

@MicNeo apologies for the delay. Here is the sample. Please replace the ikey in applicationinsights.xml and in the ApplicationInsightsConfig class with your ikey. Do mvn package. Run the jar.

You should be able to see all the telemetry on the portal. Apologies for the delay here.

@maciejkopecpl
Copy link
Author

@dhaval24 please add <SDKLogger /> in ApplicationInsights.xml file and then check logs again :) There are same errors which I mentioned in your sample app too. You just don't see them because of that log feature turned off.

@dhaval24
Copy link
Contributor

Ah crap, thanks for pointing out. Will take a look. By the way @MicNeo could you please try mvn spring-boot:run. And see if you get same error?

@dhaval24
Copy link
Contributor

@MicNeo yes, this is true and a very strange behavior. I see that on mvn package java -jar .... throws this exception but when I use the Springboot plugin mvn spring-boot:run I do not see this. I believe it is more on how maven orders while packaging. I found this issue on Spring Framework repository.

spring-projects/spring-boot#9324

Look at the comments it explains many things of this complicated behavior. By the way what stops from using mvn spring-boot:run for the time being.

Also with the SpringBoot starter that we are developing in #518 I no longer see this issue happening. So I have more questions on how initialization is happening in the Spring at the moment which seems to be addressed with the Starter.

@maciejkopecpl
Copy link
Author

@dhaval24 you're right, it looks like exception is gone when using mvn spring-boot:run. I need to take a look at this, but it seems that I would need to have maven installed to run that jar, which doesn't seems to be optimal way.

This springboot starter which you're talking about, you're running it with that maven command or with plain old java -jar ... ?

@dhaval24
Copy link
Contributor

@MicNeo yes, I am running the starter with java -jar and it runs without any issues. Though it is still getting polished :-) . This is indeed a strange issue.

@Injac
Copy link

Injac commented Mar 16, 2018

Hi guys, has this been solved? This is pretty annoying. What about publishing a complete spring boot project using AI? That would be a great help. Not only for Eclipse, but for IntelliJ as well.

@dhaval24
Copy link
Contributor

@Injac apologies for the trouble but if you look at my comment above I have described in detail about what is happening. Let me know if you need more clarification.

@dhaval24
Copy link
Contributor

@MicNeo and @Injac this issues should have been resolved now using Application Insights SpringBoot starter. Could you please confirm so I can close this issue?

@dhaval24
Copy link
Contributor

@MicNeo and @Injac I think these issues are resolved with application insights springboot starter. if you still face these issues please feel free to reopen.

@ghost ghost locked as resolved and limited conversation to collaborators Jul 21, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants