Class 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 Instrumentation is needed for class injection into bootstrap classloader. This should NOT happen during build-time muzzle verification phase.

    • 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

      • 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:
        transform in interface net.bytebuddy.agent.builder.AgentBuilder.Transformer
      • isInjectedClass

        public static boolean isInjectedClass​(Class<?> c)