Skip to content
This repository was archived by the owner on Apr 3, 2025. It is now read-only.

Commit 57bbb80

Browse files
committed
feat(logging): integrate Sentry logging support for all platforms
1 parent 3593eb3 commit 57bbb80

17 files changed

+113
-17
lines changed

.github/workflows/prepare.yml

+3
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ on:
2727
secrets:
2828
FIREBASE_TOKEN:
2929
required: true
30+
SENTRY_DSN:
31+
required: true
3032

3133
jobs:
3234
build-details:
@@ -131,6 +133,7 @@ jobs:
131133
export FLAVOR=${{ needs.build-details.outputs.build-flavor }}
132134
export COMMIT=${{ github.sha }}
133135
export BUILD=${{ needs.build-details.outputs.build-number }}
136+
export SENTRY_DSN=${{ secrets.SENTRY_DSN }}
134137
flutter packages pub run environment_config:generate
135138
136139
- name: Generate Localization

.github/workflows/release.yml

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ jobs:
2525
flavor: ${{ inputs.flavor }}
2626
secrets:
2727
FIREBASE_TOKEN: ${{ secrets.FIREBASE_TOKEN }}
28+
SENTRY_DSN: ${{ secrets.SENTRY_DSN }}
2829

2930
build-android:
3031
name: Build Android

environment_config.yaml

+5
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,8 @@ environment_config:
1515
type: String
1616
default: edge
1717
env_var: FLAVOR
18+
sentryDSN:
19+
type: String
20+
default: ""
21+
env_var: SENTRY_DSN
22+

ios/Podfile.lock

+15-2
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ PODS:
5858
- firebase_core (1.21.1):
5959
- Firebase/CoreOnly (= 9.4.0)
6060
- Flutter
61-
- firebase_messaging (12.0.1):
61+
- firebase_messaging (12.0.3):
6262
- Firebase/Messaging (= 9.4.0)
6363
- firebase_core
6464
- Flutter
@@ -163,6 +163,13 @@ PODS:
163163
- SDWebImage (5.13.2):
164164
- SDWebImage/Core (= 5.13.2)
165165
- SDWebImage/Core (5.13.2)
166+
- Sentry (7.23.0):
167+
- Sentry/Core (= 7.23.0)
168+
- Sentry/Core (7.23.0)
169+
- sentry_flutter (0.0.1):
170+
- Flutter
171+
- FlutterMacOS
172+
- Sentry (~> 7.23.0)
166173
- share_plus (0.0.1):
167174
- Flutter
168175
- shared_preferences_ios (0.0.1):
@@ -189,6 +196,7 @@ DEPENDENCIES:
189196
- package_info_plus (from `.symlinks/plugins/package_info_plus/ios`)
190197
- path_provider_ios (from `.symlinks/plugins/path_provider_ios/ios`)
191198
- quick_actions_ios (from `.symlinks/plugins/quick_actions_ios/ios`)
199+
- sentry_flutter (from `.symlinks/plugins/sentry_flutter/ios`)
192200
- share_plus (from `.symlinks/plugins/share_plus/ios`)
193201
- shared_preferences_ios (from `.symlinks/plugins/shared_preferences_ios/ios`)
194202
- sqflite (from `.symlinks/plugins/sqflite/ios`)
@@ -217,6 +225,7 @@ SPEC REPOS:
217225
- nanopb
218226
- PromisesObjC
219227
- SDWebImage
228+
- Sentry
220229
- SwiftyGif
221230

