ADR-0046: Sentry for Error Tracking
Status
Accepted - 2025-01-26
Context
Application errors need detailed tracking, stack traces, breadcrumbs, and alerts separate from logs.
Decision
Sentry for error tracking and performance monitoring.
Rationale
- Rich Context: Stack traces, breadcrumbs, user context
- Source Maps: Unminified production stack traces
- Performance: Transaction and span tracking
- Generous Free Tier: 5k errors/month
- Integrations: Slack, Linear, PagerDuty
Implementation
Setup
pnpm add @sentry/node @sentry/profiling-node
// src/telemetry/sentry.ts
import * as Sentry from '@sentry/node';
import { ProfilingIntegration } from '@sentry/profiling-node';
Sentry.init({
  dsn: process.env.SENTRY_DSN,
  environment: process.env.NODE_ENV,
  release: process.env.APP_VERSION,
  // Sampling
  tracesSampleRate: process.env.NODE_ENV === 'production' ? 0.1 : 1.0,
  profilesSampleRate: 0.1,
  // Integrations
  integrations: [
    new ProfilingIntegration(),
  ],
  // Ignore expected errors
  ignoreErrors: [
    'AbortError',
    'CanceledError',
  ],
});
Capture Errors
try {
  await createBooking(data);
} catch (error) {
  Sentry.captureException(error, {
    tags: {
      org_id: req.user.orgId,
      endpoint: '/api/v1/bookings',
    },
    extra: {
      booking_data: data,
    },
  });
  throw error;
}
Breadcrumbs
Sentry.addBreadcrumb({
  category: 'booking',
  message: 'Validation passed',
  level: 'info',
});
Sentry.addBreadcrumb({
  category: 'database',
  message: 'Inserted booking',
  level: 'info',
  data: { bookingId: booking.id },
});
Alerts
Slack notification on:
- New error (first occurrence)
- Error spike (>10 in 1 min)
- Regression (error reoccurs after resolution)
Free Tier
- 5,000 errors/month - Sufficient for MVP.0-MVP.1
- 1 user
- 90-day retention
- Upgrade at MVP.2: $26/month for 50k errors