feat: sentry 异常捕获
This commit is contained in:
@ -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(),
|
||||
],
|
||||
);
|
||||
}),
|
||||
|
||||
26
lib/services/sentry.dart
Normal file
26
lib/services/sentry.dart
Normal file
@ -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,
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user