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

  1. Create a free account at https://sentry.io.
  2. Create a new Node.js project in Sentry for the BookCars backend.
  3. Copy the provided DSN URL.

Configuration

Sentry integration is optional and controlled by environment variables in the backend.

Update your backend/.env:

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 and BC_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 to 0 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:

  1. Temporarily set BC_ENABLE_SENTRY=true and use a real DSN.
  2. Trigger an error in a controller:
throw new Error('Test Sentry integration')
  1. 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 initialization
  • backend/src/app.ts - Sentry Express middleware is attached if enabled
  • backend/src/config/logger.ts - Automatically reports errors to Sentry if enabled