Skip to content

Commit

Permalink
feat(logging): integrate Sentry logging support for all platforms
Browse files Browse the repository at this point in the history
  • Loading branch information
JagandeepBrar committed Sep 1, 2022
1 parent 3593eb3 commit 57bbb80
Show file tree
Hide file tree
Showing 17 changed files with 113 additions and 17 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/prepare.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ on:
secrets:
FIREBASE_TOKEN:
required: true
SENTRY_DSN:
required: true

jobs:
build-details:
Expand Down Expand Up @@ -131,6 +133,7 @@ jobs:
export FLAVOR=${{ needs.build-details.outputs.build-flavor }}
export COMMIT=${{ github.sha }}
export BUILD=${{ needs.build-details.outputs.build-number }}
export SENTRY_DSN=${{ secrets.SENTRY_DSN }}
flutter packages pub run environment_config:generate
- name: Generate Localization
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ jobs:
flavor: ${{ inputs.flavor }}
secrets:
FIREBASE_TOKEN: ${{ secrets.FIREBASE_TOKEN }}
SENTRY_DSN: ${{ secrets.SENTRY_DSN }}

build-android:
name: Build Android
Expand Down
5 changes: 5 additions & 0 deletions environment_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,8 @@ environment_config:
type: String
default: edge
env_var: FLAVOR
sentryDSN:
type: String
default: ""
env_var: SENTRY_DSN

17 changes: 15 additions & 2 deletions ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ PODS:
- firebase_core (1.21.1):
- Firebase/CoreOnly (= 9.4.0)
- Flutter
- firebase_messaging (12.0.1):
- firebase_messaging (12.0.3):
- Firebase/Messaging (= 9.4.0)
- firebase_core
- Flutter
Expand Down Expand Up @@ -163,6 +163,13 @@ PODS:
- SDWebImage (5.13.2):
- SDWebImage/Core (= 5.13.2)
- SDWebImage/Core (5.13.2)
- Sentry (7.23.0):
- Sentry/Core (= 7.23.0)
- Sentry/Core (7.23.0)
- sentry_flutter (0.0.1):
- Flutter
- FlutterMacOS
- Sentry (~> 7.23.0)
- share_plus (0.0.1):
- Flutter
- shared_preferences_ios (0.0.1):
Expand All @@ -189,6 +196,7 @@ DEPENDENCIES:
- package_info_plus (from `.symlinks/plugins/package_info_plus/ios`)
- path_provider_ios (from `.symlinks/plugins/path_provider_ios/ios`)
- quick_actions_ios (from `.symlinks/plugins/quick_actions_ios/ios`)
- sentry_flutter (from `.symlinks/plugins/sentry_flutter/ios`)
- share_plus (from `.symlinks/plugins/share_plus/ios`)
- shared_preferences_ios (from `.symlinks/plugins/shared_preferences_ios/ios`)
- sqflite (from `.symlinks/plugins/sqflite/ios`)
Expand Down Expand Up @@ -217,6 +225,7 @@ SPEC REPOS:
- nanopb
- PromisesObjC
- SDWebImage
- Sentry
- SwiftyGif

