Class InstrumentationModule
- java.lang.Object
-
- io.opentelemetry.javaagent.tooling.InstrumentationModule
-
public abstract class InstrumentationModule extends Object
Instrumentation module groups several connectedTypeInstrumentations together, sharing classloader matcher, helper classes, muzzle safety checks, etc. Ideally all types in a single instrumented library should live in a single module.Classes extending
InstrumentationModuleshould be public and non-final so that it's possible to extend and reuse them in vendor distributions.
-
-
Field Summary
Fields Modifier and Type Field Description static net.bytebuddy.matcher.ElementMatcher.Junction<net.bytebuddy.description.annotation.AnnotationSource>NOT_DECORATOR_MATCHER
-
Constructor Summary
Constructors Constructor Description InstrumentationModule(String mainInstrumentationName, String... additionalInstrumentationNames)Creates an instrumentation module.InstrumentationModule(List<String> instrumentationNames)Creates an instrumentation module.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description net.bytebuddy.matcher.ElementMatcher.Junction<ClassLoader>classLoaderMatcher()An instrumentation module can implement this method to make sure that the classloader contains the particular library version.List<String>getAllHelperClassNames()Returns all helper classes that will be injected into the application classloader, both ones provided by the implementation and ones that were collected by muzzle during compilation.intgetOrder()Order of adding instrumentation to ByteBuddy.String[]helperResourceNames()Returns resource names to inject into the user's classloader.net.bytebuddy.agent.builder.AgentBuilderinstrument(net.bytebuddy.agent.builder.AgentBuilder parentAgentBuilder)Add this instrumentation to an AgentBuilder.abstract List<TypeInstrumentation>typeInstrumentations()Returns a list of all individual type instrumentation in this module.
-
-
-
Constructor Detail
-
InstrumentationModule
public InstrumentationModule(String mainInstrumentationName, String... additionalInstrumentationNames)
Creates an instrumentation module. Note that all implementations ofInstrumentationModulemust have a default constructor (for SPI), so they have to pass the instrumentation names to the super class constructor.The instrumentation names should follow several rules:
- Instrumentation names should consist of hyphen-separated words, e.g.
instrumented-library; - In general, instrumentation names should be the as close as possible to the gradle module name - which in turn should be as close as possible to the instrumented library name;
- The main instrumentation name should be the same as the gradle module name, minus the version if it's a part of the module name. When several versions of a library are instrumented they should all share the same main instrumentation name so that it's easy to enable/disable the instrumentation regardless of the runtime library version;
- If the gradle module has a version as a part of its name, an additional instrumentation
name containing the version should be passed, e.g.
instrumented-library-1.0.
- Instrumentation names should consist of hyphen-separated words, e.g.
-
InstrumentationModule
public InstrumentationModule(List<String> instrumentationNames)
Creates an instrumentation module.- See Also:
InstrumentationModule(String, String...)
-
-
Method Detail
-
instrument
public final net.bytebuddy.agent.builder.AgentBuilder instrument(net.bytebuddy.agent.builder.AgentBuilder parentAgentBuilder)
Add this instrumentation to an AgentBuilder.- Parameters:
parentAgentBuilder- AgentBuilder to base instrumentation config off of.- Returns:
- the original agentBuilder and this instrumentation
-
getAllHelperClassNames
public final List<String> getAllHelperClassNames()
Returns all helper classes that will be injected into the application classloader, both ones provided by the implementation and ones that were collected by muzzle during compilation.
-
getOrder
public int getOrder()
Order of adding instrumentation to ByteBuddy. For example instrumentation with order 1 runs after an instrumentation with order 0 (default) matched on the same API.- Returns:
- the order of adding an instrumentation to ByteBuddy. Default value is 0 - no order.
-
helperResourceNames
public String[] helperResourceNames()
Returns resource names to inject into the user's classloader.
-
classLoaderMatcher
public net.bytebuddy.matcher.ElementMatcher.Junction<ClassLoader> classLoaderMatcher()
An instrumentation module can implement this method to make sure that the classloader contains the particular library version. It is useful to implement that if the muzzle check does not fail for versions out of the instrumentation's scope.E.g. supposing version 1.0 has class
A, but it was removed in version 2.0; A is not used in the helper classes at all; this module is instrumenting 2.0: this method will returnnot(hasClassesNamed("A")).- Returns:
- A type matcher used to match the classloader under transform
-
typeInstrumentations
public abstract List<TypeInstrumentation> typeInstrumentations()
Returns a list of all individual type instrumentation in this module.
-
-