as

Settings
Sign out
Notifications
Alexa
Amazonアプリストア
AWS
ドキュメント
Support
Contact Us
My Cases
開発
設計と開発
公開
リファレンス
サポート

Sentry

Sentry

Sentryはエラー追跡およびパフォーマンス監視プラットフォームで、アプリの問題解決と継続的な学習に役立ちます。@amazon-devices/sentry__react-nativeライブラリは、VegaプラットフォームにSentry用のReact Native SDKを実装します。

この段階では、Sentry機能の一部はVega用に設定されていません。Vega開発者フォーラムで質問を投稿したり、問題を報告したりできます。

インストール

  1. package.jsonファイルにJavaScriptライブラリの依存関係を追加します。

     dependencies: {
         "@sentry/react-native": "npm:@amazon-devices/sentry__react-native@~1.0.10"
     }
    
  2. npm installコマンドを使用して、依存関係をインストールします。

アプリの最上位でSentryを初期化します。

Sentryを初期化するには、Sentry.init({...})メソッドを使用します。必須のパラメーターはdsnデータソース名の略)のみです。Sentryプロジェクトの設定ページからdsnを見つけることができます。


import * as Sentry from '@sentry/react-native';
import React from 'react';
import {View, Button, Text} from 'react-native';

// コンポーネント外の最上位でSentryを初期化する
Sentry.init({
  // 環境変数SENTRY_DSNをプロジェクトのdsnに設定する
  // または、ここでDSNをインライン化する
  dsn: process.env.SENTRY_DSN,
});

export function App() {
  const captureMessage = () => {
    // メッセージをSentryに直接送信する
    Sentry.captureMessage('SentryAppDemo message');
  };

  const captureException = () => {
    // 例外をキャプチャしてSentryに送信する
    Sentry.captureException(new Error('SentryAppDemo error'));
  };

  return (
    <View
      style={{
        backgroundColor: '#181a1b',
        padding: 32,
        flex: 1,
        flexDirection: 'column',
        gap: 16,
      }}>
      <Text style={{fontSize: 32, color: 'white'}}>Sentry App Demo</Text>
      <View style={{width: '25%'}}>
        <Button onPress={captureMessage} title="Capture Message" />
      </View>
      <View style={{width: '25%'}}>
        <Button onPress={captureException} title="Capture Exception" />
      </View>
    </View>
  );
}

クリップボードにコピーしました。

Sentryを初期化した後、検出されなかったすべての例外が自動的に検出され、Sentryによって報告されます。イベントを手動で送信する必要はありません。

以下に示すように、Sentry.setContext ()またはSentry.setUser ()を使用して、Sentryイベントに情報を追加することもできます。


import * as Sentry from '@sentry/react-native';
import React from 'react';
import {View, Button, Text} from 'react-native';

// コンポーネント外の最上位でSentryを初期化する
Sentry.init({
  // 環境変数SENTRY_DSNをプロジェクトのdsnに設定する
  // または、ここでDSNをインライン化する
  dsn: 'process.env.SENTRY_DSN',
});

export function App() {
  const setContext = () => {
    // Sentryイベントにカスタムデータを追加する
    Sentry.setContext('ExampleContext', {
      category: 'ExampleCategory',
      message: 'ExampleMessage',
      level: 'info',
    });
  };

  const throwError = () => {
    // エラーを検出せずにスローする(Sentryが報告します)
    throw new Error('SentryAppDemo uncaught error');
  };

  return (
    <View
      style=>
      <Text style={{fontSize: 32, color: 'white'}}>Sentry App Demo</Text>
      <View style={{width: '25%'}}>
        <Button onPress={setContext} title="Set Context" />
      </View>
      <View style={{width: '25%'}}>
        <Button onPress={throwError} title="Throw Error" />
      </View>
    </View>
  );
}

クリップボードにコピーしました。

APIリファレンス

  • Sentry.init(options: ReactNativeOptions) - Sentryを初期化します。これを呼び出すと、すべてのエラーがSentryによって報告されます。Sentry.init ()を呼び出す前にアプリケーションがクラッシュしたり、検出されない例外が発生したりした場合、それがSentryで検出されることはありません。
  • Sentry.nativeCrash() - このメソッドはネイティブクラッシュをトリガーします。Vegaデバイスおよびシミュレーター上で動作することがテストにより確認されています。
  • Sentry.setUser(user: User) - ユーザーデータ(例:usernameemail)を設定します。このデータはSentryイベントに含まれます。
  • Sentry.setContext(contextKey: string, contextData: Object) - 渡されたcontextKeyの下に追加されるカスタムデータを設定します。このデータはSentryイベントに含まれます。
  • Sentry.flush() - すべてのSentryイベントが送信されるまで待機します。
  • Sentry.captureMessage(message: string) - メッセージイベントをキャプチャし、Sentryに送信します。
  • Sentry.captureException(exception: Error) - 例外イベントをキャプチャし、Sentryに送信します。

その他の構成

