Skip to content

Commit 54243a5

Browse files
feat(monitoring): add Sentry error tracking with user feedback widget
- instrumentation.ts: server-side Sentry init (Node.js + Edge runtimes) - instrumentation-client.ts: client-side Sentry init with replay, feedback widget - next.config.ts: wrapped with withSentryConfig for source maps - app/global-error.tsx: captures unhandled errors to Sentry Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent f08c50f commit 54243a5

4 files changed

Lines changed: 67 additions & 1 deletion

File tree

app/global-error.tsx

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

instrumentation-client.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import * as Sentry from "@sentry/nextjs";
2+
3+
Sentry.init({
4+
dsn: "https://e40fdc0a3e5965c1862e6594a8c2631f@o4507789962706944.ingest.us.sentry.io/4507789965721600",
5+
tracesSampleRate: 1.0,
6+
replaysSessionSampleRate: 0.1,
7+
replaysOnErrorSampleRate: 1.0,
8+
integrations: [
9+
Sentry.replayIntegration(),
10+
Sentry.feedbackIntegration({
11+
colorScheme: "system",
12+
}),
13+
],
14+
});

instrumentation.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import * as Sentry from "@sentry/nextjs";
2+
3+
export async function register() {
4+
if (process.env.NEXT_RUNTIME === "nodejs") {
5+
Sentry.init({
6+
dsn: "https://e40fdc0a3e5965c1862e6594a8c2631f@o4507789962706944.ingest.us.sentry.io/4507789965721600",
7+
tracesSampleRate: 1.0,
8+
});
9+
}
10+
11+
if (process.env.NEXT_RUNTIME === "edge") {
12+
Sentry.init({
13+
dsn: "https://e40fdc0a3e5965c1862e6594a8c2631f@o4507789962706944.ingest.us.sentry.io/4507789965721600",
14+
tracesSampleRate: 1.0,
15+
});
16+
}
17+
}
18+
19+
export const onRequestError = Sentry.captureRequestError;

next.config.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type { NextConfig } from "next";
22
import createNextIntlPlugin from 'next-intl/plugin';
3+
import { withSentryConfig } from "@sentry/nextjs";
34

45
const withNextIntl = createNextIntlPlugin('./i18n.ts');
56

@@ -33,4 +34,11 @@ const nextConfig: NextConfig = {
3334
},
3435
};
3536

36-
export default withNextIntl(nextConfig);
37+
export default withSentryConfig(withNextIntl(nextConfig), {
38+
org: "guillermoscript",
39+
project: "lms-front",
40+
silent: !process.env.CI,
41+
widenClientFileUpload: true,
42+
disableLogger: true,
43+
automaticVercelMonitors: true,
44+
});

0 commit comments

Comments
 (0)