React Native崩溃报告有什么好的设置? [英] What's a good setup for React Native crash reporting?

查看:157
本文介绍了React Native崩溃报告有什么好的设置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看到getSentry现在具有针对React Native的崩溃报告:

I'm seeing that getSentry has crash reporting for React Native now:

https://docs.getsentry.com/hosted/clients/javascript/integrations/react-native/

我喜欢它们,因为它们在将异常与源映射相关联方面做得很好.但我也想捕捉本机崩溃.您基本上必须同时设置getSentry和Crashlytics吗?

I like them because they do a good job correlating exceptions with your source maps. But I also want to catch native crashes. Do you basically have to setup both getSentry and Crashlytics?

以下是讨论各种选项的主题:

Here's a thread discussing various options:

https://github.com/facebook/react-native/issues/5378

这是一个看似不错,但有点app回的hokeyapp解决方案: http://blog.nparashuram.com/2015/10/crash-analytics-and-feedback-for.html

And here's a seemingly good, but somewhat roundabout hokeyapp solution: http://blog.nparashuram.com/2015/10/crash-analytics-and-feedback-for.html

我想知道人们在生产中成功使用了哪些方法来通过详细的源地图感知报告来捕获本机和javascript崩溃?

I'm wondering what people are successfully using in production to catch both native and javascript crashes with detailed source-map-aware reports??

推荐答案

我是 react-native-bugsnag .

我不隶属于该公司,但是我喜欢他们的仪表板和价格模型,因此我为响应本机的程序员创建了这个库,以便他们可以使用他们的服务.

I'm not affiliated with the company but I like their dashboard, and their pricing models so I created this library for us react-native programmers to have a way to use their service.

[TL/DR]:

1)复制下面的脚本,将其添加到您的项目根目录中,

1) Copy the script below, add it to your project root,

2)更改脚本开头的版本,使其与您的react-native项目的本机部分的版本相匹配.

2) Change the version on the beginning of the script to match the version of your native part of your react-native project.

3)运行它:

sh crash_report.sh -i <BUGSNAG_KEY>捆绑并上传ios的源地图,

sh crash_report.sh -i <BUGSNAG_KEY> to bundle and upload your source-maps for ios,

OR

sh crash_report.sh -a <BUGSNAG_KEY>捆绑并上传您的android源地图.

sh crash_report.sh -a <BUGSNAG_KEY> to bundle and upload your source-maps for android.

[更长的版本]:

官方的本机bugsnag sdk 已发布.

它支持 iOS/Android和Java 处理和未处理的崩溃报告.

It supports both iOS/Android and Javascript handled and unhanded crash reporting.

让我解释一下我怎么做:

Let me explain how I do it:

我创建了一个名为crash_report.sh的文件,该文件创建了我的项目源地图,并将它们以及所有我的项目文件上传到bugsnag,这样我就可以看到如下所示的丰富错误报告:

I've created a file called crash_report.sh that creates my project sourcemaps, and uploads them to bugsnag, as well as ALL of my project files, so that I can see rich error reports like below:

要使用此功能,只需将其添加到项目的根文件夹中,将版本变量(appVersion)更改为您的xcode项目或android studio项目具有的基本版本. (这非常重要),否则您将无法在bugnsag中看到经过混淆处理的代码,然后再运行它.

To use this, all you have to do is add it to your project root folder, change the version variable (appVersion) to basically whatever version your xcode project has, or your android studio project has. (THIS IS VERY IMPORTANT) otherwise you won't be able to see de-obfuscated code in bugnsag and then run it.

crash_report.sh :

#!/bin/bash

appVersion='1.0.0'  # IMPORTANT, this has to be the same as the version of your native project in xcode or android studio.

# Get shell args
aflag=''
iflag=''
platform=''
bugsnagKey=''
while getopts 'i:a:' flag; do
  case "${flag}" in
    a) 
    aflag='true'
    bugsnagKey=$OPTARG
    ;;
    i) iflag='true' 
    bugsnagKey=$OPTARG
    ;;
    *) printf "Usage: %s: [-a] [-i] args\n" $0
  esac
done

if [ -n "$aflag" ] && [ -z "$iflag" ]; then
    printf "Now bundling for android.\n"
    platform='android'
fi
if [ -n "$iflag" ] && [ -z "$aflag" ]; then
    printf "Now bundling for ios.\n"
    platform='ios'
fi

if [ -z "$platform" ]; then
    printf "\nUsage: <script> -i <BUGSNAG_KEY> OR -a <BUGSNAG_KEY>. \nTerminating...\n\n"
else
    printf "Now fetching project properties from package.json\n"

    echo 'Now creating sourcemaps\n App version: '${appVersion}' for platform: '${platform}

    # #Create iOS sourcemaps
    react-native bundle --dev false --platform ${platform} --entry-file index.${platform}.js --bundle-output main.${platform}.jsbundle --sourcemap-output main.${platform}.jsbundle.map

    echo 'Now uploading with key: '${bugsnagKey}' for version '${appVersion}

    CUR_DIRR=`pwd`  # Get current directory
    CUR_DIRR=${CUR_DIRR}'/' # Append a forward slash to it

    # Here we get ALL the project files, and form them as curl params, so that we can later on pass them to curl
    PROJECT_FILES=$(find src -name '*.js'  | while read -r i; do echo '-F '$CUR_DIRR$i'=@'$i; done) # Form the right file ending for curl
    # echo ${PROJECT_FILES}

    # #Upload iOS sourcemaps
    curl -w "\n\n%{http_code}\n" --progress-bar -F apiKey=${bugsnagKey} -F appVersion=${appVersion} -F minifiedUrl="main.jsbundle" -F sourceMap=@main.${platform}.jsbundle.map -F minifiedFile=@main.${platform}.jsbundle -F overwrite=true ${PROJECT_FILES} https://upload.bugsnag.com

    echo '\nDone.\n'

fi

我希望这对某人有帮助,这花了我几个小时才能弄清楚. 玩得开心..

I hope this helps someone, this took me hours to figure. Have fun..!

这篇关于React Native崩溃报告有什么好的设置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