Collect Additional Types of Data

You can use methods available in the ADEUMInstrumentation class to collect six additional types of data:

Type of Data Description Specifications Where Data is Displayed
Info points How often a method is invoked, and how long it takes to run.
  • Data is numeric.
  • Names must consist of alphanumeric characters and/or spaces.
Custom timers Any arbitrary sequence of events within your code timed, even spanning multiple methods.
  • Data is numeric.
  • Metric names must consist of alphanumeric characters and/or spaces.
Custom metrics Any integer-based data you wish to collect.
  • Data is numeric.
  • Metric names must consist of alphanumeric characters and/or spaces.
User data Any string key/value pair you think might be useful. This data is included with all listed instrumentation types until it is cleared.
  • Data can be any type.
  • Metric names have no restrictions.
Breadcrumbs The context for a crash.
  • Data can be any data type.
  • Metric names have no restrictions.
User interaction Capture when users press buttons, click on lists, and select text.
  • Data can be any data type.
  • Metric names have no restrictions.
Note: When you have set up additional data types, the Mobile Agent packages that data in a mobile beacon. Normally, the beacon is transmitted when the instrumented app sends an HTTP request or when the app is restarted following a crash, but if custom data has been collected and neither of those events has occurred for at least five minutes, the custom data is sent at that time.

Info Points

Information points allow you to track how your own code is running. You can see how often a method is invoked, and how long it takes to run, by using beginCall and endCall, something like the following:
Objective-C
JSON
- (void)myMethod
    {
        id tracker = [ADEumInstrumentation beginCall:self selector:_cmd];
        // Implementation of method here ...
        [ADEumInstrumentation endCall:tracker];
    }
Swift
JAVASCRIPT
func myMethod() {
    let tracker = ADEumInstrumentation.beginCall(self, selector: #function)
    // Implementation of method here ...
    ADEumInstrumentation.endCall(tracker)
}
If an exception is thrown, it is also reported. This information appears in the Custom Data view in the Controller UI.

Custom Timers

Custom timers allow you to time any arbitrary sequence of events within your code, even spanning multiple methods, by using startTimer and stopTimer. For example, to track the time a user spends viewing a screen, the instrumentation could look like this:
Objective-C
JSON
- (void)viewDidAppear:(BOOL)animated {
      [super viewDidAppear:animated];
      [ADEumInstrumentation startTimerWithName:@"View Lifetime"];
  }
- (void)viewDidDisappear:(BOOL)animated {
      [super viewDidDisappear:animated];
      [ADEumInstrumentation stopTimerWithName:@"View Lifetime"];
  }
Swift
JSON
func viewDidAppear(_ animated: Bool) {
    super.viewDidAppear(animated)
    ADEumInstrumentation.startTimer(withName: "View Lifetime")
}
func viewDidDisappear(_ animated: Bool) {
    super.viewDidDisappear(animated)
    ADEumInstrumentation.stopTimer(withName: "View Lifetime")
}

This information appears in the Custom Data view of the Controller UI.

Note: Calling startTimerWithName again with the same name value resets a named timer.

Custom Metrics

Any integer-based data can be passed to the agent. The first parameter to the report.MetricWithName call is the name you want the metric to appear under in the Controller UI. The metric name should only contain alphanumeric characters and spaces. Illegal characters are replaced by their ASCII hex value.

Reporting a metric called "My custom metric", for example, would look something like this:

CODE
[ADEumInstrumentation reportMetricWithName:@"My custom metric" value:<#VALUE HERE#>];

This information appears in the Custom Data view of the Controller UI.

Custom User Data

You can set, and later remove any string key/value pair using with the following methods:

  • setUserData(key, value, success, error)
  • removeUserData(key)

Once this is set, user data continues to be sent along with any instrumentation for network requests, sessions, or crashes. You can remove any previously set user data on a per-key basis. Alternatively, you can remove previously set user data for all keys using clearAllUserData().

Parameters

The following table describes the parameters:

Name Type Description
key string The key identifying the key-value pair.
value string The value associated with the key.
success function The user-defined callback for successful cases.
error function The user-defined callback for failed cases.

Example

The code example below shows how to set user data with the SDK API:
Objective-C
JSON
- (void) onUserLoggedIn:(NSString *)userid { 
    [ADEumInstrumentation setUserData:@"User ID" value:userid];
    ...
  }
Swift
JSON
func onUserLogged(in userid: String?) {
    ADEumInstrumentation.setUserData("User ID", value: userid)
}
The code example below shows how to remove user data with the SDK API:
Objective-C
JSON
- (void) onUserLoggedIn:(NSString *)userid { 
    [ADEumInstrumentation removeUserData:@"User ID"];
    ...
  }
Swift
JSON
func onUserLogged(in userid: String?) {
    ADEumInstrumentation.removeUserData("User ID")
    ...
}
You can also set user data with values of other types (Long, Boolean, Double, Date) using the following methods:

Understanding clearAllUserData()

The clearAllUserData() API clears all user data in the sense of clearing all of the above enumerated types of data at once. It does not clear any other data outside of the scope of items set with the Splunk AppDynamics setUserData() list of APIs described above. Also, it does not remove any user data already attached to existing instrumentation beacons that were previously queued for sending, and it does not affect user data attached on a per-request basis to network request instrumentation.

Example

The code example below shows how to use the clearAllUserData SDK API:
Objective-C
CODE
- (void) onUserLoggedOut { 
    [ADEumInstrumentation clearAllUserData];
    ...
  }
Swift
CODE
func onUserLoggedOut() {
    ADEumInstrumentation.clearAllUserData()
    ...
}

Breadcrumbs allow you to situate a crash in the context of your user's experience. Set a breadcrumb when something interesting happens. If your application crashes at some point in the future, the breadcrumb will be displayed along with the crash report.

There are two ways of leaving breadcrumbs:

Using this method means that breadcrumbs are reported in crash reports only.

CODE
+ (void)leaveBreadcrumb:(NSString *)breadcrumb

Using this method lets you fine tune where the breadcrumbs are reported, either only in crash reports or in crash reports and sessions.

CODE
+ (void)leaveBreadcrumb:(NSString *)breadcrumb mode:(ADEumBreadcrumbVisibility)mode

Where mode is either:

  • ADEumBreadcrumbVisibilityCrashesOnly
  • ADEumBreadcrumbVisibilityCrashesAndSessions
Note: If the breadcrumb is over 2048 characters, it is truncated. If it is empty or nil, no breadcrumb is recorded. Each crash report displays the most recent 99 breadcrumbs.