-
Notifications
You must be signed in to change notification settings - Fork 986
Description
Is your feature request related to a problem? Please describe.
Allow customizing parent ClassLoader in AgentClassLoader constructor for crash log collection or other scenarios.
Describe the solution you'd like
Background
I'm gonna implement a crash log collection feature for Java processes using the -XX:OnError
JVM parameter in our distro. This feature allows automatic execution of a script when a Java process crashes, enabling us to collect crash logs and send them to our monitoring system.
Current Implementation
I've created a CrashDataCollector class that needs to be executed via the -XX:OnError=crash_dump_collector.sh
parameter with a command, the crash_dump_collector.sh
looks like:
java -DlicenseKey=xxx \
......
-Dcrashlog.path=/path/to/crash.log \
-cp alibaba-otel-javaagent.jar \
com.xxx.bootstrap.CrashDataCollector
Problem Statement
The current AgentClassLoader constructor in the opentelemetry-java-instrumentation project doesn't support setting a custom parent ClassLoader. Specifically, I need to pass ClassLoader.getSystemClassLoader() as the parent to ensure proper class loading in crash collection scenarios.
Current constructor signature:
public AgentClassLoader(
File javaagentFile,
String internalJarFileName,
boolean isSecurityManagerSupportEnabled) {
super(new URL[] {}, getParentClassLoader());
}
Desired constructor signature:
public AgentClassLoader(
File javaagentFile,
String internalJarFileName,
boolean isSecurityManagerSupportEnabled,
ClassLoader parentClassLoader) { // Add this parameter
super(new URL[] {}, parentClassLoader != null ? parentClassLoader : getParentClassLoader());
}
Why This Change Is Needed
Class Loading Issues: In crash collection scenarios, the AgentClassLoader needs to load classes that are not in the "inst" subdirectory but are available in other modules such as instrumentation-api(Loaded by Boostrap classloader, since it does not follow the normal OpenTelemetry Java agent initialization logic, the code at
Line 98 in fe9595c
inst.appendToBootstrapClassLoaderSearch(agentJar); |
Use Case Details
When a Java process crashes:
JVM executes the -XX:OnError
script CrashDataCollector.main()
is invoked
AgentClassLoader needs to load classes like ConfigPropertiesUtil from the application class path
Current implementation fails with ClassNotFoundException because it can't access system class path classes
Describe alternatives you've considered
No response
Additional context
No response
Tip
React with 👍 to help prioritize this issue. Please use comments to provide useful context, avoiding +1
or me too
, to help us triage it. Learn more here.