• /
  • ログイン
  • 無料アカウント

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.

New Relic Mobile's 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 New Relic Mobile.
  2. Follow the Add a new app instructions in rpm.newrelic.com/mobile.

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:

    @Trace
    public void myHeavyweightMethod() {
  3. To tell New Relic Mobile 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.

Send custom attributes and events to Insights

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

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 back-end application, as long as it is already instrumented by New Relic. The appropriate header ID will be passed from the back-end application in the response, providing everything needed for cross application tracing to function.

その他のヘルプ

さらに支援が必要な場合は、これらのサポートと学習リソースを確認してください:

問題を作成するこのページを編集する
Copyright © 2020 New Relic Inc.