7

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

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

我喜欢它们,因为它们很好地将异常与您的源映射关联起来。但我也想捕捉原生崩溃。您基本上必须同时设置 getSentry 和 Crashlytics 吗?

这是一个讨论各种选项的线程:

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

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

我想知道人们在生产中成功使用什么来通过详细的源映射感知报告来捕获本机和 javascript 崩溃?

4

2 回答 2

6

我是react-native-bugsnag的作者。

我不隶属于该公司,但我喜欢他们的仪表板和定价模型,因此我为我们的 react-native 程序员创建了这个库,以便使用他们的服务。

[TL/DR]:

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

2) 更改脚本开头的版本以匹配您的 react-native 项目的本机部分的版本。

3)运行它:

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

或者

sh crash_report.sh -a <BUGSNAG_KEY>捆绑和上传你的安卓源地图。

[更长的版本]:

官方的react-native bugsnag sdk现已发布。

它支持iOS/Android 和 Javascript处理和非处理崩溃报告。

让我解释一下我是如何做到的:

我创建了一个名为的文件,该文件crash_report.sh创建了我的项目源映射,并将它们上传到 bugsnag,以及我的所有项目文件,这样我就可以看到如下丰富的错误报告: 在此处输入图像描述

要使用它,您只需将它添加到您的项目根文件夹,将版本变量appVersion((这非常重要)否则您将无法在 bugnsag 中看到去混淆的代码然后运行它。

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

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

于 2016-07-04T18:24:35.213 回答
2

Sentry 的原生 iOS 客户端支持符号化(类似于 Crashlytics),因此您可以为 javascript 和 objc 层添加 Sentry。

于 2016-04-29T22:32:32.523 回答