Skip to content

Commit 196ed04

Browse files
authored
Merge pull request #13464 from ethereum/sentry
Sentry
2 parents 576e1ad + 7529d9b commit 196ed04

File tree

6 files changed

+1134
-19
lines changed

6 files changed

+1134
-19
lines changed

.env.example

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,11 @@ BUILD_LOCALES=
3333

3434
# If resource constraints are being hit during builds, change LIMIT_CPUS to a
3535
# fixed number of CPUs (e.g. 2) to limit the demand during build time
36-
LIMIT_CPUS=
36+
LIMIT_CPUS=
37+
38+
# Sentry auth token required for error tracking
39+
SENTRY_AUTH_TOKEN=
40+
NEXT_PUBLIC_SENTRY_DSN=
41+
42+
# Enables the bundle analyzer
43+
ANALYZE=false

instrumentation.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import * as Sentry from "@sentry/nextjs"
2+
3+
export async function register() {
4+
const dsn = process.env.NEXT_PUBLIC_SENTRY_DSN
5+
6+
if (!dsn) {
7+
console.warn("Sentry DSN not found, skipping")
8+
return
9+
}
10+
11+
const commonSentryOptions = {
12+
dsn,
13+
enabled: process.env.NODE_ENV === "production",
14+
tracesSampleRate: 1.0,
15+
}
16+
17+
if (process.env.NEXT_RUNTIME === "nodejs") {
18+
Sentry.init({
19+
...commonSentryOptions,
20+
})
21+
}
22+
23+
if (process.env.NEXT_RUNTIME === "edge") {
24+
Sentry.init({
25+
...commonSentryOptions,
26+
})
27+
}
28+
}

next.config.js

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
/* eslint-disable @typescript-eslint/no-var-requires */
22
const { PHASE_DEVELOPMENT_SERVER } = require("next/constants")
3+
const { withSentryConfig } = require("@sentry/nextjs")
4+
5+
const withBundleAnalyzer = require("@next/bundle-analyzer")({
6+
enabled: process.env.ANALYZE === "true",
7+
})
38

49
const { i18n } = require("./next-i18next.config")
510

@@ -22,7 +27,7 @@ module.exports = (phase, { defaultConfig }) => {
2227
let nextConfig = {
2328
...defaultConfig,
2429
reactStrictMode: true,
25-
webpack: (config) => {
30+
webpack: (config, { webpack }) => {
2631
config.module.rules.push({
2732
test: /\.ya?ml$/,
2833
use: "yaml-loader",
@@ -53,13 +58,30 @@ module.exports = (phase, { defaultConfig }) => {
5358
// Modify the file loader rule to ignore *.svg, since we have it handled now.
5459
fileLoaderRule.exclude = /\.svg$/i
5560

61+
// Tree shake Sentry debug code
62+
// ref. https://docs.sentry.io/platforms/javascript/guides/nextjs/configuration/tree-shaking/#tree-shaking-with-nextjs
63+
config.plugins.push(
64+
new webpack.DefinePlugin({
65+
__SENTRY_DEBUG__: false,
66+
__RRWEB_EXCLUDE_IFRAME__: true,
67+
__RRWEB_EXCLUDE_SHADOW_DOM__: true,
68+
__SENTRY_EXCLUDE_REPLAY_WORKER__: true,
69+
})
70+
)
71+
5672
return config
5773
},
5874
i18n,
5975
trailingSlash: true,
6076
images: {
6177
deviceSizes: [640, 750, 828, 1080, 1200, 1504, 1920],
6278
},
79+
env: {
80+
NEXT_PUBLIC_CONTEXT: process.env.CONTEXT,
81+
},
82+
experimental: {
83+
instrumentationHook: true,
84+
},
6385
}
6486

6587
if (phase !== PHASE_DEVELOPMENT_SERVER) {
@@ -88,5 +110,15 @@ module.exports = (phase, { defaultConfig }) => {
88110
}
89111
}
90112

91-
return nextConfig
113+
return withBundleAnalyzer(
114+
withSentryConfig(nextConfig, {
115+
// TODO: temp config, update this to the correct org & project
116+
org: "ethereumorg-ow",
117+
project: "javascript-nextjs",
118+
authToken: process.env.SENTRY_AUTH_TOKEN,
119+
release: `${process.env.BUILD_ID}_${process.env.REVIEW_ID}`,
120+
disableLogger: true,
121+
silent: true,
122+
})
123+
)
92124
}

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
"@emotion/react": "^11.11.1",
3535
"@emotion/styled": "^11.11.0",
3636
"@hookform/resolvers": "^3.8.0",
37+
"@next/bundle-analyzer": "^14.2.5",
3738
"@radix-ui/react-accordion": "^1.2.0",
3839
"@radix-ui/react-checkbox": "^1.1.1",
3940
"@radix-ui/react-dialog": "^1.1.1",
@@ -42,6 +43,7 @@
4243
"@radix-ui/react-radio-group": "^1.2.0",
4344
"@radix-ui/react-slot": "^1.1.0",
4445
"@radix-ui/react-visually-hidden": "^1.1.0",
46+
"@sentry/nextjs": "^8.19.0",
4547
"@socialgouv/matomo-next": "^1.8.0",
4648
"chart.js": "^4.4.2",
4749
"chartjs-plugin-datalabels": "^2.2.0",

sentry.client.config.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import * as Sentry from "@sentry/nextjs"
2+
3+
const dsn = process.env.NEXT_PUBLIC_SENTRY_DSN
4+
5+
Sentry.init({
6+
dsn,
7+
enabled: process.env.NODE_ENV === "production",
8+
environment: process.env.NEXT_PUBLIC_CONTEXT,
9+
tracesSampleRate: 1.0,
10+
})

0 commit comments

Comments
 (0)