Add Data to Snapshot or Analytics

In many instances, there are values of interest in the code that are helpful to add to the snapshot. This aids in the root cause diagnosis of issues or to send to the Splunk AppDynamics Business Transaction analytics to help answer real-time business-oriented questions about your application. Data reported using this API appears in the same way as it had been collected with a Method Invocation Data collector.

To report a total checkout amount to Business Transaction analytics and have it presented in the APM snapshots, use the following code:

private static final Set<DataScope> dataScopeSet = new HashSet(Arrays.asList(DataScope.ANALYTICS, DataScope.SNAPSHOTS));
public String checkout(List<ItemOrders> orders) {
Transaction transaction = null;
try {
transaction = AppdynamicsAgent.startTransaction("Checkout", null, EntryTypes.POJO, false);
// ... Method code
double shoppingCartTotal = total(orders);
transaction.collectData("cart total", Double.toString(shoppingCartTotal), dataScopeSet);
} finally {
if (transaction != null) {
transaction.end();
}
}
}