diff --git a/.github/workflows/android.yaml b/.github/workflows/android.yaml index 9481c5c4..06992242 100644 --- a/.github/workflows/android.yaml +++ b/.github/workflows/android.yaml @@ -37,5 +37,4 @@ jobs: - name: Build for Android run: | flutter pub get - cp lib/dummy_dsn.dart lib/dsn.dart flutter build apk --debug diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 4e3e3718..ada4375a 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -43,7 +43,6 @@ jobs: python3 collect_translations.py - name: Static Analysis Tests run: | - cp lib/dummy_dsn.dart lib/dsn.dart python3 find_dart_files.py flutter pub get flutter analyze diff --git a/.github/workflows/ios.yaml b/.github/workflows/ios.yaml index 65c92a03..f6bf24b2 100644 --- a/.github/workflows/ios.yaml +++ b/.github/workflows/ios.yaml @@ -38,5 +38,4 @@ jobs: pod repo update pod install cd .. - cp lib/dummy_dsn.dart lib/dsn.dart flutter build ios --release --no-codesign --no-tree-shake-icons diff --git a/.gitignore b/.gitignore index dd7fc904..96b35284 100644 --- a/.gitignore +++ b/.gitignore @@ -15,9 +15,6 @@ coverage/* test/coverage_helper_test.dart InvenTreeSettings.db -# Sentry API key -lib/dsn.dart - # App signing key android/key.properties diff --git a/lib/dsn.dart b/lib/dsn.dart new file mode 100644 index 00000000..39092c82 --- /dev/null +++ b/lib/dsn.dart @@ -0,0 +1,7 @@ + +/* + * For integration with sentry.io, fill out the SENTRY_DSN_KEY value below. + * This should be set to a valid DSN key, from your sentry.io account + * + */ +String SENTRY_DSN_KEY = "https://fea705aa4b8e4c598dcf9b146b3d1b86@o378676.ingest.sentry.io/5202450"; \ No newline at end of file diff --git a/lib/dummy_dsn.dart b/lib/dummy_dsn.dart deleted file mode 100644 index d53bb6ff..00000000 --- a/lib/dummy_dsn.dart +++ /dev/null @@ -1,3 +0,0 @@ -// Dummy DSN to use for unit testing, etc - -const String SENTRY_DSN_KEY = "https://12345678901234567890@abcdef.ingest.sentry.io/11223344"; \ No newline at end of file diff --git a/lib/inventree/sentry.dart b/lib/inventree/sentry.dart index 4ca9cf41..7484d71a 100644 --- a/lib/inventree/sentry.dart +++ b/lib/inventree/sentry.dart @@ -6,6 +6,7 @@ import "package:package_info_plus/package_info_plus.dart"; import "package:sentry_flutter/sentry_flutter.dart"; import "package:inventree/api.dart"; +import "package:inventree/dsn.dart"; import "package:inventree/preferences.dart"; Future> getDeviceInfo() async { @@ -85,6 +86,10 @@ bool isInDebugMode() { Future sentryReportMessage(String message, {Map? context}) async { + if (SENTRY_DSN_KEY.isEmpty) { + return false; + } + final server_info = getServerInfo(); final app_info = await getAppInfo(); final device_info = await getDeviceInfo(); @@ -164,6 +169,10 @@ Future sentryReportError(String source, dynamic error, StackTrace? stackTr return; } + if (SENTRY_DSN_KEY.isEmpty) { + return; + } + final upload = await InvenTreeSettingsManager().getValue(INV_REPORT_ERRORS, true) as bool; if (!upload) { diff --git a/lib/main.dart b/lib/main.dart index 3a7d2f44..9359449e 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -34,13 +34,15 @@ Future main() async { String release = "${pkg}@${version}:${build}"; - await Sentry.init((options) { - options.dsn = SENTRY_DSN_KEY; - options.release = release; - options.environment = isInDebugMode() ? "debug" : "release"; - options.diagnosticLevel = SentryLevel.debug; - options.attachStacktrace = true; - }); + if (SENTRY_DSN_KEY.isNotEmpty) { + await Sentry.init((options) { + options.dsn = SENTRY_DSN_KEY; + options.release = release; + options.environment = isInDebugMode() ? "debug" : "release"; + options.diagnosticLevel = SentryLevel.debug; + options.attachStacktrace = true; + }); + } // Pass any flutter errors off to the Sentry reporting context! FlutterError.onError = (FlutterErrorDetails details) async {