Skip to content

Commit 4e39950

Browse files
committed
add sentery
1 parent 761545b commit 4e39950

10 files changed

Lines changed: 180 additions & 18 deletions

File tree

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,6 @@ yarn-error.log*
4141
next-env.d.ts
4242

4343
# Sentry
44-
.sentryclirc
44+
.sentryclirc
45+
# Sentry Config File
46+
.env.sentry-build-plugin

next.config.js

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,4 +117,46 @@ const nextConfig = {
117117
},
118118
};
119119

120-
module.exports = nextConfig;
120+
module.exports = nextConfig;
121+
122+
// Injected content via Sentry wizard below
123+
124+
const { withSentryConfig } = require("@sentry/nextjs");
125+
126+
module.exports = withSentryConfig(module.exports, {
127+
// For all available options, see:
128+
// https://www.npmjs.com/package/@sentry/webpack-plugin#options
129+
130+
org: "sentry",
131+
project: "metaverse-rang-front-nextjs",
132+
sentryUrl: "https://sentry.irpsc.com/",
133+
134+
// Only print logs for uploading source maps in CI
135+
silent: !process.env.CI,
136+
137+
// For all available options, see:
138+
// https://docs.sentry.io/platforms/javascript/guides/nextjs/manual-setup/
139+
140+
// Upload a larger set of source maps for prettier stack traces (increases build time)
141+
widenClientFileUpload: true,
142+
143+
// Uncomment to route browser requests to Sentry through a Next.js rewrite to circumvent ad-blockers.
144+
// This can increase your server load as well as your hosting bill.
145+
// Note: Check that the configured route will not match with your Next.js middleware, otherwise reporting of client-
146+
// side errors will fail.
147+
// tunnelRoute: "/monitoring",
148+
149+
webpack: {
150+
// Enables automatic instrumentation of Vercel Cron Monitors. (Does not yet work with App Router route handlers.)
151+
// See the following for more information:
152+
// https://docs.sentry.io/product/crons/
153+
// https://vercel.com/docs/cron-jobs
154+
automaticVercelMonitors: true,
155+
156+
// Tree-shaking options for reducing bundle size
157+
treeshake: {
158+
// Automatically tree-shake Sentry logger statements to reduce bundle size
159+
removeDebugLogging: true,
160+
},
161+
},
162+
});

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"overrides": {
1414
"quill": "2.0.2",
1515
"minimatch": "^9.0.6",
16-
"postcss": "^8.5.10"
16+
"postcss": "^8.5.10"
1717
},
1818
"dependencies": {
1919
"@emotion/react": "^11.13.3",
@@ -24,6 +24,7 @@
2424
"@next/font": "^13.4.19",
2525
"@react-three/drei": "^9.115.0",
2626
"@react-three/fiber": "^8.17.10",
27+
"@sentry/nextjs": "^10.55.0",
2728
"@supabase/supabase-js": "^2.81.1",
2829
"@tailwindcss/typography": "^0.5.16",
2930
"@types/node": "18.16.3",
@@ -86,7 +87,6 @@
8687
"@types/three": "^0.152.1",
8788
"autoprefixer": "^10.4.22",
8889
"eslint-config-next": "^13.3.4",
89-
9090
"postcss-import": "^16.1.1",
9191
"postcss-nesting": "^12.1.5",
9292
"tailwindcss": "^3.4.4",

sentry.edge.config.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
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://64009d742bfce4127fe796d3def9b69d@sentry.irpsc.com/8",
10+
11+
// Define how likely traces are sampled. Adjust this value in production, or use tracesSampler for greater control.
12+
tracesSampleRate: 1,
13+
14+
// Enable logs to be sent to Sentry
15+
enableLogs: true,
16+
17+
// Enable sending user PII (Personally Identifiable Information)
18+
// https://docs.sentry.io/platforms/javascript/guides/nextjs/configuration/options/#sendDefaultPii
19+
sendDefaultPii: true,
20+
});

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://64009d742bfce4127fe796d3def9b69d@sentry.irpsc.com/8",
9+
10+
// Define how likely traces are sampled. Adjust this value in production, or use tracesSampler for greater control.
11+
tracesSampleRate: 1,
12+
13+
// Enable logs to be sent to Sentry
14+
enableLogs: true,
15+
16+
// Enable sending user PII (Personally Identifiable Information)
17+
// https://docs.sentry.io/platforms/javascript/guides/nextjs/configuration/options/#sendDefaultPii
18+
sendDefaultPii: true,
19+
});
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import * as Sentry from "@sentry/nextjs";
2+
export const dynamic = "force-dynamic";
3+
4+
class SentryExampleAPIError extends Error {
5+
constructor(message: string | undefined) {
6+
super(message);
7+
this.name = "SentryExampleAPIError";
8+
}
9+
}
10+
11+
// A faulty API route to test Sentry's error monitoring
12+
export function GET() {
13+
Sentry.logger.info("Sentry example API called");
14+
throw new SentryExampleAPIError(
15+
"This error is raised on the backend called by the example page.",
16+
);
17+
}

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

