Method Invocation Data Collector Example

Method invocation data collectors are applicable to Java and .NET.

In this example of a manual setup (not using the wizard), we'll set up a method invocation data collector on a Java application. We want to create a data collector on the method getCartTotal(), which is shown in this code snippet with the method getUser() and which we will use later as a data source.

package com.appdynamicspilot.model;
...
public class Cart implements java.io.Serializable {
    ...
    private Double fakeAmount = 0.0;
    ...
    private User user; 
    ...
    public User getUser() {
        return user;
    }
    ...
    public Double getCartTotal() {
        if (fakeAmount == 0.0) {
            double total = 0;
            if (items != null) {
                for (Item item : items) {
                    total += item.getPrice();
                }
            }
            return total;
        } return fakeAmount;
    }
   ...
}

To configure a data collector for an application, add a data collector and then configure it:

  1. When you add your data collector, make your selections as appropriate for your configuration.
  2. Add a class and a method, if not already filled in. Class and Method Name are used to identify the method.
  3. At the Enable Data Collector for checkboxes, select Transactions Snapshots to add metadata for troubleshooting purposes and for APM snapshots, or select Transaction Analytics to collect metadata about every execution of the transaction to use later in the analytics platform. It is recommended that you start with ONLY Transactions Snapshots. Enable Transactions Analytics after the targeted data collection is confirmed.
  4. Click Add Parameter or Add Match Condition to select the correct parameter from the popup.
    1. Method Parameters are added if the method is overloaded. Clicking Add Parameter adds the Param Index 0. Add the fully qualified class name for the parameter.
    2. Match Conditions allow you to pick specific data when a method or line of code is called multiple times. Match Conditions engage method parameters or return values. Selecting Add Match Condition opens the Create Match Condition popup. Make your selections, and then click Save.
    3. When setting up your data collector, note the checkbox beside Apply to new Business Transactions.
      1. Checking this box automatically applies the rule to new business transactions.
      2. Not checking this box requires you to manually apply the rule to business transactions by navigating to Configuration > Instrumentation > Data Collectors.
    4. To add multiple collection types, click Add beneath Specify the Data to Collect from this Method Invocation to configure the source of data. For this section of code, use an invoked object and a getter chain of user.getCustomerName. This code snippet is an example of how to capture the user name on the invoked object. The Cart class instantiates a User object based on the following class in the same package as Cart. Note that the User class includes a method for returning the name of the user, getCustomerName().
    Using a getter chain, you can identify this method as another data source in the same data collector. For example, you could select Invoked Object as the source of the data. The getter chain getUser().getCustomerName() is the operation on the invoked object. For the PHP agent, if a method return value collected by MIDC is not stored in any variable, it is seen as null in both snapshot and Analytics data.
  5. When finished, click Save.
After you configure the method invocation data collectors, you can clickConfigure Transactions using this Data Collectoron the Instrumentation pane to drag and drop (or highlight and move) the transactions to a given data collector.

When complete, transaction snapshots for slow, very slow, and stalled transactions, the transaction snapshots will include the specified user data.