pinpoint-apm / pinpoint

APM, (Application Performance Management) tool for large-scale distributed systems.
https://pinpoint-apm.gitbook.io/
Apache License 2.0
13.41k stars 3.75k forks source link

Spring Boot Detector could not detect the right ApplicationType #2107

Closed iwin4aids closed 7 years ago

iwin4aids commented 8 years ago

`public class SpringBootDetector implements ApplicationTypeDetector {

@Override
public ServiceType getApplicationType() {
    return SpringBootConstants.SERVICE_TYPE;
}

@Override
public boolean detect(ConditionProvider provider) {
    String bootstrapMainClass = provider.getMainClass();
    return bootstrapMainClass.startsWith(SpringBootConstants.BOOTSTRAP_MAIN_PREFIX);
}

}` I just run a spirng boot application, the web ui show me it is a stande_alone application with a specified icon, but i saw an spring boot application type in the definitions.Then i found the code in SpringBootDetector like above.Our spring boot main class always start with our own company name, just like com.mycompany.xxxxx.It can't be start with an "org.springframework.boot.loader." package so that method detect alwasy return false.I thought it can be fixed as well :)

Xylus commented 8 years ago

Interesting, how are you starting up your SpringBoot app? I was under the impression that spring boot launches with its own loader class and calls the application main class afterwards. (Unless you start it from an IDE which has its own loader)

Either way, you can override the auto detection by setting the profiler.applicationservertype option in profiler.config.

iwin4aids commented 8 years ago

Thanks for ur reply.I has start spring boot app in both way of IDE and java -jar 。 I don't know how it works inside, but i just debug the code, the variable bootstrapMainClass seems to be the main class which has the Spring boot annotation @SpringBootApplication but not spring boot's own loader class.

Xylus commented 8 years ago

Ah, I see.. So when starting from IDE, the application registering itself as STAND_ALONE is the correct behavior. If you're launching from an IDE, I suggest setting profiler.applicationservertype=SPRING_BOOT in profiler.config.

When running the executable jar, it should properly detect the application as SPRING_BOOT without setting the config option above. Could you tell me what the values for Main-Class and Start-Class are for the MANIFEST.MF file? The file should be under META-INF folder once you unpack the executable jar.

Thanks!

iwin4aids commented 8 years ago

You are right :), It only occurs in IDE laucher The executable jar's MANIFEST.MF like this:

Manifest-Version: 1.0 Archiver-Version: Plexus Archiver Built-By: Administrator Start-Class: com.xxx.Application Spring-Boot-Classes: BOOT-INF/classes/ Spring-Boot-Lib: BOOT-INF/lib/ Spring-Boot-Version: 1.4.1.RELEASE Created-By: Apache Maven 3.2.1 Build-Jdk: 1.8.0_102 Main-Class: org.springframework.boot.loader.JarLauncher

But i thought in either way we start the application, it should be properly detected as well :) First we can directly check the Main-Class start with a package like 'org.org.springframework.boot.loader' then it can check if the Main-Class has the annotation present of '@SpringBootApplication' or '@SpringBootConfiguration' it can properly solved. Thanks for ur reply :)

Xylus commented 8 years ago

@iwin4aids Thanks for your suggestions. Your suggestion would definitely work (checking for @SpringBootApplication annotation on the application main class) as IDEs seem to launch by calling the application main class directly without going through the launchers in org.springframework.boot.loader.

However, I'm not sure fiddling with the main class via reflection in premain is a good idea (it might mess with class transformation and load order?) You can of course simply set profiler.applicationservertype=SPRING_BOOT to pinpoint.config.

Thanks!