• English日本語한국어
  • Log inStart now

Android SDK API guide


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:

Install the SDK

Before using the Android SDK API:

  1. Review the Android SDK API release notes to ensure you have your app instrumented with a current SDK for mobile monitoring.
  2. 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


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:

  1. Use the following Java annotation:

    import com.newrelic.agent.android.instrumentation.Trace;
  2. Add the @Trace annotation to the methods you want to instrument:

    public void myHeavyweightMethod() {
  3. 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 recordBreadcrumb.

Track a method as an interaction

See startInteraction.

Name or rename an interaction

See setInteractionName.

End an interaction

See endInteraction.

Disable or enable all interactions

See withInteractionTracing.

Set an app version associated with an interaction

See withApplicationVersion.

Set custom build ID

See withApplicationBuild.

Create custom metrics

See recordMetric.

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 recordHandledException().

Record JavaScript errors from ReactNative apps

See recordJSErrorException.

Set app launch time target activity

See withLaunchActivityName.

Shut down agent

See shutdown.

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.

Copyright © 2023 New Relic Inc.

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