Skip to content

Commit 71d09da

Browse files
devakoneclaude
andcommitted
feat: add Sentry error tracking
Configure Sentry for client, server, and edge runtime error monitoring. Files placed in apps/web/ for monorepo compatibility. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent cb5f40c commit 71d09da

8 files changed

Lines changed: 2247 additions & 224 deletions

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,6 @@ coverage/
7070
*.pid
7171
*.seed
7272
*.pem
73+
74+
# Sentry Config File
75+
.env.sentry-build-plugin

apps/web/instrumentation-client.js

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: "https://0ddc11d7b3f42d5ca32ecf0b74ff61ef@o4510870266118144.ingest.us.sentry.io/4510870274899968",
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;

apps/web/instrumentation.js

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;

apps/web/next.config.ts

Lines changed: 16 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 path from "node:path";
34

@@ -34,4 +35,18 @@ const nextConfig: NextConfig = {
3435
},
3536
};
3637

37-
export default nextConfig;
38+
export default withSentryConfig(nextConfig, {
39+
// For all available options, see:
40+
// https://www.npmjs.com/package/@sentry/webpack-plugin#options
41+
org: "100kode",
42+
project: "javascript-nextjs",
43+
44+
// Only print logs for uploading source maps in CI
45+
silent: !process.env.CI,
46+
47+
// Upload a larger set of source maps for prettier stack traces (increases build time)
48+
widenClientFileUpload: true,
49+
50+
// Route browser requests to Sentry through a Next.js rewrite to circumvent ad-blockers.
51+
tunnelRoute: "/monitoring",
52+
});

apps/web/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"test:watch": "vitest"
1313
},
1414
"dependencies": {
15+
"@sentry/nextjs": "^10.38.0",
1516
"@radix-ui/react-dropdown-menu": "^2.1.16",
1617
"@radix-ui/react-popover": "^1.1.15",
1718
"@radix-ui/react-toast": "^1.2.15",

apps/web/sentry.edge.config.js

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://0ddc11d7b3f42d5ca32ecf0b74ff61ef@o4510870266118144.ingest.us.sentry.io/4510870274899968",
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+
});

apps/web/sentry.server.config.js

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://0ddc11d7b3f42d5ca32ecf0b74ff61ef@o4510870266118144.ingest.us.sentry.io/4510870274899968",
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+
});

0 commit comments

Comments
 (0)