Important
Starting with version 5.9.0 of the New Relic Android agent, you can set a custom user identifier value to associate user sessions with analytics events and attributes. For more information, see the NewRelic.setUserId
method.
The Android agent provides an SDK API to set up custom instrumentation for monitoring your application. The API gives you the ability to:
- Instrument your own code.
- Create, name, and end interaction traces from events in your mobile app.
- Record custom metrics.
- Send custom attributes and events.
- Track networking from libraries not supported automatically.
Install the SDK
Before using the Android SDK API:
- Review the Android SDK API release notes to ensure you have your app instrumented with a current SDK for mobile monitoring.
- Go to one.newrelic.com, click Add more data and then follow the steps for Android.
For more information, see the detailed Android installation and configuration procedures. If you need to support Android 2.2, see the legacy Android agent SDK procedures.
Instrument your code
Caution
Tracing is heavily optimized, but it does impose a performance overhead. Avoid instrumenting methods that are expected to be called hundreds of times.
If you have custom libraries or application code that you want to include in interaction traces:
Use the following Java annotation:
import com.newrelic.agent.android.instrumentation.Trace;Add the
@Trace
annotation to the methods you want to instrument:@Tracepublic void myHeavyweightMethod() {…To indicate what kind of method is being traced, use the optional
category
attribute.
Use the API methods
The following table lists all the New Relic Android SDK API calls, ordered by common use cases.
If you want to... | Do this |
---|---|
Track app activity that may be helpful for troubleshooting crashes | See |
Track a method as an interaction | See |
Name or rename an interaction | See |
End an interaction | See |
Disable or enable all interactions | |
Set an app version associated with an interaction | |
Set custom build ID | See |
Create custom metrics | See |
Report custom attributes and events | There are several ways to add custom attributes and events. For more about which would be the best method to use and why, see Add custom data.
|
Track custom network requests and failures | Use these methods:
|
Record a handled exception as an event, including context | See |
Record JavaScript errors from ReactNative apps | |
Set app launch time target activity | |
Shut down agent | See |
Manual cross application tracing
The noticeHttpTransaction
code does not automatically append the appropriate header ID value needed to get cross application tracing to work. This is why you will not see the application link in your Android app on New Relic's Map page for mobile apps or on the HTTP requests page.
You can use a public method in the New Relic Android SDK to get the appropriate ID to pass along with your HTTP request to your backend application, as long as it is already instrumented by New Relic. The appropriate header ID will be passed from the backend application in the response, providing everything needed for cross application tracing to function.