src/components/module/footer/Footer.tsx

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -236,20 +236,11 @@ function Footer({ footerTabs, mainData, params }: any) {
236236
</p>
237237
</div>
238238
<div className="flex items-center justify-center px-5">
239-
<a
240-
referrerPolicy="origin"
241-
target="_blank"
242-
href="https://trustseal.enamad.ir/?id=721065&Code=fLkLFNhooBCR33C1ntVXIBxJFAj9gf3q"
243-
rel="noreferrer"
244-
>
245-
<img
246-
referrerPolicy="origin"
247-
src="https://trustseal.enamad.ir/logo.aspx?id=721065&Code=fLkLFNhooBCR33C1ntVXIBxJFAj9gf3q"
248-
alt="اینماد"
249-
style={{ cursor: "pointer" }}
250-
data-code="fLkLFNhooBCR33C1ntVXIBxJFAj9gf3q"
251-
/>
252-
</a>
239+
<div
240+
dangerouslySetInnerHTML={{
241+
__html: `<a referrerpolicy='origin' target='_blank' href='https://trustseal.enamad.ir/?id=721065&Code=fLkLFNhooBCR33C1ntVXIBxJFAj9gf3q'><img referrerpolicy='origin' src='https://trustseal.enamad.ir/logo.aspx?id=721065&Code=fLkLFNhooBCR33C1ntVXIBxJFAj9gf3q' alt='' style='cursor:pointer' code='fLkLFNhooBCR33C1ntVXIBxJFAj9gf3q'></a>`,
242+
}}
243+
/>
253244
</div>
254245
<div className="xl:col-span-2 col-span-6 mt-6 w-full flex flex-col items-center ">
255246
<p className="text-center w-full font-medium font-azarMehr text-[20px] text-[#4C4C4C] dark:text-white">

src/instrumentation-client.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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: process.env.NEXT_PUBLIC_SENTRY_DSN,
9+
10+
// Add optional integrations for additional features
11+
integrations: [Sentry.replayIntegration()],
12+
13+
// Define how likely traces are sampled. Adjust this value in production, or use tracesSampler for greater control.
14+
tracesSampleRate: 1,
15+
// Enable logs to be sent to Sentry
16+
enableLogs: true,
17+
18+
// Define how likely Replay events are sampled.
19+
// This sets the sample rate to be 10%. You may want this to be 100% while
20+
// in development and sample at a lower rate in production
21+
replaysSessionSampleRate: 0.1,
22+
23+
// Define how likely Replay events are sampled when an error occurs.
24+
replaysOnErrorSampleRate: 1.0,
25+
26+
// Enable sending user PII (Personally Identifiable Information)
27+
// https://docs.sentry.io/platforms/javascript/guides/nextjs/configuration/options/#sendDefaultPii
28+
sendDefaultPii: true,
29+
});
30+
31+
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)