Related pages:

You can add custom data using the Java Agent SDK as an alternative to adding data collectors from the Controller UI.

The fields show up on Transaction Analytics under a section called "Custom Method Data".

Add the code similar the following to your application:

//include the app agent SDK packages
 
import com.appdynamics.apm.appagent.api.AgentDelegate;
import com.appdynamics.apm.appagent.api.DataScope;
import com.appdynamics.apm.appagent.api.IMetricAndEventReporter;
 
public void someMethod(String stringParam, int intParam, ComplexObject complexObjParam) {

    //Get the data reporter.
    IMetricAndEventReporter reporter = AgentDelegate.getMetricAndEventPublisher();

    //Define the scope for data collection.
    Set<DataScope> allScopes = new HashSet<DataScope>();
    allScopes.add(DataScope.ANALYTICS);
    allScopes.add(DataScope.SNAPSHOTS);

    Set<DataScope> analyticsScope = new HashSet<DataScope>();
    analyticsScope.add(DataScope.ANALYTICS);

    //Add data to different scopes based on the need.
    //Here both key1 and key2 are collected for both snapshots and analytics
    reporter.addSnapshotData("key1", stringParam, allScopes);
    reporter.addSnapshotData("key2", intParam, allScopes);

    //Here key3 is only collected for analytics.
    //Since the passed object is a complex java object and not a primitive type, toString() method is invoked on it and the string value will
    //be collected.
    reporter.addSnapshotData("key3", complexObjParam, analyticsScope);

    .........
    Business logic.

JAVA

The third parameter to the method is a set of enums, DataScope, that define the scope for collecting the custom data:

  • To collect custom data only for snapshots, use DataScope.SNAPSHOTS as the third parameter. 
  • To collect the custom data for analytics,  use DataScope.ANALYTICS as the third parameter.
  • If custom data should be added to both snapshots and analytics then both the enums should be passed in a set as the third parameter. 

Method details for addSnapshotData() 

boolean addSnapshotData(java.lang.String key,
                        java.lang.Object value,
                        java.util.Set<DataScopes> dataScopes
CODE

Method Parameters

  • key - key
  • value - Primitive types can be passed as values and the types (int, boolean, etc) will be respected. Strings can be passed as values, however, note that if you pass composite objects then agent performs a .toString() operation on it.
  • dataScopes - scope for the custom data collection:
    • Datascope.SNAPSHOTS
    • Datascope.ANALYTICS

Returns

true if the agent successfully collects the key-value pair for the given scope