EXTERNAL SOURCES:
Expand Down Expand Up @@ -247,6 +256,8 @@ EXTERNAL SOURCES:
:path: ".symlinks/plugins/path_provider_ios/ios"
quick_actions_ios:
:path: ".symlinks/plugins/quick_actions_ios/ios"
sentry_flutter:
:path: ".symlinks/plugins/sentry_flutter/ios"
share_plus:
:path: ".symlinks/plugins/share_plus/ios"
shared_preferences_ios:
Expand All @@ -269,7 +280,7 @@ SPEC CHECKSUMS:
Firebase: 7703fc4022824b6d6db1bf7bea58d13b8e17ec46
firebase_auth: 74cfbf7be1e3e7fdaac9e7f117cefd89155251a9
firebase_core: 8e500850dd138c269d197c8dfca3ae886fa3b6f2
firebase_messaging: 2a3412ef5e30b84adfb66ae358e7a8fdebcd7462
firebase_messaging: b65dacd4de1b469893dea0d754b1947f45ef4f7a
firebase_storage: 846832b7f2d22238678dc9abc513f2151f102462
FirebaseAppCheckInterop: 8e95b4329809e3c06fb425acb3839dcadfe23673
FirebaseAuth: ae5d4402e1516497357d909162b091b3ca2a2e9c
Expand All @@ -296,6 +307,8 @@ SPEC CHECKSUMS:
PromisesObjC: ab77feca74fa2823e7af4249b8326368e61014cb
quick_actions_ios: 5ec8f5f1ae81512ac803fe10c197ebb875767a9e
SDWebImage: 72f86271a6f3139cc7e4a89220946489d4b9a866
Sentry: a0d4563fa4ddacba31fdcc35daaa8573d87224d6
sentry_flutter: 8bde7d0e57a721727fe573f13bb292c497b5a249
share_plus: 056a1e8ac890df3e33cb503afffaf1e9b4fbae68
shared_preferences_ios: 548a61f8053b9b8a49ac19c1ffbc8b92c50d68ad
sqflite: 6d358c025f5b867b29ed92fc697fd34924e11904
Expand Down
4 changes: 4 additions & 0 deletions ios/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,7 @@
"${BUILT_PRODUCTS_DIR}/GoogleUtilities/GoogleUtilities.framework",
"${BUILT_PRODUCTS_DIR}/PromisesObjC/FBLPromises.framework",
"${BUILT_PRODUCTS_DIR}/SDWebImage/SDWebImage.framework",
"${BUILT_PRODUCTS_DIR}/Sentry/Sentry.framework",
"${BUILT_PRODUCTS_DIR}/SwiftyGif/SwiftyGif.framework",
"${BUILT_PRODUCTS_DIR}/file_picker/file_picker.framework",
"${BUILT_PRODUCTS_DIR}/flutter_native_splash/flutter_native_splash.framework",
Expand All @@ -432,6 +433,7 @@
"${BUILT_PRODUCTS_DIR}/package_info_plus/package_info_plus.framework",
"${BUILT_PRODUCTS_DIR}/path_provider_ios/path_provider_ios.framework",
"${BUILT_PRODUCTS_DIR}/quick_actions_ios/quick_actions_ios.framework",
"${BUILT_PRODUCTS_DIR}/sentry_flutter/sentry_flutter.framework",
"${BUILT_PRODUCTS_DIR}/share_plus/share_plus.framework",
"${BUILT_PRODUCTS_DIR}/shared_preferences_ios/shared_preferences_ios.framework",
"${BUILT_PRODUCTS_DIR}/sqflite/sqflite.framework",
Expand All @@ -458,6 +460,7 @@
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/GoogleUtilities.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/FBLPromises.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/SDWebImage.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Sentry.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/SwiftyGif.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/file_picker.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/flutter_native_splash.framework",
Expand All @@ -466,6 +469,7 @@
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/package_info_plus.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/path_provider_ios.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/quick_actions_ios.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/sentry_flutter.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/share_plus.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/shared_preferences_ios.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/sqflite.framework",
Expand Down
4 changes: 3 additions & 1 deletion lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import 'package:lunasea/system/cache/image/image_cache.dart';
import 'package:lunasea/system/in_app_purchase/in_app_purchase.dart';
import 'package:lunasea/system/localization.dart';
import 'package:lunasea/system/network/network.dart';
import 'package:lunasea/system/sentry.dart';
import 'package:lunasea/system/window_manager/window_manager.dart';
import 'package:lunasea/system/platform.dart';

