From acc8dd2e3518af83d26fa8065bbd0d426b83f30e Mon Sep 17 00:00:00 2001 From: Delilah C <23665803+goplayoutside3@users.noreply.github.com> Date: Fri, 15 Dec 2023 13:23:09 -0600 Subject: [PATCH] app-content-pages: Remove Sentry, New Relic, and Million.js (#5762) * remove sentry, new relic, and million * remove outdated next-absolute-path --- packages/app-content-pages/.storybook/main.js | 1 - packages/app-content-pages/README.md | 1 - packages/app-content-pages/newrelic.js | 24 ------ packages/app-content-pages/next.config.js | 35 +------- packages/app-content-pages/package.json | 4 - packages/app-content-pages/pages/_app.js | 2 - packages/app-content-pages/pages/_document.js | 5 -- packages/app-content-pages/pages/_error.js | 5 -- .../app-content-pages/pages/publications.js | 2 - packages/app-content-pages/pages/team.js | 2 - .../app-content-pages/sentry.client.config.js | 18 ----- .../app-content-pages/sentry.edge.config.js | 14 ---- .../app-content-pages/sentry.server.config.js | 15 ---- packages/app-content-pages/server/server.js | 18 ----- .../server/set-cache-headers.js | 25 ------ .../server/set-cache-headers.spec.js | 79 ------------------- .../app-content-pages/server/set-logging.js | 22 ------ .../server/set-logging.spec.js | 52 ------------ .../src/helpers/logger/README.md | 3 - .../src/helpers/logger/index.js | 2 - .../src/helpers/logger/logNodeError.js | 11 --- .../src/helpers/logger/logReactError.js | 16 ---- yarn.lock | 7 +- 23 files changed, 4 insertions(+), 359 deletions(-) delete mode 100644 packages/app-content-pages/newrelic.js delete mode 100644 packages/app-content-pages/sentry.client.config.js delete mode 100644 packages/app-content-pages/sentry.edge.config.js delete mode 100644 packages/app-content-pages/sentry.server.config.js delete mode 100644 packages/app-content-pages/server/set-cache-headers.js delete mode 100644 packages/app-content-pages/server/set-cache-headers.spec.js delete mode 100644 packages/app-content-pages/server/set-logging.js delete mode 100644 packages/app-content-pages/server/set-logging.spec.js delete mode 100644 packages/app-content-pages/src/helpers/logger/README.md delete mode 100644 packages/app-content-pages/src/helpers/logger/index.js delete mode 100644 packages/app-content-pages/src/helpers/logger/logNodeError.js delete mode 100644 packages/app-content-pages/src/helpers/logger/logReactError.js diff --git a/packages/app-content-pages/.storybook/main.js b/packages/app-content-pages/.storybook/main.js index 4a812ac170..9cc976dc44 100644 --- a/packages/app-content-pages/.storybook/main.js +++ b/packages/app-content-pages/.storybook/main.js @@ -7,7 +7,6 @@ function webpackFinal(config, options) { ...config.resolve, alias: { ...webpackConfig.resolve.alias, - ['@sentry/node']: '@sentry/browser', 'next-i18next': 'react-i18next' }, fallback: { diff --git a/packages/app-content-pages/README.md b/packages/app-content-pages/README.md index a78eaf8287..e936b2eb06 100644 --- a/packages/app-content-pages/README.md +++ b/packages/app-content-pages/README.md @@ -5,7 +5,6 @@ A [Next.js](https://github.com/zeit/next.js) app for handling the content pages. ## Ops - [Jenkins](https://jenkins.zooniverse.org/job/Zooniverse%20GitHub/job/front-end-monorepo/) -- [New Relic](https://rpm.newrelic.com/accounts/23619/applications/319037799) ## Getting started diff --git a/packages/app-content-pages/newrelic.js b/packages/app-content-pages/newrelic.js deleted file mode 100644 index ab353c8e17..0000000000 --- a/packages/app-content-pages/newrelic.js +++ /dev/null @@ -1,24 +0,0 @@ -'use strict' - -exports.config = { - app_name: ['Front End - Content Pages app'], - license_key: process.env.NEWRELIC_LICENSE_KEY, - logging: { - level: 'info' - }, - allow_all_headers: true, - attributes: { - exclude: [ - 'request.headers.cookie', - 'request.headers.authorization', - 'request.headers.proxyAuthorization', - 'request.headers.setCookie*', - 'request.headers.x*', - 'response.headers.cookie', - 'response.headers.authorization', - 'response.headers.proxyAuthorization', - 'response.headers.setCookie*', - 'response.headers.x*' - ] - } -} diff --git a/packages/app-content-pages/next.config.js b/packages/app-content-pages/next.config.js index 6efe613259..c458d025dc 100644 --- a/packages/app-content-pages/next.config.js +++ b/packages/app-content-pages/next.config.js @@ -1,14 +1,8 @@ -if (process.env.NEWRELIC_LICENSE_KEY) { - require('newrelic') -} - require('dotenv').config() -const million = require('million/compiler') const { execSync } = require('child_process') const Dotenv = require('dotenv-webpack') const path = require('path') -const { withSentryConfig } = require('@sentry/nextjs') const { i18n } = require('./next-i18next.config') const assetPrefixes = {} @@ -21,10 +15,8 @@ function commitID () { } } -const isDevelopment = process.env.NODE_ENV === 'development' const PANOPTES_ENV = process.env.PANOPTES_ENV || 'staging' const webpackConfig = require('./webpack.config') -const SENTRY_CONTENT_DSN = isDevelopment ? '' : 'https://1f0126a750244108be76957b989081e8@sentry.io/1492498' const APP_ENV = process.env.APP_ENV || 'development' const COMMIT_ID = process.env.COMMIT_ID || commitID() const assetPrefix = assetPrefixes[APP_ENV] @@ -44,12 +36,12 @@ const nextConfig = { env: { COMMIT_ID, PANOPTES_ENV, - SENTRY_CONTENT_DSN, APP_ENV }, experimental: { - forceSwcTransforms: true + forceSwcTransforms: true, + optimizePackageImports: ['@zooniverse/react-components', 'grommet', 'grommet-icons'] }, /** localeDetection is a Next.js feature, while the rest of i18n config pertains to next-i18next */ @@ -58,21 +50,8 @@ const nextConfig = { ...i18n }, - modularizeImports: { - lodash: { - transform: 'lodash/{{member}}', - }, - '@zooniverse/react-components': { - transform: '@zooniverse/react-components/{{member}}' - } - }, - reactStrictMode: true, - sentry: { - hideSourceMaps: true - }, - webpack: (config, options) => { config.plugins.concat([ new Dotenv({ @@ -96,12 +75,4 @@ const nextConfig = { } } -module.exports = million.next( - withSentryConfig(nextConfig, { - org: 'zooniverse-27', - project: 'fem-app-content-pages' - }), - { - auto: true - } -) +module.exports = nextConfig diff --git a/packages/app-content-pages/package.json b/packages/app-content-pages/package.json index ad04b5719f..4a8080cf12 100644 --- a/packages/app-content-pages/package.json +++ b/packages/app-content-pages/package.json @@ -16,7 +16,6 @@ "build-storybook": "storybook build" }, "dependencies": { - "@sentry/nextjs": "~7.84.0", "@zooniverse/async-states": "~0.0.1", "@zooniverse/grommet-theme": "~3.2.0", "@zooniverse/panoptes-js": "~0.5.0", @@ -29,11 +28,8 @@ "grommet-icons": "~4.11.0", "i18next": "~23.7.1", "lodash": "~4.17.11", - "million": "~2.6.4", "morgan": "^1.10.0", - "newrelic": "^11.0.0", "next": "~13.5.5", - "next-absolute-url": "~1.2.2", "next-i18next": "~15.1.1", "panoptes-client": "~5.6.0", "path-match": "~1.2.4", diff --git a/packages/app-content-pages/pages/_app.js b/packages/app-content-pages/pages/_app.js index 712f89a13c..e40748e513 100644 --- a/packages/app-content-pages/pages/_app.js +++ b/packages/app-content-pages/pages/_app.js @@ -9,7 +9,6 @@ import Error from 'next/error' import PageHeader from '../src/shared/components/PageHeader/PageHeader.js' import { PanoptesAuthContext, ThemeModeContext } from '../src/shared/contexts' import { usePanoptesUser } from '@zooniverse/react-components/hooks' -import { logReactError } from '../src/helpers/logger' const GlobalStyle = createGlobalStyle` body { @@ -74,7 +73,6 @@ function MyApp({ Component, pageProps }) { ) } catch (error) { - logReactError(error) return } } diff --git a/packages/app-content-pages/pages/_document.js b/packages/app-content-pages/pages/_document.js index d56cb64b2c..9019bb9aa5 100644 --- a/packages/app-content-pages/pages/_document.js +++ b/packages/app-content-pages/pages/_document.js @@ -1,11 +1,6 @@ import Document from 'next/document' import { ServerStyleSheet } from 'styled-components' -import { logNodeError } from '../src/helpers/logger' - -process.on('unhandledRejection', logNodeError) -process.on('uncaughtException', logNodeError) - export default class MyDocument extends Document { static async getInitialProps (ctx) { const sheet = new ServerStyleSheet() diff --git a/packages/app-content-pages/pages/_error.js b/packages/app-content-pages/pages/_error.js index c634614100..698c30f142 100644 --- a/packages/app-content-pages/pages/_error.js +++ b/packages/app-content-pages/pages/_error.js @@ -1,4 +1,3 @@ -import * as Sentry from '@sentry/nextjs' import NextErrorComponent from 'next/error' const CustomErrorComponent = (props) => ( @@ -6,10 +5,6 @@ const CustomErrorComponent = (props) => ( ) CustomErrorComponent.getInitialProps = async (contextData) => { - // In case this is running in a serverless function, await this in order to give Sentry - // time to send the error before the lambda exits - await Sentry.captureUnderscoreErrorException(contextData) - // This will contain the status code of the response return NextErrorComponent.getInitialProps(contextData) } diff --git a/packages/app-content-pages/pages/publications.js b/packages/app-content-pages/pages/publications.js index 1695ab6af8..ff65bdcad5 100644 --- a/packages/app-content-pages/pages/publications.js +++ b/packages/app-content-pages/pages/publications.js @@ -1,6 +1,5 @@ import { serverSideTranslations } from 'next-i18next/serverSideTranslations' import createPublicationsResponse from '../src/api/publications/publications.js' -import logNodeError from '../src/helpers/logger/logNodeError.js' export { default } from '../src/screens/Publications' export async function getStaticProps({ locale }) { @@ -27,7 +26,6 @@ export async function getStaticProps({ locale }) { revalidate: 60 * 60 * 1 // 1 hour } } catch (error) { - logNodeError(error) throw error } } diff --git a/packages/app-content-pages/pages/team.js b/packages/app-content-pages/pages/team.js index df75e32ee4..7cd2f1e7e1 100644 --- a/packages/app-content-pages/pages/team.js +++ b/packages/app-content-pages/pages/team.js @@ -1,6 +1,5 @@ import { serverSideTranslations } from 'next-i18next/serverSideTranslations' import createTeamResponse from '../src/api/team/team.js' -import logNodeError from '../src/helpers/logger/logNodeError.js' export { default } from '../src/screens/Teams' export async function getStaticProps({ locale }) { @@ -27,7 +26,6 @@ export async function getStaticProps({ locale }) { revalidate: 60 * 60 * 1 // 1 hour } } catch (error) { - logNodeError(error) throw error } } diff --git a/packages/app-content-pages/sentry.client.config.js b/packages/app-content-pages/sentry.client.config.js deleted file mode 100644 index cea99c7742..0000000000 --- a/packages/app-content-pages/sentry.client.config.js +++ /dev/null @@ -1,18 +0,0 @@ -import * as Sentry from '@sentry/nextjs' - -const dsn = process.env.SENTRY_CONTENT_DSN -const release = process.env.COMMIT_ID -const environment = process.env.APP_ENV - -Sentry.init({ - dsn, - environment, - integrations: [new Sentry.BrowserTracing()], - release, - tracesSampleRate: 1.0, - ignoreErrors: [ - 'ResizeObserver loop limit exceeded' // Ignore benign error: https://github.com/WICG/resize-observer/issues/38 - ] -}) - -console.log('Initialising Sentry (browser runtime):', dsn, environment, release) diff --git a/packages/app-content-pages/sentry.edge.config.js b/packages/app-content-pages/sentry.edge.config.js deleted file mode 100644 index 77ec5ad60d..0000000000 --- a/packages/app-content-pages/sentry.edge.config.js +++ /dev/null @@ -1,14 +0,0 @@ -import * as Sentry from '@sentry/nextjs' - -const dsn = process.env.SENTRY_CONTENT_DSN -const release = process.env.COMMIT_ID -const environment = process.env.APP_ENV - -Sentry.init({ - dsn, - environment, - release, - tracesSampleRate: 1.0 -}) - -console.log('Initialising Sentry (Edge runtime):', dsn, environment, release) diff --git a/packages/app-content-pages/sentry.server.config.js b/packages/app-content-pages/sentry.server.config.js deleted file mode 100644 index 00e718d5f7..0000000000 --- a/packages/app-content-pages/sentry.server.config.js +++ /dev/null @@ -1,15 +0,0 @@ -import * as Sentry from '@sentry/nextjs' - -const dsn = process.env.SENTRY_CONTENT_DSN -const release = process.env.COMMIT_ID -const environment = process.env.APP_ENV - -Sentry.init({ - dsn, - environment, - integrations: [...Sentry.autoDiscoverNodePerformanceMonitoringIntegrations()], - release, - tracesSampleRate: 1.0 -}) - -console.log('Initialising Sentry (Node runtime):', dsn, environment, release) diff --git a/packages/app-content-pages/server/server.js b/packages/app-content-pages/server/server.js index 1bde54e3c1..cd77b1ffae 100644 --- a/packages/app-content-pages/server/server.js +++ b/packages/app-content-pages/server/server.js @@ -1,14 +1,6 @@ -if (process.env.NEWRELIC_LICENSE_KEY) { - require('newrelic') -} - -const Sentry = require('@sentry/nextjs') const express = require('express') const next = require('next') -const setLogging = require('./set-logging') -const setCacheHeaders = require('./set-cache-headers') - const port = parseInt(process.env.PORT, 10) || 3000 const dev = process.env.NODE_ENV !== 'production' @@ -28,20 +20,10 @@ const handle = app.getRequestHandler() app.prepare().then(() => { const server = express() - server.use(Sentry.Handlers.requestHandler()) - setLogging(server) - server.get('*', (req, res) => { - setCacheHeaders(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") - }) - let selfsigned try { selfsigned = require('selfsigned') diff --git a/packages/app-content-pages/server/set-cache-headers.js b/packages/app-content-pages/server/set-cache-headers.js deleted file mode 100644 index 4a42f7ff29..0000000000 --- a/packages/app-content-pages/server/set-cache-headers.js +++ /dev/null @@ -1,25 +0,0 @@ -// Sets cache headers dependent on asset type. Caching headers are set here so -// that they are respected downstream by CloudFront. -// -// Javascript files can have a massive `max-age` as they are cache-busted -// by filename. Everything else is set to a minute. - -const process = require('process') - -const enableCacheHeaders = process.env.ENABLE_CACHE_HEADERS === 'true' -const DEFAULT_MAX_AGE = process.env.DEFAULT_MAX_AGE || 60 // 1 minute -const JS_MAX_AGE = process.env.JS_MAX_AGE || 31536000 // 1 year - -function setCacheHeaders (req, res) { - if (enableCacheHeaders) { - let maxAge = isJsRequest(req) ? JS_MAX_AGE : DEFAULT_MAX_AGE - res.setHeader('Cache-Control', `max-age=${maxAge}`) - } -} - -function isJsRequest (req) { - const regex = /\.js$/i - return regex.test(req.path) -} - -module.exports = setCacheHeaders diff --git a/packages/app-content-pages/server/set-cache-headers.spec.js b/packages/app-content-pages/server/set-cache-headers.spec.js deleted file mode 100644 index 72d6626392..0000000000 --- a/packages/app-content-pages/server/set-cache-headers.spec.js +++ /dev/null @@ -1,79 +0,0 @@ -const proxyquire = require('proxyquire') -const sinon = require('sinon') - -describe('Server > setCacheHeaders', function () { - let setCacheHeaders - const mockRes = { - setHeader: Function.prototype - } - const setHeaderSpy = sinon.spy(mockRes, 'setHeader') - - describe('default behaviour', function () { - before(function () { - setCacheHeaders = require('./set-cache-headers') - }) - - afterEach(function () { - setHeaderSpy.resetHistory() - }) - - it(`shouldn't set any extra headers`, function () { - setCacheHeaders({ path: '/foo.html' }, mockRes) - expect(setHeaderSpy).to.have.not.been.called() - }) - }) - - describe('behaviour with caching enabled', function () { - before(function () { - setCacheHeaders = proxyquire('./set-cache-headers', { - process: { - env: { - ENABLE_CACHE_HEADERS: 'true' - } - } - }) - }) - - afterEach(function () { - setHeaderSpy.resetHistory() - }) - - it('should set the max-age to 1 minute by default', function () { - setCacheHeaders({ path: '/foo.html' }, mockRes) - expect(setHeaderSpy).to.be.calledWith('Cache-Control', 'max-age=60') - }) - - it('should set the max-age to 1 year for `.js` files', function () { - setCacheHeaders({ path: '/foo.js' }, mockRes) - expect(setHeaderSpy).to.be.calledWith('Cache-Control', 'max-age=31536000') - }) - }) - - describe('configured behaviour with caching enabled', function () { - before(function () { - setCacheHeaders = proxyquire('./set-cache-headers', { - process: { - env: { - DEFAULT_MAX_AGE: '100', - ENABLE_CACHE_HEADERS: 'true', - JS_MAX_AGE: '200' - } - } - }) - }) - - afterEach(function () { - setHeaderSpy.resetHistory() - }) - - it('should set the default max-age to the value of `DEFAULT_MAX_AGE`', function () { - setCacheHeaders({ path: '/foo.html' }, mockRes) - expect(setHeaderSpy).to.be.calledWith('Cache-Control', 'max-age=100') - }) - - it('should set the max-age for `.js` files to the value of `JS_MAX_AGE`', function () { - setCacheHeaders({ path: '/foo.js' }, mockRes) - expect(setHeaderSpy).to.be.calledWith('Cache-Control', 'max-age=200') - }) - }) -}) diff --git a/packages/app-content-pages/server/set-logging.js b/packages/app-content-pages/server/set-logging.js deleted file mode 100644 index 863f56e77d..0000000000 --- a/packages/app-content-pages/server/set-logging.js +++ /dev/null @@ -1,22 +0,0 @@ -// Sets up morgan for request logging in production - -const morgan = require('morgan') -const process = require('process') - -const production = process.env.NODE_ENV === 'production' - -function setLogging (expressInstance) { - if (production) { - expressInstance.use(morgan('combined', { - skip: (req, res) => res.statusCode < 400, - stream: process.stderr - })) - - expressInstance.use(morgan('combined', { - skip: (req, res) => res.statusCode >= 400, - stream: process.stdout - })) - } -} - -module.exports = setLogging diff --git a/packages/app-content-pages/server/set-logging.spec.js b/packages/app-content-pages/server/set-logging.spec.js deleted file mode 100644 index 9e1858c008..0000000000 --- a/packages/app-content-pages/server/set-logging.spec.js +++ /dev/null @@ -1,52 +0,0 @@ -const proxyquire = require('proxyquire') -const sinon = require('sinon') - -describe('Server > setLogging', function () { - let setLogging - const expressInstance = { - use: Function.prototype - } - const useSpy = sinon.spy(expressInstance, 'use') - - describe('in development', function () { - before(function () { - setLogging = proxyquire('./set-logging', { - process: { - env: { - NODE_ENV: 'development' - } - } - }) - }) - - afterEach(function () { - useSpy.resetHistory() - }) - - it(`shouldn't enable morgan`, function () { - setLogging(expressInstance) - expect(useSpy).to.have.not.been.called() - }) - }) - - describe('in production', function () { - before(function () { - setLogging = proxyquire('./set-logging', { - process: { - env: { - NODE_ENV: 'production' - } - } - }) - }) - - afterEach(function () { - useSpy.resetHistory() - }) - - it('should enable morgan', function () { - setLogging(expressInstance) - expect(useSpy).to.have.been.called() - }) - }) -}) diff --git a/packages/app-content-pages/src/helpers/logger/README.md b/packages/app-content-pages/src/helpers/logger/README.md deleted file mode 100644 index 3047d56757..0000000000 --- a/packages/app-content-pages/src/helpers/logger/README.md +++ /dev/null @@ -1,3 +0,0 @@ -# Logger functions - -Some helper functions for the Sentry logging service, taken from https://leerob.io/blog/configuring-sentry-for-nextjs-apps. diff --git a/packages/app-content-pages/src/helpers/logger/index.js b/packages/app-content-pages/src/helpers/logger/index.js deleted file mode 100644 index 53525f667d..0000000000 --- a/packages/app-content-pages/src/helpers/logger/index.js +++ /dev/null @@ -1,2 +0,0 @@ -export { default as logNodeError } from './logNodeError' -export { default as logReactError } from './logReactError' diff --git a/packages/app-content-pages/src/helpers/logger/logNodeError.js b/packages/app-content-pages/src/helpers/logger/logNodeError.js deleted file mode 100644 index 1b86ccd4cc..0000000000 --- a/packages/app-content-pages/src/helpers/logger/logNodeError.js +++ /dev/null @@ -1,11 +0,0 @@ -import { captureException } from '@sentry/nextjs' - -export default function logNodeError (error) { - const dsn = process.env.SENTRY_CONTENT_DSN - - if (dsn) { - captureException(error) - } - - return null -} diff --git a/packages/app-content-pages/src/helpers/logger/logReactError.js b/packages/app-content-pages/src/helpers/logger/logReactError.js deleted file mode 100644 index bc6fd938bd..0000000000 --- a/packages/app-content-pages/src/helpers/logger/logReactError.js +++ /dev/null @@ -1,16 +0,0 @@ -import { withScope, captureException} from '@sentry/nextjs' - -export default function logReactError (error, errorInfo) { - const dsn = process.env.SENTRY_CONTENT_DSN - - if (dsn) { - withScope((scope) => { - Object.keys(errorInfo).forEach((key) => { - scope.setExtra(key, errorInfo[key]) - }); - captureException(error) - }) - } - - return null -} diff --git a/yarn.lock b/yarn.lock index 38da222891..b7eef72605 100644 --- a/yarn.lock +++ b/yarn.lock @@ -13253,7 +13253,7 @@ neo-async@^2.5.0, neo-async@^2.6.0, neo-async@^2.6.2: resolved "https://registry.npmjs.org/neo-async/-/neo-async-2.6.2.tgz" integrity sha512-Yd3UES5mWCSqR+qNT93S3UoYUkqAZ9lLg8a7g9rimsWmYGK8cVToA4/sF3RrshdyV3sAGMXVUmpMYOw+dLpOuw== -newrelic@^11.0.0, newrelic@~11.6.0: +newrelic@~11.6.0: version "11.6.0" resolved "https://registry.yarnpkg.com/newrelic/-/newrelic-11.6.0.tgz#0a75ef5382428cb0e9a219edc4ed9b392b1b3341" integrity sha512-peYHffhstQlPQnjTYnXZmz/VX4rvnk8rE9n/kM0KKDbStQbcQE+COkdliDS7jg82ERf90aawu8YGWQRVD/w/GQ== @@ -13280,11 +13280,6 @@ newrelic@^11.0.0, newrelic@~11.6.0: "@newrelic/native-metrics" "^10.0.0" "@prisma/prisma-fmt-wasm" "^4.17.0-16.27eb2449f178cd9fe1a4b892d732cc4795f75085" -next-absolute-url@~1.2.2: - version "1.2.2" - resolved "https://registry.npmjs.org/next-absolute-url/-/next-absolute-url-1.2.2.tgz" - integrity sha512-Z2+LZXQTthhw2je9u4eq8QWXxXd57a6b54x9exBfQX4Dct6YxaMjcXZWNLHd9AOlCue84EsMpdSGP7wACqUnPg== - next-i18next@~15.1.1: version "15.1.1" resolved "https://registry.yarnpkg.com/next-i18next/-/next-i18next-15.1.1.tgz#9fa04bb0260b55cb315dbc437912a991b1b914fa"