Skip to content

Commit f0c14e5

Browse files
committed
setup contexts for sentry
1 parent 8c14b3e commit f0c14e5

File tree

5 files changed

+34
-20
lines changed

5 files changed

+34
-20
lines changed

instrumentation.ts

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

623
if (process.env.NEXT_RUNTIME === "edge") {
7-
await import("./sentry.edge.config")
24+
Sentry.init({
25+
...commonSentryOptions,
26+
})
827
}
928
}

next.config.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,12 @@ module.exports = (phase, { defaultConfig }) => {
5555
images: {
5656
deviceSizes: [640, 750, 828, 1080, 1200, 1504, 1920],
5757
},
58+
env: {
59+
NEXT_PUBLIC_CONTEXT: process.env.CONTEXT,
60+
},
61+
experimental: {
62+
instrumentationHook: true,
63+
},
5864
}
5965

6066
if (phase !== PHASE_DEVELOPMENT_SERVER) {
@@ -89,9 +95,9 @@ module.exports = (phase, { defaultConfig }) => {
8995
org: "ethereumorg-ow",
9096
project: "javascript-nextjs",
9197
authToken: process.env.SENTRY_AUTH_TOKEN,
92-
silent: true,
93-
disableLogger: true,
9498
release: `${process.env.BUILD_ID}_${process.env.REVIEW_ID}`,
99+
disableLogger: true,
100+
silent: true,
95101
})
96102
)
97103
}

sentry.client.config.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
import * as Sentry from "@sentry/nextjs"
22

3+
const dns = process.env.NEXT_PUBLIC_SENTRY_DSN
4+
35
Sentry.init({
4-
dsn: process.env.NEXT_PUBLIC_SENTRY_DSN,
5-
enabled: process.env.CONTEXT === "production",
6+
dsn: dns,
7+
enabled: process.env.NODE_ENV === "production",
8+
environment: process.env.NEXT_PUBLIC_CONTEXT,
69
tracesSampleRate: 1.0,
710
})

sentry.edge.config.ts

Lines changed: 0 additions & 7 deletions
This file was deleted.

sentry.server.config.ts

Lines changed: 0 additions & 7 deletions
This file was deleted.

0 commit comments

Comments
 (0)