Skip to content

Commit 7850fb5

Browse files
committed
func(sentry) : added sentry.
1 parent 3c2186e commit 7850fb5

11 files changed

+2667
-147
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,6 @@ yarn-error.log*
3434
# typescript
3535
*.tsbuildinfo
3636
next-env.d.ts
37+
38+
# Sentry Config File
39+
.env.sentry-build-plugin

app/api/sentry-example-api/route.ts

+9
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

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

app/sentry-example-page/page.tsx

+79
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
"use client";
2+
3+
import Head from "next/head";
4+
import * as Sentry from "@sentry/nextjs";
5+
6+
export default function Page() {
7+
return (
8+
<div>
9+
<Head>
10+
<title>Sentry Onboarding</title>
11+
<meta name="description" content="Test Sentry for your Next.js app!" />
12+
</Head>
13+
14+
<main
15+
style={{
16+
minHeight: "100vh",
17+
display: "flex",
18+
flexDirection: "column",
19+
justifyContent: "center",
20+
alignItems: "center",
21+
}}
22+
>
23+
<h1 style={{ fontSize: "4rem", margin: "14px 0" }}>
24+
<svg
25+
style={{
26+
height: "1em",
27+
}}
28+
xmlns="http://www.w3.org/2000/svg"
29+
viewBox="0 0 200 44"
30+
>
31+
<path
32+
fill="currentColor"
33+
d="M124.32,28.28,109.56,9.22h-3.68V34.77h3.73V15.19l15.18,19.58h3.26V9.22h-3.73ZM87.15,23.54h13.23V20.22H87.14V12.53h14.93V9.21H83.34V34.77h18.92V31.45H87.14ZM71.59,20.3h0C66.44,19.06,65,18.08,65,15.7c0-2.14,1.89-3.59,4.71-3.59a12.06,12.06,0,0,1,7.07,2.55l2-2.83a14.1,14.1,0,0,0-9-3c-5.06,0-8.59,3-8.59,7.27,0,4.6,3,6.19,8.46,7.52C74.51,24.74,76,25.78,76,28.11s-2,3.77-5.09,3.77a12.34,12.34,0,0,1-8.3-3.26l-2.25,2.69a15.94,15.94,0,0,0,10.42,3.85c5.48,0,9-2.95,9-7.51C79.75,23.79,77.47,21.72,71.59,20.3ZM195.7,9.22l-7.69,12-7.64-12h-4.46L186,24.67V34.78h3.84V24.55L200,9.22Zm-64.63,3.46h8.37v22.1h3.84V12.68h8.37V9.22H131.08ZM169.41,24.8c3.86-1.07,6-3.77,6-7.63,0-4.91-3.59-8-9.38-8H154.67V34.76h3.8V25.58h6.45l6.48,9.2h4.44l-7-9.82Zm-10.95-2.5V12.6h7.17c3.74,0,5.88,1.77,5.88,4.84s-2.29,4.86-5.84,4.86Z M29,2.26a4.67,4.67,0,0,0-8,0L14.42,13.53A32.21,32.21,0,0,1,32.17,40.19H27.55A27.68,27.68,0,0,0,12.09,17.47L6,28a15.92,15.92,0,0,1,9.23,12.17H4.62A.76.76,0,0,1,4,39.06l2.94-5a10.74,10.74,0,0,0-3.36-1.9l-2.91,5a4.54,4.54,0,0,0,1.69,6.24A4.66,4.66,0,0,0,4.62,44H19.15a19.4,19.4,0,0,0-8-17.31l2.31-4A23.87,23.87,0,0,1,23.76,44H36.07a35.88,35.88,0,0,0-16.41-31.8l4.67-8a.77.77,0,0,1,1.05-.27c.53.29,20.29,34.77,20.66,35.17a.76.76,0,0,1-.68,1.13H40.6q.09,1.91,0,3.81h4.78A4.59,4.59,0,0,0,50,39.43a4.49,4.49,0,0,0-.62-2.28Z"
34+
></path>
35+
</svg>
36+
</h1>
37+
38+
<p>Get started by sending us a sample error:</p>
39+
<button
40+
type="button"
41+
style={{
42+
padding: "12px",
43+
cursor: "pointer",
44+
backgroundColor: "#AD6CAA",
45+
borderRadius: "4px",
46+
border: "none",
47+
color: "white",
48+
fontSize: "14px",
49+
margin: "18px",
50+
}}
51+
onClick={async () => {
52+
await Sentry.startSpan({
53+
name: 'Example Frontend Span',
54+
op: 'test'
55+
}, async () => {
56+
const res = await fetch("/api/sentry-example-api");
57+
if (!res.ok) {
58+
throw new Error("Sentry Example Frontend Error");
59+
}
60+
});
61+
}}
62+
>
63+
Throw error!
64+
</button>
65+
66+
<p>
67+
Next, look for the error on the{" "}
68+
<a href="https://nvidia-bv.sentry.io/issues/?project=4507690696114256">Issues Page</a>.
69+
</p>
70+
<p style={{ marginTop: "24px" }}>
71+
For more information, see{" "}
72+
<a href="https://docs.sentry.io/platforms/javascript/guides/nextjs/">
73+
https://docs.sentry.io/platforms/javascript/guides/nextjs/
74+
</a>
75+
</p>
76+
</main>
77+
</div>
78+
);
79+
}

instrumentation.ts

+9
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.mjs

+35-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,42 @@
1+
import {withSentryConfig} from '@sentry/nextjs';
12
/** @type {import('next').NextConfig} */
23
const nextConfig = {
34
images: {
45
remotePatterns: [{ protocol: 'https' , hostname: 'img.clerk.com'}]
56
}
67
};
78

8-
export default nextConfig;
9+
export default withSentryConfig(nextConfig, {
10+
// For all available options, see:
11+
// https://github.com/getsentry/sentry-webpack-plugin#options
12+
13+
org: "nvidia-bv",
14+
project: "oss_doc",
15+
16+
// Only print logs for uploading source maps in CI
17+
silent: !process.env.CI,
18+
19+
// For all available options, see:
20+
// https://docs.sentry.io/platforms/javascript/guides/nextjs/manual-setup/
21+
22+
// Upload a larger set of source maps for prettier stack traces (increases build time)
23+
widenClientFileUpload: true,
24+
25+
// Uncomment to route browser requests to Sentry through a Next.js rewrite to circumvent ad-blockers.
26+
// This can increase your server load as well as your hosting bill.
27+
// Note: Check that the configured route will not match with your Next.js middleware, otherwise reporting of client-
28+
// side errors will fail.
29+
// tunnelRoute: "/monitoring",
30+
31+
// Hides source maps from generated client bundles
32+
hideSourceMaps: true,
33+
34+
// Automatically tree-shake Sentry logger statements to reduce bundle size
35+
disableLogger: true,
36+
37+
// Enables automatic instrumentation of Vercel Cron Monitors. (Does not yet work with App Router route handlers.)
38+
// See the following for more information:
39+
// https://docs.sentry.io/product/crons/
40+
// https://vercel.com/docs/cron-jobs
41+
automaticVercelMonitors: true,
42+
});

0 commit comments

Comments
 (0)