//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.