Expand All @@ -21,9 +22,10 @@ Future<void> main() async {
runZonedGuarded(
() async {
//LunaSea initialization
await LunaSentry().initialize();
await LunaDatabase().initialize();
if (LunaFirebase.isSupported) await LunaFirebase().initialize();
LunaLogger().initialize();
if (LunaFirebase.isSupported) await LunaFirebase().initialize();
LunaTheme().initialize();
if (LunaWindowManager.isSupported) await LunaWindowManager().initialize();
if (LunaNetwork.isSupported) LunaNetwork().initialize();
Expand Down
6 changes: 3 additions & 3 deletions lib/router/router.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:flutter/foundation.dart';
import 'package:lunasea/system/logger.dart';
import 'package:lunasea/system/sentry.dart';
import 'package:lunasea/widgets/pages/error_route.dart';
import 'package:lunasea/router/routes.dart';
import 'package:lunasea/vendor.dart';
Expand All @@ -10,11 +11,10 @@ class LunaRouter {
void initialize() {
router = GoRouter(
debugLogDiagnostics: kDebugMode,
errorBuilder: (_, state) => ErrorRoutePage(exception: state.error),
initialLocation: LunaRoutes.initialLocation,
observers: [LunaSentry().navigatorObserver],
routes: LunaRoutes.values.map((r) => r.root.routes).toList(),
errorBuilder: (_, state) {
return ErrorRoutePage(exception: state.error);
},
);
}

Expand Down
29 changes: 20 additions & 9 deletions lib/system/logger.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:lunasea/core.dart';
import 'package:lunasea/database/models/log.dart';
import 'package:lunasea/system/sentry.dart';
import 'package:lunasea/types/exception.dart';
import 'package:lunasea/types/log_type.dart';

Expand Down Expand Up @@ -53,34 +54,44 @@ class LunaLogger {
}

void error(String message, dynamic error, StackTrace? stackTrace) {
if (kDebugMode) {
print(message);
print(error);
print(stackTrace);
}

if (error is! NetworkImageLoadException) {
if (error is! DioError) {
LunaSentry().captureException(error, stackTrace);
}

LunaLog log = LunaLog.withError(
type: LunaLogType.ERROR,
message: message,
error: error,
stackTrace: stackTrace,
);
if (kDebugMode) {
print(message);
print(error);
print(stackTrace);
}
LunaBox.logs.create(log);
}
}

void critical(dynamic error, StackTrace stackTrace) {
if (kDebugMode) {
print(error);
print(stackTrace);
}

if (error is! NetworkImageLoadException) {
if (error is! DioError) {
LunaSentry().captureException(error, stackTrace);
}

LunaLog log = LunaLog.withError(
type: LunaLogType.CRITICAL,
message: error?.toString() ?? LunaUI.TEXT_EMDASH,
error: error,
stackTrace: stackTrace,
);
if (kDebugMode) {
print(error);
print(stackTrace);
}
LunaBox.logs.create(log);
}
}
Expand Down
18 changes: 18 additions & 0 deletions lib/system/sentry.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import 'package:lunasea/system/environment.dart';
import 'package:sentry_flutter/sentry_flutter.dart';

class LunaSentry {
Future<void> initialize() async {
await SentryFlutter.init((options) {
options.dsn = LunaEnvironment.sentryDSN;
options.environment = LunaEnvironment.flavor;
options.release = LunaEnvironment.commit;
});
}

Future<void> captureException(dynamic error, StackTrace? stackTrace) async {
await Sentry.captureException(error, stackTrace: stackTrace);
}

SentryNavigatorObserver get navigatorObserver => SentryNavigatorObserver();
}
4 changes: 4 additions & 0 deletions linux/flutter/generated_plugin_registrant.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,17 @@
#include "generated_plugin_registrant.h"

#include <screen_retriever/screen_retriever_plugin.h>
#include <sentry_flutter/sentry_flutter_plugin.h>
#include <url_launcher_linux/url_launcher_plugin.h>
#include <window_manager/window_manager_plugin.h>

void fl_register_plugins(FlPluginRegistry* registry) {
g_autoptr(FlPluginRegistrar) screen_retriever_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "ScreenRetrieverPlugin");
screen_retriever_plugin_register_with_registrar(screen_retriever_registrar);
g_autoptr(FlPluginRegistrar) sentry_flutter_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "SentryFlutterPlugin");
sentry_flutter_plugin_register_with_registrar(sentry_flutter_registrar);
g_autoptr(FlPluginRegistrar) url_launcher_linux_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "UrlLauncherPlugin");
url_launcher_plugin_register_with_registrar(url_launcher_linux_registrar);
Expand Down
1 change: 1 addition & 0 deletions linux/flutter/generated_plugins.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

list(APPEND FLUTTER_PLUGIN_LIST
screen_retriever
sentry_flutter
url_launcher_linux
window_manager
)
Expand Down
2 changes: 2 additions & 0 deletions macos/Flutter/GeneratedPluginRegistrant.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import firebase_storage
import package_info_plus_macos
import path_provider_macos
import screen_retriever
import sentry_flutter
import share_plus_macos
import shared_preferences_macos
import sqflite
Expand All @@ -28,6 +29,7 @@ func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
FLTPackageInfoPlusPlugin.register(with: registry.registrar(forPlugin: "FLTPackageInfoPlusPlugin"))
PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin"))
ScreenRetrieverPlugin.register(with: registry.registrar(forPlugin: "ScreenRetrieverPlugin"))
SentryFlutterPlugin.register(with: registry.registrar(forPlugin: "SentryFlutterPlugin"))
SharePlusMacosPlugin.register(with: registry.registrar(forPlugin: "SharePlusMacosPlugin"))
SharedPreferencesPlugin.register(with: registry.registrar(forPlugin: "SharedPreferencesPlugin"))
SqflitePlugin.register(with: registry.registrar(forPlugin: "SqflitePlugin"))
Expand Down
17 changes: 15 additions & 2 deletions macos/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ PODS:
- firebase_core (1.21.1):
- Firebase/CoreOnly (~> 9.4.0)
- FlutterMacOS
- firebase_messaging (12.0.1):
- firebase_messaging (12.0.3):
- Firebase/CoreOnly (~> 9.4.0)
- Firebase/Messaging (~> 9.4.0)
- firebase_core
Expand Down Expand Up @@ -126,6 +126,13 @@ PODS:
- PromisesObjC (2.1.1)
- screen_retriever (0.0.1):
- FlutterMacOS
- Sentry (7.23.0):
- Sentry/Core (= 7.23.0)
- Sentry/Core (7.23.0)
- sentry_flutter (0.0.1):
- Flutter
- FlutterMacOS
- Sentry (~> 7.23.0)
- share_plus_macos (0.0.1):
- FlutterMacOS
- shared_preferences_macos (0.0.1):
Expand All @@ -149,6 +156,7 @@ DEPENDENCIES:
- package_info_plus_macos (from `Flutter/ephemeral/.symlinks/plugins/package_info_plus_macos/macos`)
- path_provider_macos (from `Flutter/ephemeral/.symlinks/plugins/path_provider_macos/macos`)
- screen_retriever (from `Flutter/ephemeral/.symlinks/plugins/screen_retriever/macos`)
- sentry_flutter (from `Flutter/ephemeral/.symlinks/plugins/sentry_flutter/macos`)
- share_plus_macos (from `Flutter/ephemeral/.symlinks/plugins/share_plus_macos/macos`)
- shared_preferences_macos (from `Flutter/ephemeral/.symlinks/plugins/shared_preferences_macos/macos`)
- sqflite (from `Flutter/ephemeral/.symlinks/plugins/sqflite/macos`)
Expand All @@ -175,6 +183,7 @@ SPEC REPOS:
- GTMSessionFetcher
- nanopb
- PromisesObjC
- Sentry

EXTERNAL SOURCES:
cloud_firestore:
Expand All @@ -198,6 +207,8 @@ EXTERNAL SOURCES:
:path: Flutter/ephemeral/.symlinks/plugins/path_provider_macos/macos
screen_retriever:
:path: Flutter/ephemeral/.symlinks/plugins/screen_retriever/macos
sentry_flutter:
:path: Flutter/ephemeral/.symlinks/plugins/sentry_flutter/macos
share_plus_macos:
:path: Flutter/ephemeral/.symlinks/plugins/share_plus_macos/macos
shared_preferences_macos:
Expand All @@ -219,7 +230,7 @@ SPEC CHECKSUMS:
Firebase: 7703fc4022824b6d6db1bf7bea58d13b8e17ec46
firebase_auth: d73121234b93a92fa130c1595c59afd37cbfcce8
firebase_core: 822a1076483bf9764284322c9310daa98e1e6817
firebase_messaging: 564a55c225276ba69412e29557c8d280916aa22f
firebase_messaging: b76079f26d7a22470b2de423198a0cabf98ebf03
firebase_storage: 5e4de184fe773a22f4c65875d1e71c009a4cc7b0
FirebaseAppCheckInterop: 8e95b4329809e3c06fb425acb3839dcadfe23673
FirebaseAuth: ae5d4402e1516497357d909162b091b3ca2a2e9c
Expand All @@ -243,6 +254,8 @@ SPEC CHECKSUMS:
path_provider_macos: 3c0c3b4b0d4a76d2bf989a913c2de869c5641a19
PromisesObjC: ab77feca74fa2823e7af4249b8326368e61014cb
screen_retriever: 59634572a57080243dd1bf715e55b6c54f241a38
Sentry: a0d4563fa4ddacba31fdcc35daaa8573d87224d6
sentry_flutter: 8bde7d0e57a721727fe573f13bb292c497b5a249
share_plus_macos: 853ee48e7dce06b633998ca0735d482dd671ade4
shared_preferences_macos: a64dc611287ed6cbe28fd1297898db1336975727
sqflite: a5789cceda41d54d23f31d6de539d65bb14100ea
Expand Down
14 changes: 14 additions & 0 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1029,6 +1029,20 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "0.1.2"
sentry:
dependency: transitive
description:
name: sentry
url: "https://pub.dartlang.org"
source: hosted
version: "6.9.1"
sentry_flutter:
dependency: "direct main"
description:
name: sentry_flutter
url: "https://pub.dartlang.org"
source: hosted
version: "6.9.1"
share_plus:
dependency: "direct main"
description:
Expand Down
1 change: 1 addition & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ dependencies:
percent_indicator: ^4.2.2
quick_actions: ^1.0.0
retrofit: ^3.0.1+1
sentry_flutter: ^6.9.1
share_plus: ^4.0.10+1
shimmer: ^2.0.0
simple_icons: ^7.1.0
Expand Down
Loading

0 comments on commit 57bbb80

Please sign in to comment.