React-native Sentry
github:github.com/getsentry/s…
文档:docs.sentry.io/platforms/r…
npm仓库:www.npmjs.com/package/@se…
根据项目选择版本
Sentry支持的react-native版本要>=0.56,因不同项目开发时间不一导致Sentry版本过低,在接入Sentry时会遇到以下错误:
找不到android资源标识符
[No resource identifier found for attribute 'appComponentFactory' in package 'android']
解决办法
1、升级compileSdkVersion至28及以上,
出现这个错误原因是由于AndroidManifest.xml -> application ->中没有增加android:appComponentFactory 这个属性,但是appComponentFactory需要在compileSdkVersion >=28以上才会生效
如果targetSdkVersion>=28时模拟器无法连接debugger 这是因为28的版本对debugger有所更改,需要在 项目名称/android/app/src/main/res/目录下新建xml/network_security_config.xml 文件,添加以下内容
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<debug-overrides>
<trust-anchors>
<certificates src="system" />
<certificates src="user" />
</trust-anchors>
</debug-overrides>
<base-config cleartextTrafficPermitted="true" />
</network-security-config>
无法调用startWithOptions方法
Could not invoke RNSentry.startWithOptions
解决方法 打开node_modules/@sentry/react-native/android/build.gradle,查看相关信息
检查项目是否为java1.8的环境,如果不是可以在android/app/build.gradle文件 android中添加
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
Sentry数据发送失败
不能在Sentry可视化中收到消息,检查link无误后在vscode终端中输入adb logcat命令调试,推荐安装java扩展方便调试相关信息
adb logcat
或者可以在android中调试logcat (输出内容级别可以百度或者谷歌)
测试功能
在Sentry react-natibe 2.6.0版本中,会出现单次点击数据无法发送,连续点击的部分数据丢失的情况。 检查后有2个原因
1、java对传入的时间戳无法转换
在node_modules/@sentry/react-native/dist/js/wrapper.js sendEvent方法中对时间戳进行处理。
2、数据量过大 在初始化中maxBreadcrumbs应该捕获的面包屑数值
Sentry.init({
dsn: "https://examplePublicKey@o0.ingest.sentry.io/0",
maxBreadcrumbs:10
});
然后可以使用Sentry.captureMessage()测试消息是否正常发送,事务会有15秒左右的延时,错误和消息会及时反馈到列表中