222231
EXTERNAL SOURCES:
@@ -247,6 +256,8 @@ EXTERNAL SOURCES:
247256
:path: ".symlinks/plugins/path_provider_ios/ios"
248257
quick_actions_ios:
249258
:path: ".symlinks/plugins/quick_actions_ios/ios"
259+
sentry_flutter:
260+
:path: ".symlinks/plugins/sentry_flutter/ios"
250261
share_plus:
251262
:path: ".symlinks/plugins/share_plus/ios"
252263
shared_preferences_ios:
@@ -269,7 +280,7 @@ SPEC CHECKSUMS:
269280
Firebase: 7703fc4022824b6d6db1bf7bea58d13b8e17ec46
270281
firebase_auth: 74cfbf7be1e3e7fdaac9e7f117cefd89155251a9
271282
firebase_core: 8e500850dd138c269d197c8dfca3ae886fa3b6f2
272-
firebase_messaging: 2a3412ef5e30b84adfb66ae358e7a8fdebcd7462
283+
firebase_messaging: b65dacd4de1b469893dea0d754b1947f45ef4f7a
273284
firebase_storage: 846832b7f2d22238678dc9abc513f2151f102462
274285
FirebaseAppCheckInterop: 8e95b4329809e3c06fb425acb3839dcadfe23673
275286
FirebaseAuth: ae5d4402e1516497357d909162b091b3ca2a2e9c
@@ -296,6 +307,8 @@ SPEC CHECKSUMS:
296307
PromisesObjC: ab77feca74fa2823e7af4249b8326368e61014cb
297308
quick_actions_ios: 5ec8f5f1ae81512ac803fe10c197ebb875767a9e
298309
SDWebImage: 72f86271a6f3139cc7e4a89220946489d4b9a866
310+
Sentry: a0d4563fa4ddacba31fdcc35daaa8573d87224d6
311+
sentry_flutter: 8bde7d0e57a721727fe573f13bb292c497b5a249
299312
share_plus: 056a1e8ac890df3e33cb503afffaf1e9b4fbae68
300313
shared_preferences_ios: 548a61f8053b9b8a49ac19c1ffbc8b92c50d68ad
301314
sqflite: 6d358c025f5b867b29ed92fc697fd34924e11904

ios/Runner.xcodeproj/project.pbxproj

+4
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,7 @@
424424
"${BUILT_PRODUCTS_DIR}/GoogleUtilities/GoogleUtilities.framework",
425425
"${BUILT_PRODUCTS_DIR}/PromisesObjC/FBLPromises.framework",
426426
"${BUILT_PRODUCTS_DIR}/SDWebImage/SDWebImage.framework",
427+
"${BUILT_PRODUCTS_DIR}/Sentry/Sentry.framework",
427428
"${BUILT_PRODUCTS_DIR}/SwiftyGif/SwiftyGif.framework",
428429
"${BUILT_PRODUCTS_DIR}/file_picker/file_picker.framework",
429430
"${BUILT_PRODUCTS_DIR}/flutter_native_splash/flutter_native_splash.framework",
@@ -432,6 +433,7 @@
432433
"${BUILT_PRODUCTS_DIR}/package_info_plus/package_info_plus.framework",
433434
"${BUILT_PRODUCTS_DIR}/path_provider_ios/path_provider_ios.framework",
434435
"${BUILT_PRODUCTS_DIR}/quick_actions_ios/quick_actions_ios.framework",
436+
"${BUILT_PRODUCTS_DIR}/sentry_flutter/sentry_flutter.framework",
435437
"${BUILT_PRODUCTS_DIR}/share_plus/share_plus.framework",
436438
"${BUILT_PRODUCTS_DIR}/shared_preferences_ios/shared_preferences_ios.framework",
437439
"${BUILT_PRODUCTS_DIR}/sqflite/sqflite.framework",
@@ -458,6 +460,7 @@
458460
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/GoogleUtilities.framework",
459461
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/FBLPromises.framework",
460462
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/SDWebImage.framework",
463+
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Sentry.framework",
461464
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/SwiftyGif.framework",
462465
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/file_picker.framework",
463466
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/flutter_native_splash.framework",
@@ -466,6 +469,7 @@
466469
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/package_info_plus.framework",
467470
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/path_provider_ios.framework",
468471
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/quick_actions_ios.framework",
472+
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/sentry_flutter.framework",
469473
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/share_plus.framework",
470474
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/shared_preferences_ios.framework",
471475
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/sqflite.framework",

lib/main.dart

+3-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import 'package:lunasea/system/cache/image/image_cache.dart';
1010
import 'package:lunasea/system/in_app_purchase/in_app_purchase.dart';
1111
import 'package:lunasea/system/localization.dart';
1212
import 'package:lunasea/system/network/network.dart';
13+
import 'package:lunasea/system/sentry.dart';
1314
import 'package:lunasea/system/window_manager/window_manager.dart';
1415
import 'package:lunasea/system/platform.dart';
1516

