From 5aae169a25159dd84e6f0ba4ddd6ad58cefd5f76 Mon Sep 17 00:00:00 2001 From: Ross Date: Mon, 20 Jul 2026 08:51:29 +0100 Subject: [PATCH] add sentry --- index.html | 2 ++ js/main.js | 4 ++++ js/sentry.js | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 52 insertions(+) create mode 100644 js/sentry.js diff --git a/index.html b/index.html index 2004557..0078906 100644 --- a/index.html +++ b/index.html @@ -441,7 +441,9 @@ + + diff --git a/js/main.js b/js/main.js index f9cf338..6f25a9e 100644 --- a/js/main.js +++ b/js/main.js @@ -5,6 +5,10 @@ import * as interact from "./interact.js"; import * as config from "./config.js"; import { db, question_db } from "./db.js"; import { initSync, triggerImmediateSync, updateSyncUI } from "./sync.js"; +import { initSentry } from "./sentry.js"; + +initSentry(); + // const { v4: uuidv4 } = require('uuid'); function initLogging() { diff --git a/js/sentry.js b/js/sentry.js new file mode 100644 index 0000000..034c04d --- /dev/null +++ b/js/sentry.js @@ -0,0 +1,46 @@ +/** + * Sentry Error Monitoring initializer for RTS. + * + * Configurable via window.SENTRY_DSN or window.RTS_SENTRY_DSN or + */ + +export function initSentry() { + try { + const metaDsn = document.querySelector('meta[name="sentry-dsn"]')?.getAttribute('content'); + const dsn = window.SENTRY_DSN || window.RTS_SENTRY_DSN || metaDsn; + + if (!dsn) { + return; + } + + if (window.Sentry) { + window.Sentry.init({ + dsn: dsn, + environment: window.SENTRY_ENVIRONMENT || 'production', + tracesSampleRate: parseFloat(window.SENTRY_TRACES_SAMPLE_RATE || '0.05'), + integrations: [ + 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'; + script.onload = () => { + if (window.Sentry) { + window.Sentry.init({ + dsn: dsn, + environment: window.SENTRY_ENVIRONMENT || 'production', + tracesSampleRate: parseFloat(window.SENTRY_TRACES_SAMPLE_RATE || '0.05') + }); + console.log("[RTS] Sentry error monitoring initialized via dynamic load"); + } + }; + document.head.appendChild(script); + } + } catch (err) { + console.warn("[RTS] Sentry initialization failed:", err); + } +}