Setup Sentry - aelassas/bookcars GitHub Wiki
Enabling Sentry Error Monitoring
BookCars supports error monitoring through Sentry (https://sentry.io), which captures runtime exceptions and performance metrics. This is useful for diagnosing backend issues in production or staging environments.
Prerequisites
- Create a free account at https://sentry.io.
- Create a new Node.js project in Sentry for the BookCars backend.
- Copy the provided DSN URL.
Configuration
Sentry integration is optional and controlled by environment variables in the backend.
backend/.env
:
Update your BC_ENABLE_SENTRY=true
BC_SENTRY_DSN_BACKEND=https://[email protected]/your_project_id
BC_SENTRY_TRACES_SAMPLE_RATE=0.1
Do not commit the real DSN to version control.
How It Works
- When
BC_ENABLE_SENTRY=true
andBC_SENTRY_DSN_BACKEND
is defined, the backend initializes Sentry at startup. - Runtime errors (especially in
try/catch
blocks or unhandled routes) are automatically reported to Sentry. - When
BC_SENTRY_TRACES_SAMPLE_RATE
is is greater than 0, transactions will be sent to Sentry. Sentry will capture performance transactions, showing request duration, slow routes, and trace spans. Set to0
to disable tracing. 0.1 means 10% of transactions will be sent to Sentry. 1 means 100% of transactions will be sent to Sentry. We recommend adjusting this value in production. - The integration complements the existing Winston-based logging system.
Testing Sentry Integration
To verify Sentry is working:
- Temporarily set
BC_ENABLE_SENTRY=true
and use a real DSN. - Trigger an error in a controller:
throw new Error('Test Sentry integration')
- Check your Sentry dashboard under Issues.
Notes
- Sentry is only enabled if both:
BC_ENABLE_SENTRY=true
BC_SENTRY_DSN_BACKEND
is set
- You can safely use BookCars without Sentry if you prefer other monitoring solutions.
Related Files
backend/src/monitoring/instrument.ts
- Sentry integration and initializationbackend/src/app.ts
- Sentry Express middleware is attached if enabledbackend/src/config/logger.ts
- Automatically reports errors to Sentry if enabled