Monitoring Implementations
newrelic_monitoring_impl Free
- Tier
- Freeversion 1.2.7
- Command
archipelago generate newrelic_monitoring_impl- Generates
infrastructure/newrelic_monitoring_impl
- Depends on
- monitoring_sdkgenerate these first
New Relic Mobile vendor plugin for
monitoring_sdk— implementsAppMonitoringVendorwith interaction tracing and distributed tracing, and registers itself into theAppMonitoringfanout under the'newrelic'key.
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 |
Selected during flutter_modular_monorepo generation via the monitoringVendors multi-select (newrelic option) — see monitoring_sdk, not a variable of this brick itself.
Usage
Interactive
archipelago generate newrelic_monitoring_implNon-interactive (CI)
archipelago generate newrelic_monitoring_impl --config my_config.jsonGenerated Structure
infrastructure/
└── newrelic_monitoring_impl/
├── pubspec.yaml
└── lib/
├── newrelic_monitoring_impl.dart # Barrel export
└── src/
├── newrelic_monitoring_impl.dart # NewRelicMonitoringImpl
├── 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)API
@Named(MonitoringInjectorKey.newrelic) // 'newrelic'
@LazySingleton(as: AppMonitoringVendor)
class NewRelicMonitoringImpl({required this.config})
implements AppMonitoringVendor {
Future<void> initialize(); // builds Config from NewRelicConfig, startAgent
Future<void> dispose(); // sets isEnabled false — no native shutdown call
Future<void> setUserContext(String userId, {Map<String, dynamic>? extras});
Future<void> clearUserContext();
void log(String message, {String? tag, MonitoringLevel level});
Future<void> recordError(Object exception, StackTrace? stackTrace, {bool fatal = false, Map<String, dynamic>? context});
Future<T> recordTransaction<T>(String name, Future<T> Function() action, {String? operation, Map<String, dynamic>? data});
void breadcrumb(String message, {String? category, Map<String, dynamic>? data, MonitoringLevel level});
}You never call this class directly — install the brick, and getIt<AppMonitoring>() (from monitoring_sdk) fans out to it. Real behavior, verified against source:
initialize()takes no parameters — it always callsNewrelicMobile.instance.startAgent(...)with aConfigbuilt fromNewRelicConfig. There is noenable:bool toggle; collection is on onceinitialize()has run.setUserContext(userId, extras)callsNewrelicMobile.instance.setUserId, then setsextras['email']/extras['token'](if present) as attributes — arbitrary otherextraskeys are not forwarded yet (aTODO(archipelago)in source notes the SDK has no batchsetCustomAttribute).clearUserContext()resets the user id to''and removes theemail/tokenattributes.logdispatches tologDebug/logInfo/logWarning/logErrorbased onMonitoringLevel(botherrorandfatalmap tologError); formats as[tag] messagewhen a tag is given.recordErrorsets anycontextentries as attributes first, then callsNewrelicMobile.instance.recordError(exception, stackTrace ?? StackTrace.current, attributes: {'fatal': fatal}, isFatal: fatal).recordTransactionwrapsaction()instartInteraction('name:operation')/endInteraction(in afinally), settingdataentries as attributes beforehand — this is the interaction-tracing feature.breadcrumbmaps toNewrelicMobile.instance.recordBreadcrumb, withcategoryfolded into the message as[category] message.
Configuration
NewrelicRegisterModule.newRelicConfig throws UnimplementedError by default — you must override it in your app's DI module to supply a real app token:
@module
abstract class AppNewRelicModule extends NewrelicRegisterModule {
@override
@lazySingleton
NewRelicConfig get newRelicConfig => NewRelicConfig(
appToken: Env.newRelicAppToken,
enableCrashReporting: true,
enableInteractionTracing: true,
enableDistributedTracing: true,
enableLogging: true,
);
}class const NewRelicConfig({
required this.appToken,
this.enableCrashReporting = true,
this.enableInteractionTracing = true,
this.enableDistributedTracing = true,
this.enableLogging = true,
this.collectorAddress,
this.crashCollectorAddress,
});The app token comes from New Relic Dashboard → Mobile → (your app) → Settings → Application token — a separate token is issued per platform; supply the right one per build via env vars.
Dependency injection
pubspec.yaml's archipelago: manifest declares the module for monorepo_toolkit generate host-registry:
archipelago:
di_modules:
- class: NewrelicMonitoringImplPackageModulepost_gen.dart adds the package to the host app's pubspec.yaml and registers NewrelicMonitoringImplPackageModule in the app's injector.dart. The monitoring_impl fanout builds its vendor list from the @Named registrations when AppMonitoring is first resolved, so every vendor module must run before that. Install order does not decide this. The hook rebuilds the injector entries from each package's archipelago: di_modules manifest in dependency order (the order monorepo_toolkit generate host-registry computes). Generate monitoring_sdk first when you install standalone, because the vendor imports monitoring_api. flutter_modular_monorepo generates the vendors first in one run, and both orders work. After you add a vendor, run flutter test test/di/injector_test.dart to confirm AppMonitoring resolves.
Dependencies
monitoring_api— theAppMonitoringVendorcontractnewrelic_mobile: ^1.2.9dependencies(shared workspaceinjectable/get_itre-export)
Platform Setup
New Relic's Flutter agent requires native project configuration (Gradle plugin on Android, an NEW_RELIC_APP_TOKEN/agent init on iOS) per the newrelic_mobile package's own install instructions — this brick only generates the Dart-side vendor plugin, not the native agent setup.
Known Limitations
- Arbitrary
extraskeys passed tosetUserContextbeyondemail/tokenare silently dropped (see API notes above) — a real gap, not just a doc gap. dispose()flipsisEnabledtofalselocally but does not call any native "stop agent" API — the New Relic agent keeps running once started. Withdrawing diagnostics consent is different: the vendor callsshutDown(), and the native agent may only collect again from the next app launch.
Changelog
Run archipelago brick info newrelic_monitoring_impl to see the latest published version. Enterprise customers can read the full CHANGELOG.md in the brick source repository.