Skip to content

Commit

Permalink
Upgrade Sentry (#1664)
Browse files Browse the repository at this point in the history
  • Loading branch information
rschlaefli authored Sep 23, 2020
1 parent eeabcb5 commit 53a28c1
Show file tree
Hide file tree
Showing 12 changed files with 357 additions and 609 deletions.
9 changes: 5 additions & 4 deletions .env.prod
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@ SECURITY_FRAMEGUARD_ENABLED=
SECURITY_HSTS_ENABLED=
SECURITY_REFERRER_POLICY=

SERVICES_APM_ENABLED=
SERVICES_APM_SECRET_TOKEN=
SERVICES_APM_SERVER_URL=
SERVICES_APM_SERVICE_NAME=
SERVICES_GOOGLE_ANALYTICS_ENABLED=
SERVICES_LOGROCKET_ENABLED=
SERVICES_SLAASK_ENABLED=
SERVICES_SENTRY_ENABLED=
SERVICES_SENTRY_DSN=
SERVICES_SENTRY_AUTH_TOKEN=
SERVICES_SENTRY_PROJECT=
SERVICES_SENTRY_ORG=
2 changes: 1 addition & 1 deletion next-env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ declare module '*.graphql' {
declare interface Window {
ReactIntlLocaleData: any
__NEXT_DATA__: any
INIT_GA: any
INIT_GA?: any
}
32 changes: 28 additions & 4 deletions next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

const webpack = require('webpack')
const withCSS = require('@zeit/next-css')
const withSourceMaps = require('@zeit/next-source-maps')
const withSourceMaps = require('@zeit/next-source-maps')()
const { DEVELOPMENT_SERVER, PHASE_PRODUCTION_BUILD } = require('next/constants')
const SentryWebpackPlugin = require('@sentry/webpack-plugin')

const CFG = require('./src/klicker.conf.js')

Expand All @@ -13,16 +14,15 @@ const S3_CFG = CFG.get('s3')
const SECURITY_CFG = CFG.get('security')
const SERVICES_CFG = CFG.get('services')

const basePath = ''

module.exports = (phase) => {
let config = {
// custom runtime configuration
publicRuntimeConfig: {
analyticsTrackingID: SERVICES_CFG.googleAnalytics.trackingId,
apiUrl: API_CFG.endpoint,
apiUrlWS: API_CFG.endpointWS,
apmServerUrl: SERVICES_CFG.apm.serverUrl,
apmServiceName: SERVICES_CFG.apm.serviceName,
apmWithRum: SERVICES_CFG.apm.withRum,
baseUrl: APP_CFG.baseUrl,
joinUrl: APP_CFG.joinUrl,
logrocketAppID: SERVICES_CFG.logrocket.appId,
Expand All @@ -34,9 +34,16 @@ module.exports = (phase) => {
},
serverRuntimeConfig: {
apiUrlSSR: API_CFG.endpointSSR,
rootDir: __dirname,
},
// setup custom webpack configuration
webpack: (webpackConfig, { isServer }) => {
// replace the sentry library when rendering on the client
// ref: https://github.com/vercel/next.js/blob/canary/examples/with-sentry/next.config.js
if (!isServer) {
webpackConfig.resolve.alias['@sentry/node'] = '@sentry/browser'
}

// ignore test files when bundling
webpackConfig.plugins.push(new webpack.IgnorePlugin(/src\/pages.*\/test.*/))

Expand Down Expand Up @@ -77,6 +84,23 @@ module.exports = (phase) => {
type: 'javascript/auto',
})

if (
SERVICES_CFG.sentry.dsn &&
SERVICES_CFG.sentry.org &&
SERVICES_CFG.sentry.project &&
SERVICES_CFG.sentry.authToken &&
process.env.NODE_ENV === 'production'
)
webpackConfig.plugins.push(
new SentryWebpackPlugin({
include: '.next',
ignore: ['node_modules'],
stripPrefix: ['webpack://_N_E/'],
urlPrefix: `~${basePath}/_next`,
release: process.env.npm_package_version,
})
)

webpackConfig.resolve.extensions = ['.ts', '.tsx', '.mjs', '.js']

return webpackConfig
Expand Down
Loading

0 comments on commit 53a28c1

Please sign in to comment.