Class 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 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.
      static java.lang.ClassLoader getAgentClassLoader()  
      static java.lang.String getAgentHome()
      Returns the directory the agent jar resides in.
      static java.io.File getAgentJarFile()  
      static java.lang.ClassLoader getInstrumentationClassLoader​(java.lang.String adviceClass)
      Returns the class loader that loaded the instrumentation class corresponding the given advice class.
      static void initialize​(java.lang.String agentArguments, java.lang.instrument.Instrumentation instrumentation, java.io.File agentJarFile, boolean premain)
      Called reflectively by AgentMain to initialize the agent
      static void initInstrumentation​(ElasticApmTracer tracer, java.lang.instrument.Instrumentation instrumentation)  
      static void initInstrumentation​(ElasticApmTracer tracer, java.lang.instrument.Instrumentation instrumentation, java.lang.Iterable<co.elastic.apm.agent.sdk.ElasticApmInstrumentation> instrumentations)  
      static java.util.concurrent.Future<?> reInitInstrumentation()  
      static void reset()
      Reverts instrumentation of classes and re-transforms them to their state without the agent.
      static void validateAdvice​(java.lang.Class<?> adviceClass)
      Validates invariants explained in TracerAwareInstrumentation.indyPlugin()
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • ElasticApmAgent

        public ElasticApmAgent()
    • 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 by AgentMain to initialize the agent
        Parameters:
        instrumentation - the instrumentation instance
        agentJarFile - 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 in TracerAwareInstrumentation.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 computed TypeDescription that is specific to the provided class to instrument.

        Parameters:
        classToInstrument - the class which should be instrumented
        instrumentationClasses - 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