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_sdkalready generated (see Monitoring SDK)- A New Relic account with a mobile application created
Step 1: Generate the Brick
archipelago generate newrelic_monitoring_implYou will be prompted for:
- appName — must match your monorepo app name (e.g.
MyApp) - isForMonorepo —
true
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:
# 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
// 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:
| Field | Default |
|---|---|
appToken | required |
enableCrashReporting | true |
enableInteractionTracing | true |
enableDistributedTracing | true |
enableLogging | true |
collectorAddress | null (New Relic default) |
crashCollectorAddress | null (New Relic default) |
Set collectorAddress / crashCollectorAddress only when routing through a private data center or EU endpoint.
Step 4: Register the Micro-Package
@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
- Configure Grafana as a zero-SDK alternative for log and trace shipping
- Add Crashlytics for native crash symbolication alongside New Relic