@@ -21,9 +22,10 @@ Future<void> main() async {
2122
runZonedGuarded(
2223
() async {
2324
//LunaSea initialization
25+
await LunaSentry().initialize();
2426
await LunaDatabase().initialize();
25-
if (LunaFirebase.isSupported) await LunaFirebase().initialize();
2627
LunaLogger().initialize();
28+
if (LunaFirebase.isSupported) await LunaFirebase().initialize();
2729
LunaTheme().initialize();
2830
if (LunaWindowManager.isSupported) await LunaWindowManager().initialize();
2931
if (LunaNetwork.isSupported) LunaNetwork().initialize();

lib/router/router.dart

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import 'package:flutter/foundation.dart';
22
import 'package:lunasea/system/logger.dart';
3+
import 'package:lunasea/system/sentry.dart';
34
import 'package:lunasea/widgets/pages/error_route.dart';
45
import 'package:lunasea/router/routes.dart';
56
import 'package:lunasea/vendor.dart';
@@ -10,11 +11,10 @@ class LunaRouter {
1011
void initialize() {
1112
router = GoRouter(
1213
debugLogDiagnostics: kDebugMode,
14+
errorBuilder: (_, state) => ErrorRoutePage(exception: state.error),
1315
initialLocation: LunaRoutes.initialLocation,
16+
observers: [LunaSentry().navigatorObserver],
1417
routes: LunaRoutes.values.map((r) => r.root.routes).toList(),
15-
errorBuilder: (_, state) {
16-
return ErrorRoutePage(exception: state.error);
17-
},
1818
);
1919
}
2020

lib/system/logger.dart

+20-9
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import 'package:flutter/foundation.dart';
22
import 'package:flutter/material.dart';
33
import 'package:lunasea/core.dart';
44
import 'package:lunasea/database/models/log.dart';
5+
import 'package:lunasea/system/sentry.dart';
56
import 'package:lunasea/types/exception.dart';
67
import 'package:lunasea/types/log_type.dart';
78

@@ -53,34 +54,44 @@ class LunaLogger {
5354
}
5455

5556
void error(String message, dynamic error, StackTrace? stackTrace) {
57+
if (kDebugMode) {
58+
print(message);
59+
print(error);
60+
print(stackTrace);
61+
}
62+
5663
if (error is! NetworkImageLoadException) {
64+
if (error is! DioError) {
65+
LunaSentry().captureException(error, stackTrace);
66+
}
67+
5768
LunaLog log = LunaLog.withError(
5869
type: LunaLogType.ERROR,
5970
message: message,
6071
error: error,
6172
stackTrace: stackTrace,
6273
);
63-
if (kDebugMode) {
64-
print(message);
65-
print(error);
66-
print(stackTrace);
67-
}
6874
LunaBox.logs.create(log);
6975
}
7076
}
7177

7278
void critical(dynamic error, StackTrace stackTrace) {
79+
if (kDebugMode) {
80+
print(error);
81+
print(stackTrace);
82+
}
83+
7384
if (error is! NetworkImageLoadException) {
85+
if (error is! DioError) {
86+
LunaSentry().captureException(error, stackTrace);
87+
}
88+
7489
LunaLog log = LunaLog.withError(
7590
type: LunaLogType.CRITICAL,
7691
message: error?.toString() ?? LunaUI.TEXT_EMDASH,
7792
error: error,
7893
stackTrace: stackTrace,
7994
);
80-
if (kDebugMode) {
81-
print(error);
82-
print(stackTrace);
83-
}
8495
LunaBox.logs.create(log);
8596
}
8697
}

lib/system/sentry.dart

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import 'package:lunasea/system/environment.dart';
2+
import 'package:sentry_flutter/sentry_flutter.dart';
3+
4+
class LunaSentry {
5+
Future<void> initialize() async {
6+
await SentryFlutter.init((options) {
7+
options.dsn = LunaEnvironment.sentryDSN;
8+
options.environment = LunaEnvironment.flavor;
9+
options.release = LunaEnvironment.commit;
10+
});
11+
}
12+
13+
Future<void> captureException(dynamic error, StackTrace? stackTrace) async {
14+
await Sentry.captureException(error, stackTrace: stackTrace);
15+
}
16+
17+
SentryNavigatorObserver get navigatorObserver => SentryNavigatorObserver();
18+
}

linux/flutter/generated_plugin_registrant.cc

+4
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,17 @@
77
#include "generated_plugin_registrant.h"
88

99
#include <screen_retriever/screen_retriever_plugin.h>
10+
#include <sentry_flutter/sentry_flutter_plugin.h>
1011
#include <url_launcher_linux/url_launcher_plugin.h>
1112
#include <window_manager/window_manager_plugin.h>
1213

1314
void fl_register_plugins(FlPluginRegistry* registry) {
1415
g_autoptr(FlPluginRegistrar) screen_retriever_registrar =
1516
fl_plugin_registry_get_registrar_for_plugin(registry, "ScreenRetrieverPlugin");
1617
screen_retriever_plugin_register_with_registrar(screen_retriever_registrar);
18+
g_autoptr(FlPluginRegistrar) sentry_flutter_registrar =
19+
fl_plugin_registry_get_registrar_for_plugin(registry, "SentryFlutterPlugin");
20+
sentry_flutter_plugin_register_with_registrar(sentry_flutter_registrar);
1721
g_autoptr(FlPluginRegistrar) url_launcher_linux_registrar =
1822
fl_plugin_registry_get_registrar_for_plugin(registry, "UrlLauncherPlugin");
1923
url_launcher_plugin_register_with_registrar(url_launcher_linux_registrar);

linux/flutter/generated_plugins.cmake

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
list(APPEND FLUTTER_PLUGIN_LIST
66
screen_retriever
7+
sentry_flutter
78
url_launcher_linux
89
window_manager
910
)

macos/Flutter/GeneratedPluginRegistrant.swift

+2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import firebase_storage
1313
import package_info_plus_macos
1414
import path_provider_macos
1515
import screen_retriever
16+
import sentry_flutter
1617
import share_plus_macos
1718
import shared_preferences_macos
1819
import sqflite
@@ -28,6 +29,7 @@ func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
2829
FLTPackageInfoPlusPlugin.register(with: registry.registrar(forPlugin: "FLTPackageInfoPlusPlugin"))
2930
PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin"))
3031
ScreenRetrieverPlugin.register(with: registry.registrar(forPlugin: "ScreenRetrieverPlugin"))
32+
SentryFlutterPlugin.register(with: registry.registrar(forPlugin: "SentryFlutterPlugin"))
3133
SharePlusMacosPlugin.register(with: registry.registrar(forPlugin: "SharePlusMacosPlugin"))
3234
SharedPreferencesPlugin.register(with: registry.registrar(forPlugin: "SharedPreferencesPlugin"))
3335
SqflitePlugin.register(with: registry.registrar(forPlugin: "SqflitePlugin"))

macos/Podfile.lock

+15-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ PODS:
2626
- firebase_core (1.21.1):
2727
- Firebase/CoreOnly (~> 9.4.0)
2828
- FlutterMacOS
29-
- firebase_messaging (12.0.1):
29+
- firebase_messaging (12.0.3):
3030
- Firebase/CoreOnly (~> 9.4.0)
3131
- Firebase/Messaging (~> 9.4.0)
3232
- firebase_core
@@ -126,6 +126,13 @@ PODS:
126126
- PromisesObjC (2.1.1)
127127
- screen_retriever (0.0.1):
128128
- FlutterMacOS
129+
- Sentry (7.23.0):
130+
- Sentry/Core (= 7.23.0)
131+
- Sentry/Core (7.23.0)
132+
- sentry_flutter (0.0.1):
133+
- Flutter
134+
- FlutterMacOS
135+
- Sentry (~> 7.23.0)
129136
- share_plus_macos (0.0.1):
130137
- FlutterMacOS
131138
- shared_preferences_macos (0.0.1):
@@ -149,6 +156,7 @@ DEPENDENCIES:
149156
- package_info_plus_macos (from `Flutter/ephemeral/.symlinks/plugins/package_info_plus_macos/macos`)
150157
- path_provider_macos (from `Flutter/ephemeral/.symlinks/plugins/path_provider_macos/macos`)
151158
- screen_retriever (from `Flutter/ephemeral/.symlinks/plugins/screen_retriever/macos`)
159+
- sentry_flutter (from `Flutter/ephemeral/.symlinks/plugins/sentry_flutter/macos`)
152160
- share_plus_macos (from `Flutter/ephemeral/.symlinks/plugins/share_plus_macos/macos`)
153161
- shared_preferences_macos (from `Flutter/ephemeral/.symlinks/plugins/shared_preferences_macos/macos`)
154162
- sqflite (from `Flutter/ephemeral/.symlinks/plugins/sqflite/macos`)
@@ -175,6 +183,7 @@ SPEC REPOS:
175183
- GTMSessionFetcher
176184
- nanopb
177185
- PromisesObjC
186+
- Sentry
178187

179188
EXTERNAL SOURCES:
180189
cloud_firestore:
@@ -198,6 +207,8 @@ EXTERNAL SOURCES:
198207
:path: Flutter/ephemeral/.symlinks/plugins/path_provider_macos/macos
199208
screen_retriever:
200209
:path: Flutter/ephemeral/.symlinks/plugins/screen_retriever/macos
210+
sentry_flutter:
211+
:path: Flutter/ephemeral/.symlinks/plugins/sentry_flutter/macos
201212
share_plus_macos:
202213
:path: Flutter/ephemeral/.symlinks/plugins/share_plus_macos/macos
203214
shared_preferences_macos:
@@ -219,7 +230,7 @@ SPEC CHECKSUMS:
219230
Firebase: 7703fc4022824b6d6db1bf7bea58d13b8e17ec46
220231
firebase_auth: d73121234b93a92fa130c1595c59afd37cbfcce8
221232
firebase_core: 822a1076483bf9764284322c9310daa98e1e6817
222-
firebase_messaging: 564a55c225276ba69412e29557c8d280916aa22f
233+
firebase_messaging: b76079f26d7a22470b2de423198a0cabf98ebf03
223234
firebase_storage: 5e4de184fe773a22f4c65875d1e71c009a4cc7b0
224235
FirebaseAppCheckInterop: 8e95b4329809e3c06fb425acb3839dcadfe23673
225236
FirebaseAuth: ae5d4402e1516497357d909162b091b3ca2a2e9c
@@ -243,6 +254,8 @@ SPEC CHECKSUMS:
243254
path_provider_macos: 3c0c3b4b0d4a76d2bf989a913c2de869c5641a19
244255
PromisesObjC: ab77feca74fa2823e7af4249b8326368e61014cb
245256
screen_retriever: 59634572a57080243dd1bf715e55b6c54f241a38
257+
Sentry: a0d4563fa4ddacba31fdcc35daaa8573d87224d6
258+
sentry_flutter: 8bde7d0e57a721727fe573f13bb292c497b5a249
246259
share_plus_macos: 853ee48e7dce06b633998ca0735d482dd671ade4
247260
shared_preferences_macos: a64dc611287ed6cbe28fd1297898db1336975727
248261
sqflite: a5789cceda41d54d23f31d6de539d65bb14100ea

pubspec.lock

+14
Original file line numberDiff line numberDiff line change
@@ -1029,6 +1029,20 @@ packages:
10291029
url: "https://pub.dartlang.org"
10301030
source: hosted
10311031
version: "0.1.2"
1032+
sentry:
1033+
dependency: transitive
1034+
description:
1035+
name: sentry
1036+
url: "https://pub.dartlang.org"
1037+
source: hosted
1038+
version: "6.9.1"
1039+
sentry_flutter:
1040+
dependency: "direct main"
1041+
description:
1042+
name: sentry_flutter
1043+
url: "https://pub.dartlang.org"
1044+
source: hosted
1045+
version: "6.9.1"
10321046
share_plus:
10331047
dependency: "direct main"
10341048
description:

pubspec.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ dependencies:
4444
percent_indicator: ^4.2.2
4545
quick_actions: ^1.0.0
4646
retrofit: ^3.0.1+1
47+
sentry_flutter: ^6.9.1
4748
share_plus: ^4.0.10+1
4849
shimmer: ^2.0.0
4950
simple_icons: ^7.1.0

0 commit comments

Comments
 (0)