12
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Sentryでバグレポートを受け取る【React Native Expo】

Posted at

Sentryとは

アプリケーションからイベントログを送信してくれるもの。
https://sentry.io/

Expoに対応している(bugsnagはExpo未対応)

導入方法

登録してプロジェクト作成

  • Sentryに登録する

  • 言語やフレームワークを選択、project nameを記入してCreate Projectする

  • 下の方にあるPublic DSNをコピーしておく(Sentry.config('https://**********@sentry.io/***').install();みたいな所のアドレス部分)

  • Sentry APIでauth tokenを作成(設定はデフォルトでOK)、auth tokenをコピーしておく

  • ダッシュボードに行き、プロジェクトのsettingsタブからNameをコピーしておく

  • 左上のボタンからOrganization settingsに行き、Nameをコピーしておく

Sentryをインストール、設定する

  • async/awaitを利用するため、Node 7.6+であることを確認
  • npm i sentry-expo --save
  • App.jsに以下を追加
App.js
import Sentry from 'sentry-expo';

// Remove this once Sentry is correctly setup.
Sentry.enableInExpoDevelopment = true;

Sentry.config('your Public DSN goes here').install();
  • app.jsonpostPublish hookを追加、先ほどコピーした項目を記入してください
app.json
{
  "expo": {
    // ... your existing configuration

    "hooks": {
      "postPublish": [
        {
          "file": "sentry-expo/upload-sourcemaps",
          "config": {
            "organization": "your organization's short name here",
            "project": "your project name here",
            "authToken": "your auth token here"
          }
        }
      ]
    }
  }

動作確認

強制的にエラーを発生させてみます(Button追加)
https://docs.sentry.io/clients/javascript/usage/

App.js
import React from 'react';
import { StyleSheet, Text, View, Button } from 'react-native';
import Sentry from 'sentry-expo';

// Remove this once Sentry is correctly setup.
Sentry.enableInExpoDevelopment = true;

Sentry.config('https://********@sentry.io/****').install();

export default class App extends React.Component {
  render() {
    return (
      <View style={styles.container}>
        <Text>Open up App.js to start working on your app!</Text>
        <Text>Changes you make will automatically reload.</Text>
        <Text>Shake your phone to open the developer menu.</Text>
        <Button onPress={() => {throw new Error('sample error from expo')}} title="broken"/>
      </View>
    );
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    backgroundColor: '#fff',
    alignItems: 'center',
    justifyContent: 'center',
  },
});

Sentryのダッシュボードでエラーを確認できました
5416238b-cbe2-45ed-8fcf-9917460ca8fe.png

12
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
12
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?