Sentryエラーに読み取り可能なスタックトレースを追加する

アプリをビルドしたら、アプリのリリース名、バージョン、およびdist番号をSentryに通知し、JavaScriptバンドルとデバッグファイルのソースマップを送信する必要があります。これにより、Sentryがイベントを検出し、情報を読み取り可能なスタックトレースに正しくマッピングできます。

アプリをビルドすると、フォルダ構造は以下のようになります。

├── sentrydemoapp
│   ├── build
│   │   ├── lib
│   │   │   ├── rn-bundles
│   │   │   │   ├── Debug #use the path for debug build
│   │   │   │   ├── Release #use the path for release build
│   │   ├── x86_64-release
│   │   │   ├── debug #use the path for app meant for simulator for x86 machines
│   │   ├── armv7-release
│   │   │   ├── debug #use the path for app meant for Fire TV Stick
│   │   ├── aarch64-release
│   │   │   ├── debug #use the path for app meant for simulator for M-series machines
  1. Sentryの初期化時にリリースバージョンとdistバージョンを作成します。$SENTRY_RELEASE_VERSION(例:my-kepler-project@2.3.12)と$SENTRY_DIST_NUMBER(例:52)を定義する必要があります。詳細については、Sentryの公式ドキュメント(英語のみ)を参照してください。
     Sentry.init({
       release: process.env.SENTRY_RELEASE_VERSION,
       dist: process.env.SENTRY_DIST_NUMBER,
     });
    
  2. Sentry Metro Serializerをmetro.config.jsに追加して、アプリを再ビルドします。

     ...
     const {createSentryMetroSerializer} = require('@sentry/react-native/dist/js/tools/sentryMetroSerializer');
     ...
    
     const sentryMetroSerializer = createSentryMetroSerializer()
    
     const config = {
       serializer: {
         customSerializer(entryPoint, preModules, graph, options) {
           return sentryMetroSerializer(entryPoint, preModules, graph, options)
         },
       },
     };
    
     module.exports = mergeConfig(getDefaultConfig(__dirname), config);
    
  3. sentry-cliをインストールします。詳細については、Sentryの公式ドキュメント(英語のみ)を参照してください。
     curl -sL https://sentry.io/get-cli/ | sh
    
  4. 新しいSentryリリースを作成します。以前に定義した$SENTRY_RELEASE_VERSIONを渡す必要があります。詳細については、Sentryの公式ドキュメント(英語のみ)を参照してください。
     sentry-cli releases new $SENTRY_RELEASE_VERSION
    
  5. JavaScriptシンボリケーションのソースマップをアップロードします。sentry-wizardがまだサポートされていないことに注意してください。詳細については、Sentryの公式ドキュメント(英語のみ)を参照してください。
    # Vegaアプリディレクトリ内
     # BUILD_TYPEはDebugまたはReleaseのいずれかです
     # デバッグIDを使用する場合、--releaseフラグと--distフラグはオプションです
     sentry-cli sourcemaps upload "build/lib/rn-bundles/$BUILD_TYPE" --release "$SENTRY_RELEASE_VERSION" --dist "$SENTRY_DIST_NUMBER"
    

Sentryに情報を送信すると、アプリでエラーが発生した場所に関する正確な情報を受け取ることができます。

実装の詳細

  • 現在、sentry-wizardSentry React Native Metro Pluginはサポートされていないことに注意してください。
  • @sentry /wizard - Vegaプロジェクトでは動作しません。
  • withSentryConfig metro tool - Vegaプロジェクトでは動作しません。
  • Tracingは実装されていません。
  • Profilingは実装されていません。

既知の問題

  • SentryオフラインサポートはVegaでは機能しません。

既知の制限事項

API 現在の動作
Sentry.addBreadcrumb() アクションが一切実行されません。
Sentry.init(options: ReactNativeOptions) 特定のオプションはサポートされていません。以下のReactNativeOptionsの表をご覧ください。

Sentry.init() オプションが不足しています。

Sentry.initオプション 現在の動作
options.enableNativeCrashHandling 現時点では無効化できません。
options.sessionTrackingIntervalMillis サポートされません。
options.enableNdk NDKはAndroidでのみ動作します。
options.enableNdkScopeSync NDKはAndroidでのみ動作します。
options.attachThreads Android専用のオプションです。
options.sendDefaultPii Android専用のオプションです。
options.enableAutoPerformanceTracing パフォーマンス監視は動作しません。
options.enableWatchdogTerminationTracking iOS専用のオプションです。
options.enableAppHangTracking iOS専用のオプションです。
options.appHangTimeoutInterval iOS専用のオプションです。
options.attachScreenshot サポートされません。
options.attachViewHierarchy サポートされません。

サポートされているバージョン

パッケージのバージョン ベース @amazon-devices/react-native-keplerバージョン
1.0.0 5.15.2 2.x.x

関連リソース

その他のライブラリについては、サポート対象のサードパーティのライブラリとサービスを参照してください。


Last updated: 2025年9月30日