Skip to content

New Relic Monitoring Implementation

What you'll learn

  • Generating the New Relic monitoring implementation brick
  • Obtaining and configuring a per-platform app token
  • Enabling crash reporting, interaction tracing, and distributed tracing

Prerequisites

  • monitoring_sdk already generated (see Monitoring SDK)
  • A New Relic account with a mobile application created

Step 1: Generate the Brick

bash
archipelago generate newrelic_monitoring_impl

You will be prompted for:

  • appName — must match your monorepo app name (e.g. MyApp)
  • isForMonorepotrue

The brick generates in infrastructure/newrelic_monitoring_impl/.

Step 2: Retrieve Your App Token

In the New Relic dashboard, navigate to Mobile → (your app) → Settings → Application token.

New Relic issues separate tokens per platform (iOS vs Android). Pass the correct token at build time using --dart-define:

bash
# Android
flutter build apk --dart-define=NEW_RELIC_APP_TOKEN=<android-token>

# iOS
flutter build ipa --dart-define=NEW_RELIC_APP_TOKEN=<ios-token>

Expose the value in your Env class via String.fromEnvironment('NEW_RELIC_APP_TOKEN').

Step 3: Override NewrelicRegisterModule

dart
// apps/<appName>/lib/di/app_newrelic_module.dart
@module
abstract class AppNewRelicModule extends NewrelicRegisterModule {
  @override
  @lazySingleton
  NewRelicConfig get newRelicConfig => NewRelicConfig(
    appToken: Env.newRelicAppToken,
    enableCrashReporting: true,
    enableInteractionTracing: true,
    enableDistributedTracing: true,
    enableLogging: true,
  );
}

Available NewRelicConfig fields and their defaults:

FieldDefault
appTokenrequired
enableCrashReportingtrue
enableInteractionTracingtrue
enableDistributedTracingtrue
enableLoggingtrue
collectorAddressnull (New Relic default)
crashCollectorAddressnull (New Relic default)

Set collectorAddress / crashCollectorAddress only when routing through a private data center or EU endpoint.

Step 4: Register the Micro-Package

dart
@InjectableInit(
  initializerName: 'configureDependencies',
  microPackages: [
    NewrelicMonitoringImplPackageModule(),
  ],
)
Future<void> configureDependencies() => getIt.init();

The impl is registered as a @LazySingleton named MonitoringInjectorKey.newrelicImpl.

initialize(enable:) calls NewrelicMobile.instance.startAgent with the config. Logging is level-aware — MonitoringLevel values map to logDebug, logInfo, logWarning, and logError respectively. recordTransaction uses startInteraction / endInteraction wrapped in a try/finally so the interaction always closes.

Step 5: Verify in New Relic Dashboard

Run the app and navigate between screens. After a few minutes, interaction traces should appear under New Relic → Mobile → (your app) → Interactions. Crashes appear under Crash analysis.

Next Steps

Built by Banua Coder