Skip to content

Commit 5fbff7f

Browse files
Merge pull request #307 from DevLoversTeam/feature/sentry
(SP: 2) [Monitoring] Add Sentry for production error tracking
2 parents dd79c1b + 05d9429 commit 5fbff7f

9 files changed

Lines changed: 7710 additions & 5783 deletions

frontend/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,6 @@ next-env.d.ts
4848
CLAUDE.md
4949
_dev-notes/
5050
.claude
51+
52+
# Sentry Config File
53+
.env.sentry-build-plugin

frontend/app/global-error.tsx

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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({
8+
error,
9+
}: {
10+
error: Error & { digest?: string };
11+
}) {
12+
useEffect(() => {
13+
Sentry.captureException(error);
14+
}, [error]);
15+
16+
return (
17+
<html lang="en">
18+
<body>
19+
{/* `NextError` is the default Next.js error page component. Its type
20+
definition requires a `statusCode` prop. However, since the App Router
21+
does not expose status codes for errors, we simply pass 0 to render a
22+
generic error message. */}
23+
<NextError statusCode={0} />
24+
</body>
25+
</html>
26+
);
27+
}

frontend/instrumentation-client.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+
const isProduction =
4+
process.env.NEXT_PUBLIC_VERCEL_ENV === 'production' ||
5+
process.env.NODE_ENV === 'production';
6+
7+
Sentry.init({
8+
dsn: process.env.NEXT_PUBLIC_SENTRY_DSN,
9+
10+
enabled: isProduction,
11+
12+
tracesSampleRate: 0.1,
13+
14+
environment: process.env.NEXT_PUBLIC_VERCEL_ENV || process.env.NODE_ENV,
15+
16+
release: process.env.NEXT_PUBLIC_VERCEL_GIT_COMMIT_SHA,
17+
18+
sendDefaultPii: false,
19+
});

frontend/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;

frontend/next.config.ts

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { withSentryConfig } from '@sentry/nextjs';
12
import type { NextConfig } from 'next';
23
import createNextIntlPlugin from 'next-intl/plugin';
34

@@ -50,4 +51,40 @@ const nextConfig: NextConfig = {
5051
},
5152
};
5253

53-
export default withNextIntl(nextConfig);
54+
export default withSentryConfig(withNextIntl(nextConfig), {
55+
// For all available options, see:
56+
// https://www.npmjs.com/package/@sentry/webpack-plugin#options
57+
58+
org: "devlovers",
59+
60+
project: "devlovers-nextjs",
61+
62+
// Only print logs for uploading source maps in CI
63+
silent: !process.env.CI,
64+
65+
// For all available options, see:
66+
// https://docs.sentry.io/platforms/javascript/guides/nextjs/manual-setup/
67+
68+
// Upload a larger set of source maps for prettier stack traces (increases build time)
69+
widenClientFileUpload: true,
70+
71+
// Uncomment to route browser requests to Sentry through a Next.js rewrite to circumvent ad-blockers.
72+
// This can increase your server load as well as your hosting bill.
73+
// Note: Check that the configured route will not match with your Next.js middleware, otherwise reporting of client-
74+
// side errors will fail.
75+
// tunnelRoute: "/monitoring",
76+
77+
webpack: {
78+
// Enables automatic instrumentation of Vercel Cron Monitors. (Does not yet work with App Router route handlers.)
79+
// See the following for more information:
80+
// https://docs.sentry.io/product/crons/
81+
// https://vercel.com/docs/cron-jobs
82+
automaticVercelMonitors: true,
83+
84+
// Tree-shaking options for reducing bundle size
85+
treeshake: {
86+
// Automatically tree-shake Sentry logger statements to reduce bundle size
87+
removeDebugLogging: true,
88+
},
89+
},
90+
});

0 commit comments

Comments
 (0)