Helper to implements sentry.io with Angular.
import "package:angular/angular.dart";
import "package:angular_sentry/angular_sentry.dart";
// ignore: uri_has_not_been_generated
import 'main.template.dart' as ng;
const sentryModule = Module(provide: [
ClassProvider(ExceptionHandler, useClass: AngularSentry),
]);
@GenerateInjector([sentryModule])
const scannerApp = ng.scannerApp$Injector;
Future<void> main() async {
await Sentry.init(
(options) {
options.dsn = 'https://[email protected]/add-your-dsn-here';
options.environment = 'production';
options.release = '1.0.0';
},
appRunner: initApp,
);
}
void initApp() {
runApp(ng.AppComponentNgFactory, createInjector: scannerApp);
}
Implement your own class using AngularSentry
class AppSentry extends AngularSentry {
@override
Event transformEvent(SentryEvent e) {
return super.transformEvent(e).copyWith(
user: SentryUser(id: '1', ipAddress: '0.0.0.0'),
extra: {"location_url": window.location.href},
);
}
@override
void capture(exception, [trace, String reason]) {
if (exception is ClientException) {
logError("Network error");
} else {
super.capture(exception, trace, reason);
}
}
}
const sentryModule = Module(provide: [
FactoryProvider(SentryClient, sentryProdider),
ClassProvider(ExceptionHandler, useClass: AppSentry),
]);
main() {
runApp(appComponentNgFactory, createInjector: scannerApp);
}