Skip to content

Commit

Permalink
[pinpoint-apm#10828] Backport: Resolve issue for rewritten launcher o…
Browse files Browse the repository at this point in the history
…n spring-boot 3.2
  • Loading branch information
donghun-cho committed Apr 1, 2024
1 parent 8253c00 commit 0939682
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import com.navercorp.pinpoint.bootstrap.plugin.ProfilerPlugin;
import com.navercorp.pinpoint.bootstrap.plugin.ProfilerPluginSetupContext;
import com.navercorp.pinpoint.common.trace.ServiceType;
import com.navercorp.pinpoint.common.util.VarArgs;
import com.navercorp.pinpoint.plugin.spring.boot.interceptor.LauncherLaunchInterceptor;

import java.security.ProtectionDomain;
Expand Down Expand Up @@ -71,6 +72,7 @@ public void setTransformTemplate(TransformTemplate transformTemplate) {

private void addLauncherEditor() {
transformTemplate.transform("org.springframework.boot.loader.Launcher", LauncherTransform.class);
transformTemplate.transform("org.springframework.boot.loader.launch.Launcher", LauncherTransform.class);
}

public static class LauncherTransform implements TransformCallback {
Expand All @@ -83,9 +85,14 @@ public byte[] doInTransform(Instrumentor instrumentor, ClassLoader classLoader,
InstrumentClass target = instrumentor.getInstrumentClass(classLoader, className, classfileBuffer);
InstrumentMethod method = target.getDeclaredMethod("launch", "java.lang.String[]", "java.lang.String", "java.lang.ClassLoader");
if (method != null) {
method.addInterceptor(LauncherLaunchInterceptor.class);
method.addInterceptor(LauncherLaunchInterceptor.class, VarArgs.va(2));
} else {
// >= '3.2.0'
method = target.getDeclaredMethod("launch", "java.lang.ClassLoader", "java.lang.String", "java.lang.String[]");
if (method != null) {
method.addInterceptor(LauncherLaunchInterceptor.class, VarArgs.va(0));
}
}

return target.toBytecode();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import com.navercorp.pinpoint.bootstrap.interceptor.AroundInterceptor;
import com.navercorp.pinpoint.bootstrap.logging.PLogger;
import com.navercorp.pinpoint.bootstrap.logging.PLoggerFactory;
import com.navercorp.pinpoint.common.util.ArrayArgumentUtils;
import com.navercorp.pinpoint.plugin.spring.boot.SpringBootConstants;

import java.net.URL;
Expand All @@ -44,8 +45,15 @@ public class LauncherLaunchInterceptor implements AroundInterceptor {

private final TraceContext traceContext;

private final int classLoaderIndex;

public LauncherLaunchInterceptor(TraceContext traceContext) {
this(traceContext, 2);
}

public LauncherLaunchInterceptor(TraceContext traceContext, int classLoaderIndex) {
this.traceContext = traceContext;
this.classLoaderIndex = classLoaderIndex;
}

@Override
Expand All @@ -57,7 +65,7 @@ public void before(Object target, Object[] args) {
return;
}
String serviceName = createServiceName(target);
URLClassLoader classLoader = (URLClassLoader) args[2];
URLClassLoader classLoader = ArrayArgumentUtils.getArgument(args, classLoaderIndex, URLClassLoader.class);
URL[] urls = classLoader.getURLs();
List<String> loadedJarNames = new ArrayList<String>(extractLibJarNamesFromURLs(urls));
ServerMetaDataHolder holder = this.traceContext.getServerMetaDataHolder();
Expand All @@ -83,7 +91,8 @@ private boolean validate(Object target, Object[] args) {
if (args.length < 3) {
return false;
}
if (!(args[2] instanceof URLClassLoader)) {
URLClassLoader classLoader = ArrayArgumentUtils.getArgument(args, classLoaderIndex, URLClassLoader.class);
if (classLoader == null) {
return false;
}
return true;
Expand Down

0 comments on commit 0939682

Please sign in to comment.