Package co.elastic.apm.agent.impl
Class ElasticApmTracer
- java.lang.Object
-
- co.elastic.apm.agent.impl.ElasticApmTracer
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface co.elastic.apm.agent.impl.Tracer
Tracer.TracerState
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidactivate(AbstractSpan<?> span)voidaddShutdownHook(java.io.Closeable closeable)java.lang.StringcaptureAndReportException(long epochMicros, java.lang.Throwable e, AbstractSpan<?> parent)voidcaptureAndReportException(java.lang.Throwable e, java.lang.ClassLoader initiatingClassLoader)Captures an exception without providing an explicit reference to a parentAbstractSpanErrorCapturecaptureException(java.lang.Throwable e, AbstractSpan<?> parent, java.lang.ClassLoader initiatingClassLoader)SpancreateExitChildSpan()TransactioncurrentTransaction()voiddeactivate(AbstractSpan<?> span)voidendError(ErrorCapture error)voidendSpan(Span span)voidendTransaction(Transaction transaction)java.util.List<ActivationListener>getActivationListeners()AbstractSpan<?>getActive()SpangetActiveExitSpan()SpangetActiveSpan()ApmServerClientgetApmServerClient()<T extends org.stagemonitor.configuration.ConfigurationOptionProvider>
TgetConfig(java.lang.Class<T> configProvider)org.stagemonitor.configuration.ConfigurationRegistrygetConfigurationRegistry()java.lang.StringgetEphemeralId()<T> TgetLifecycleListener(java.lang.Class<T> listenerClass)java.util.concurrent.Future<MetaData>getMetaData()MetricRegistrygetMetricRegistry()ObjectPoolFactorygetObjectPoolFactory()ReportergetReporter()SamplergetSampler()java.util.concurrent.ScheduledThreadPoolExecutorgetSharedSingleThreadedPool()Tracer.TracerStategetState()booleanisRunning()TransactionnoopTransaction()voidonStressDetected()voidonStressRelieved()voidoverrideServiceNameForClassLoader(java.lang.ClassLoader classLoader, java.lang.String serviceName)Overrides the service name for allTransactions,Spans andErrorCaptures which are created by the service which corresponds to the providedClassLoader.voidrecycle(ErrorCapture error)voidrecycle(Span span)voidrecycle(Transaction transaction)voidregisterSpanListener(ActivationListener activationListener)voidresetServiceNameOverrides()voidstart(boolean premain)Starts the tracer.<C> TransactionstartChildTransaction(C headerCarrier, BinaryHeaderGetter<C> binaryHeadersGetter, Sampler sampler, long epochMicros, java.lang.ClassLoader initiatingClassLoader)Starts a transaction as a child of the context headers obtained through the providedHeaderGetter.<C> TransactionstartChildTransaction(C headerCarrier, BinaryHeaderGetter<C> binaryHeadersGetter, java.lang.ClassLoader initiatingClassLoader)Starts a transaction as a child of the context headers obtained through the providedHeaderGetter.<C> TransactionstartChildTransaction(C headerCarrier, TextHeaderGetter<C> textHeadersGetter, Sampler sampler, long epochMicros, java.lang.ClassLoader initiatingClassLoader)Starts a transaction as a child of the context headers obtained through the providedHeaderGetter.<C> TransactionstartChildTransaction(C headerCarrier, TextHeaderGetter<C> textHeadersGetter, java.lang.ClassLoader initiatingClassLoader)Starts a transaction as a child of the context headers obtained through the providedHeaderGetter.<C> TransactionstartChildTransaction(C headerCarrier, TextHeaderGetter<C> textHeadersGetter, java.lang.ClassLoader initiatingClassLoader, long epochMicros)TransactionstartRootTransaction(Sampler sampler, long epochMicros, java.lang.ClassLoader initiatingClassLoader)Starts a trace-root transaction with a specified sampler and start timestampTransactionstartRootTransaction(java.lang.ClassLoader initiatingClassLoader)Starts a trace-root transactionTransactionstartRootTransaction(java.lang.ClassLoader initiatingClassLoader, long epochMicro)SpanstartSpan(AbstractSpan<?> parent, long epochMicros)<T> SpanstartSpan(TraceContext.ChildContextCreator<T> childContextCreator, T parentContext)Starts a span with a given parent context.<T> SpanstartSpan(TraceContext.ChildContextCreator<T> childContextCreator, T parentContext, long epochMicros)voidstop()Called when the container shuts down.
-
-
-
Method Detail
-
startRootTransaction
@Nullable public Transaction startRootTransaction(@Nullable java.lang.ClassLoader initiatingClassLoader)
Description copied from interface:TracerStarts a trace-root transaction- Specified by:
startRootTransactionin interfaceTracer- 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:
startRootTransactionin interfaceTracer
-
startRootTransaction
@Nullable public Transaction startRootTransaction(Sampler sampler, long epochMicros, @Nullable java.lang.ClassLoader initiatingClassLoader)
Description copied from interface:TracerStarts a trace-root transaction with a specified sampler and start timestamp- Specified by:
startRootTransactionin interfaceTracer- Parameters:
sampler- theSamplerinstance which is responsible for determining the sampling decision if this is a root transactionepochMicros- the start timestampinitiatingClassLoader- 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 theMDC, 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:TracerStarts a transaction as a child of the context headers obtained through the providedHeaderGetter. 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:
startChildTransactionin interfaceTracer- Parameters:
headerCarrier- the Object from which context headers can be obtained, typically a request or a messagetextHeadersGetter- provides the trace context headers required in order to create a child transactioninitiatingClassLoader- 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:
startChildTransactionin interfaceTracer
-
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:TracerStarts a transaction as a child of the context headers obtained through the providedHeaderGetter. 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:
startChildTransactionin interfaceTracer- Parameters:
headerCarrier- the Object from which context headers can be obtained, typically a request or a messagetextHeadersGetter- provides the trace context headers required in order to create a child transactionsampler- theSamplerinstance which is responsible for determining the sampling decision if this is a root transactionepochMicros- the start timestampinitiatingClassLoader- 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 theMDC, 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:TracerStarts a transaction as a child of the context headers obtained through the providedHeaderGetter. 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:
startChildTransactionin interfaceTracer- Parameters:
headerCarrier- the Object from which context headers can be obtained, typically a request or a messagebinaryHeadersGetter- provides the trace context headers required in order to create a child transactioninitiatingClassLoader- 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:TracerStarts a transaction as a child of the context headers obtained through the providedHeaderGetter. 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:
startChildTransactionin interfaceTracer- Parameters:
headerCarrier- the Object from which context headers can be obtained, typically a request or a messagebinaryHeadersGetter- provides the trace context headers required in order to create a child transactionsampler- theSamplerinstance which is responsible for determining the sampling decision if this is a root transactionepochMicros- the start timestampinitiatingClassLoader- 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 theMDC, 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()
-
currentTransaction
@Nullable public Transaction currentTransaction()
- Specified by:
currentTransactionin interfaceTracer
-
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)
-
startSpan
public <T> Span startSpan(TraceContext.ChildContextCreator<T> childContextCreator, T parentContext, long epochMicros)
- Parameters:
parentContext- the trace context of the parentepochMicros- the start timestamp of the span in microseconds after epoch- Returns:
- a new started span
- See Also:
startSpan(TraceContext.ChildContextCreator, Object)
-
captureAndReportException
public void captureAndReportException(@Nullable java.lang.Throwable e, java.lang.ClassLoader initiatingClassLoader)Description copied from interface:TracerCaptures an exception without providing an explicit reference to a parentAbstractSpan- Specified by:
captureAndReportExceptionin interfaceTracer- Parameters:
e- the exception to captureinitiatingClassLoader- the class
-
captureAndReportException
@Nullable public java.lang.String captureAndReportException(long epochMicros, @Nullable java.lang.Throwable e, @Nullable AbstractSpan<?> parent)- Specified by:
captureAndReportExceptionin interfaceTracer
-
captureException
@Nullable public ErrorCapture captureException(@Nullable java.lang.Throwable e, @Nullable AbstractSpan<?> parent, @Nullable java.lang.ClassLoader initiatingClassLoader)
- Specified by:
captureExceptionin interfaceTracer
-
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)
-
endError
public void endError(ErrorCapture error)
-
recycle
public void recycle(Transaction transaction)
-
recycle
public void recycle(Span span)
-
recycle
public void recycle(ErrorCapture error)
-
stop
public void stop()
Description copied from interface:TracerCalled when the container shuts down. Cleans up thread pools and other resources.
-
getReporter
public Reporter getReporter()
-
getSampler
public Sampler getSampler()
-
getObjectPoolFactory
public ObjectPoolFactory getObjectPoolFactory()
-
getActive
@Nullable public AbstractSpan<?> getActive()
-
getActiveSpan
@Nullable public Span getActiveSpan()
- Specified by:
getActiveSpanin interfaceTracer
-
getActiveExitSpan
@Nullable public Span getActiveExitSpan()
- Specified by:
getActiveExitSpanin interfaceTracer
-
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 thepremain()method (i.e. using the `javaagent` jvm parameter); false otherwise
-
onStressDetected
public void onStressDetected()
-
onStressRelieved
public void onStressRelieved()
-
createExitChildSpan
@Nullable public Span createExitChildSpan()
- Specified by:
createExitChildSpanin interfaceTracer
-
getState
public Tracer.TracerState getState()
-
getLifecycleListener
@Nullable public <T> T getLifecycleListener(java.lang.Class<T> listenerClass)
-
activate
public void activate(AbstractSpan<?> span)
-
deactivate
public void deactivate(AbstractSpan<?> span)
-
getMetricRegistry
public MetricRegistry getMetricRegistry()
-
overrideServiceNameForClassLoader
public void overrideServiceNameForClassLoader(@Nullable java.lang.ClassLoader classLoader, @Nullable java.lang.String serviceName)Description copied from interface:TracerOverrides the service name for allTransactions,Spans andErrorCaptures which are created by the service which corresponds to the providedClassLoader.The main use case is being able to differentiate between multiple services deployed to the same application server.
- Specified by:
overrideServiceNameForClassLoaderin interfaceTracer- Parameters:
classLoader- the class loader which corresponds to a particular serviceserviceName- the service name for this class loader
-
resetServiceNameOverrides
public void resetServiceNameOverrides()
-
getApmServerClient
public ApmServerClient getApmServerClient()
-
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)
-
-