美文网首页
flutter 错误日志上报sentry

flutter 错误日志上报sentry

作者: liboxiang | 来源:发表于2020-03-18 15:30 被阅读0次

    project

    新建project,语言可以选other

    flutter加入依赖

    https://github.com/flutter/sentry

    DNS

    Settings->Projects->对应的项目->Client Keys(DSN)下有对应的DSN


    WeChatc7ec7f72a32813f662001bfcaa083aa9.png

    代码

    final SentryClient _sentry = new SentryClient(dsn: SENTRY_DNS);
    /// Reports [error] along with its [stackTrace] to Sentry.io.
    Future<Null> _reportError(dynamic error, dynamic stackTrace) async {
      print('Caught error: $error');
    
      // Errors thrown in development mode are unlikely to be interesting. You can
      // check if you are running in dev mode using an assertion and omit sending
      // the report.
      if (Util.isInDebugMode) {
        print(stackTrace);
        print('In dev mode. Not sending report to Sentry.io.');
        return;
      }
    
      print('Reporting to Sentry.io...');
    
      final SentryResponse response = await _sentry.captureException(
        exception: error,
        stackTrace: stackTrace,
      );
    
      if (response.isSuccessful) {
        print('Success! Event ID: ${response.eventId}');
      } else {
        print('Failed to report to Sentry.io: ${response.error}');
      }
    }
    Future<Null> main() async {
      // This captures errors reported by the Flutter framework.
      FlutterError.onError = (FlutterErrorDetails details) async {
        if (Util.isInDebugMode) {
          // In development mode simply print to console.
          FlutterError.dumpErrorToConsole(details);
        } else {
          // In production mode report to the application zone to report to
          // Sentry.
          Zone.current.handleUncaughtError(details, details.stack);
        }
      };
      runZoned<Future<void>>(() async {
        runApp(MyApp());
      }, onError: (error, stackTrace) async {
        await _reportError(error, stackTrace);
      });
    }
    
    

    相关文章

      网友评论

          本文标题:flutter 错误日志上报sentry

          本文链接:https://www.haomeiwen.com/subject/jstcyhtx.html