diff --git a/scripts/build-web.sh b/scripts/build-web.sh index 9a06260..8758928 100755 --- a/scripts/build-web.sh +++ b/scripts/build-web.sh @@ -102,10 +102,14 @@ rm pkg/evo.js.bak web/pkg/evo.js.bak # Update cache-busting version in index.html echo "🔄 Updating cache busting version in index.html..." sed -i.bak "s/src=\"js\/app\.js?v=[0-9a-f]*\"/src=\"js\/app.js?v=$CACHE_VERSION\"/g" web/index.html +sed -i.bak "s/src=\"js\/sentry-config\.js?v=[0-9a-z]*\"/src=\"js\/sentry-config.js?v=$CACHE_VERSION\"/g" web/index.html +sed -i.bak "s/src=\"js\/sentry\.js?v=[0-9a-z]*\"/src=\"js\/sentry.js?v=$CACHE_VERSION\"/g" web/index.html # Cache-bust the stylesheet too — without a ?v= a stale style.css is served after a deploy. sed -i.bak "s|href=\"css/style.css?v=[0-9a-z]*\"|href=\"css/style.css?v=$CACHE_VERSION\"|g" web/index.html rm web/index.html.bak +node scripts/write-sentry-config.mjs evo web/js/sentry-config.js "$CACHE_VERSION" + # Verify the build echo "🔍 Verifying build..." if [ -f "pkg/evo.js" ] && [ -f "pkg/evo_bg.wasm" ]; then @@ -118,4 +122,4 @@ fi echo "🎉 Build complete! Run 'npm run dev' to start the server." echo "📁 Built files:" ls -la pkg/ -echo "🔢 Cache version: $CACHE_VERSION" \ No newline at end of file +echo "🔢 Cache version: $CACHE_VERSION" diff --git a/scripts/write-sentry-config.mjs b/scripts/write-sentry-config.mjs new file mode 100644 index 0000000..2c7720e --- /dev/null +++ b/scripts/write-sentry-config.mjs @@ -0,0 +1,19 @@ +import { writeFileSync } from 'node:fs'; + +const app = process.argv[2] || 'evo'; +const target = process.argv[3] || 'web/js/sentry-config.js'; +const fallbackRelease = process.argv[4] || ''; + +writeFileSync( + target, + `window.TRE_STATIC_SENTRY_CONFIG = ${JSON.stringify( + { + app, + dsn: process.env.SENTRY_DSN || '', + environment: process.env.SENTRY_ENVIRONMENT || 'production', + release: process.env.SENTRY_RELEASE || process.env.GITHUB_SHA || fallbackRelease, + }, + null, + 2, + )};\n`, +); diff --git a/web/index.html b/web/index.html index 0d6605a..74e159b 100644 --- a/web/index.html +++ b/web/index.html @@ -178,6 +178,8 @@ + + diff --git a/web/js/sentry-config.js b/web/js/sentry-config.js new file mode 100644 index 0000000..c0f43eb --- /dev/null +++ b/web/js/sentry-config.js @@ -0,0 +1,6 @@ +window.TRE_STATIC_SENTRY_CONFIG = { + app: "evo", + dsn: "", + environment: "production", + release: "", +}; diff --git a/web/js/sentry.js b/web/js/sentry.js new file mode 100644 index 0000000..a088a9e --- /dev/null +++ b/web/js/sentry.js @@ -0,0 +1,37 @@ +(() => { + const config = window.TRE_STATIC_SENTRY_CONFIG; + if (!config?.dsn) return; + + const script = document.createElement("script"); + script.src = "https://browser.sentry-cdn.com/10.57.0/bundle.min.js"; + script.crossOrigin = "anonymous"; + script.onload = () => { + if (!window.Sentry) return; + window.Sentry.init({ + dsn: config.dsn, + environment: config.environment || "production", + release: config.release, + sendDefaultPii: false, + tracesSampleRate: config.environment === "production" ? 0.01 : 0, + replaysSessionSampleRate: 0, + replaysOnErrorSampleRate: 0, + beforeSend(event) { + if (event.request) { + delete event.request.cookies; + delete event.request.data; + if (event.request.headers) { + for (const key of Object.keys(event.request.headers)) { + const lowerKey = key.toLowerCase(); + if (lowerKey.includes("authorization") || lowerKey.includes("cookie")) { + event.request.headers[key] = "[Filtered]"; + } + } + } + } + event.tags = { ...event.tags, app: config.app || "evo" }; + return event; + }, + }); + }; + document.head.appendChild(script); +})();