Custom Instrumentation Using Java Annotations
Custom Instrumentation Using Java Annotations
Using Java annotations, APM Insight provides an easier way to custom instrument your application classes and methods. Usage of Java annotation enables you to define custom names for the transaction and also assign a custom component.
This feature is available from agent version 2.2.
Configuration Steps for Java Agent
- As a prerequisite, apminsight-javaagent.zip needs to be downloaded from your Site24x7 account. It comprises of agent jar with its associated files and the apminsight-javaagent-api.jar
- Include the apminsight-javaagent-api.jar file to the project build path and also ensure this file is exported along with other libraries of the application.
- The apminsight library provides two annotations to instrument classes and methods of your application
- ApmTracker: Can be used upon any classes and methods, which will be instrumented and included in the traces.
- ApmRootTracker: Can be used upon the methods which are likely to be the starting point of a transaction execution.
ApmTracker
ApmTracker annotation can be used on Classes and Methods. When used upon a class, the attributes are applied for all the methods in that class. It will override the method-wise annotations.
Attributes:
component - Default Value: POJO (Plain Java Object)
It defines a component name for the annotated element. It's an optional attribute.
Example:
Case 1: Usage on Class
@ApmTracker
public class Category {
...
}
@ApmTracker(component="payment")
public class PaymentProcessor {
...
}
Case 2: Usage on Methods
public class Product {
@ApmTracker
public int getPrice(String product, String brand) {
...
}
...
@ApmTracker(component="FetchBrand")
private List fetchAllBrandsList(String product) {
...
}
}
ApmRootTracker
ApmRootTracker annotation can be used only on methods. If annotated method is the first method invoked on the server for processing the transaction; it is then that the transaction is renamed using the value of the txnName attribute. Else, it is considered to be a normal method call and is included in the traces.
Attributes:
txnName - Mandatory attribute.
Value of this attribute is used to name the transaction. It's a mandatory attribute.
component - Default Value: POJO
It defines a component name for the annotated element. It's an optional attribute.
Example:
public class AppService {
@ApmRootTracker(txnName="Service-Initialisation")
public void init() {
...
}
}