Sentry Monitoring Implementation
What you'll learn
- Generating the Sentry monitoring implementation brick
- Overriding
SentryRegisterModuleto supply your DSN and config - Enabling performance tracing and session tracking
Prerequisites
monitoring_sdkalready generated (see Monitoring SDK)- A Sentry account with a Flutter project created
Step 1: Generate the Brick
bash
archipelago generate sentry_monitoring_implYou will be prompted for:
- appName — must match your monorepo app name (e.g.
MyApp) - isForMonorepo —
true
The brick generates in infrastructure/sentry_monitoring_impl/.
Step 2: Retrieve Your DSN
In the Sentry dashboard, navigate to Project → Settings → Client Keys (DSN) and copy the DSN value. Store it as an environment variable (e.g. SENTRY_DSN) and expose it via your Env class using dart-define.
Step 3: Override SentryRegisterModule
Create a module in your app DI that extends SentryRegisterModule and provides SentryConfig:
dart
// apps/<appName>/lib/di/app_sentry_module.dart
@module
abstract class AppSentryModule extends SentryRegisterModule {
@override
@lazySingleton
SentryConfig get sentryConfig => SentryConfig(
dsn: Env.sentryDsn,
environment: Flavor.status.name,
release: '${Env.appName}@${Env.version}',
tracesSampleRate: 1.0,
enableAutoPerformanceTracing: true,
enableAutoSessionTracking: true,
attachStacktrace: true,
);
}Available SentryConfig fields and their defaults:
| Field | Default |
|---|---|
dsn | required |
environment | 'production' |
release | null |
tracesSampleRate | 1.0 |
enableAutoPerformanceTracing | true |
enableAutoSessionTracking | true |
attachStacktrace | true |
Step 4: Register the Micro-Package
Add the impl's package module to your host app's DI init:
dart
@InjectableInit(
initializerName: 'configureDependencies',
microPackages: [
SentryMonitoringImplPackageModule(),
],
)
Future<void> configureDependencies() => getIt.init();The impl is registered as a @LazySingleton named MonitoringInjectorKey.sentryImpl.
Step 5: Verify in Sentry Dashboard
Run the app and trigger a caught error:
dart
getIt<AppMonitoring>(instanceName: MonitoringInjectorKey.sentryImpl)
.recordError(Exception('test'), StackTrace.current, fatal: false);Check Sentry → Issues for the event. Performance transactions started via recordTransaction appear under Sentry → Performance.
Next Steps
- Configure Grafana for HTTP-native log + trace shipping without a proprietary SDK
- Set up New Relic for mobile-first APM with distributed tracing