reuse class file locator for DDAdvice
This commit is contained in:
parent
7f643ab680
commit
b5c2a3af63
|
@ -9,6 +9,7 @@ import net.bytebuddy.dynamic.ClassFileLocator;
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class DDAdvice extends AgentBuilder.Transformer.ForAdvice {
|
public class DDAdvice extends AgentBuilder.Transformer.ForAdvice {
|
||||||
private static ClassLoader AGENT_CLASSLOADER;
|
private static ClassLoader AGENT_CLASSLOADER;
|
||||||
|
private static ClassFileLocator AGENT_CLASS_LOCATOR;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
try {
|
try {
|
||||||
|
@ -20,13 +21,17 @@ public class DDAdvice extends AgentBuilder.Transformer.ForAdvice {
|
||||||
log.error("Unable to locate agent classloader. Falling back to System Classloader");
|
log.error("Unable to locate agent classloader. Falling back to System Classloader");
|
||||||
AGENT_CLASSLOADER = ClassLoader.getSystemClassLoader();
|
AGENT_CLASSLOADER = ClassLoader.getSystemClassLoader();
|
||||||
}
|
}
|
||||||
|
AGENT_CLASS_LOCATOR = ClassFileLocator.ForClassLoader.of(AGENT_CLASSLOADER);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create bytebuddy advice with default datadog settings.
|
||||||
|
*
|
||||||
|
* @return the bytebuddy advice
|
||||||
|
*/
|
||||||
public static AgentBuilder.Transformer.ForAdvice create() {
|
public static AgentBuilder.Transformer.ForAdvice create() {
|
||||||
return new DDAdvice()
|
return new DDAdvice()
|
||||||
.with(
|
.with(new AgentBuilder.LocationStrategy.Simple(AGENT_CLASS_LOCATOR))
|
||||||
new AgentBuilder.LocationStrategy.Simple(
|
|
||||||
ClassFileLocator.ForClassLoader.of(AGENT_CLASSLOADER)))
|
|
||||||
.withExceptionHandler(ExceptionHandlers.defaultExceptionHandler());
|
.withExceptionHandler(ExceptionHandlers.defaultExceptionHandler());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue