Skip to content
Back to archipelago.banuacoder.com

Monitoring Implementations

crashlytics_monitoring_impl Free ​

Tier
Freeversion 1.2.8
Command
archipelago generate crashlytics_monitoring_impl
Generates
  • infrastructure/crashlytics_monitoring_impl
Depends on
monitoring_sdkgenerate these first

Firebase Crashlytics vendor plugin for monitoring_sdk — implements AppMonitoringVendor and registers itself into the AppMonitoring fanout under the 'crashlytics' key.

Variables ​

VariableTypeDefaultDescription
appNamestring—The name of your application
isForMonorepobooleantrueWhether this is being generated as part of a monorepo

Selected during flutter_modular_monorepo generation via the monitoringVendors multi-select (crashlytics option) — see monitoring_sdk, not a variable of this brick itself.

Usage ​

Interactive ​

bash
archipelago generate crashlytics_monitoring_impl

Non-interactive (CI) ​

bash
archipelago generate crashlytics_monitoring_impl --config my_config.json

Generated Structure ​

text
infrastructure/
└── crashlytics_monitoring_impl/
    ├── pubspec.yaml
    └── lib/
        ├── crashlytics_monitoring_impl.dart        # Barrel export
        └── src/
            ├── crashlytics_monitoring_impl.dart    # CrashlyticsMonitoringVendor
            └── di/
                ├── injector.dart                   # microPackage init
                ├── injector.module.dart            # Generated DI module
                └── register_module.dart            # FirebaseCrashlytics provider

API ​

dart
@Named(MonitoringInjectorKey.crashlytics)   // 'crashlytics'
@LazySingleton(as: AppMonitoringVendor)
class CrashlyticsMonitoringVendor
    implements AppMonitoringVendor, FlutterAwareMonitoringVendor {
  CrashlyticsMonitoringVendor(this._crashlytics);

  Future<void> initialize();   // setCrashlyticsCollectionEnabled(true)
  Future<void> dispose();      // setCrashlyticsCollectionEnabled(false)
  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});
  Future<void> recordFlutterError(FlutterErrorDetails details);
}

You never call this class directly — install the brick, and getIt<AppMonitoring>() (from monitoring_sdk) fans out to it automatically once monitoring.initialize() runs. Notes on the real implementation:

  • When diagnostics consent is withdrawn, the vendor disables collection, calls deleteUnsentReports() and clears the user id.
  • initialize()/dispose() take no parameters — collection is toggled purely by calling initialize() (enable) or dispose() (disable); there is no enable: bool argument.
  • setUserContext(userId, extras) maps to Crashlytics setUserIdentifier + one setCustomKey per extras entry (stringified). clearUserContext() resets the identifier to ''.
  • recordError forwards to FirebaseCrashlytics.recordError(fatal: ..., printDetails: kDebugMode); any context map is written as custom keys first.
  • recordTransaction is a pass-through — Crashlytics has no span/transaction concept, so it just awaits and returns action().
  • Implementing FlutterAwareMonitoringVendor means MonitoringFanoutImpl.recordFlutterError (reached from bootstrap's FlutterError.onError) uses recordFlutterError (Crashlytics' dedicated API, preserves widget-tree info) instead of the generic recordError.

Dependency injection ​

register_module.dart provides the FirebaseCrashlytics singleton:

dart
@module
abstract class CrashlyticsRegisterModule {
  @lazySingleton
  FirebaseCrashlytics get firebaseCrashlytics => FirebaseCrashlytics.instance;
}

pubspec.yaml's archipelago: manifest declares the package's DI module for monorepo_toolkit generate host-registry:

yaml
archipelago:
  di_modules:
    - class: CrashlyticsMonitoringImplPackageModule

post_gen.dart adds the package to the host app's pubspec.yaml and registers CrashlyticsMonitoringImplPackageModule 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 — the AppMonitoringVendor/FlutterAwareMonitoringVendor contracts
  • firebase_crashlytics: ^5.2.7
  • dependencies (shared workspace injectable/get_it re-export)

Platform Setup ​

Firebase Crashlytics needs native configuration independent of this brick. Firebase must be configured with flutterfire configure: see Firebase Setup. The brick wires a guarded Firebase.initializeApp() into bootstrap.dart (before initializeInjector()). Without Firebase config the app still boots and this vendor is skipped with a debug message.

  1. Add google-services.json (Android) and GoogleService-Info.plist (iOS) to the respective platform directories.
  2. Apply the Google Services / Crashlytics Gradle plugin on Android.
  3. Enable Crashlytics for the project in the Firebase console.

Known Limitations ​

  • No performance-transaction support (see recordTransaction above) — pair with a tracing-capable vendor (Sentry, Grafana) if spans are needed.

Changelog ​

Run archipelago brick info crashlytics_monitoring_impl to see the latest published version. Enterprise customers can read the full CHANGELOG.md in the brick source repository.