sentry diagnostics
This commit is contained in:
+73
-3
@@ -1,3 +1,5 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:aitrainer_app/view/account.dart';
|
||||
import 'package:aitrainer_app/view/customer_bodytype_page.dart';
|
||||
import 'package:aitrainer_app/view/customer_fitness_page.dart';
|
||||
@@ -25,8 +27,73 @@ import 'package:flutter/widgets.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:flutter_localizations/flutter_localizations.dart';
|
||||
import 'package:aitrainer_app/localization/app_localization.dart';
|
||||
import 'package:sentry/sentry.dart';
|
||||
|
||||
void main() {
|
||||
final SentryClient _sentry = new SentryClient(dsn: 'https://5fac40cbfcfb4c15aa80c7a8638d7310@o418565.ingest.sentry.io/5322520');
|
||||
|
||||
/// Whether the VM is running in debug mode.
|
||||
///
|
||||
/// This is useful to decide whether a report should be sent to sentry. Usually
|
||||
/// reports from dev mode are not very useful, as these happen on developers'
|
||||
/// workspaces rather than on users' devices in production.
|
||||
bool get isInDebugMode {
|
||||
bool inDebugMode = false;
|
||||
assert(inDebugMode = true);
|
||||
return inDebugMode;
|
||||
}
|
||||
|
||||
/// Reports [error] along with its [stackTrace] to Sentry.io.
|
||||
Future<Null> _reportError(dynamic error, dynamic stackTrace) async {
|
||||
print('Caught error: $error');
|
||||
|
||||
// Errors thrown in development mode are unlikely to be interesting. You can
|
||||
// check if you are running in dev mode using an assertion and omit sending
|
||||
// the report.
|
||||
if (isInDebugMode) {
|
||||
print(stackTrace);
|
||||
print('In dev mode. Not sending report to Sentry.io.');
|
||||
return;
|
||||
}
|
||||
|
||||
print('Reporting to Sentry.io...');
|
||||
|
||||
final SentryResponse response = await _sentry.captureException(
|
||||
exception: error,
|
||||
stackTrace: stackTrace,
|
||||
);
|
||||
|
||||
if (response.isSuccessful) {
|
||||
print('Success! Event ID: ${response.eventId}');
|
||||
} else {
|
||||
print('Failed to report to Sentry.io: ${response.error}');
|
||||
}
|
||||
}
|
||||
|
||||
Future<Null> main() async {
|
||||
// This captures errors reported by the Flutter framework.
|
||||
FlutterError.onError = (FlutterErrorDetails details) async {
|
||||
if (isInDebugMode) {
|
||||
// In development mode simply print to console.
|
||||
FlutterError.dumpErrorToConsole(details);
|
||||
} else {
|
||||
// In production mode report to the application zone to report to
|
||||
// Sentry.
|
||||
Zone.current.handleUncaughtError(details.exception, details.stack);
|
||||
}
|
||||
};
|
||||
|
||||
// This creates a [Zone] that contains the Flutter application and stablishes
|
||||
// an error handler that captures errors and reports them.
|
||||
//
|
||||
// Using a zone makes sure that as many errors as possible are captured,
|
||||
// including those thrown from [Timer]s, microtasks, I/O, and those forwarded
|
||||
// from the `FlutterError` handler.
|
||||
//
|
||||
// More about zones:
|
||||
//
|
||||
// - https://api.dartlang.org/stable/1.24.2/dart-async/Zone-class.html
|
||||
// - https://www.dartlang.org/articles/libraries/zones
|
||||
runZonedGuarded<Future<Null>>(() async {
|
||||
runApp(
|
||||
MultiProvider(
|
||||
// Initialize the model in the builder. That way, Provider
|
||||
@@ -38,10 +105,13 @@ void main() {
|
||||
],
|
||||
|
||||
child: AitrainerApp(),
|
||||
),
|
||||
);
|
||||
));
|
||||
}, (error, stackTrace) async {
|
||||
await _reportError(error, stackTrace);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
class AitrainerApp extends StatelessWidget {
|
||||
|
||||
@override
|
||||
|
||||
@@ -40,6 +40,10 @@ class BottomNavigator {
|
||||
Navigator.of(context).pop();
|
||||
Navigator.of(context).pushNamed('home');
|
||||
|
||||
break;
|
||||
case 1:
|
||||
throw new StateError('This is a Dart exception on event.');
|
||||
|
||||
break;
|
||||
case 2:
|
||||
Navigator.of(context).pop();
|
||||
|
||||
Reference in New Issue
Block a user