Skip to content

Commit

Permalink
Simplify DSN file (#475)
Browse files Browse the repository at this point in the history
* Add checks for empty sentry DSN

* Add default DSN key

* Fix CI workflows
  • Loading branch information
SchrodingersGat committed Mar 6, 2024
1 parent a889c4a commit b02dc5b
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 16 deletions.
1 change: 0 additions & 1 deletion .github/workflows/android.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 0 additions & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/ios.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@ coverage/*
test/coverage_helper_test.dart
InvenTreeSettings.db

# Sentry API key
lib/dsn.dart

# App signing key
android/key.properties

Expand Down
7 changes: 7 additions & 0 deletions lib/dsn.dart
Original file line number Diff line number Diff line change
@@ -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";
3 changes: 0 additions & 3 deletions lib/dummy_dsn.dart

This file was deleted.

9 changes: 9 additions & 0 deletions lib/inventree/sentry.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<Map<String, dynamic>> getDeviceInfo() async {
Expand Down Expand Up @@ -85,6 +86,10 @@ bool isInDebugMode() {

Future<bool> sentryReportMessage(String message, {Map<String, String>? context}) async {

if (SENTRY_DSN_KEY.isEmpty) {
return false;
}

final server_info = getServerInfo();
final app_info = await getAppInfo();
final device_info = await getDeviceInfo();
Expand Down Expand Up @@ -164,6 +169,10 @@ Future<void> 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) {
Expand Down
16 changes: 9 additions & 7 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,15 @@ Future<void> 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 {
Expand Down

0 comments on commit b02dc5b

Please sign in to comment.