mirror of
https://github.com/inventree/inventree-app.git
synced 2025-04-28 05:26:47 +00:00
Re-integrate sentry.io
This commit is contained in:
parent
feaafe068d
commit
90a74fec16
3
.gitignore
vendored
3
.gitignore
vendored
@ -9,6 +9,9 @@
|
|||||||
.history
|
.history
|
||||||
.svn/
|
.svn/
|
||||||
|
|
||||||
|
# Sentry API key
|
||||||
|
lib/dsn.dart
|
||||||
|
|
||||||
# App signing key
|
# App signing key
|
||||||
android/key.properties
|
android/key.properties
|
||||||
|
|
||||||
|
141
lib/inventree/sentry.dart
Normal file
141
lib/inventree/sentry.dart
Normal file
@ -0,0 +1,141 @@
|
|||||||
|
import 'dart:io';
|
||||||
|
|
||||||
|
import 'package:device_info/device_info.dart';
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
|
||||||
|
import 'package:package_info/package_info.dart';
|
||||||
|
import 'package:sentry_flutter/sentry_flutter.dart';
|
||||||
|
import 'package:one_context/one_context.dart';
|
||||||
|
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
||||||
|
|
||||||
|
import 'package:InvenTree/api.dart';
|
||||||
|
|
||||||
|
Future<Map<String, dynamic>> getDeviceInfo() async {
|
||||||
|
|
||||||
|
// Extract device information
|
||||||
|
final DeviceInfoPlugin deviceInfo = DeviceInfoPlugin();
|
||||||
|
|
||||||
|
Map<String, dynamic> device_info = {};
|
||||||
|
|
||||||
|
// Extract some platform information
|
||||||
|
if (Platform.isIOS) {
|
||||||
|
final iosDeviceInfo = await deviceInfo.iosInfo;
|
||||||
|
|
||||||
|
device_info = {
|
||||||
|
'name': iosDeviceInfo.name,
|
||||||
|
'model': iosDeviceInfo.model,
|
||||||
|
'systemName': iosDeviceInfo.systemName,
|
||||||
|
'systemVersion': iosDeviceInfo.systemVersion,
|
||||||
|
'localizedModel': iosDeviceInfo.localizedModel,
|
||||||
|
'utsname': iosDeviceInfo.utsname.sysname,
|
||||||
|
'identifierForVendor': iosDeviceInfo.identifierForVendor,
|
||||||
|
'isPhysicalDevice': iosDeviceInfo.isPhysicalDevice,
|
||||||
|
};
|
||||||
|
|
||||||
|
} else if (Platform.isAndroid) {
|
||||||
|
final androidDeviceInfo = await deviceInfo.androidInfo;
|
||||||
|
|
||||||
|
device_info = {
|
||||||
|
'type': androidDeviceInfo.type,
|
||||||
|
'model': androidDeviceInfo.model,
|
||||||
|
'device': androidDeviceInfo.device,
|
||||||
|
'id': androidDeviceInfo.id,
|
||||||
|
'androidId': androidDeviceInfo.androidId,
|
||||||
|
'brand': androidDeviceInfo.brand,
|
||||||
|
'display': androidDeviceInfo.display,
|
||||||
|
'hardware': androidDeviceInfo.hardware,
|
||||||
|
'manufacturer': androidDeviceInfo.manufacturer,
|
||||||
|
'product': androidDeviceInfo.product,
|
||||||
|
'version': androidDeviceInfo.version.release,
|
||||||
|
'supported32BitAbis': androidDeviceInfo.supported32BitAbis,
|
||||||
|
'supported64BitAbis': androidDeviceInfo.supported64BitAbis,
|
||||||
|
'supportedAbis': androidDeviceInfo.supportedAbis,
|
||||||
|
'isPhysicalDevice': androidDeviceInfo.isPhysicalDevice,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
return device_info;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Map<String, dynamic> getServerInfo() => {
|
||||||
|
"version": InvenTreeAPI().version,
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
Future<Map<String, dynamic>> getAppInfo() async {
|
||||||
|
// Add app info
|
||||||
|
final package_info = await PackageInfo.fromPlatform();
|
||||||
|
|
||||||
|
return {
|
||||||
|
"name": package_info.appName,
|
||||||
|
"build": package_info.buildNumber,
|
||||||
|
"version": package_info.version,
|
||||||
|
"package": package_info.packageName,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool isInDebugMode() {
|
||||||
|
bool inDebugMode = false;
|
||||||
|
|
||||||
|
assert(inDebugMode = true);
|
||||||
|
|
||||||
|
return inDebugMode;
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> sentryReportError(dynamic error, dynamic stackTrace) async {
|
||||||
|
|
||||||
|
print('Intercepted error: $error');
|
||||||
|
print(stackTrace);
|
||||||
|
|
||||||
|
// 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('In dev mode. Not sending report to Sentry.io.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
final server_info = getServerInfo();
|
||||||
|
final app_info = await getAppInfo();
|
||||||
|
final device_info = await getDeviceInfo();
|
||||||
|
|
||||||
|
Sentry.configureScope((scope) {
|
||||||
|
scope.setExtra("server", server_info);
|
||||||
|
scope.setExtra("app", app_info);
|
||||||
|
scope.setExtra("device", device_info);
|
||||||
|
});
|
||||||
|
|
||||||
|
Sentry.captureException(error, stackTrace: stackTrace).catchError((error) {
|
||||||
|
print("Error uploading information to Sentry.io:");
|
||||||
|
print(error);
|
||||||
|
}).then((response) {
|
||||||
|
print("Uploaded information to Sentry.io : ${response.toString()}");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Future<bool> sentryReportMessage(String message) async {
|
||||||
|
|
||||||
|
final server_info = getServerInfo();
|
||||||
|
final app_info = await getAppInfo();
|
||||||
|
final device_info = await getDeviceInfo();
|
||||||
|
|
||||||
|
print("Sending user message to Sentry");
|
||||||
|
|
||||||
|
Sentry.configureScope((scope) {
|
||||||
|
scope.setExtra("server", server_info);
|
||||||
|
scope.setExtra("app", app_info);
|
||||||
|
scope.setExtra("device", device_info);
|
||||||
|
});
|
||||||
|
|
||||||
|
final sentryId = await Sentry.captureMessage(message).catchError((error) {
|
||||||
|
print("Error uploading sentry messages...");
|
||||||
|
print(error);
|
||||||
|
return null;
|
||||||
|
});
|
||||||
|
|
||||||
|
return sentryId != null;
|
||||||
|
}
|
@ -1,3 +1,7 @@
|
|||||||
|
import 'dart:async';
|
||||||
|
import 'dart:io';
|
||||||
|
|
||||||
|
import 'package:InvenTree/inventree/sentry.dart';
|
||||||
import 'package:flutter_localizations/flutter_localizations.dart';
|
import 'package:flutter_localizations/flutter_localizations.dart';
|
||||||
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
||||||
|
|
||||||
@ -6,11 +10,42 @@ import 'package:flutter/cupertino.dart';
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:one_context/one_context.dart';
|
import 'package:one_context/one_context.dart';
|
||||||
|
|
||||||
|
import 'dsn.dart';
|
||||||
|
|
||||||
|
import 'package:sentry_flutter/sentry_flutter.dart';
|
||||||
|
|
||||||
|
|
||||||
void main() async {
|
void main() async {
|
||||||
|
|
||||||
|
|
||||||
|
await Sentry.init((options) {
|
||||||
|
options.dsn = SENTRY_DSN_KEY;
|
||||||
|
},
|
||||||
|
//appRunner: () => runApp(InvenTreeApp())
|
||||||
|
);
|
||||||
|
|
||||||
|
await runZonedGuarded<Future<void>>(() async {
|
||||||
|
|
||||||
WidgetsFlutterBinding.ensureInitialized();
|
WidgetsFlutterBinding.ensureInitialized();
|
||||||
|
|
||||||
|
// 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);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
runApp(InvenTreeApp());
|
runApp(InvenTreeApp());
|
||||||
|
|
||||||
|
}, (Object error, StackTrace stackTrace) {
|
||||||
|
sentryReportError(error, stackTrace);
|
||||||
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class InvenTreeApp extends StatelessWidget {
|
class InvenTreeApp extends StatelessWidget {
|
||||||
|
14
pubspec.lock
14
pubspec.lock
@ -427,6 +427,20 @@ packages:
|
|||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "2.4.9"
|
version: "2.4.9"
|
||||||
|
sentry:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: sentry
|
||||||
|
url: "https://pub.dartlang.org"
|
||||||
|
source: hosted
|
||||||
|
version: "4.0.5"
|
||||||
|
sentry_flutter:
|
||||||
|
dependency: "direct main"
|
||||||
|
description:
|
||||||
|
name: sentry_flutter
|
||||||
|
url: "https://pub.dartlang.org"
|
||||||
|
source: hosted
|
||||||
|
version: "4.0.5"
|
||||||
shared_preferences:
|
shared_preferences:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
|
@ -29,6 +29,7 @@ dependencies:
|
|||||||
device_info: ^1.0.0 # Information about the device
|
device_info: ^1.0.0 # Information about the device
|
||||||
font_awesome_flutter: ^8.8.1 # FontAwesome icon set
|
font_awesome_flutter: ^8.8.1 # FontAwesome icon set
|
||||||
flutter_speed_dial: ^1.2.5 # FAB menu elements
|
flutter_speed_dial: ^1.2.5 # FAB menu elements
|
||||||
|
sentry_flutter: ^4.0.4 # Error reporting
|
||||||
flutter_typeahead: ^1.8.1 # Auto-complete input field
|
flutter_typeahead: ^1.8.1 # Auto-complete input field
|
||||||
image_picker: ^0.6.6 # Select or take photos
|
image_picker: ^0.6.6 # Select or take photos
|
||||||
url_launcher: ^5.7.10 # Open link in system browser
|
url_launcher: ^5.7.10 # Open link in system browser
|
||||||
|
Loading…
x
Reference in New Issue
Block a user