Skip to content

newrelic_monitoring_impl Free

New Relic vendor implementation for monitoring_api with interaction tracing and distributed tracing support.

Version: 1.0.0

Variables

VariableTypeDefaultDescription
appNamestringThe name of your application
isForMonorepobooleantrueWhether 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 startupinitialize(enable:) builds a Config from NewRelicConfig and calls NewrelicMobile.instance.startAgent; no-ops if enable is false
  • User identitysetUserId calls NewrelicMobile.instance.setUserId and sets optional email / token as custom attributes; removeUser resets user ID and removes both attributes
  • Level-aware logginglog dispatches to logDebug, logInfo, logWarning, or logError based on MonitoringLevel; formats message as [tag] message when a tag is provided
  • Error recordingrecordError calls NewrelicMobile.instance.recordError with isFatal flag and attributes: {'fatal': fatal}
  • Interaction tracingrecordTransaction uses startInteraction('name:operation') as the performance span, sets custom attributes for each data entry, and always calls endInteraction in a finally block
  • Distributed tracing — Enabled via NewRelicConfig.enableDistributedTracing passed to the native agent Config

Dependencies

PackageVersionPurpose
newrelic_mobile^1.1.21New Relic Mobile SDK
monitoring_apipathAppMonitoring contract
dependenciespathinjectable / get_it re-export

Configuration

Override NewrelicRegisterModule in your app DI module to supply the app token:

dart
@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

FieldTypeDefaultDescription
appTokenStringrequiredNew Relic mobile application token
enableCrashReportingbooltrueEnable native crash reporting
enableInteractionTracingbooltrueEnable interaction/transaction tracing
enableDistributedTracingbooltrueEnable distributed tracing headers
enableLoggingbooltrueEnable log forwarding to New Relic
collectorAddressString?nullCustom data collector endpoint
crashCollectorAddressString?nullCustom 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.

Built by Banua Coder