public class AppdynamicsAgent
extends java.lang.Object
AppdynamicsAgent
is the entry point for access to the agent API. Transactions and segments are started
directly from this class in a static fashion. Once created the Transaction
s and segments are managed via
Transaction
methods. It also provides access to metric and event reporting via their respective publisher
classes.
Transaction Monitoring Example:
public String foo(String bar) {
return "Input was: " + bar;
}
This method can be monitored as follows:
public String foo(String bar) {
Transaction transaction = null;
try {
transaction = AppdynamicsAgent.startTransaction("MyFooBT", null, false);
return "Input was: " + bar;
} finally {
transaction.end();
}
}
Note: the try/finally block ensures the transaction ends even if the method ends with an exception.
This will create a Business Transaction named "MyFooBT" and will collect metrics and snapshots for the transaction. There is no second argument (correlation header) provided because this is an originating transaction.
Modifier and Type | Field and Description |
---|---|
static int |
AGENT_API_LEVEL |
static java.lang.String |
TRANSACTION_CORRELATION_HEADER |
Modifier and Type | Method and Description |
---|---|
static void |
cancelHandoff(java.lang.Object commonObject)
Cancels the tracking of an asynchronous handoff.
|
static ExitCall |
fetchExitCall(java.lang.Object uniqueObject)
Fetches an
ExitCall that was previously stashed with ExitCall.stash(Object) |
static EventPublisher |
getEventPublisher()
Gets the handle to the event publish API.
|
static ISDKLogger |
getLogger()
Gets a non-null logger that forwards messages to the Java agent logs.
|
static MetricPublisher |
getMetricPublisher()
Gets the handle to the metric publish API.
|
static Transaction |
getTransaction()
Gets the
Transaction corresponding to the transaction pending on the current thread. |
static Transaction |
getTransaction(java.lang.String uniqueIdentifier)
Gets the
Transaction corresponding to the transaction with the matching UUID. |
static Transaction |
setCurrentTransactionName(java.lang.String name)
Sets the name of the current transaction if no asynchronous hand-offs or exit calls have been made, or
starts a new synchronous transaction if there is no current transaction.
|
static Transaction |
startSegment(java.lang.Object commonObject)
Starts an asynchronous segment.
|
static Transaction |
startSegmentNoHandoff(java.lang.String uniqueIdentifier)
Starts an asynchronous segment with no handoff.
|
static Transaction |
startServletTransaction(ServletContext servletContext,
java.lang.String entryType,
java.lang.String correlationHeader,
boolean isAsync)
Starts a servlet transaction.
|
static Transaction |
startTransaction(java.lang.String btName,
java.lang.String correlationHeader,
java.lang.String entryType,
boolean isAsync)
Starts a transaction.
|
static Transaction |
startTransactionAndServiceEndPoint(java.lang.String btName,
java.lang.String correlationHeader,
java.lang.String serviceEndpointName,
java.lang.String entryType,
boolean isAsync)
Starts a transaction and a service endpoint.
|
public static final int AGENT_API_LEVEL
public static final java.lang.String TRANSACTION_CORRELATION_HEADER
public static Transaction startTransaction(java.lang.String btName, java.lang.String correlationHeader, java.lang.String entryType, boolean isAsync)
btName
. The agent
generates a random UUID for this request.
To start an asynchronous transaction, specify the isAsync flag. After all the tasks that include the current transaction
context are done, for example, making an exit call and so on, ensure to invoke the endSegment call to end the context in this thread
or use the try-with-resources construct that handles this internally.
Note: This returns a no-op transaction if the thread invoking it is in the context of a pending transaction, or if it is unable to start a transaction.
btName
- The name of the Business Transaction, if not continuingcorrelationHeader
- The correlation header retrieved from the inbound request, used to continue a transactionentryType
- The entry type from EntryTypes
to be used for the BT.
For custom entry pass null or EntryTypes.POJO
isAsync
- Boolean indicating if it is an asynchronous entry. If unsure, set the value as true.public static Transaction startServletTransaction(ServletContext servletContext, java.lang.String entryType, java.lang.String correlationHeader, boolean isAsync)
servletContext
.
The agent will generate a random UUID for this request.
To start an asynchronous transaction, specify the isAsync flag. After all the tasks that include the current transaction
context are done, for example, making an exit call and so on, ensure to invoke the endSegment call to end the context in this thread
or use the try-with-resources construct which handles this internally.
Note: This returns a no-op Transaction if the thread invoking it is already in the context of a pending transaction, or if it is unable to start a transaction.
servletContext
- The context for this servlet transaction, used for ootb transaction namingentryType
- The entry type from EntryTypes
to be used for the BT.
For custom entry pass null or EntryTypes.POJO
correlationHeader
- The correlation header retrieved from the inbound request, used to continue a transactionisAsync
- Boolean indicating if it is an asynchronous entry. If you are not sure, set the value to true.public static Transaction startTransactionAndServiceEndPoint(java.lang.String btName, java.lang.String correlationHeader, java.lang.String serviceEndpointName, java.lang.String entryType, boolean isAsync)
btName
.
The agent generates a random UUID for this request. A service endpoint is started with name sepName
at
this point, and ends when this transaction ends.
Note: This returns a no-op transaction if the thread invoking it is already in the context of a pending transaction, or if it is unable to start a transaction. An SEP is created only if the transaction is successfully created.
btName
- The name of the Business Transaction, if not continuingcorrelationHeader
- The correlation header retrieved from the inbound request, used to continue a transactionserviceEndpointName
- The name assigned to the Service Endpoint created by this callentryType
- The entry type from EntryTypes
to be used for the BT.
For custom entry pass null or EntryTypes.POJO
isAsync
- Boolean indicating if it is an asynchronous entry. If unsure set it as true.Transaction
object corresponding to this Business Transaction requestpublic static Transaction getTransaction()
Transaction
corresponding to the transaction pending on the current thread.Transaction
corresponding to the transaction pending on the current thread.public static Transaction getTransaction(java.lang.String uniqueIdentifier)
Transaction
corresponding to the transaction with the matching UUID.uniqueIdentifier
- The String to be used to look up the transaction to returnTransaction
corresponding to the transaction with the matching uniqueIdentifierpublic static Transaction setCurrentTransactionName(java.lang.String name)
Note: This will return a no-op transaction in case of the above reasons, or if the name is null.
name
- The name this transaction is set to.Transaction
corresponding to the updated transaction.public static Transaction startSegment(java.lang.Object commonObject)
Transaction.markHandoff(Object)
call.
To end the segment, use Transaction.endSegment()
from the same thread.commonObject
- The object used to match this call to the Transaction.markHandoff(Object)
call.Transaction
object representing this asynchronous segmentpublic static Transaction startSegmentNoHandoff(java.lang.String uniqueIdentifier)
Transaction.markHandoff(Object)
. The segment started
with this asynchronous task is associated with the originating segment of the transaction. This method only succeeds if
the originating segment is still alive at the time of this call.uniqueIdentifier
- The unique identifier for the transaction that is associated with this segment.Transaction
object representing this asynchronous segmentpublic static void cancelHandoff(java.lang.Object commonObject)
Transaction.markHandoff(Object)
call. Call this method if the asynchronous task is not run. If the task has not run, no tracking information
is added to the transaction.commonObject
- object previously used to uniquely identify this async handoffpublic static MetricPublisher getMetricPublisher()
MetricPublisher
interfaceMetricPublisher
public static EventPublisher getEventPublisher()
EventPublisher
interfaceEventPublisher
public static ISDKLogger getLogger()
ISDKLogger
objectpublic static ExitCall fetchExitCall(java.lang.Object uniqueObject)
ExitCall
that was previously stashed with ExitCall.stash(Object)
uniqueObject
- The unique object key that the exit call was stashed withExitCall
or NoOpExitCall
object