Skip to content
Back to archipelago.banuacoder.com

Monitoring Implementations

sentry_monitoring_impl Free ​

Tier
Freeversion 1.2.7
Command
archipelago generate sentry_monitoring_impl
Generates
  • infrastructure/sentry_monitoring_impl
Depends on
monitoring_sdkgenerate these first

Sentry vendor implementation for monitoring_api with full error tracking and performance tracing.

Variables ​

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

Install ​

Interactive ​

bash
archipelago generate sentry_monitoring_impl

Non-interactive (CI) ​

bash
archipelago generate sentry_monitoring_impl --config my_config.json

Generate monitoring_sdk first — this brick depends on its monitoring_api package.

Public API ​

dart
final vendor = getIt<AppMonitoringVendor>(instanceName: MonitoringInjectorKey.sentry);
await vendor.initialize();                          // calls SentryFlutter.init(...)
await vendor.setUserContext(userId, extras: {'plan': 'pro'});
vendor.log('checkout opened', level: MonitoringLevel.info); // Sentry breadcrumb
await vendor.recordError(exception, stackTrace, fatal: false);
await vendor.recordTransaction('checkout', () => api.submitOrder());

Architecture ​

sentry_monitoring_impl is a vendor brick that implements the AppMonitoringVendor contract from monitoring_api using the Sentry Flutter SDK. It is selected during flutter_modular_monorepo generation when the user picks sentry from the monitoringVendors multi-select.

SentryMonitoringImpl is registered as a @LazySingleton named MonitoringInjectorKey.sentry (not sentryImpl) and bound to the AppMonitoringVendor interface. It receives a SentryConfig instance via constructor injection. The config is provided by SentryRegisterModule, which the host app must override to supply the real DSN.

DI Registration ​

The package uses @InjectableInit.microPackage() for modular registration. post_gen.dart adds the package to the host app's pubspec.yaml and registers SentryMonitoringImplPackageModule 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. You then override SentryRegisterModule to provide the project DSN.

Generated Structure ​

text
infrastructure/
└── sentry_monitoring_impl/
    ├── pubspec.yaml
    └── lib/
        ├── sentry_monitoring_impl.dart        # Barrel export
        └── src/
            ├── sentry_monitoring_impl.dart    # AppMonitoring impl
            ├── config/
            │   └── sentry_config.dart         # SentryConfig data class
            └── di/
                ├── injector.dart              # microPackage init
                ├── injector.module.dart       # Generated DI module
                └── register_module.dart       # SentryConfig provider (override required)

Key Features ​

  • Full SDK init — initialize() calls SentryFlutter.init with every option from SentryConfig (dsn, environment, tracesSampleRate, enableAutoPerformanceTracing, enableAutoSessionTracking, attachStacktrace, optional release)
  • Scoped user identity — setUserContext(userId, {extras}) uses Sentry.configureScope to attach a SentryUser(id:, data:); clearUserContext() sets scope user to null
  • Breadcrumbs — log(message, {tag, level}) and breadcrumb(message, {category, data, level}) both map to Sentry.addBreadcrumb with category/data and level translation
  • Level mapping — MonitoringLevel values map 1:1 to SentryLevel (debug → debug, info → info, warning → warning, error → error, fatal → fatal)
  • Exception capture — recordError calls Sentry.captureException; fatal errors set scope level to SentryLevel.fatal, and context is attached via scope.setContexts('context', context)
  • Performance transactions — recordTransaction wraps Sentry.startTransaction(name, operation ?? 'task', bindToScope: true), attaches data entries via transaction.setData, marks status ok/internalError, and always calls transaction.finish() in a finally block

Dependencies ​

PackageVersionPurpose
sentry_flutter^9.26.0Sentry Flutter SDK
monitoring_apipathAppMonitoringVendor contract
dependenciespathinjectable / get_it re-export

Platform Setup ​

None required beyond sentry_flutter's own defaults — no native symbol upload or manifest changes are generated by this brick.

Limitations ​

  • No enable/kill-switch parameter on initialize() — call it conditionally in your own bootstrap code if you need to skip Sentry entirely (e.g. local dev).
  • recordTransaction's operation argument maps directly to Sentry's own operation parameter (Sentry.startTransaction(name, operation ?? 'task', ...)) — unlike grafana_monitoring_impl, which instead folds operation into the span name as '$name:$operation'. The two vendors are not interchangeable in how they label spans.

Changelog ​

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

Configuration ​

Override SentryRegisterModule in your app DI module to supply the DSN and any other settings:

dart
@module
abstract class AppSentryModule extends SentryRegisterModule {
  @override
  @lazySingleton
  SentryConfig get sentryConfig => SentryConfig(
    dsn: Env.sentryDsn,               // required — from your .env / build config
    environment: Flavor.status.name,  // 'production', 'staging', etc.
    release: '${Env.appName}@${Env.version}',
    tracesSampleRate: 1.0,
    enableAutoPerformanceTracing: true,
    enableAutoSessionTracking: true,
    attachStacktrace: true,
  );
}

SentryConfig Fields ​

FieldTypeDefaultDescription
dsnStringrequiredSentry project DSN
environmentString'production'Environment label
releaseString?nullRelease string e.g. my-app@1.0.0
tracesSampleRatedouble1.0Performance trace sample rate (0.0–1.0)
enableAutoPerformanceTracingbooltrueAutomatic route/widget tracing
enableAutoSessionTrackingbooltrueSession tracking
attachStacktracebooltrueAttach stack traces to all events

The DSN is found in Sentry Dashboard → Project → Settings → Client Keys (DSN).