newrelic_mobile 0.0.1-dev.11 icon indicating copy to clipboard operation
newrelic_mobile: ^0.0.1-dev.11 copied to clipboard

Flutter plugin for NewRelic Mobile. This plugin allows you to instrument Flutter apps with help of native New Relic Android and iOS agents.

Community Plus header

New Relic Flutter Agent #

This agent allows you to instrument Flutter apps with help of native New Relic Android and iOS agents. The New Relic SDKs collect crashes, network traffic, and other information for hybrid apps using native components.

NOTE: This agent SDK is not yet officially supported. If you’re interested in participating in our Limited Preview, contact Support or your account representative.

Features #

  • Capture Dart errors
  • Network Request tracking
  • Distributed Tracing
  • Future errors tracking
  • Capture interactions and the sequence in which they were created
  • Pass user information to New Relic to track user sessions
  • Screen tracking via NavigationObserver
  • Capture print and debug print statement as CustomEvents

Current Support: #

  • Android API 24+
  • iOS 10
  • Depends on New Relic iOS/XCFramework and Android agents

Requirements #

Installation #

Install NewRelic plugin into your dart project by adding it to dependecies in your pubspec.yaml

  newrelic_mobile: 0.0.1-dev.11

Flutter Setup #

  1. Now open your main.dart and add the following code to launch NewRelic (don't forget to put proper application tokens):

import 'package:newrelic_mobile/newrelic_mobile.dart';

  var appToken = "";

  if (Platform.isAndroid) {
    appToken = "<android app token>";
  } else if (Platform.isIOS) {
    appToken = "<ios app token>";

  Config config =
      Config(accessToken: appToken,

      //Android Specific
      // Optional:Enable or disable collection of event data.
      analyticsEventEnabled: true,

      // Optional:Enable or disable reporting successful HTTP requests to the MobileRequest event type.
      networkErrorRequestEnabled: true,

      // Optional:Enable or disable reporting network and HTTP request errors to the MobileRequestError event type.
      networkRequestEnabled: true,

      // Optional:Enable or disable crash reporting.
      crashReportingEnabled: true,

      // Optional:Enable or disable interaction tracing. Trace instrumentation still occurs, but no traces are harvested. This will disable default and custom interactions.
      interactionTracingEnabled: true,

      // Optional:Enable or disable capture of HTTP response bodies for HTTP error traces, and MobileRequestError events.
       httpResponseBodyCaptureEnabled: true,

      // Optional: Enable or disable agent logging.
      loggingEnabled: true,

      //iOS Specific
      // Optional:Enable/Disable automatic instrumentation of WebViews
      webViewInstrumentation: true,
      //Optional: Enable or Disable Print Statements as Analytics Events
      printStatementAsEventsEnabled : true,

       // Optional:Enable/Disable automatic instrumentation of Http Request

  NewrelicMobile.instance.start(config, () {

  class MyApp extends StatelessWidget {

  1. Alternatively, you can manually set up error tracking and resource tracking. Because NewRelic Mobile Start calls WidgetsFlutterBinding.ensureInitialized, if you are not using NewRelic Mobile Start, you need to call this method prior to calling NewrelicMobile.instance.startAgent.
if (Platform.isAndroid) {
  appToken = AppConfig.androidToken;
} else if (Platform.isIOS) {
  appToken = AppConfig.iOSToken;

Config config = Config(
    accessToken: appToken,
    analyticsEventEnabled: true,
    networkErrorRequestEnabled: true,
    networkRequestEnabled: true,
    crashReportingEnabled: true,
    interactionTracingEnabled: true,
    httpResponseBodyCaptureEnabled: true,
    loggingEnabled: true,
    webViewInstrumentation: true,
    printStatementAsEventsEnabled: true,

// NewrelicMobile.instance.start(config, () {
//   runApp(MyApp());
// });

runZonedGuarded(() async {
  FlutterError.onError = NewrelicMobile.onError;
  await NewrelicMobile.instance.startAgent(config);
}, (Object error, StackTrace stackTrace) {
  NewrelicMobile.instance.recordError(error, stackTrace);

AppToken is platform-specific. You need to generate the seprate token for Android and iOS apps.

Screen Tracking Events #

In order to track navigation events you have to add the NewRelicNavigationObserver to your MaterialApp, WidgetsApp or CupertinoApp.

You should provide a name to route settings: RouteSettings(name: 'Your Route Name'). The root route name / will be replaced by root "/" for clarity's sake.

import 'package:newrelic_mobile/newrelic_navigation_observer.dart';


  navigatorObservers: [
  // other parameters

GoRouter Instrumentation #

When using the go_router[] library, the automatic routing instrumentation can be enabled by adding an instance of NewRelicNavigationObserver to your application's GoRouter.observers:


import 'package:go_router/go_router.dart';
import 'package:newrelic_mobile/newrelic_navigation_observer.dart';

final router = GoRouter(
  routes: ...,
    observers: [NewRelicNavigationObserver()],

Android Setup #

  1. Add the following changes to android/build.gradle:
  buildscript {
    repositories {
    dependencies {
      classpath ""
  1. Apply the newrelic plugin to the top of the android/app/build.gradle file::
  apply plugin: ""
  apply plugin: 'newrelic' // <-- add this

  1. Make sure your app requests INTERNET and ACCESS_NETWORK_STATE permissions by adding these lines to your AndroidManifest.xml
  <uses-permission android:name="android.permission.INTERNET" />
  <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

Usage #

See the examples below, and for more detail, see New Relic IOS SDK doc or Android SDK .

startInteraction(String actionName) Future

Track a method as an interaction.

InteractionId is string.

endInteraction(String interactionId): void; #

End an interaction (Required). This uses the string ID for the interaction you want to end. This string is returned when you use startInteraction().

          var id = await NewrelicMobile.instance.startInteraction("Getting Data from Service");
              try {
                var dio = Dio();
                var response = await dio.get(
              } catch (e) {

[setAttribute] ( name, dynamic value) : void; #

Creates a session-level attribute shared by multiple mobile event types. Overwrites its previous value and type each time it is called.

    NewrelicMobile.instance.setAttribute('RNCustomAttrNumber', 37);

setUserId(String userId): void; #

Set a custom user identifier value to associate user sessions with analytics events and attributes.


recordBreadcrumb(String name,{Map<String, dynamic>? eventAttributes}): void; #

Track app activity/screen that may be helpful for troubleshooting crashes.

    NewrelicMobile.instance.recordBreadcrumb("Button Got Pressed on Screen 3"),

recordCustomEvent(String eventType,{String eventName = "", Map<String, dynamic>? eventAttributes}): void; #

Creates and records a custom event for use in New Relic Insights.

    NewrelicMobile.instance.recordCustomEvent("Major",eventName: "User Purchase",eventAttributes: {"item1":"Clothes","price":34.00}),
          child: const Text('Record Custom Event'),

setMaxEventBufferTime(int maxBufferTimeInSec) void; #

Sets the event harvest cycle length.


setMaxEventPoolSize(int maxSize): void; #

Sets the maximum size of the event pool.


noticeHttpTransaction(String url,String httpMethod,int statusCode,int startTime,int endTime,int bytesSent,int bytesReceived,Map<String, dynamic>? traceData,{String responseBody = ""}): void; #

Tracks network requests manually. You can use this method to record HTTP transactions, with an option to also send a response body.

    NewrelicMobile.instance.noticeNetworkFailure("", "GET", 1000, 2000,'Test Network Failure', NetworkFailure.dnsLookupFailed);

noticeNetworkFailure(String url,String httpMethod,int startTime,int endTime,NetworkFailure errorCode): void; #

Records network failures. If a network request fails, use this method to record details about the failures. In most cases, place this call inside exception handlers, such as catch blocks. Supported failures are: Unknown, BadURL, TimedOut, CannotConnectToHost, DNSLookupFailed, BadServerResponse, SecureConnectionFailed.

   NewrelicMobile.instance.noticeNetworkFailure("", "GET", 1000, 2000,'Test Network Failure', NetworkFailure.dnsLookupFailed);

Manual Error reporting #

You can register non fatal exceptions using the following method with Custom Attributes:

try {
} catch (ex) {
        .recordError(error, StackTrace.current, attributes: attributes);

Troubleshoot #

No Http data appears:

Problem After installing the Flutter agent and waiting at least 5 minutes, no http data appears in New Relic UI.

Solution If no http data appears after you wait at least five minutes, check you are not overriding inside your flutter app.

pub points


verified publisher

Flutter plugin for NewRelic Mobile. This plugin allows you to instrument Flutter apps with help of native New Relic Android and iOS agents.

Repository (GitHub)
View/report issues


Icon for licenses.unknown (LICENSE)


flutter, stack_trace


Packages that depend on newrelic_mobile