diff --git a/packages/app-project/instrumentation.js b/packages/app-project/instrumentation.js new file mode 100644 index 0000000000..5316f8eb27 --- /dev/null +++ b/packages/app-project/instrumentation.js @@ -0,0 +1,9 @@ +export async function register() { + if (process.env.NEXT_RUNTIME === 'nodejs') { + await import('./sentry.server.config') + } + + if (process.env.NEXT_RUNTIME === 'edge') { + await import('./sentry.edge.config') + } +} diff --git a/packages/app-project/next.config.js b/packages/app-project/next.config.js index f08d2f91e1..cc119e63f8 100644 --- a/packages/app-project/next.config.js +++ b/packages/app-project/next.config.js @@ -57,6 +57,7 @@ const nextConfig = { experimental: { forceSwcTransforms: true, + instrumentationHook: true, optimizePackageImports: ['@zooniverse/react-components', 'grommet', 'grommet-icons'] }, @@ -96,10 +97,6 @@ const nextConfig = { ] }, - sentry: { - hideSourceMaps: true - }, - webpack: (config, options) => { config.resolve = { ...config.resolve, @@ -119,7 +116,12 @@ const nextConfig = { module.exports = million.next( withSentryConfig(nextConfig, { org: 'zooniverse-27', - project: 'fem-app-project' + project: 'fem-app-project', + sourcemaps: { + disable: true, + }, + telemetry: false, + authToken: process.env.SENTRY_AUTH_TOKEN }), { auto: true diff --git a/packages/app-project/package.json b/packages/app-project/package.json index 35ea86f070..2ad45909dc 100644 --- a/packages/app-project/package.json +++ b/packages/app-project/package.json @@ -17,7 +17,7 @@ "build-storybook": "storybook build" }, "dependencies": { - "@sentry/nextjs": "~7.109.0", + "@sentry/nextjs": "~8.34.0", "@sindresorhus/string-hash": "~1.2.0", "@visx/axis": "~3.10.1", "@visx/group": "~3.3.0", diff --git a/packages/app-project/pages/_document.js b/packages/app-project/pages/_document.js index b1def65955..ee079929ec 100644 --- a/packages/app-project/pages/_document.js +++ b/packages/app-project/pages/_document.js @@ -8,37 +8,6 @@ const GA_TRACKING_ID = 'GTM-WDW6V4' const GA_TRACKING_SCRIPT = ` (function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start': new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src='https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);})(window,document,'script','dataLayer','${GA_TRACKING_ID}'); ` - -const ERROR_LOGGING_SCRIPT = ` - function setUpLogging() { - Sentry.init({ - dsn: '${process.env.SENTRY_PROJECT_DSN}', - environment: '${process.env.APP_ENV}', - release: '${process.env.COMMIT_ID}', - integrations: [new Sentry.BrowserTracing()], - tracesSampleRate: 1.0 - }); - console.log('Sentry init: ${process.env.SENTRY_PROJECT_DSN} ${process.env.APP_ENV}'); - } - - function onError(e) { - const error = new Error('External script failed to load'); - Sentry.withScope((scope) => { - scope.setTag('ScriptError', 'loadFailed'); - scope.setExtra('scriptSrc', e.srcElement.src); - Sentry.captureException(error); - }); - console.log('errored', e.srcElement.src); - }; - - const scripts = document.querySelectorAll('script'); - scripts.forEach(scriptNode => { - scriptNode.onload = e => console.log('loaded', e.srcElement.src); - scriptNode.onerror = onError; - }); - const sentryScript = document.querySelector('#sentryScript'); - sentryScript.onload = setUpLogging; -` const isProduction = process.env.NODE_ENV === 'production' process.on('unhandledRejection', logToSentry) @@ -77,14 +46,6 @@ export default class MyDocument extends Document { {isProduction && ( {isProduction && ( @@ -100,7 +61,6 @@ export default class MyDocument extends Document { )}
-