diff --git a/lib/services/create-services.server.ts b/lib/services/create-services.server.ts index a45457e5..09ae5e48 100644 --- a/lib/services/create-services.server.ts +++ b/lib/services/create-services.server.ts @@ -65,7 +65,15 @@ export function getServerAppServices(): AppServices { } const errors = config.errors.glitchtip.enabled - ? new GlitchtipErrorReportingService({ enabled: true }, logger, notifications) + ? new GlitchtipErrorReportingService( + { + enabled: true, + dsn: config.errors.glitchtip.dsn, + tracesSampleRate: 1.0, // Server-side we usually want higher visibility + }, + logger, + notifications, + ) : new NoopErrorReportingService(); if (config.errors.glitchtip.enabled) { diff --git a/lib/services/create-services.ts b/lib/services/create-services.ts index 57c1bcee..53412527 100644 --- a/lib/services/create-services.ts +++ b/lib/services/create-services.ts @@ -69,7 +69,15 @@ export function getAppServices(): AppServices { // Create error reporting service (GlitchTip/Sentry or no-op) const errors = sentryEnabled - ? new GlitchtipErrorReportingService({ enabled: true }, logger, notifications) + ? new GlitchtipErrorReportingService( + { + enabled: true, + dsn: config.errors.glitchtip.dsn, + tracesSampleRate: 0.1, // Default to 10% sampling + }, + logger, + notifications, + ) : new NoopErrorReportingService(); if (sentryEnabled) { diff --git a/lib/services/errors/glitchtip-error-reporting-service.ts b/lib/services/errors/glitchtip-error-reporting-service.ts index 957099f1..ae4de333 100644 --- a/lib/services/errors/glitchtip-error-reporting-service.ts +++ b/lib/services/errors/glitchtip-error-reporting-service.ts @@ -8,6 +8,8 @@ import type { LoggerService } from '../logging/logger-service'; export type GlitchtipErrorReportingServiceOptions = { enabled: boolean; + dsn?: string; + tracesSampleRate?: number; }; // GlitchTip speaks the Sentry protocol; @sentry/nextjs can send to GlitchTip via DSN. @@ -46,12 +48,12 @@ export class GlitchtipErrorReportingService implements ErrorReportingService { if (!this.sentryPromise) { this.sentryPromise = import('@sentry/nextjs').then((Sentry) => { // Client-side initialization must happen here since sentry.client.config.ts is empty - if (typeof window !== 'undefined' && process.env.NODE_ENV === 'production') { + if (typeof window !== 'undefined' && this.options.enabled) { Sentry.init({ - dsn: 'https://public@errors.infra.mintel.me/1', + dsn: this.options.dsn || 'https://public@errors.infra.mintel.me/1', tunnel: '/errors/api/relay', enabled: true, - tracesSampleRate: 0, + tracesSampleRate: this.options.tracesSampleRate ?? 0.1, replaysOnErrorSampleRate: 1.0, replaysSessionSampleRate: 0.1, });