๐ Error Tracking with Sentry
Shipnative integrates Sentry for real-time error tracking and performance monitoring. This guide will help you set up Sentry to proactively identify, diagnose, and resolve issues in your application.Sentry Project Setup
1. Create Your Sentry Project
If you havenโt already, create a new project on the Sentry platform:- Go to https://sentry.io/ and sign up.
- Create a new project, selecting โReact Nativeโ or โReactโ as your platform.
2. Obtain Your DSN
Once your project is ready, youโll need your Data Source Name (DSN):- In your Sentry project dashboard, navigate to Project Settings > Client Keys (DSN).
- Copy your DSN.
3. Configure Environment Variables
During theyarn setup process, you were prompted to enter this credential. If you skipped this or need to update it, you can manually add it to your apps/app/.env file:
Using Sentry in Your App
Shipnative provides a convenientuseAnalytics hook (which includes error tracking functionality) and utility functions for interacting with Sentry.
Using the useAnalytics Hook (Recommended)
The useAnalytics hook (found in apps/app/app/hooks/useAnalytics.ts) includes a trackError function.
Using Utility Functions
For direct error tracking or logging outside of React components, you can use the utility functions:Direct Sentry Client Access
For advanced usage, you can directly access the Sentry client instance:Key Sentry Features
Exception Tracking
Automatically or manually capture unhandled exceptions and errors.For more details on capturing errors, refer to the Sentry documentation on capturing errors.
Message Logging
Log informational messages, warnings, or custom events to Sentry.Breadcrumbs
Record a trail of events leading up to an error, providing valuable context.Learn more about breadcrumbs in the Sentry Breadcrumbs documentation.
User Context
Associate errors with specific users to understand who is affected.For more on user context, see the Sentry User Context documentation.
Tags and Extra Context
Add custom tags and arbitrary data to error reports for better filtering and debugging.Refer to the Sentry Tags and Extra Data documentation for more information.
Performance Monitoring
Sentry can also help monitor your applicationโs performance.For comprehensive details on performance monitoring, visit the Sentry Performance Monitoring documentation.
Testing Your Integration
Mock Mode Testing
- Ensure your
EXPO_PUBLIC_SENTRY_DSNis not set in yourapps/app/.envfile. - Run your app (
yarn iosoryarn android). - Trigger a test error (e.g.,
throw new Error("Test error from mock mode");). - Check your console logs for messages like
๐ [MockSentry] Exception: Error message, indicating that mock errors are being captured.
Testing with Real Services
- Add your
EXPO_PUBLIC_SENTRY_DSNtoapps/app/.env. - Run your app.
- Trigger a test error:
- Log in to your Sentry dashboard and navigate to Issues to see the captured error. You should also see any associated breadcrumbs, user context, and tags.
Troubleshooting
Errors not showing in Sentry
Problem: Errors are captured in your app but not appearing in the Sentry dashboard. Solution:- Double-check that your
EXPO_PUBLIC_SENTRY_DSNis correct inapps/app/.env. - Verify your device has network connectivity.
- Ensure your Sentry project is active and correctly configured.
- Check if the error is being filtered by any
beforeSendcallbacks in your Sentry configuration. - Review your Sentry projectโs quota usage.
- Check your browserโs developer console or device logs for any errors related to Sentry.
Mock mode in production
Problem: Your app is using mock Sentry services in production. Solution:- Verify that your
apps/app/.envfile exists and is correctly configured withEXPO_PUBLIC_SENTRY_DSN. - Ensure your environment variables are prefixed with
EXPO_PUBLIC_. - Restart your Metro bundler with
yarn app:start --clearto ensure environment variables are reloaded. - Review your build configuration to ensure
.envvariables are correctly bundled.