Package co.elastic.apm.agent.bci
Class ElasticApmAgent
- java.lang.Object
-
- co.elastic.apm.agent.bci.ElasticApmAgent
-
public class ElasticApmAgent extends java.lang.Object
-
-
Constructor Summary
Constructors Constructor Description ElasticApmAgent()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidensureInstrumented(java.lang.Class<?> classToInstrument, java.util.Collection<java.lang.Class<? extends co.elastic.apm.agent.sdk.ElasticApmInstrumentation>> instrumentationClasses)Instruments a specific class at runtime with one or multiple instrumentation classes.static java.lang.ClassLoadergetAgentClassLoader()static java.lang.StringgetAgentHome()Returns the directory the agent jar resides in.static java.io.FilegetAgentJarFile()static java.lang.ClassLoadergetInstrumentationClassLoader(java.lang.String adviceClass)Returns the class loader that loaded the instrumentation class corresponding the given advice class.static voidinitialize(java.lang.String agentArguments, java.lang.instrument.Instrumentation instrumentation, java.io.File agentJarFile, boolean premain)Called reflectively byAgentMainto initialize the agentstatic voidinitInstrumentation(ElasticApmTracer tracer, java.lang.instrument.Instrumentation instrumentation)static voidinitInstrumentation(ElasticApmTracer tracer, java.lang.instrument.Instrumentation instrumentation, java.lang.Iterable<co.elastic.apm.agent.sdk.ElasticApmInstrumentation> instrumentations)static java.util.concurrent.Future<?>reInitInstrumentation()static voidreset()Reverts instrumentation of classes and re-transforms them to their state without the agent.static voidvalidateAdvice(java.lang.Class<?> adviceClass)Validates invariants explained inTracerAwareInstrumentation.indyPlugin()
-
-
-
Method Detail
-
initialize
public static void initialize(@Nullable java.lang.String agentArguments, java.lang.instrument.Instrumentation instrumentation, java.io.File agentJarFile, boolean premain)Called reflectively byAgentMainto initialize the agent- Parameters:
instrumentation- the instrumentation instanceagentJarFile- a reference to the agent jar on the file system
-
initInstrumentation
public static void initInstrumentation(ElasticApmTracer tracer, java.lang.instrument.Instrumentation instrumentation)
-
initInstrumentation
public static void initInstrumentation(ElasticApmTracer tracer, java.lang.instrument.Instrumentation instrumentation, java.lang.Iterable<co.elastic.apm.agent.sdk.ElasticApmInstrumentation> instrumentations)
-
reInitInstrumentation
public static java.util.concurrent.Future<?> reInitInstrumentation()
-
validateAdvice
public static void validateAdvice(java.lang.Class<?> adviceClass)
Validates invariants explained inTracerAwareInstrumentation.indyPlugin()- Parameters:
adviceClass- the advice class
-
reset
public static void reset()
Reverts instrumentation of classes and re-transforms them to their state without the agent.NOTE: THIS IS ONLY TO BE USED FOR UNIT TESTS NOTE2: THIS METHOD MUST BE CALLED AFTER AGENT WAS INITIALIZED
-
getAgentHome
@Nullable public static java.lang.String getAgentHome()
Returns the directory the agent jar resides in.In scenarios where the agent jar can't be resolved, like in unit tests, this method returns
null.- Returns:
- the directory the agent jar resides in
-
getAgentJarFile
@Nullable public static java.io.File getAgentJarFile()
-
ensureInstrumented
public static void ensureInstrumented(java.lang.Class<?> classToInstrument, java.util.Collection<java.lang.Class<? extends co.elastic.apm.agent.sdk.ElasticApmInstrumentation>> instrumentationClasses)Instruments a specific class at runtime with one or multiple instrumentation classes.Note that
ElasticApmInstrumentation.getTypeMatcher()will be conjoined with a computedTypeDescriptionthat is specific to the provided class to instrument.- Parameters:
classToInstrument- the class which should be instrumentedinstrumentationClasses- the instrumentation which should be applied to the class to instrument.
-
getAgentClassLoader
public static java.lang.ClassLoader getAgentClassLoader()
-
getInstrumentationClassLoader
public static java.lang.ClassLoader getInstrumentationClassLoader(java.lang.String adviceClass)
Returns the class loader that loaded the instrumentation class corresponding the given advice class. We expect to be able to find the advice class file through this class loader.- Parameters:
adviceClass- name of the advice class- Returns:
- class loader that can be used for the advice class file lookup
-
-