몽땅뚝딱 개발자

[React Native] Sentry 적용하기 본문

Development/React Native

[React Native] Sentry 적용하기

레오나르도 다빈츠 2024. 8. 11. 22:37

 

 

 

갖가지 핑계로 미루고 미루다가..... 

드뎌 적용,,^^

 

 

 


 

 

 

1. App.tsx를 감싸준다.

import { registerRootComponent } from 'expo'
import 'react-native-gesture-handler'
import * as Sentry from '@sentry/react-native'

import App from './App'

Sentry.init({
  dsn: {settings > DNS 정보에서 가져온 key},
  tracesSampleRate: 0.5,
})

registerRootComponent(Sentry.wrap(App))

 

 

2. 에러가 발생한 부분에 적용한다.

Sentry.captureException의 두번째 파라미터는 hint로 자세한 정보를 보낼 수 있다.

나 같은 경우.. 디바이스 정보 + 사용한 유저의 식별자 id를 보낸다.

import * as Sentry from '@sentry/react-native'
import DeviceInfo from 'react-native-device-info'

// ... 기타 로직

const genError = () => {
  try {
    throw new Error('Sentry Test')
  } catch (e) {
    Sentry.captureException(e, {
      tags: {
        appVersion: DeviceInfo.getVersion(),
        deviceInfo: `${DeviceInfo.getModel()} (${DeviceInfo.getBrand()})`,
        systemVersion: `${DeviceInfo.getSystemName()} ${DeviceInfo.getSystemVersion()}`,
        userId: {유저식별자}
      },
    })
  }
}

 

Comments