Skip to content

Commit 4b423ee

Browse files
authored
Merge pull request #16061 from ethereum/sentry
Sentry setup
2 parents b670c75 + f859698 commit 4b423ee

9 files changed

+1394
-17
lines changed

app/global-error.tsx

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
"use client"
2+
3+
import { useEffect } from "react"
4+
import NextError from "next/error"
5+
import * as Sentry from "@sentry/nextjs"
6+
7+
export default function GlobalError({
8+
error,
9+
}: {
10+
error: Error & { digest?: string }
11+
}) {
12+
useEffect(() => {
13+
Sentry.captureException(error)
14+
}, [error])
15+
16+
return (
17+
<html>
18+
<body>
19+
<NextError statusCode={0} />
20+
</body>
21+
</html>
22+
)
23+
}

app/layout.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import { ReactNode } from "react"
2+
import type { Metadata } from "next"
3+
import * as Sentry from "@sentry/nextjs"
24

35
import "@/styles/global.css"
46

@@ -11,3 +13,12 @@ type Props = {
1113
export default function RootLayout({ children }: Props) {
1214
return children
1315
}
16+
17+
// Sentry trace data
18+
export function generateMetadata(): Metadata {
19+
return {
20+
other: {
21+
...Sentry.getTraceData(),
22+
},
23+
}
24+
}

instrumentation-client.ts

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

instrumentation.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import * as Sentry from "@sentry/nextjs"
2+
3+
export async function register() {
4+
if (process.env.NEXT_RUNTIME === "nodejs") {
5+
await import("./sentry.server.config")
6+
}
7+
8+
if (process.env.NEXT_RUNTIME === "edge") {
9+
await import("./sentry.edge.config")
10+
}
11+
}
12+
13+
export const onRequestError = Sentry.captureRequestError

next.config.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ const withBundleAnalyzer = require("@next/bundle-analyzer")({
77

88
const createNextIntlPlugin = require("next-intl/plugin")
99

10+
const { withSentryConfig } = require("@sentry/nextjs")
11+
1012
const withNextIntl = createNextIntlPlugin()
1113

1214
const LIMIT_CPUS = Number(process.env.LIMIT_CPUS ?? 2)
@@ -28,6 +30,11 @@ module.exports = (phase, { defaultConfig }) => {
2830
let nextConfig = {
2931
...defaultConfig,
3032
reactStrictMode: true,
33+
env: {
34+
// Context is used to determine the environment for Sentry
35+
// ref. https://docs.netlify.com/configure-builds/environment-variables/#build-metadata
36+
NEXT_PUBLIC_CONTEXT: process.env.CONTEXT,
37+
},
3138
webpack: (config) => {
3239
config.module.rules.push({
3340
test: /\.ya?ml$/,
@@ -143,6 +150,12 @@ module.exports = (phase, { defaultConfig }) => {
143150
"node_modules/@swc/core-linux-x64-gnu",
144151
"node_modules/@swc/core-linux-x64-musl",
145152
"node_modules/@esbuild/linux-x64",
153+
"node_modules/@sentry/cli/**/*",
154+
"node_modules/sharp/**/*",
155+
"node_modules/three/**/*",
156+
"node_modules/canvas/**/*",
157+
"node_modules/@playwright/**/*",
158+
"node_modules/chromium-bidi/**/*",
146159
"src/data",
147160
"public/**/*.jpg",
148161
"public/**/*.png",
@@ -164,3 +177,12 @@ module.exports = (phase, { defaultConfig }) => {
164177

165178
return withBundleAnalyzer(withNextIntl(nextConfig))
166179
}
180+
181+
module.exports = withSentryConfig(module.exports, {
182+
org: "ethereumorg-ow",
183+
project: "ethorg",
184+
silent: true,
185+
widenClientFileUpload: true,
186+
disableLogger: true,
187+
automaticVercelMonitors: true,
188+
})

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
"@radix-ui/react-tooltip": "^1.1.2",
5555
"@radix-ui/react-visually-hidden": "^1.1.0",
5656
"@rainbow-me/rainbowkit": "^2.2.3",
57+
"@sentry/nextjs": "^10.5.0",
5758
"@socialgouv/matomo-next": "^1.8.0",
5859
"@tanstack/react-query": "^5.66.7",
5960
"@tanstack/react-table": "^8.19.3",

0 commit comments

Comments
 (0)