newrelic_monitoring_impl Free
New Relic vendor implementation for
monitoring_apiwith interaction tracing and distributed tracing support.
Version: 1.0.0
Variables
| Variable | Type | Default | Description |
|---|---|---|---|
| appName | string | — | The name of your application |
| isForMonorepo | boolean | true | Whether this is being generated as part of a monorepo |
Architecture
newrelic_monitoring_impl is a vendor brick that implements the AppMonitoring contract from monitoring_api using the New Relic Mobile SDK. It is selected during flutter_modular_monorepo generation when the user picks newrelic from the monitoringVendors multi-select.
NewRelicMonitoringImpl is registered as a @LazySingleton named MonitoringInjectorKey.newrelicImpl and bound to the AppMonitoring interface. It receives a NewRelicConfig instance via constructor injection. The config is provided by NewrelicRegisterModule, which the host app must override to supply the real app token.
DI Registration
The package uses @InjectableInit.microPackage() for modular registration. The host app imports NewRelicMonitoringImplPackageModule and calls initNewRelicMonitoringImplModule() during DI bootstrap, then overrides NewrelicRegisterModule to provide the app token.
Generated Structure
infrastructure/
└── newrelic_monitoring_impl/
├── pubspec.yaml
└── lib/
├── newrelic_monitoring_impl.dart # Barrel export
└── src/
├── newrelic_monitoring_impl.dart # AppMonitoring impl
├── config/
│ └── newrelic_config.dart # NewRelicConfig data class
└── di/
├── injector.dart # microPackage init
├── injector.module.dart # Generated DI module
└── register_module.dart # NewRelicConfig provider (override required)Key Features
- Agent startup —
initialize(enable:)builds aConfigfromNewRelicConfigand callsNewrelicMobile.instance.startAgent; no-ops ifenableis false - User identity —
setUserIdcallsNewrelicMobile.instance.setUserIdand sets optionalemail/tokenas custom attributes;removeUserresets user ID and removes both attributes - Level-aware logging —
logdispatches tologDebug,logInfo,logWarning, orlogErrorbased onMonitoringLevel; formats message as[tag] messagewhen a tag is provided - Error recording —
recordErrorcallsNewrelicMobile.instance.recordErrorwithisFatalflag andattributes: {'fatal': fatal} - Interaction tracing —
recordTransactionusesstartInteraction('name:operation')as the performance span, sets custom attributes for each data entry, and always callsendInteractionin afinallyblock - Distributed tracing — Enabled via
NewRelicConfig.enableDistributedTracingpassed to the native agentConfig
Dependencies
| Package | Version | Purpose |
|---|---|---|
newrelic_mobile | ^1.1.21 | New Relic Mobile SDK |
monitoring_api | path | AppMonitoring contract |
dependencies | path | injectable / get_it re-export |
Configuration
Override NewrelicRegisterModule in your app DI module to supply the app token:
@module
abstract class AppNewRelicModule extends NewrelicRegisterModule {
@override
@lazySingleton
NewRelicConfig get newRelicConfig => NewRelicConfig(
appToken: Env.newRelicAppToken, // required — from your .env / build config
enableCrashReporting: true,
enableInteractionTracing: true,
enableDistributedTracing: true,
enableLogging: true,
// collectorAddress: 'https://custom-collector.example.com',
// crashCollectorAddress: 'https://custom-crash.example.com',
);
}NewRelicConfig Fields
| Field | Type | Default | Description |
|---|---|---|---|
appToken | String | required | New Relic mobile application token |
enableCrashReporting | bool | true | Enable native crash reporting |
enableInteractionTracing | bool | true | Enable interaction/transaction tracing |
enableDistributedTracing | bool | true | Enable distributed tracing headers |
enableLogging | bool | true | Enable log forwarding to New Relic |
collectorAddress | String? | null | Custom data collector endpoint |
crashCollectorAddress | String? | null | Custom crash collector endpoint |
The app token is found in New Relic Dashboard → Mobile → (your app) → Settings → Application token. A separate token is issued per platform (iOS vs Android); use build-time env vars to supply the correct one per platform.