Class ElasticApmTracer

  • All Implemented Interfaces:
    Tracer

    public class ElasticApmTracer
    extends java.lang.Object
    implements Tracer
    This is the tracer implementation which provides access to lower level agent functionality.

    Note that this is a internal API, so there are no guarantees in terms of backwards compatibility.

    • Method Detail

      • startRootTransaction

        @Nullable
        public Transaction startRootTransaction​(@Nullable
                                                java.lang.ClassLoader initiatingClassLoader)
        Description copied from interface: Tracer
        Starts a trace-root transaction
        Specified by:
        startRootTransaction in interface Tracer
        Parameters:
        initiatingClassLoader - the class loader corresponding to the service which initiated the creation of the transaction. Used to determine the service name.
        Returns:
        a transaction that will be the root of the current trace if the agent is currently RUNNING; null otherwise
      • startRootTransaction

        @Nullable
        public Transaction startRootTransaction​(@Nullable
                                                java.lang.ClassLoader initiatingClassLoader,
                                                long epochMicro)
        Specified by:
        startRootTransaction in interface Tracer
      • startRootTransaction

        @Nullable
        public Transaction startRootTransaction​(Sampler sampler,
                                                long epochMicros,
                                                @Nullable
                                                java.lang.ClassLoader initiatingClassLoader)
        Description copied from interface: Tracer
        Starts a trace-root transaction with a specified sampler and start timestamp
        Specified by:
        startRootTransaction in interface Tracer
        Parameters:
        sampler - the Sampler instance which is responsible for determining the sampling decision if this is a root transaction
        epochMicros - the start timestamp
        initiatingClassLoader - the class loader corresponding to the service which initiated the creation of the transaction. Used to determine the service name and to load application-scoped classes like the MDC, for log correlation.
        Returns:
        a transaction that will be the root of the current trace if the agent is currently RUNNING; null otherwise
      • startChildTransaction

        @Nullable
        public <C> Transaction startChildTransaction​(@Nullable
                                                     C headerCarrier,
                                                     TextHeaderGetter<C> textHeadersGetter,
                                                     @Nullable
                                                     java.lang.ClassLoader initiatingClassLoader)
        Description copied from interface: Tracer
        Starts a transaction as a child of the context headers obtained through the provided HeaderGetter. If the created transaction cannot be started as a child transaction (for example - if no parent context header is available), then it will be started as the root transaction of the trace.
        Specified by:
        startChildTransaction in interface Tracer
        Parameters:
        headerCarrier - the Object from which context headers can be obtained, typically a request or a message
        textHeadersGetter - provides the trace context headers required in order to create a child transaction
        initiatingClassLoader - the class loader corresponding to the service which initiated the creation of the transaction. Used to determine the service name.
        Returns:
        a transaction which is a child of the provided parent if the agent is currently RUNNING; null otherwise
      • startChildTransaction

        @Nullable
        public <C> Transaction startChildTransaction​(@Nullable
                                                     C headerCarrier,
                                                     TextHeaderGetter<C> textHeadersGetter,
                                                     @Nullable
                                                     java.lang.ClassLoader initiatingClassLoader,
                                                     long epochMicros)
        Specified by:
        startChildTransaction in interface Tracer
      • startChildTransaction

        @Nullable
        public <C> Transaction startChildTransaction​(@Nullable
                                                     C headerCarrier,
                                                     TextHeaderGetter<C> textHeadersGetter,
                                                     Sampler sampler,
                                                     long epochMicros,
                                                     @Nullable
                                                     java.lang.ClassLoader initiatingClassLoader)
        Description copied from interface: Tracer
        Starts a transaction as a child of the context headers obtained through the provided HeaderGetter. If the created transaction cannot be started as a child transaction (for example - if no parent context header is available), then it will be started as the root transaction of the trace.
        Specified by:
        startChildTransaction in interface Tracer
        Parameters:
        headerCarrier - the Object from which context headers can be obtained, typically a request or a message
        textHeadersGetter - provides the trace context headers required in order to create a child transaction
        sampler - the Sampler instance which is responsible for determining the sampling decision if this is a root transaction
        epochMicros - the start timestamp
        initiatingClassLoader - the class loader corresponding to the service which initiated the creation of the transaction. Used to determine the service name and to load application-scoped classes like the MDC, for log correlation.
        Returns:
        a transaction which is a child of the provided parent if the agent is currently RUNNING; null otherwise
      • startChildTransaction

        @Nullable
        public <C> Transaction startChildTransaction​(@Nullable
                                                     C headerCarrier,
                                                     BinaryHeaderGetter<C> binaryHeadersGetter,
                                                     @Nullable
                                                     java.lang.ClassLoader initiatingClassLoader)
        Description copied from interface: Tracer
        Starts a transaction as a child of the context headers obtained through the provided HeaderGetter. If the created transaction cannot be started as a child transaction (for example - if no parent context header is available), then it will be started as the root transaction of the trace.
        Specified by:
        startChildTransaction in interface Tracer
        Parameters:
        headerCarrier - the Object from which context headers can be obtained, typically a request or a message
        binaryHeadersGetter - provides the trace context headers required in order to create a child transaction
        initiatingClassLoader - the class loader corresponding to the service which initiated the creation of the transaction. Used to determine the service name.
        Returns:
        a transaction which is a child of the provided parent if the agent is currently RUNNING; null otherwise
      • startChildTransaction

        @Nullable
        public <C> Transaction startChildTransaction​(@Nullable
                                                     C headerCarrier,
                                                     BinaryHeaderGetter<C> binaryHeadersGetter,
                                                     Sampler sampler,
                                                     long epochMicros,
                                                     @Nullable
                                                     java.lang.ClassLoader initiatingClassLoader)
        Description copied from interface: Tracer
        Starts a transaction as a child of the context headers obtained through the provided HeaderGetter. If the created transaction cannot be started as a child transaction (for example - if no parent context header is available), then it will be started as the root transaction of the trace.
        Specified by:
        startChildTransaction in interface Tracer
        Parameters:
        headerCarrier - the Object from which context headers can be obtained, typically a request or a message
        binaryHeadersGetter - provides the trace context headers required in order to create a child transaction
        sampler - the Sampler instance which is responsible for determining the sampling decision if this is a root transaction
        epochMicros - the start timestamp
        initiatingClassLoader - the class loader corresponding to the service which initiated the creation of the transaction. Used to determine the service name and to load application-scoped classes like the MDC, for log correlation.
        Returns:
        a transaction which is a child of the provided parent if the agent is currently RUNNING; null otherwise
      • noopTransaction

        public Transaction noopTransaction()
      • startSpan

        public <T> Span startSpan​(TraceContext.ChildContextCreator<T> childContextCreator,
                                  T parentContext)
        Starts a span with a given parent context.

        This method makes it possible to start a span after the parent has already ended.

        Parameters:
        parentContext - the trace context of the parent
        Returns:
        a new started span
      • startSpan

        public Span startSpan​(AbstractSpan<?> parent,
                              long epochMicros)
      • captureAndReportException

        public void captureAndReportException​(@Nullable
                                              java.lang.Throwable e,
                                              java.lang.ClassLoader initiatingClassLoader)
        Description copied from interface: Tracer
        Captures an exception without providing an explicit reference to a parent AbstractSpan
        Specified by:
        captureAndReportException in interface Tracer
        Parameters:
        e - the exception to capture
        initiatingClassLoader - the class
      • captureAndReportException

        @Nullable
        public java.lang.String captureAndReportException​(long epochMicros,
                                                          @Nullable
                                                          java.lang.Throwable e,
                                                          @Nullable
                                                          AbstractSpan<?> parent)
        Specified by:
        captureAndReportException in interface Tracer
      • captureException

        @Nullable
        public ErrorCapture captureException​(@Nullable
                                             java.lang.Throwable e,
                                             @Nullable
                                             AbstractSpan<?> parent,
                                             @Nullable
                                             java.lang.ClassLoader initiatingClassLoader)
        Specified by:
        captureException in interface Tracer
      • getConfigurationRegistry

        public org.stagemonitor.configuration.ConfigurationRegistry getConfigurationRegistry()
      • getConfig

        public <T extends org.stagemonitor.configuration.ConfigurationOptionProvider> T getConfig​(java.lang.Class<T> configProvider)
      • endTransaction

        public void endTransaction​(Transaction transaction)
      • endSpan

        public void endSpan​(Span span)
      • recycle

        public void recycle​(Transaction transaction)
      • recycle

        public void recycle​(Span span)
      • stop

        public void stop()
        Description copied from interface: Tracer
        Called when the container shuts down. Cleans up thread pools and other resources.
        Specified by:
        stop in interface Tracer
      • getReporter

        public Reporter getReporter()
      • getSampler

        public Sampler getSampler()
      • registerSpanListener

        public void registerSpanListener​(ActivationListener activationListener)
      • getActivationListeners

        public java.util.List<ActivationListener> getActivationListeners()
      • start

        public void start​(boolean premain)
        Starts the tracer. Depending on several environment and setup parameters, the tracer may be started synchronously on this thread, or its start may be delayed and invoked on a dedicated thread.
        Parameters:
        premain - true if this tracer is attached through the premain() method (i.e. using the `javaagent` jvm parameter); false otherwise
      • onStressDetected

        public void onStressDetected()
      • onStressRelieved

        public void onStressRelieved()
      • isRunning

        public boolean isRunning()
        Specified by:
        isRunning in interface Tracer
      • getLifecycleListener

        @Nullable
        public <T> T getLifecycleListener​(java.lang.Class<T> listenerClass)
      • deactivate

        public void deactivate​(AbstractSpan<?> span)
      • overrideServiceNameForClassLoader

        public void overrideServiceNameForClassLoader​(@Nullable
                                                      java.lang.ClassLoader classLoader,
                                                      @Nullable
                                                      java.lang.String serviceName)
        Description copied from interface: Tracer
        Overrides the service name for all Transactions, Spans and ErrorCaptures which are created by the service which corresponds to the provided ClassLoader.

        The main use case is being able to differentiate between multiple services deployed to the same application server.

        Specified by:
        overrideServiceNameForClassLoader in interface Tracer
        Parameters:
        classLoader - the class loader which corresponds to a particular service
        serviceName - the service name for this class loader
      • resetServiceNameOverrides

        public void resetServiceNameOverrides()
      • getEphemeralId

        public java.lang.String getEphemeralId()
      • getMetaData

        public java.util.concurrent.Future<MetaData> getMetaData()
      • getSharedSingleThreadedPool

        public java.util.concurrent.ScheduledThreadPoolExecutor getSharedSingleThreadedPool()
      • addShutdownHook

        public void addShutdownHook​(java.io.Closeable closeable)