This project uses Sentry for production error tracking and monitoring with request ID correlation between mobile and backend.
You need to complete the manual Sentry project setup before the monitoring will be active.
- Go to sentry.io and create an account (or log in)
- Create two projects:
- Project 1:
commitx-mobile- Platform: React Native
- Copy the DSN URL
- Project 2:
commitx-backend- Platform: Node.js
- Copy the DSN URL
- Project 1:
Add to Railway environment variables:
NODE_ENV=production
SENTRY_DSN=https://your-backend-dsn@sentry.io/your-project-idFor local testing, create backend/.env:
NODE_ENV=production
SENTRY_DSN=https://your-backend-dsn@sentry.io/your-project-id
DATABASE_URL=postgresql://...Update frontend/.env:
EXPO_PUBLIC_API_URL=https://backend-production-xxxx.up.railway.app
EXPO_PUBLIC_SENTRY_DSN=https://your-mobile-dsn@sentry.io/your-project-id
EXPO_PUBLIC_E2E_MODE=false
EXPO_PUBLIC_DEV_MODE=trueUpdate frontend/sentry.properties:
defaults.url=https://sentry.io/
defaults.org=your-sentry-org-slug
defaults.project=commitx-mobile
auth.token=your-sentry-auth-tokenTo get an auth token:
- Go to Sentry → Settings → Auth Tokens
- Create new token with
project:releasesandproject:writescopes - Copy token to
sentry.properties
Update frontend/eas.json production build env vars:
"production": {
"env": {
"SENTRY_ORG": "your-sentry-org-slug",
"SENTRY_PROJECT": "commitx-mobile"
}
}- Start backend:
pnpm dev:backend - In dev mode, use the "Test Backend" button in the mobile app
- Or visit:
http://localhost:8080/commitments/test-sentry - Check Sentry dashboard → Backend project for the error
Expected in Sentry:
- Error message: "This is a test error for Sentry monitoring"
- Tags:
requestId,path,method - Request context
- In dev mode, tap "Test Mobile" button
- Check Sentry dashboard → Mobile project for the error
Expected in Sentry:
- Error message: "Test mobile Sentry error"
- Screen name in breadcrumbs
- Recent API calls in breadcrumbs
- In mobile app, trigger an API call that causes a backend error
- Find error in Sentry Mobile → check breadcrumbs for
requestId - Copy the
requestId - Search in Sentry Backend for same
requestIdtag - Copy
requestId→ search in Railway logs:requestId:"abc-123"
You should see:
- Mobile error with API breadcrumb containing requestId
- Backend error with same requestId tag
- Railway logs showing full request context
- Set environment variables in Railway dashboard
- Deploy (automatic from git push)
- Sentry will only initialize if
NODE_ENV=productionandSENTRY_DSNis set
- Ensure
sentry.propertieshas auth token - Build production version:
cd frontend eas build --platform android --profile production - Source maps will be automatically uploaded to Sentry
- Sentry will only initialize in production builds (not Expo Go)
After confirming Sentry works:
-
Backend: Remove test endpoint from
backend/src/commitments/commitments.controller.ts// DELETE THIS: @Get('test-sentry') testSentry() { ... }
-
Frontend: Remove test buttons and method from:
frontend/screens/CommitmentsListScreen.tsx(remove test buttons)frontend/utils/api.ts(removetestSentry()method)
1. Mobile makes API call
2. Backend middleware generates UUID (requestId)
3. Backend logs with requestId (pino JSON logs)
4. Backend returns X-Request-Id header
5. Mobile extracts requestId → adds to breadcrumb
6. On error:
- Backend: Sentry event tagged with requestId
- Mobile: Breadcrumb shows requestId from API call
- Railway: JSON logs searchable by requestId
- Backend: Only active when
NODE_ENV=productionANDSENTRY_DSNis set - Mobile: Only active when
!__DEV__ANDEXPO_PUBLIC_SENTRY_DSNis set - Dev errors: Stay in console (faster iteration, no noise in Sentry)
When a user reports a crash:
- Open Sentry → find error
- Check tags for
requestId - Copy
requestId - Search Railway logs:
requestId:"abc-123" - See full 30-second context around the error
✅ Backend: Uncaught exceptions captured ✅ Backend: HTTP errors (5xx) captured ✅ Backend: Structured JSON logging with pino ✅ Backend: Request ID in every log entry ✅ Mobile: Crashes captured ✅ Mobile: Screen navigation tracked ✅ Mobile: API calls logged as breadcrumbs ✅ Mobile: Request ID correlation ✅ Mobile: Source maps for readable stack traces ✅ Request correlation between mobile ↔ backend
If you have high traffic, reduce sample rates to save quota:
Backend (backend/src/main.ts):
tracesSampleRate: 0.1, // 10% of requests
profilesSampleRate: 0.1,Mobile (frontend/App.tsx):
tracesSampleRate: 0.1, // 10% of sessionsThe mobile app already sets user ID. To add more context:
Sentry.setUser({
id: user.id,
email: user.email, // if you have it
username: user.name,
});// Backend
Sentry.setTag('feature', 'collaborative-challenge');
Sentry.setContext('challenge', { id, participants });
// Mobile
Sentry.setTag('screen', 'CommitmentsList');
Sentry.setContext('commitment', { id, type });- Check environment variables are set correctly
- Verify
NODE_ENV=production(backend) or not__DEV__(mobile) - Check Sentry dashboard → Settings → Projects for correct DSN
- Look for "Sentry initialized" log on backend startup
- Verify
sentry.propertieshas valid auth token - Check EAS build logs for "Uploading source maps" message
- Ensure
eas.jsonhas SENTRY_ORG and SENTRY_PROJECT env vars
- Check Railway logs for
X-Request-Idheader in response - Verify mobile breadcrumbs show
requestIdfield - Ensure backend middleware is applied globally
- pino outputs JSON by default (Railway auto-formats)
- Use Railway log search:
requestId:"exact-id" - For pretty logs locally: set
NODE_ENV=development
- Sentry docs: https://docs.sentry.io/
- NestJS integration: https://docs.sentry.io/platforms/node/guides/nestjs/
- React Native integration: https://docs.sentry.io/platforms/react-native/