Overview
PC Fix uses Sentry to monitor:- Backend Errors: API exceptions, database errors, server crashes
- Frontend Errors: JavaScript errors, React component failures, Astro SSR errors
- Performance: Request tracing, slow queries, response times
Configuration
Create a Sentry Account
Sign up for a free account at sentry.io. The free tier includes 5,000 errors per month.
Create Two Projects
Create two projects in your Sentry organization:
- Backend Project: Node.js/Express
- Frontend Project: Astro
Backend Setup (Node.js/Express)
Sentry is initialized at the very beginning ofpackages/api/src/server.ts:
Sentry is only initialized if
SENTRY_DSN is set, allowing you to disable monitoring in local development.Automatic Error Capture
With Sentry initialized, all uncaught exceptions and unhandled promise rejections are automatically captured:Manual Error Capture
You can manually capture errors with additional context:Adding User Context
Attach user information to errors for better debugging:Frontend Setup (Astro)
Sentry is conditionally integrated inpackages/web/astro.config.mjs:
Client-Side Error Capture
Frontend errors are automatically captured:Manual Frontend Capture
Error Context
Add contextual information to help debug issues:Performance Monitoring
Sentry automatically tracks performance metrics:Backend Performance
Frontend Performance
Environment Configuration
Backend Sentry DSN (kept secret on the server)
Frontend Sentry DSN (exposed to the browser)
Environment name (development, staging, production)
Percentage of transactions to monitor (1.0 = 100%)
Filtering Errors
Exclude known errors or noisy issues:Release Tracking
Track which version of your code is running:Integration with Error Handler
Sentry works seamlessly with your existing error middleware:globalErrorHandler.ts
Dashboard Features
Issues
View and triage errors grouped by root cause
Performance
Monitor transaction speeds and identify bottlenecks
Releases
Track errors by deployment version
Alerts
Get notified of new errors via email, Slack, or webhooks
Best Practices
Use Separate Projects
Use Separate Projects
Create separate Sentry projects for frontend and backend to keep errors organized and easier to filter.
Add Contextual Information
Add Contextual Information
Always include relevant context like user ID, order ID, or page name to make debugging easier.
Set Up Alerts
Set Up Alerts
Configure alerts for critical errors so you can respond quickly to production issues.
Sample in Production
Sample in Production
Use a lower
tracesSampleRate (e.g., 0.1 = 10%) in high-traffic production environments to reduce costs.Disable in Development
Disable in Development
Don’t send errors to Sentry during local development. Only initialize when
SENTRY_DSN is set.Troubleshooting
Errors not appearing in Sentry
Errors not appearing in Sentry
- Verify your DSN is correct
- Check that
SENTRY_DSN(backend) orPUBLIC_SENTRY_DSN(frontend) is set - Ensure Sentry.init() is called before any other code
- Check your network/firewall isn’t blocking sentry.io
Too many errors
Too many errors
- Use
beforeSendto filter out noisy errors - Increase the issue alert threshold in Sentry settings
- Fix the underlying bugs causing repeated errors
Source maps not working
Source maps not working
Enable source map upload in production:
Security Considerations
- Never log sensitive information (passwords, credit cards, tokens)
- Use
beforeSendto scrub PII (personally identifiable information) - Keep backend DSN secret (use
SENTRY_DSNwithoutPUBLIC_prefix) - Frontend DSN can be public (it’s exposed in browser code)