diff --git a/index.html b/index.html index 0078906..71d8718 100644 --- a/index.html +++ b/index.html @@ -424,6 +424,10 @@
+ @@ -447,6 +451,7 @@ + diff --git a/js/sentry.js b/js/sentry.js index 034c04d..78cbe70 100644 --- a/js/sentry.js +++ b/js/sentry.js @@ -1,7 +1,6 @@ /** * Sentry Error Monitoring initializer for RTS. - * - * Configurable via window.SENTRY_DSN or window.RTS_SENTRY_DSN or + * Optimized for Free Tier with beforeSend noise filtering. */ export function initSentry() { @@ -13,28 +12,58 @@ export function initSentry() { return; } + const beforeSend = (event, hint) => { + const error = hint?.originalException; + const message = event?.message || (error && error.message) || ""; + + // Ignore common harmless browser/network noise to preserve Sentry free quota + const noisePatterns = [ + /ResizeObserver loop/i, + /Failed to fetch/i, + /NetworkError/i, + /Load failed/i, + /Script error/i, + /top.GLOBALS/i, + /chrome-extension:\/\//i, + /moz-extension:\/\//i, + ]; + + if (noisePatterns.some((pattern) => pattern.test(message))) { + return null; + } + + return event; + }; + + const config = { + dsn: dsn, + environment: window.SENTRY_ENVIRONMENT || "production", + tracesSampleRate: parseFloat(window.SENTRY_TRACES_SAMPLE_RATE || "0.02"), + beforeSend: beforeSend, + ignoreErrors: [ + "ResizeObserver loop limit exceeded", + "ResizeObserver loop completed with undelivered notifications.", + "NetworkError when attempting to fetch resource.", + "Failed to fetch", + "Load failed", + ], + }; + if (window.Sentry) { window.Sentry.init({ - dsn: dsn, - environment: window.SENTRY_ENVIRONMENT || 'production', - tracesSampleRate: parseFloat(window.SENTRY_TRACES_SAMPLE_RATE || '0.05'), + ...config, integrations: [ - window.Sentry.browserTracingIntegration ? window.Sentry.browserTracingIntegration() : null - ].filter(Boolean) + window.Sentry.browserTracingIntegration ? window.Sentry.browserTracingIntegration() : null, + ].filter(Boolean), }); console.log("[RTS] Sentry error monitoring initialized"); } else { - // Dynamically load Sentry bundle if DSN is set but Sentry library tag isn't explicitly loaded - const script = document.createElement('script'); - script.src = 'https://browser.sentry-cdn.com/8.48.0/bundle.min.js'; - script.crossOrigin = 'anonymous'; + const script = document.createElement("script"); + script.src = "https://browser.sentry-cdn.com/8.48.0/bundle.min.js"; + script.crossOrigin = "anonymous"; script.onload = () => { if (window.Sentry) { - window.Sentry.init({ - dsn: dsn, - environment: window.SENTRY_ENVIRONMENT || 'production', - tracesSampleRate: parseFloat(window.SENTRY_TRACES_SAMPLE_RATE || '0.05') - }); + window.Sentry.init(config); console.log("[RTS] Sentry error monitoring initialized via dynamic load"); } };