• /
  • EnglishEspañol日本語한국어Português
  • Log inStart now

Mobile SDK guide

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

While our 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

  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

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

Track a method as an interaction.

Start interactions Stop interactions

Tip

If you use these methods, the instrumented interactions will not show up on the Interactions page, but they can be still found with a NRQL query, such as:

SELECT name FROM Mobile SINCE 7 DAYS AGO

Name or rename an interaction.

Name interactions

Set your app's build ID or version to be associated with interactions.

Set app build number

Set app version number

Create custom metrics.

Record custom metrics

Report custom attributes and events.

There are several ways to report custom attributes and events:

Track custom network requests and failures.

Track HTTP requests

Track failing HTTP requests

Record a handled exception as an event, including the context of what happened.

Record handled exceptions

Record errors.

Record errors

Name activity for app launch time.

Set app launch time target activity

Shut down the agent.

Shut down the agent

Enable/disable default mobile monitoring settings.

Enable/disable monitoring features

Run a test crash report.

Test crash reporting

Using the mobile SDK API

(Android) Automatically instrumented methods

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

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

When reporting custom attributes and events, 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 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.
Copyright © 2024 New Relic Inc.

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.