Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate Sentry packages to v8 #6387

Merged
merged 5 commits into from
Oct 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions packages/app-project/instrumentation.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export async function register() {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if (process.env.NEXT_RUNTIME === 'nodejs') {
await import('./sentry.server.config')
}

if (process.env.NEXT_RUNTIME === 'edge') {
await import('./sentry.edge.config')
}
}
12 changes: 7 additions & 5 deletions packages/app-project/next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ const nextConfig = {

experimental: {
forceSwcTransforms: true,
instrumentationHook: true,
optimizePackageImports: ['@zooniverse/react-components', 'grommet', 'grommet-icons']
},

Expand Down Expand Up @@ -96,10 +97,6 @@ const nextConfig = {
]
},

sentry: {
hideSourceMaps: true
},

webpack: (config, options) => {
config.resolve = {
...config.resolve,
Expand All @@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like this was not required previously, but is with these changes, it looks like per https://docs.sentry.io/platforms/javascript/guides/nextjs/manual-setup/#extend-your-nextjs-configuration .

}),
{
auto: true
Expand Down
2 changes: 1 addition & 1 deletion packages/app-project/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
40 changes: 0 additions & 40 deletions packages/app-project/pages/_document.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -77,14 +46,6 @@ export default class MyDocument extends Document {
{isProduction && (
<script dangerouslySetInnerHTML={{ __html: GA_TRACKING_SCRIPT }} />
)}
{/* https://docs.sentry.io/platforms/javascript/install/loader/#default-bundle */}
<script
src="https://browser.sentry-cdn.com/7.109.0/bundle.tracing.min.js"
integrity="sha384-FyHLiOgn1wcBUetfKq3+RF+aukePV5acbpdkgdYJRWepBQ8AMoNNEucU/6+JYRuJ"
crossOrigin='anonymous'
defer
id='sentryScript'
></script>
</Head>
<body>
{isProduction && (
Expand All @@ -100,7 +61,6 @@ export default class MyDocument extends Document {
)}
<Main />
<NextScript />
<script dangerouslySetInnerHTML={{ __html: ERROR_LOGGING_SCRIPT }} />
</body>
</Html>
)
Expand Down
2 changes: 1 addition & 1 deletion packages/app-project/sentry.client.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const environment = process.env.APP_ENV
Sentry.init({
dsn,
environment,
integrations: [new Sentry.BrowserTracing()],
integrations: [Sentry.browserTracingIntegration()],
release,
tracesSampleRate: 1.0,
ignoreErrors: [
Expand Down
1 change: 0 additions & 1 deletion packages/app-project/sentry.server.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ const environment = process.env.APP_ENV
Sentry.init({
dsn,
environment,
integrations: [...Sentry.autoDiscoverNodePerformanceMonitoringIntegrations()],
release,
tracesSampleRate: 1.0
})
Expand Down
4 changes: 0 additions & 4 deletions packages/app-project/server/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ if (process.env.NEWRELIC_LICENSE_KEY) {
require('newrelic')
}

const Sentry = require('@sentry/nextjs')
const express = require('express')
const next = require('next')

Expand All @@ -26,15 +25,12 @@ const handle = app.getRequestHandler()

app.prepare().then(() => {
const server = express()

server.use(Sentry.Handlers.requestHandler())
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sentry.Handlers isn't needed anymore

setLogging(server)

server.get('*', (req, res) => {
return handle(req, res)
})

server.use(Sentry.Handlers.errorHandler())
server.use(function onError(error, req, res, next) {
res.statusCode = 500
res.end(res.sentry + "\n")
Expand Down
2 changes: 1 addition & 1 deletion packages/lib-classifier/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
},
"dependencies": {
"@babel/runtime": "~7.25.6",
"@sentry/browser": "~7.109.0",
"@sentry/browser": "~8.34.0",
"@visx/axis": "~3.10.1",
"@visx/brush": "~3.6.1",
"@visx/event": "~3.3.0",
Expand Down
Loading