Skip to main content
Sentry provides real-time error tracking and performance monitoring for both the frontend and backend of PC Fix. It helps identify, debug, and resolve issues quickly.

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

1

Create a Sentry Account

Sign up for a free account at sentry.io. The free tier includes 5,000 errors per month.
2

Create Two Projects

Create two projects in your Sentry organization:
  • Backend Project: Node.js/Express
  • Frontend Project: Astro
Copy the DSN (Data Source Name) from each project.
3

Set Environment Variables

Add the DSNs to your environment files:Backend (packages/api/.env):
Frontend (packages/web/.env):
The frontend DSN is prefixed with PUBLIC_ because it’s exposed to the browser. Use separate DSNs for frontend and backend to organize errors properly.

Backend Setup (Node.js/Express)

Sentry is initialized at the very beginning of packages/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 in packages/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

string
Backend Sentry DSN (kept secret on the server)
string
Frontend Sentry DSN (exposed to the browser)
string
default:"development"
Environment name (development, staging, production)
number
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

Create separate Sentry projects for frontend and backend to keep errors organized and easier to filter.
Always include relevant context like user ID, order ID, or page name to make debugging easier.
Configure alerts for critical errors so you can respond quickly to production issues.
Use a lower tracesSampleRate (e.g., 0.1 = 10%) in high-traffic production environments to reduce costs.
Don’t send errors to Sentry during local development. Only initialize when SENTRY_DSN is set.

Troubleshooting

  • Verify your DSN is correct
  • Check that SENTRY_DSN (backend) or PUBLIC_SENTRY_DSN (frontend) is set
  • Ensure Sentry.init() is called before any other code
  • Check your network/firewall isn’t blocking sentry.io
  • Use beforeSend to filter out noisy errors
  • Increase the issue alert threshold in Sentry settings
  • Fix the underlying bugs causing repeated errors
Enable source map upload in production:

Security Considerations

  • Never log sensitive information (passwords, credit cards, tokens)
  • Use beforeSend to scrub PII (personally identifiable information)
  • Keep backend DSN secret (use SENTRY_DSN without PUBLIC_ prefix)
  • Frontend DSN can be public (it’s exposed in browser code)