Skip to content

Commit

Permalink
Migrate Sentry packages to v8 (#6387)
Browse files Browse the repository at this point in the history
* build(deps): bump @sentry/browser from 7.109.0 to 8.34.0

Bumps [@sentry/browser](https://github.com/getsentry/sentry-javascript) from 7.109.0 to 8.34.0.
- [Release notes](https://github.com/getsentry/sentry-javascript/releases)
- [Changelog](https://github.com/getsentry/sentry-javascript/blob/8.34.0/CHANGELOG.md)
- [Commits](getsentry/sentry-javascript@7.109.0...8.34.0)

---
updated-dependencies:
- dependency-name: "@sentry/browser"
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <[email protected]>

* migrate @sentry/nextjs to v8

* configure SENTRY_AUTH_TOKEN

* replace missing tilda

---------

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
  • Loading branch information
goplayoutside3 and dependabot[bot] authored Oct 18, 2024
1 parent 9022a32 commit 449acac
Show file tree
Hide file tree
Showing 9 changed files with 943 additions and 229 deletions.
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() {
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
}),
{
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())
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

0 comments on commit 449acac

Please sign in to comment.