Class HelperInjector
java.lang.Object
io.opentelemetry.javaagent.tooling.HelperInjector
- All Implemented Interfaces:
net.bytebuddy.agent.builder.AgentBuilder.Transformer
public class HelperInjector
extends Object
implements net.bytebuddy.agent.builder.AgentBuilder.Transformer
Injects instrumentation helper classes into the user's class loader.
Care must be taken when using this class. It is used both by the javaagent during its runtime
and by gradle muzzle verification plugin during build time. And some code paths in this class
require the usage of Instrumentation, which is available for the former, but not for the
latter. Unfortunately, these two "modes of operations" and not easily discernible just by reading
source code. Be careful.
In a nutshell, an instance of Instrumentation is needed for class injection into the
bootstrap class loader. This should NOT happen during build-time muzzle verification phase.
-
Nested Class Summary
Nested classes/interfaces inherited from interface net.bytebuddy.agent.builder.AgentBuilder.Transformer
net.bytebuddy.agent.builder.AgentBuilder.Transformer.ForAdvice, net.bytebuddy.agent.builder.AgentBuilder.Transformer.ForBuildPlugin -
Constructor Summary
ConstructorsConstructorDescriptionHelperInjector(String requestingName, List<String> helperClassNames, List<HelperResource> helperResources, ClassLoader helpersSource, Instrumentation instrumentation) Construct HelperInjector. -
Method Summary
Modifier and TypeMethodDescriptionstatic HelperInjectorforDynamicTypes(String requestingName, Collection<net.bytebuddy.dynamic.DynamicType.Unloaded<?>> helpers, Instrumentation instrumentation) static booleanisInjectedClass(Class<?> clazz) static booleanisInjectedClass(ClassLoader classLoader, String className) static Class<?>loadHelperClass(ClassLoader classLoader, String className) static voidnet.bytebuddy.dynamic.DynamicType.Builder<?>transform(net.bytebuddy.dynamic.DynamicType.Builder<?> builder, net.bytebuddy.description.type.TypeDescription typeDescription, ClassLoader classLoader, net.bytebuddy.utility.JavaModule javaModule, ProtectionDomain protectionDomain)
-
Constructor Details
-
HelperInjector
public HelperInjector(String requestingName, List<String> helperClassNames, List<HelperResource> helperResources, ClassLoader helpersSource, Instrumentation instrumentation) Construct HelperInjector.- Parameters:
helperClassNames- binary names of the helper classes to inject. These class names must be resolvable by the class loader returned by io.opentelemetry.javaagent.tooling.Utils#getAgentClassLoader(). Classes are injected in the order provided. This is important if there is interdependency between helper classes that requires them to be injected in a specific order. And be careful, the class's package in library will be renamed like 'io.opentelemetry.instrumentation' to 'io.opentelemetry.javaagent.shaded.instrumentation'
-
-
Method Details
-
forDynamicTypes
public static HelperInjector forDynamicTypes(String requestingName, Collection<net.bytebuddy.dynamic.DynamicType.Unloaded<?>> helpers, Instrumentation instrumentation) -
setHelperInjectorListener
-
transform
public net.bytebuddy.dynamic.DynamicType.Builder<?> transform(net.bytebuddy.dynamic.DynamicType.Builder<?> builder, net.bytebuddy.description.type.TypeDescription typeDescription, ClassLoader classLoader, net.bytebuddy.utility.JavaModule javaModule, ProtectionDomain protectionDomain) - Specified by:
transformin interfacenet.bytebuddy.agent.builder.AgentBuilder.Transformer
-
isInjectedClass
-
isInjectedClass
-
loadHelperClass
-