When it comes to swift app development, customizing your mobile app's data reporting is crucial for gaining valuable insights into user behavior and app performance. New Relic offers powerful out-of-the-box data collection, but sometimes you may need to take things a step further. That's where our mobile SDK API calls come in – allowing you to extend the data your mobile app reports to New Relic.
Customizing Your Mobile App
To get started, make sure you have the latest mobile agent installed. Then, select a customization from the table below and follow the method's documentation. With our public SDK API calls, you can:
- 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
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. | |
| Track a method as an interaction. | Start interactions Stop interactions |
| Name or rename an interaction. | |
| Set your app's build ID or version to be associated with interactions. | |
| Create custom metrics. | |
| Report custom attributes and events. | See Report mobile monitoring custom events and attributes |
| Track custom network requests and failures. | |
| Record a handled exception as an event, including the context of what happened. | |
| Record errors. | |
| Name activity for app launch time. | |
| Shut down the agent. | |
| Enable/disable default mobile monitoring settings. | |
| Run a test crash report. | |
Using the Mobile SDK API
(Android) Automatically Instrumented Methods
Automatic instrumentation is one of the Android agent's most 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 |
| --- | --- |
| onCreate onCreateView | |
| execute executeOnExecutor | |
| decodeFile decodeResourceStream decodeResource decodeByteArray decodeStream decodeFileDescriptor decodeResourceStream | |
| query queryWithFactory rawQuery rawQueryWithFactory insert insertOrThrow insertWithOnConflict replace replaceOrThrow delete update updateWithOnConflict execSql | |
| toJson fromJson | |
|
|
| d // debug w // warning i // info v // verbose e // error | |
(iOS) Automatically Instrumented Methods
Automatic instrumentation is one of the iOS agent's most convenient features. It is enabled by default. To disable, please configure feature flags NRFeatureFlag_DefaultInteractions and NRFeatureFlag_InteractionTracing.
The table below lists automatically instrumented classes and methods in the iOS agent.
| Classes | Methods |
| --- | --- |
| viewDidLoad viewWillAppear viewDidAppear viewWillDisappear viewDidDisappear viewWillLayoutSubviews viewDidLayoutSubviews | |
| imageNamed imageWithContentsOfFile imageWithData imageWithData:scale: initWithContentsOfFile: initWithData: initWithData:scale: | |
| JSONObjectWithData:options:error: JSONObjectWithStream:options:error: dataWithJSONObject:options:error: writeJSONObject:toStream:options:error: | |
| 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 /], [*, or \
- Avoid multi-byte characters