import * as Sentry from '@sentry/react-native'Sentry.addBreadcrumb({ category: 'navigation', message: 'User navigated to Profile', level: 'info', data: { from: 'Home', to: 'Profile', },})
User Context
Associate errors with users:
import * as Sentry from '@sentry/react-native'// Set user (on login)Sentry.setUser({ id: user.id, email: user.email, username: user.name,})// Clear user (on logout)Sentry.setUser(null)
Performance Monitoring
Track custom operations:
import * as Sentry from '@sentry/react-native'// Track async operationawait Sentry.startSpan( { name: 'fetch-user-data', op: 'http.client', }, async (span) => { const response = await fetch('https://api.example.com/users') const data = await response.json() span?.setAttribute('http.status_code', response.status) span?.setAttribute('user.count', data.length) return data })
import * as Sentry from '@sentry/react-native'// Capture test errorSentry.captureMessage('Test error from app', { level: 'error', tags: { test: true },})// Or throw errorthrow new Error('Test native crash')
View errors in Sentry Dashboard → Issues.
Filtering Errors
Configure what gets reported in services/sentry.ts:
Sentry.init({ beforeSend: (event, hint) => { // Filter out specific errors if (event.exception?.values?.[0]?.value?.includes('Network request failed')) { return null // Don't send } // Remove sensitive data if (event.user) { delete event.user.email } return event },})
Production Best Practices
Environment tagging - Automatically set via EXPO_PUBLIC_ENV
Release tracking - Set release version for tracking issues across versions
Source maps - Uploaded automatically for readable stack traces
User privacy - Avoid sending PII (personally identifiable information)