From 28c4a1048ecbf14d5ca87adbe7c66bfc82a5394c Mon Sep 17 00:00:00 2001 From: Hillel Coren Date: Tue, 22 Dec 2020 22:58:33 +0200 Subject: [PATCH] Update Sentry package --- android/app/build.gradle.dev | 2 + android/app/build.gradle.prod | 3 +- lib/main.dart | 50 +++++++----------- lib/main_app.dart | 4 ++ lib/ui/dashboard/dashboard_panels.dart | 20 +++---- lib/utils/sentry.dart | 72 -------------------------- pubspec.lock | 20 +++---- pubspec.yaml | 3 +- 8 files changed, 48 insertions(+), 126 deletions(-) delete mode 100644 lib/utils/sentry.dart diff --git a/android/app/build.gradle.dev b/android/app/build.gradle.dev index 9a6df302f..afe4c0f59 100644 --- a/android/app/build.gradle.dev +++ b/android/app/build.gradle.dev @@ -43,6 +43,7 @@ android { versionCode flutterVersionCode.toInteger() versionName flutterVersionName testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" + multiDexEnabled true } buildTypes { @@ -62,4 +63,5 @@ dependencies { androidTestImplementation 'androidx.test:runner:1.1.1' androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1' implementation 'com.google.guava:guava:27.0.1-android' // https://stackoverflow.com/a/56639924/497368 + implementation 'androidx.multidex:multidex:2.0.1' // https://stackoverflow.com/a/55592039/497368 } \ No newline at end of file diff --git a/android/app/build.gradle.prod b/android/app/build.gradle.prod index f89789388..ef3b9bbd2 100644 --- a/android/app/build.gradle.prod +++ b/android/app/build.gradle.prod @@ -47,6 +47,7 @@ android { versionCode flutterVersionCode.toInteger() versionName flutterVersionName testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" + multiDexEnabled true } signingConfigs { @@ -78,7 +79,7 @@ dependencies { androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1' implementation 'com.google.firebase:firebase-core:17.2.0' implementation 'com.google.guava:guava:27.0.1-android' // https://stackoverflow.com/a/56639924/497368 - + implementation 'androidx.multidex:multidex:2.0.1' // https://stackoverflow.com/a/55592039/497368 } apply plugin: 'com.google.gms.google-services' \ No newline at end of file diff --git a/lib/main.dart b/lib/main.dart index b6e0a3a4a..3bdce4f30 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -31,10 +31,9 @@ import 'package:invoiceninja_flutter/redux/tax_rate/tax_rate_middleware.dart'; import 'package:invoiceninja_flutter/redux/ui/pref_state.dart'; import 'package:invoiceninja_flutter/redux/user/user_middleware.dart'; import 'package:invoiceninja_flutter/redux/vendor/vendor_middleware.dart'; -import 'package:invoiceninja_flutter/utils/sentry.dart'; import 'package:redux/redux.dart'; import 'package:redux_logging/redux_logging.dart'; -import 'package:sentry/sentry.dart'; +import 'package:sentry_flutter/sentry_flutter.dart'; import 'package:shared_preferences/shared_preferences.dart'; import 'package:invoiceninja_flutter/utils/web_stub.dart' if (dart.library.html) 'package:invoiceninja_flutter/utils/web.dart'; @@ -50,12 +49,6 @@ import 'package:invoiceninja_flutter/redux/payment_term/payment_term_middleware. void main({bool isTesting = false}) async { WidgetsFlutterBinding.ensureInitialized(); - final SentryClient _sentry = Config.SENTRY_DNS.isEmpty - ? null - : SentryClient( - dsn: Config.SENTRY_DNS, - environmentAttributes: await getSentryEvent()); - final store = Store(appReducer, initialState: await _initialState(isTesting), middleware: [] @@ -95,32 +88,27 @@ void main({bool isTesting = false}) async { ), ])); - if (_sentry == null) { + if (kIsWeb || !kReleaseMode || Config.SENTRY_DNS.isEmpty) { runApp(InvoiceNinjaApp(store: store)); } else { - runZonedGuarded(() { - runApp(InvoiceNinjaApp(store: store)); - }, (Object error, StackTrace stackTrace) async { - if (kDebugMode || kIsWeb) { - print(stackTrace); - } else if (store.state.reportErrors) { - final event = await getSentryEvent( - state: store.state, - exception: error, - stackTrace: stackTrace, - ); - _sentry.capture(event: event); - } - }); + await SentryFlutter.init( + (options) { + options.dsn = Config.SENTRY_DNS; + options.release = kClientVersion; + options.beforeSend = (SentryEvent event, {dynamic hint}) { + final state = store.state; + event = event.copyWith( + environment: '${state.environment}'.split('.').last, + extra: { + 'server_version': state.account?.currentVersion ?? 'Unknown', + }, + ); + return event; + }; + }, + appRunner: () => runApp(InvoiceNinjaApp(store: store)), + ); } - - FlutterError.onError = (FlutterErrorDetails details) { - if (kDebugMode || kIsWeb) { - FlutterError.dumpErrorToConsole(details); - } else if (store.state.reportErrors) { - Zone.current.handleUncaughtError(details.exception, details.stack); - } - }; } Future _initialState(bool isTesting) async { diff --git a/lib/main_app.dart b/lib/main_app.dart index da090f82f..e9e3be2df 100644 --- a/lib/main_app.dart +++ b/lib/main_app.dart @@ -78,6 +78,7 @@ import 'package:invoiceninja_flutter/ui/token/view/token_view_vm.dart'; import 'package:invoiceninja_flutter/ui/token/token_screen_vm.dart'; import 'package:invoiceninja_flutter/utils/web_stub.dart' if (dart.library.html) 'package:invoiceninja_flutter/utils/web.dart'; +import 'package:sentry_flutter/sentry_flutter.dart'; class InvoiceNinjaApp extends StatefulWidget { const InvoiceNinjaApp({Key key, this.store}) : super(key: key); @@ -191,6 +192,9 @@ class InvoiceNinjaAppState extends State { .toList(), //debugShowCheckedModeBanner: false, //showPerformanceOverlay: true, + navigatorObservers: [ + SentryNavigatorObserver(), + ], localizationsDelegates: [ const AppLocalizationsDelegate(), GlobalCupertinoLocalizations.delegate, diff --git a/lib/ui/dashboard/dashboard_panels.dart b/lib/ui/dashboard/dashboard_panels.dart index 6e55b7af0..dde51eeea 100644 --- a/lib/ui/dashboard/dashboard_panels.dart +++ b/lib/ui/dashboard/dashboard_panels.dart @@ -412,28 +412,28 @@ class DashboardPanels extends StatelessWidget { _InvoiceChart( viewModel: viewModel, context: context, - onDateSelected: (entityIds) => viewModel.onSelectionChanged( - EntityType.invoice, entityIds)), + onDateSelected: (entityIds) => viewModel + .onSelectionChanged(EntityType.invoice, entityIds)), if (company.isModuleEnabled(EntityType.invoice)) _paymentChart( context: context, - onDateSelected: (entityIds) => viewModel.onSelectionChanged( - EntityType.payment, entityIds)), + onDateSelected: (entityIds) => viewModel + .onSelectionChanged(EntityType.payment, entityIds)), if (company.isModuleEnabled(EntityType.quote)) _quoteChart( context: context, - onDateSelected: (entityIds) => viewModel.onSelectionChanged( - EntityType.quote, entityIds)), + onDateSelected: (entityIds) => viewModel + .onSelectionChanged(EntityType.quote, entityIds)), if (company.isModuleEnabled(EntityType.task)) _taskChart( context: context, - onDateSelected: (entityIds) => - viewModel.onSelectionChanged(EntityType.task, entityIds)), + onDateSelected: (entityIds) => viewModel + .onSelectionChanged(EntityType.task, entityIds)), if (company.isModuleEnabled(EntityType.expense)) _expenseChart( context: context, - onDateSelected: (entityIds) => viewModel.onSelectionChanged( - EntityType.expense, entityIds)), + onDateSelected: (entityIds) => viewModel + .onSelectionChanged(EntityType.expense, entityIds)), SizedBox( height: 500, ) diff --git a/lib/utils/sentry.dart b/lib/utils/sentry.dart deleted file mode 100644 index c9466fd2c..000000000 --- a/lib/utils/sentry.dart +++ /dev/null @@ -1,72 +0,0 @@ -import 'dart:io'; - -import 'package:device_info/device_info.dart'; -import 'package:flutter/foundation.dart'; -import 'package:invoiceninja_flutter/constants.dart'; -import 'package:invoiceninja_flutter/redux/app/app_state.dart'; -import 'package:sentry/sentry.dart'; - -Future getSentryEvent( - {AppState state, dynamic exception, dynamic stackTrace}) async { - OperatingSystem os; - Device device; - - if (kIsWeb) { - // TODO track web info - os = OperatingSystem( - name: 'Web', - ); - } else { - //final packageInfo = await PackageInfo.fromPlatform(); - final deviceInfo = DeviceInfoPlugin(); - - if (Platform.isAndroid) { - final androidInfo = await deviceInfo.androidInfo; - os = OperatingSystem( - name: 'Android', - version: androidInfo.version.release, - ); - device = Device( - model: androidInfo.model, - manufacturer: androidInfo.manufacturer, - modelId: androidInfo.product, - ); - } else if (Platform.isIOS) { - final iosInfo = await deviceInfo.iosInfo; - os = OperatingSystem( - name: iosInfo.systemName, - version: iosInfo.systemVersion, - ); - device = Device( - model: iosInfo.utsname.machine, - manufacturer: 'Apple', - family: iosInfo.model, - ); - } - } - - String environment = 'Unknown'; - if (state != null) { - environment = '${state.environment}'.split('.').last; - } - - return Event( - release: kClientVersion, - //release: packageInfo.version, - environment: environment, - stackTrace: stackTrace, - exception: exception, - extra: { - 'server_version': state?.account?.currentVersion ?? 'Unknown', - }, - contexts: Contexts( - operatingSystem: os, - device: device, - app: App( - //version: kClientVersion, - //name: packageInfo.appName, - //version: packageInfo.version, - //build: packageInfo.buildNumber, - )), - ); -} diff --git a/pubspec.lock b/pubspec.lock index 1236982d1..02d182c19 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -219,7 +219,7 @@ packages: source: hosted version: "1.3.6" device_info: - dependency: "direct main" + dependency: transitive description: name: device_info url: "https://pub.dartlang.org" @@ -860,12 +860,19 @@ packages: source: hosted version: "0.24.1" sentry: - dependency: "direct main" + dependency: transitive description: name: sentry url: "https://pub.dartlang.org" source: hosted - version: "3.0.1" + version: "4.0.1" + sentry_flutter: + dependency: "direct main" + description: + name: sentry_flutter + url: "https://pub.dartlang.org" + source: hosted + version: "4.0.1" share: dependency: "direct main" description: @@ -1123,13 +1130,6 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "0.0.1+3" - usage: - dependency: transitive - description: - name: usage - url: "https://pub.dartlang.org" - source: hosted - version: "3.4.2" uuid: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index b14aaaad2..dce1762a3 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -39,7 +39,7 @@ dependencies: #firebase_auth: ^0.18.4+1 google_sign_in: ^4.5.1 local_auth: ^0.6.1+3 - sentry: ^3.0.1 + sentry_flutter: ^4.0.1 image_picker: ^0.6.3+4 flutter_colorpicker: ^0.3.2 flutter_json_widget: ^1.0.2 @@ -52,7 +52,6 @@ dependencies: url: git://github.com/hillelcoren/flutter_typeahead.git flutter_share: ^1.0.2+1 package_info: ^0.4.0+16 - device_info: ^0.4.2+1 rounded_loading_button: ^1.0.0 # quick_actions: ^0.2.1 version: ^1.0.0