我正在寻找如何捕获自定义键值的示例,例如 Device-Model
、Android Version
和 class & method 等到 sentry.io。但目前还没有找到。
例如下面的代码:
Future doWatchVideo(BuildContext context) async {
RewardedVideoAd.instance.show().catchError((error, stackTrace) {
sentry.capture(
event: null,
stackFrameFilter: null,
)
sentry.captureException(
exception: error,
stackTrace: stackTrace,
);
});
}
报告了错误和 StackTrace,但我不知道如何发送用户的设备信息,也不知道这个错误是在什么类和方法中引发的。
有什么想法吗?
谢谢
最佳答案
您需要在事件类中使用extra
参数
final Event event = Event(
loggerName: '',
exception: error,
stackTrace: stackTrace,
release: '${info.version}_${info.buildNumber}',
environment: 'qa',
tags: tags,
extra: extra,
);
当然,您必须使用 device_info
插件来获取有关设备的信息:
final PackageInfo info = await PackageInfo.fromPlatform();
Map<String, dynamic> extra = {};
if (defaultTargetPlatform == TargetPlatform.android) {
extra['device_info'] = await DeviceInfoPlugin.channel.invokeMethod('getAndroidDeviceInfo');
}
else if (defaultTargetPlatform == TargetPlatform.iOS) {
extra['device_info'] = await DeviceInfoPlugin.channel.invokeMethod('getIosDeviceInfo');
}
有关更多信息,请考虑阅读此 full example作者:西蒙·莱特富特
关于flutter - 如何通过 Sentry 发送设备信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57321992/