From 67c9ff699cbcf45d2720cbce239799d9bd70d3d8 Mon Sep 17 00:00:00 2001 From: guozhigq Date: Sat, 23 Mar 2024 14:15:51 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20sentry=20=E5=BC=82=E5=B8=B8=E6=8D=95?= =?UTF-8?q?=E8=8E=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ios/Podfile.lock | 15 ++++++++ lib/main.dart | 38 ++++++++++++++++--- lib/services/sentry.dart | 26 +++++++++++++ linux/flutter/generated_plugin_registrant.cc | 4 ++ linux/flutter/generated_plugins.cmake | 1 + macos/Flutter/GeneratedPluginRegistrant.swift | 2 + pubspec.lock | 12 +++++- pubspec.yaml | 1 + .../flutter/generated_plugin_registrant.cc | 3 ++ windows/flutter/generated_plugins.cmake | 1 + 10 files changed, 95 insertions(+), 8 deletions(-) create mode 100644 lib/services/sentry.dart diff --git a/ios/Podfile.lock b/ios/Podfile.lock index 8db59815..1d0598fe 100644 --- a/ios/Podfile.lock +++ b/ios/Podfile.lock @@ -45,6 +45,13 @@ PODS: - Flutter - screen_brightness_ios (0.1.0): - Flutter + - Sentry/HybridSDK (8.19.0): + - SentryPrivate (= 8.19.0) + - sentry_flutter (0.0.1): + - Flutter + - FlutterMacOS + - Sentry/HybridSDK (= 8.19.0) + - SentryPrivate (8.19.0) - share_plus (0.0.1): - Flutter - sqflite (0.0.3): @@ -86,6 +93,7 @@ DEPENDENCIES: - permission_handler_apple (from `.symlinks/plugins/permission_handler_apple/ios`) - saver_gallery (from `.symlinks/plugins/saver_gallery/ios`) - screen_brightness_ios (from `.symlinks/plugins/screen_brightness_ios/ios`) + - sentry_flutter (from `.symlinks/plugins/sentry_flutter/ios`) - share_plus (from `.symlinks/plugins/share_plus/ios`) - sqflite (from `.symlinks/plugins/sqflite/ios`) - status_bar_control (from `.symlinks/plugins/status_bar_control/ios`) @@ -101,6 +109,8 @@ SPEC REPOS: - FMDB - GT3Captcha-iOS - ReachabilitySwift + - Sentry + - SentryPrivate - Toast EXTERNAL SOURCES: @@ -142,6 +152,8 @@ EXTERNAL SOURCES: :path: ".symlinks/plugins/saver_gallery/ios" screen_brightness_ios: :path: ".symlinks/plugins/screen_brightness_ios/ios" + sentry_flutter: + :path: ".symlinks/plugins/sentry_flutter/ios" share_plus: :path: ".symlinks/plugins/share_plus/ios" sqflite: @@ -184,6 +196,9 @@ SPEC CHECKSUMS: ReachabilitySwift: 985039c6f7b23a1da463388634119492ff86c825 saver_gallery: 2b4e584106fde2407ab51560f3851564963e6b78 screen_brightness_ios: 715ca807df953bf676d339f11464e438143ee625 + Sentry: 1ebcaef678a27c8ac515f974cb5425dd1bbdec2f + sentry_flutter: ecdfbedee55337205561cfa782ee02d31ec83e1f + SentryPrivate: 765c9b4ebe9ac1a5fcdc067c5a1cfbf3f10e1677 share_plus: c3fef564749587fc939ef86ffb283ceac0baf9f5 sqflite: 31f7eba61e3074736dff8807a9b41581e4f7f15a status_bar_control: 7c84146799e6a076315cc1550f78ef53aae3e446 diff --git a/lib/main.dart b/lib/main.dart index 44bb1dcd..e8c48e6c 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -25,6 +25,9 @@ import 'package:media_kit/media_kit.dart'; // Provides [Player], [Media], [Playl import 'package:pilipala/utils/recommend_filter.dart'; import 'package:catcher_2/catcher_2.dart'; import './services/loggeer.dart'; +import 'package:sentry_flutter/sentry_flutter.dart'; + +import 'services/sentry.dart'; void main() async { WidgetsFlutterBinding.ensureInitialized(); @@ -55,14 +58,36 @@ void main() async { [FileHandler(await getLogsPath())], ); - Catcher2( - debugConfig: debugConfig, - releaseConfig: releaseConfig, - runAppFunction: () { - runApp(const MyApp()); - }, + // Catcher2( + // debugConfig: debugConfig, + // releaseConfig: releaseConfig, + // runAppFunction: () { + // runApp(const MyApp()); + // }, + // ); + + await SentryService.sentryInit( + () => runApp( + SentryScreenshotWidget( + child: SentryUserInteractionWidget( + child: DefaultAssetBundle( + bundle: SentryAssetBundle(), + child: const MyApp(), + ), + ), + ), + ), ); + // try { + // int? test; + // test! + 3; + // } catch (exception, stackTrace) { + // debugPrint('111'); + // await Sentry.captureException(exception, stackTrace: '$stackTrace'); + // debugPrint('222'); + // } + // 小白条、导航栏沉浸 SystemChrome.setEnabledSystemUIMode(SystemUiMode.edgeToEdge); SystemChrome.setSystemUIOverlayStyle(const SystemUiOverlayStyle( @@ -195,6 +220,7 @@ class MyApp extends StatelessWidget { navigatorObservers: [ VideoDetailPage.routeObserver, SearchPage.routeObserver, + SentryNavigatorObserver(), ], ); }), diff --git a/lib/services/sentry.dart b/lib/services/sentry.dart new file mode 100644 index 00000000..d1b50a0b --- /dev/null +++ b/lib/services/sentry.dart @@ -0,0 +1,26 @@ +import 'package:sentry_flutter/sentry_flutter.dart'; + +class SentryService { + static sentryInit(AppRunner appRunner) async { + return await SentryFlutter.init( + (options) => options + ..dsn = + 'https://cb0ce70fcda1c903072a6c73cc2d89e2@o4506669621182464.ingest.sentry.io/4506669624459264' + ..debug = true // 调试模式下启用 + ..attachThreads = true // 附带线程信息 + ..sendDefaultPii = true + ..reportPackages = false // 禁用报告包信息 + ..tracesSampleRate = 0.1 // 要发送的事件百分比 + ..attachScreenshot = false // 屏幕截图 + ..attachViewHierarchy = true // 包含视图结构 + ..reportSilentFlutterErrors = true // 报告静默的 Flutter 错误 + ..enableAutoPerformanceTracing = true // 自动性能跟踪 + ..considerInAppFramesByDefault = false // 不考虑应用内帧 + ..enableWindowMetricBreadcrumbs = true // 启用窗口度量面包屑 + ..screenshotQuality = SentryScreenshotQuality.low // 屏幕截图质量 + ..maxRequestBodySize = MaxRequestBodySize.small // 请求体大小 + ..maxResponseBodySize = MaxResponseBodySize.small, // 响应体大小 + appRunner: appRunner, + ); + } +} diff --git a/linux/flutter/generated_plugin_registrant.cc b/linux/flutter/generated_plugin_registrant.cc index c3b56ecd..fcbba27d 100644 --- a/linux/flutter/generated_plugin_registrant.cc +++ b/linux/flutter/generated_plugin_registrant.cc @@ -10,6 +10,7 @@ #include #include #include +#include #include void fl_register_plugins(FlPluginRegistry* registry) { @@ -25,6 +26,9 @@ void fl_register_plugins(FlPluginRegistry* registry) { g_autoptr(FlPluginRegistrar) media_kit_video_registrar = fl_plugin_registry_get_registrar_for_plugin(registry, "MediaKitVideoPlugin"); media_kit_video_plugin_register_with_registrar(media_kit_video_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); diff --git a/linux/flutter/generated_plugins.cmake b/linux/flutter/generated_plugins.cmake index 70cdeb4b..78ea0834 100644 --- a/linux/flutter/generated_plugins.cmake +++ b/linux/flutter/generated_plugins.cmake @@ -7,6 +7,7 @@ list(APPEND FLUTTER_PLUGIN_LIST flutter_volume_controller media_kit_libs_linux media_kit_video + sentry_flutter url_launcher_linux ) diff --git a/macos/Flutter/GeneratedPluginRegistrant.swift b/macos/Flutter/GeneratedPluginRegistrant.swift index 3e5f82f7..247f1060 100644 --- a/macos/Flutter/GeneratedPluginRegistrant.swift +++ b/macos/Flutter/GeneratedPluginRegistrant.swift @@ -16,6 +16,7 @@ import media_kit_video import package_info_plus import path_provider_foundation import screen_brightness_macos +import sentry_flutter import share_plus import sqflite import url_launcher_macos @@ -33,6 +34,7 @@ func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) { FPPPackageInfoPlusPlugin.register(with: registry.registrar(forPlugin: "FPPPackageInfoPlusPlugin")) PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin")) ScreenBrightnessMacosPlugin.register(with: registry.registrar(forPlugin: "ScreenBrightnessMacosPlugin")) + SentryFlutterPlugin.register(with: registry.registrar(forPlugin: "SentryFlutterPlugin")) SharePlusMacosPlugin.register(with: registry.registrar(forPlugin: "SharePlusMacosPlugin")) SqflitePlugin.register(with: registry.registrar(forPlugin: "SqflitePlugin")) UrlLauncherPlugin.register(with: registry.registrar(forPlugin: "UrlLauncherPlugin")) diff --git a/pubspec.lock b/pubspec.lock index 8972ef45..40166bdb 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -1267,10 +1267,18 @@ packages: dependency: transitive description: name: sentry - sha256: "5686ed515bb620dc52b4ae99a6586fe720d443591183cf1f620ec5d1f0eec100" + sha256: a7946f4a90b0feb47214981d881b98149e05f6c576da9f2a2f33945bf561de25 url: "https://pub.flutter-io.cn" source: hosted - version: "7.15.0" + version: "7.16.0" + sentry_flutter: + dependency: "direct main" + description: + name: sentry_flutter + sha256: "6db7fa1b076faf2f5dd77d8cc9ef206171f32a290cc638842d78e5d62b441a27" + url: "https://pub.flutter-io.cn" + source: hosted + version: "7.16.0" share_plus: dependency: "direct main" description: diff --git a/pubspec.yaml b/pubspec.yaml index 5c25f044..994bde76 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -142,6 +142,7 @@ dependencies: path: 1.8.3 # 电池优化 disable_battery_optimization: ^1.1.1 + sentry_flutter: ^7.16.0 dev_dependencies: flutter_test: diff --git a/windows/flutter/generated_plugin_registrant.cc b/windows/flutter/generated_plugin_registrant.cc index d2cff3b2..bd413bf4 100644 --- a/windows/flutter/generated_plugin_registrant.cc +++ b/windows/flutter/generated_plugin_registrant.cc @@ -13,6 +13,7 @@ #include #include #include +#include #include #include @@ -31,6 +32,8 @@ void RegisterPlugins(flutter::PluginRegistry* registry) { registry->GetRegistrarForPlugin("PermissionHandlerWindowsPlugin")); ScreenBrightnessWindowsPluginRegisterWithRegistrar( registry->GetRegistrarForPlugin("ScreenBrightnessWindowsPlugin")); + SentryFlutterPluginRegisterWithRegistrar( + registry->GetRegistrarForPlugin("SentryFlutterPlugin")); SharePlusWindowsPluginCApiRegisterWithRegistrar( registry->GetRegistrarForPlugin("SharePlusWindowsPluginCApi")); UrlLauncherWindowsRegisterWithRegistrar( diff --git a/windows/flutter/generated_plugins.cmake b/windows/flutter/generated_plugins.cmake index 5d25e134..e2a4d437 100644 --- a/windows/flutter/generated_plugins.cmake +++ b/windows/flutter/generated_plugins.cmake @@ -10,6 +10,7 @@ list(APPEND FLUTTER_PLUGIN_LIST media_kit_video permission_handler_windows screen_brightness_windows + sentry_flutter share_plus url_launcher_windows )