Skip to content

Commit 4061e02

Browse files
authored
Add Sentry for observability (#11)
1 parent fe3beaf commit 4061e02

9 files changed

+2393
-457
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,6 @@ yarn-error.log*
4343
# typescript
4444
*.tsbuildinfo
4545
next-env.d.ts
46+
47+
# Sentry Config File
48+
.env.sentry-build-plugin

next.config.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,18 @@
11
import type { NextConfig } from 'next'
22
import createMDX from '@next/mdx'
3+
import { withSentryConfig } from '@sentry/nextjs'
34

45
const nextConfig: NextConfig = {
5-
productionBrowserSourceMaps: true
6+
productionBrowserSourceMaps: true,
67
}
78

8-
export default createMDX({})(nextConfig)
9+
export default withSentryConfig(
10+
createMDX()(nextConfig),
11+
{
12+
org: 'cucumber-i5',
13+
project: 'cucumber-reports',
14+
silent: !process.env.CI,
15+
widenClientFileUpload: true,
16+
disableLogger: true,
17+
},
18+
)

package-lock.json

Lines changed: 2293 additions & 455 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
"@mdx-js/react": "^3.1.0",
2020
"@next/mdx": "^15.3.3",
2121
"@next/third-parties": "^15.3.3",
22+
"@sentry/nextjs": "^9.31.0",
2223
"@tailwindcss/typography": "^0.5.16",
2324
"@tanstack/react-query": "^5.64.2",
2425
"next": "15.3.3",

sentry.edge.config.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// This file configures the initialization of Sentry for edge features (middleware, edge routes, and so on).
2+
// The config you add here will be used whenever one of the edge features is loaded.
3+
// Note that this config is unrelated to the Vercel Edge Runtime and is also required when running locally.
4+
// https://docs.sentry.io/platforms/javascript/guides/nextjs/
5+
6+
import * as Sentry from '@sentry/nextjs'
7+
8+
Sentry.init({
9+
dsn: 'https://c3ae677edf55795aca256db1bb0e7aa3@o4509553056546816.ingest.us.sentry.io/4509553058250752',
10+
11+
// Define how likely traces are sampled. Adjust this value in production, or use tracesSampler for greater control.
12+
tracesSampleRate: 1,
13+
14+
// Setting this option to true will print useful information to the console while you're setting up Sentry.
15+
debug: false,
16+
})

sentry.server.config.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// This file configures the initialization of Sentry on the server.
2+
// The config you add here will be used whenever the server handles a request.
3+
// https://docs.sentry.io/platforms/javascript/guides/nextjs/
4+
5+
import * as Sentry from '@sentry/nextjs'
6+
7+
Sentry.init({
8+
dsn: 'https://c3ae677edf55795aca256db1bb0e7aa3@o4509553056546816.ingest.us.sentry.io/4509553058250752',
9+
10+
// Define how likely traces are sampled. Adjust this value in production, or use tracesSampler for greater control.
11+
tracesSampleRate: 1,
12+
13+
// Setting this option to true will print useful information to the console while you're setting up Sentry.
14+
debug: false,
15+
})

src/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 * as Sentry from '@sentry/nextjs'
4+
import NextError from 'next/error'
5+
import { useEffect } from 'react'
6+
7+
export default function GlobalError({ error }: { error: Error & { digest?: string } }) {
8+
useEffect(() => {
9+
Sentry.captureException(error)
10+
}, [error])
11+
12+
return (
13+
<html>
14+
<body>
15+
{/* `NextError` is the default Next.js error page component. Its type
16+
definition requires a `statusCode` prop. However, since the App Router
17+
does not expose status codes for errors, we simply pass 0 to render a
18+
generic error message. */}
19+
<NextError statusCode={0} />
20+
</body>
21+
</html>
22+
)
23+
}

src/instrumentation-client.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// This file configures the initialization of Sentry on the client.
2+
// The added config here will be used whenever a users loads a page in their browser.
3+
// https://docs.sentry.io/platforms/javascript/guides/nextjs/
4+
5+
import * as Sentry from '@sentry/nextjs'
6+
7+
Sentry.init({
8+
dsn: 'https://c3ae677edf55795aca256db1bb0e7aa3@o4509553056546816.ingest.us.sentry.io/4509553058250752',
9+
10+
// Define how likely traces are sampled. Adjust this value in production, or use tracesSampler for greater control.
11+
tracesSampleRate: 1,
12+
13+
// Setting this option to true will print useful information to the console while you're setting up Sentry.
14+
debug: false,
15+
})
16+
17+
export const onRouterTransitionStart = Sentry.captureRouterTransitionStart

src/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

0 commit comments

Comments
 (0)