---
title: Mobile SDK guide
source: https://docs.newrelic.com/docs/mobile-monitoring/new-relic-mobile/mobile-sdk/mobile-sdk-api-guide
---

Use the New Relic mobile SDK API calls to customize and extend the data your mobile app reports to New Relic.

While our mobile monitoring solution offers powerful out-of-the-box data collection, you may need to customize and extend the data your mobile app reports to New Relic. For example, you can use the public SDK API calls to:

-   Start and stop interaction traces from events in your mobile app
-   Record custom metrics
-   Send custom attributes and events
-   Track network requests from libraries not supported automatically
-   Set custom IDs to user sessions

## Get started [#get-started]

1.  Make sure you have the latest mobile agent installed.
2.  Select a customization from the table below and follow the method's documentation.

## Available customizations [#methods]

The table below lists supported SDK methods to customize your mobile agent instrumentation. Select a method to view syntax and usage examples for each agent type.

| If you want to...                                                                         | Use this method                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             |
| ----------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Record breadcrumbs to track app activity that may be helpful for troubleshooting crashes. | [Record breadcrumbs](https://docs.newrelic.com/docs/mobile-monitoring/new-relic-mobile/mobile-sdk/record-breadcrumb)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        |
| Track a method as an interaction.                                                         | [Start interactions](https://docs.newrelic.com/docs/mobile-monitoring/new-relic-mobile/mobile-sdk/start-interaction) [Stop interactions](https://docs.newrelic.com/docs/mobile-monitoring/new-relic-mobile/mobile-sdk/stop-interaction) > #### 💡 TIP > > If you use these methods, the instrumented interactions will not show up on the [Interactions](https://docs.newrelic.com/docs/mobile-monitoring/mobile-monitoring-ui/mobile-app-pages/interactions-page) page, but they can be still found with a NRQL query, such as: > > ````sql > SELECT name FROM Mobile SINCE 7 DAYS AGO > ``` >      > ````                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 |
| Name or rename an interaction.                                                            | [Name interactions](https://docs.newrelic.com/docs/mobile-monitoring/new-relic-mobile/mobile-sdk/name-interaction)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          |
| Set your app's build ID or version to be associated with interactions.                    | [Set app build number](https://docs.newrelic.com/docs/mobile-monitoring/new-relic-mobile/mobile-sdk/set-application-build-number/) [Set app version number](https://docs.newrelic.com/docs/mobile-monitoring/new-relic-mobile/mobile-sdk/set-application-version/)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          |
| Create custom metrics.                                                                    | [Record custom metrics](https://docs.newrelic.com/docs/mobile-monitoring/new-relic-mobile/mobile-sdk/record-custom-metrics/)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                |
| Report custom attributes and events.                                                      | There are several ways to report custom attributes and events: - [Record custom attributes](https://docs.newrelic.com/docs/mobile-monitoring/new-relic-mobile/mobile-sdk/create-attribute) - [Increment session attribute count](https://docs.newrelic.com/docs/mobile-monitoring/new-relic-mobile/mobile-sdk/increment-session-attribute-count) - [Remove an attribute](https://docs.newrelic.com/docs/mobile-monitoring/new-relic-mobile/mobile-sdk/remove-attribute) - [Remove all attributes](https://docs.newrelic.com/docs/mobile-monitoring/new-relic-mobile/mobile-sdk/remove-all-attributes) - [Record custom events](https://docs.newrelic.com/docs/mobile-monitoring/new-relic-mobile/mobile-sdk/record-custom-events) - [Record breadcrumbs](https://docs.newrelic.com/docs/mobile-monitoring/new-relic-mobile/mobile-sdk/record-breadcrumb) - [Set the maximum size of an event pool](https://docs.newrelic.com/docs/mobile-monitoring/new-relic-mobile/mobile-sdk/set-max-event-pool-size) - [Set maximum time the agent stores events in memory](https://docs.newrelic.com/docs/mobile-monitoring/new-relic-mobile/mobile-sdk/set-max-event-buffer-time) - [Get a current session's ID](https://docs.newrelic.com/docs/mobile-monitoring/new-relic-mobile/mobile-sdk/current-session-id) - [Set a custom user ID to associate with events and attributes](https://docs.newrelic.com/docs/mobile-monitoring/new-relic-mobile/mobile-sdk/set-custom-user-id) For more about which would be the best method to use and why, see [Report mobile monitoring custom events and attributes](https://docs.newrelic.com/docs/data-apis/custom-data/custom-events/report-mobile-monitoring-custom-events-attributes/). |
| Track custom network requests and failures.                                               | [Track HTTP requests](https://docs.newrelic.com/docs/mobile-monitoring/new-relic-mobile/mobile-sdk/network-request-success) [Track failing HTTP requests](https://docs.newrelic.com/docs/mobile-monitoring/new-relic-mobile/mobile-sdk/network-request-failures)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            |
| Record a handled exception as an event, including the context of what happened.           | [Record handled exceptions](https://docs.newrelic.com/docs/mobile-monitoring/new-relic-mobile/mobile-sdk/record-handled-exceptions)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         |
| Record errors.                                                                            | [Record errors](https://docs.newrelic.com/docs/mobile-monitoring/new-relic-mobile/mobile-sdk/record-errors)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 |
| Name activity for app launch time.                                                        | [Set app launch time target activity](https://docs.newrelic.com/docs/mobile-monitoring/new-relic-mobile/mobile-sdk/name-android-activity)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   |
| Shut down the agent.                                                                      | [Shut down the agent](https://docs.newrelic.com/docs/mobile-monitoring/new-relic-mobile/mobile-sdk/shut-down-agent)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         |
| Enable/disable default mobile monitoring settings.                                        | [Enable/disable monitoring features](https://docs.newrelic.com/docs/mobile-monitoring/new-relic-mobile/mobile-sdk/configure-settings)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       |
| Run a test crash report.                                                                  | [Test crash reporting](https://docs.newrelic.com/docs/mobile-monitoring/new-relic-mobile/mobile-sdk/test-crash-reporting)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   |

## Using the mobile SDK API [#android-sdk-usage]

### (Android) Automatically instrumented methods [#method-list]

Automatic instrumentation is one of the Android agent's more convenient features. However, if it interferes with the method being traced, add `@SkipTrace` to the method, and the agent will skip it during compile time instrumentation.

| **Classes**      | **Methods**                                                                                                                                                                                                         |
| ---------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `Activity`       | - `onCreate` - `onCreateView`                                                                                                                                                                                       |
| `AsyncTask`      | - `execute` - `executeOnExecutor`                                                                                                                                                                                   |
| `BitmapFactory`  | - `decodeFile` - `decodeResourceStream` - `decodeResource` - `decodeByteArray` - `decodeStream` - `decodeFileDescriptor` - `decodeResourceStream`                                                                   |
| `SQLiteDatabase` | - `query` - `queryWithFactory` - `rawQuery` - `rawQueryWithFactory` - `insert` - `insertOrThrow` - `insertWithOnConflict` - `replace` - `replaceOrThrow` - `delete` - `update` - `updateWithOnConflict` - `execSql` |
| `GSON`           | - `toJson` - `fromJson`                                                                                                                                                                                             |
| `JSONObject`     | - `<init>` - `toString`                                                                                                                                                                                             |
| `JSONArray`      | - `<init>` - `toString`                                                                                                                                                                                             |
| `Log`            | - `d // debug` - `w // warning` - `i // info` - `v // verbose` - `e // error`                                                                                                                                       |

### (iOS) Automatically instrumented methods [#method-list-ios]

Automatic instrumentation is one of the iOS agent's more convenient features. It is enabled by default. To disable please configure feature flags `NRFeatureFlag_DefaultInteractions` and `NRFeatureFlag_InteractionTracing`.

The table below lists the automatically instrumented classes and methods in iOS agent.

| **Classes**              | **Methods**                                                                                                                                                     |
| ------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `UIViewController`       | - `viewDidLoad` - `viewWillAppear` - `viewDidAppear` - `viewWillDisappear` - `viewDidDisappear` - `viewWillLayoutSubviews` - `viewDidLayoutSubviews`            |
| `UIImage`                | - `imageNamed` - `imageWithContentsOfFile` - `imageWithData` - `imageWithData:scale:` - `initWithContentsOfFile:` - `initWithData:` - `initWithData:scale:`     |
| `NSJSONSerialization`    | - `JSONObjectWithData:options:error:` - `JSONObjectWithStream:options:error:` - `dataWithJSONObject:options:error:` - `writeJSONObject:toStream:options:error:` |
| `NSManagedObjectContext` | - `executeFetchRequest:error:` - `processPendingChanges`                                                                                                        |

## (iOS) Sending custom attributes and events [#custom-att-events]

When [reporting custom attributes and events](https://docs.newrelic.com/docs/insights/new-relic-insights/adding-querying-data/custom-attributes-events-new-relic-mobile), use the SDK methods within the `NewRelic` object.

Methods that return `BOOL` results return `YES` if they succeed, or `NO` if the operation did not complete. These methods are available in versions 5.0.0 or higher of the New Relic iOS agent.

The SDK can store up to 128 user-defined [custom attributes](https://docs.newrelic.com/docs/insights/insights-data-sources/custom-events/insert-custom-events-attributes-mobile-data#event-definition) at a time. If you attempt to store more than 128 attributes, the SDK returns `NO`.

When naming custom attributes, we recommend that you use the simplest format needed, such as using single word attributes and no spaces. For example, `My Custom Attribute` should be formatted to `myCustomAttribute`.

When naming custom metrics:

-   Avoid using the characters `/` `]` `[` `|` `*` when naming things.
-   Avoid multi-byte characters.
