sentry-react-native-sdk은(는) 무엇을 하나요?
React Native 및 Expo를 위한 전체 Sentry SDK 설정입니다. "React Native에 Sentry 추가", "@sentry/react-native 설치", "Expo에서 Sentry 설정"과 같은 요청이나 React Native 애플리케이션에서 오류 모니터링, 트레이싱, 프로파일링, 세션 리플레이, 로깅을 구성할 때 사용하세요. Expo managed, Expo bare, vanilla React Native를 지원합니다.
설치
npm install @sentry/react-native
# 또는
yarn add @sentry/react-native
초기화
애플리케이션의 진입점(보통 App.tsx 또는 index.js)에서 Sentry를 초기화합니다.
import * as Sentry from '@sentry/react-native';
Sentry.init({
dsn: 'YOUR_DSN_HERE',
// 성능 트레이싱 활성화
tracesSampleRate: 1.0,
// 프로파일링 활성화 (선택 사항)
profilesSampleRate: 1.0,
});
Expo 설정
Expo managed 워크플로우
expo install @sentry/react-native
app.json 또는 app.config.js에 Sentry 플러그인을 추가합니다.
{
"expo": {
"plugins": [
"@sentry/react-native/expo"
]
}
}
Expo bare 워크플로우
vanilla React Native와 동일한 단계를 따르되, Expo 사전 빌드 명령어를 사용합니다.
expo prebuild
환경 변수
SENTRY_DSN 환경 변수를 설정하여 DSN을 보호하세요.
export SENTRY_DSN=https://[email protected]/0
소스 맵 업로드
배포 시 소스 맵을 업로드하려면 sentry-wizard를 사용합니다.
npx @sentry/wizard -i reactNative
사용 예시
오류 보고
Sentry.captureException(new Error('테스트 오류'));
성능 트레이싱
const transaction = Sentry.startTransaction({ name: '테스트 트랜잭션' });
Sentry.getCurrentHub().configureScope(scope => scope.setSpan(transaction));
// ... 작업 수행 ...
transaction.finish();