Skip to content

Commit 723dfbf

Browse files
codercatdevAlex Patterson
andauthored
Sentry (#588)
* add sentry * add auth token --------- Co-authored-by: Alex Patterson <alex.patterson@fusionauth.io>
1 parent cbcdf1a commit 723dfbf

10 files changed

Lines changed: 1767 additions & 93 deletions

‎.gitignore‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,6 @@ next-env.d.ts
3939

4040
# Env files created by scripts for working locally
4141
.env
42-
.env.local
42+
.env.local
43+
# Sentry Config File
44+
.env.sentry-build-plugin
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { NextResponse } from "next/server";
2+
3+
export const dynamic = "force-dynamic";
4+
5+
// A faulty API route to test Sentry's error monitoring
6+
export function GET() {
7+
throw new Error("Sentry Example API Route Error");
8+
return NextResponse.json({ data: "Testing Sentry Error..." });
9+
}

‎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+
}

‎instrumentation.ts‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
export async function register() {
2+
if (process.env.NEXT_RUNTIME === 'nodejs') {
3+
await import('./sentry.server.config');
4+
}
5+
6+
if (process.env.NEXT_RUNTIME === 'edge') {
7+
await import('./sentry.edge.config');
8+
}
9+
}

‎next.config.js‎

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,47 @@ module.exports = {
55
taint: true,
66
},
77
};
8+
9+
10+
// Injected content via Sentry wizard below
11+
12+
const { withSentryConfig } = require("@sentry/nextjs");
13+
14+
module.exports = withSentryConfig(
15+
module.exports,
16+
{
17+
// For all available options, see:
18+
// https://github.com/getsentry/sentry-webpack-plugin#options
19+
20+
org: "codingcatdev",
21+
project: "main-codingcat-dev",
22+
authToken: process.env.SENTRY_AUTH_TOKEN,
23+
24+
// Only print logs for uploading source maps in CI
25+
silent: !process.env.CI,
26+
27+
// For all available options, see:
28+
// https://docs.sentry.io/platforms/javascript/guides/nextjs/manual-setup/
29+
30+
// Upload a larger set of source maps for prettier stack traces (increases build time)
31+
widenClientFileUpload: true,
32+
33+
// Route browser requests to Sentry through a Next.js rewrite to circumvent ad-blockers.
34+
// This can increase your server load as well as your hosting bill.
35+
// Note: Check that the configured route will not match with your Next.js middleware, otherwise reporting of client-
36+
// side errors will fail.
37+
tunnelRoute: "/monitoring",
38+
39+
// Hides source maps from generated client bundles
40+
hideSourceMaps: true,
41+
42+
// Automatically tree-shake Sentry logger statements to reduce bundle size
43+
disableLogger: true,
44+
45+
// Enables automatic instrumentation of Vercel Cron Monitors. (Does not yet work with App Router route handlers.)
46+
// See the following for more information:
47+
// https://docs.sentry.io/product/crons/
48+
// https://vercel.com/docs/cron-jobs
49+
automaticVercelMonitors: true,
50+
}
51+
);

‎package.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
"@sanity/ui": "^2.1.14",
5757
"@sanity/vision": "^3.44.0",
5858
"@sanity/webhook": "^4.0.4",
59+
"@sentry/nextjs": "^8",
5960
"@types/node": "^20.13.0",
6061
"@types/react": "^18.3.3",
6162
"@types/react-dom": "^18.3.0",

‎pnpm-lock.yaml‎

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

‎sentry.client.config.ts‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// This file configures the initialization of Sentry on the client.
2+
// The config you add 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://076379982c5a04c49899c2f8172f35db@o1029244.ingest.us.sentry.io/4507489501708288",
9+
10+
// 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+
replaysOnErrorSampleRate: 1.0,
17+
18+
// This sets the sample rate to be 10%. You may want this to be 100% while
19+
// in development and sample at a lower rate in production
20+
replaysSessionSampleRate: 0.1,
21+
22+
// You can remove this option if you're not planning to use the Sentry Session Replay feature:
23+
integrations: [
24+
Sentry.replayIntegration({
25+
// Additional Replay configuration goes in here, for example:
26+
maskAllText: true,
27+
blockAllMedia: true,
28+
}),
29+
],
30+
});

‎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://076379982c5a04c49899c2f8172f35db@o1029244.ingest.us.sentry.io/4507489501708288",
10+
11+
// 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: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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://076379982c5a04c49899c2f8172f35db@o1029244.ingest.us.sentry.io/4507489501708288",
9+
10+
// 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+
// Uncomment the line below to enable Spotlight (https://spotlightjs.com)
17+
// spotlight: process.env.NODE_ENV === 'development',
18+
19+
});

0 commit comments

Comments
 (0)