Add Sentry for crash analytics

This commit is contained in:
Vishnu Mohandas 2020-05-02 17:16:59 +05:30
parent 3dfb1cf875
commit c96afe7af4
3 changed files with 61 additions and 1 deletions

View file

@ -1,3 +1,5 @@
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:logger/logger.dart';
import 'core/configuration.dart';
@ -5,12 +7,41 @@ import 'photo_loader.dart';
import 'photo_sync_manager.dart';
import 'ui/home_widget.dart';
import 'package:provider/provider.dart';
import 'package:sentry/sentry.dart';
void main() async {
WidgetsFlutterBinding.ensureInitialized();
runApp(MyApp());
Configuration.instance.init();
PhotoSyncManager.instance.sync();
final SentryClient sentry = new SentryClient(
dsn: "http://96780dc0b00f4c69a16c02e90d379996@3.211.17.56/2");
FlutterError.onError = (FlutterErrorDetails details) async {
print('Flutter error caught by Sentry');
FlutterError.dumpErrorToConsole(details, forceReport: true);
_sendErrorToSentry(sentry, details.exception, details.stack);
};
runZoned(
() => runApp(MyApp()),
onError: (Object error, StackTrace stackTrace) =>
_sendErrorToSentry(sentry, error, stackTrace),
);
}
void _sendErrorToSentry(
SentryClient sentry, Object error, StackTrace stackTrace) {
try {
sentry.captureException(
exception: error,
stackTrace: stackTrace,
);
print('Error sent to sentry.io: $error');
} catch (e) {
print('Sending report to sentry.io failed: $e');
print('Original error: $error');
}
}
class MyApp extends StatelessWidget with WidgetsBindingObserver {

View file

@ -142,6 +142,13 @@ packages:
description: flutter
source: sdk
version: "0.0.0"
http:
dependency: transitive
description:
name: http
url: "https://pub.dartlang.org"
source: hosted
version: "0.12.1"
http_parser:
dependency: transitive
description:
@ -226,6 +233,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.1"
pedantic:
dependency: transitive
description:
name: pedantic
url: "https://pub.dartlang.org"
source: hosted
version: "1.9.0"
petitparser:
dependency: transitive
description:
@ -275,6 +289,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.5"
sentry:
dependency: "direct main"
description:
name: sentry
url: "https://pub.dartlang.org"
source: hosted
version: "3.0.1"
shared_preferences:
dependency: "direct main"
description:
@ -385,6 +406,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.6"
usage:
dependency: transitive
description:
name: usage
url: "https://pub.dartlang.org"
source: hosted
version: "3.4.1"
vector_math:
dependency: transitive
description:

View file

@ -41,6 +41,7 @@ dependencies:
visibility_detector: ^0.1.4
connectivity: ^0.4.8+2
event_bus: ^1.1.1
sentry: ">=3.0.0 <4.0.0"
dev_dependencies:
flutter_test: