【问题标题】:Sentry is NOT reporting error inside FlutterSentry 没有在 Flutter 中报告错误
【发布时间】:2020-05-12 02:40:36
【问题描述】:

我的哨兵设置是这样的:

void main() => runZonedGuarded(() {
  runApp(MyApp());
}, (Object error, StackTrace stackTrace) {
  reportError(error, stackTrace);
});

及相关功能

final SentryClient sentry = new SentryClient(dsn: '<my-dsn>');


Future<void> reportError(dynamic error, dynamic stackTrace) async {
  sentry.captureException(
    exception: error,
    stackTrace: stackTrace,
  );
}

我在小部件的构建方法中添加了throw Exception("my-error"),我看不到 Sentry Web 控制台上显示的错误。

我创建了一个文件来抛出异常和哨兵捕获,我确实看到哨兵正在报告错误。

runZonedGuarded 一定有问题。

【问题讨论】:

  • 我也有同样的问题。你找到解决办法了吗?
  • 对我来说,这是我使用 Sentry 的专用网络中的问题。

标签: flutter sentry


【解决方案1】:

如果您使用的是免费版本并且没有超过每月配额,请查看您的哨兵仪表板。如果是这种情况,您将不会收到任何事件。

【讨论】:

  • 我认为我们的代码库在工作中出现了错误,但事实就是这样。经过一天的调试,这为我解决了!谢谢!
【解决方案2】:
  1. 你必须使函数异步发送错误到哨兵控制台
  2. 确保为移动应用导入此文件:
    import 'package:sentry/io_client.dart';
    例如:

main.dart

import 'package:sentry/io_client.dart';
final SentryClient sentry = new SentryClient(dsn: YOUR_DSN);

main() async {
  try {
    throw new StateError('This is a Dart exception.');
  } catch(error, stackTrace) {
    await sentry.captureException(
      exception: error,
      stackTrace: stackTrace,
    );
  }
}

主屏幕

floatingActionButton: FloatingActionButton(
          onPressed: () async{

            throw new StateError('This is a Dart exception.');

          },

【讨论】:

    【解决方案3】:

    顺便说一句,在发布版本中它会发送每个异常,因为在调试中颤振不会捕获控制台中显示的每个错误,为了简化它,您可以使用以下软件包之一:

    【讨论】:

      【解决方案4】:

      在一些似乎无法正常工作的 Sentry 设置之后,我找到了这个可行的设置:

      Future<void> main() async {
        final sentry = Sentry.SentryClient(Sentry.SentryOptions(dsn: '[Add dsn URI here]'));
      
        runZonedGuarded(() {
          WidgetsFlutterBinding.ensureInitialized();
      
          FlutterError.onError = (FlutterErrorDetails errorDetails) {
            sentry.captureException(
              errorDetails.exception,
              stackTrace: errorDetails.stack,
            );
          };
      
          runApp(MyApp());
        }, (Object error, StackTrace stackTrace) {
          sentry.captureException(
            error,
            stackTrace: stackTrace,
          );
        });
      }
      

      【讨论】:

        猜你喜欢
        • 2020-08-28
        • 2021-05-22
        • 2018-04-30
        • 2021-06-05
        • 2013-01-18
        • 1970-01-01
        • 1970-01-01
        • 2020-06-19
        • 2021-08-04
        相关资源
        最近更新 更多