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 classloader.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
Instrumentationis needed for class injection into bootstrap classloader. This should NOT happen during build-time muzzle verification phase.
-
-
Constructor Summary
Constructors Constructor Description HelperInjector(String requestingName, List<String> helperClassNames, List<HelperResource> helperResources, ClassLoader helpersSource, Instrumentation instrumentation)Construct HelperInjector.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static HelperInjectorforDynamicTypes(String requestingName, Collection<net.bytebuddy.dynamic.DynamicType.Unloaded<?>> helpers, Instrumentation instrumentation)static booleanisInjectedClass(Class<?> c)net.bytebuddy.dynamic.DynamicType.Builder<?>transform(net.bytebuddy.dynamic.DynamicType.Builder<?> builder, net.bytebuddy.description.type.TypeDescription typeDescription, ClassLoader classLoader, net.bytebuddy.utility.JavaModule module)
-
-
-
Constructor Detail
-
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 classloader 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 Detail
-
forDynamicTypes
public static HelperInjector forDynamicTypes(String requestingName, Collection<net.bytebuddy.dynamic.DynamicType.Unloaded<?>> helpers, Instrumentation instrumentation)
-
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 module)- Specified by:
transformin interfacenet.bytebuddy.agent.builder.AgentBuilder.Transformer
-
isInjectedClass
public static boolean isInjectedClass(Class<?> c)
-
-