Skip to content

Commit 67309fe

Browse files
committed
fix: disable sentry when debugging with vscode
1 parent 7963565 commit 67309fe

File tree

3 files changed

+58
-46
lines changed

3 files changed

+58
-46
lines changed

.vscode/launch.json

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,20 @@
66
"configurations": [
77
{
88
"name": "Next.js: debug full stack",
9-
"type": "node-terminal",
9+
"type": "node",
1010
"request": "launch",
11-
"command": "npm run dev",
11+
"program": "${workspaceFolder}/node_modules/next/dist/bin/next",
12+
"runtimeArgs": ["--inspect"],
13+
"skipFiles": ["<node_internals>/**"],
14+
"env": {
15+
"NEXT_PUBLIC_SENTRY_DISABLED": "true"
16+
},
1217
"serverReadyAction": {
18+
"action": "debugWithChrome",
19+
"killOnServerStop": true,
1320
"pattern": "- Local:.+(https?://.+)",
1421
"uriFormat": "%s",
15-
"action": "debugWithChrome"
22+
"webRoot": "${workspaceFolder}"
1623
}
1724
}
1825
]

next.config.ts

Lines changed: 41 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import createNextIntlPlugin from 'next-intl/plugin';
55
import './src/libs/Env';
66

77
// Define the base Next.js configuration
8-
let nextConfig: NextConfig = {
8+
const baseConfig: NextConfig = {
99
eslint: {
1010
dirs: ['.'],
1111
},
@@ -15,46 +15,49 @@ let nextConfig: NextConfig = {
1515
};
1616

1717
// Initialize the Next-Intl plugin
18-
nextConfig = createNextIntlPlugin('./src/libs/i18n.ts')(nextConfig);
18+
let configWithPlugins = createNextIntlPlugin('./src/libs/i18n.ts')(baseConfig);
1919

2020
// Conditionally enable bundle analysis
2121
if (process.env.ANALYZE === 'true') {
22-
nextConfig = withBundleAnalyzer()(nextConfig);
22+
configWithPlugins = withBundleAnalyzer()(configWithPlugins);
2323
}
2424

25-
// Sentry configuration
26-
const sentryOptions = {
27-
// For all available options, see:
28-
// https://www.npmjs.com/package/@sentry/webpack-plugin#options
29-
// FIXME: Add your Sentry organization and project names
30-
org: 'nextjs-boilerplate-org',
31-
project: 'nextjs-boilerplate',
32-
33-
// Only print logs for uploading source maps in CI
34-
silent: !process.env.CI,
35-
36-
// For all available options, see:
37-
// https://docs.sentry.io/platforms/javascript/guides/nextjs/manual-setup/
38-
39-
// Upload a larger set of source maps for prettier stack traces (increases build time)
40-
widenClientFileUpload: true,
41-
42-
// Upload a larger set of source maps for prettier stack traces (increases build time)
43-
reactComponentAnnotation: {
44-
enabled: true,
45-
},
46-
47-
// Route browser requests to Sentry through a Next.js rewrite to circumvent ad-blockers.
48-
// This can increase your server load as well as your hosting bill.
49-
// Note: Check that the configured route will not match with your Next.js middleware, otherwise reporting of client-
50-
// side errors will fail.
51-
tunnelRoute: '/monitoring',
52-
53-
// Automatically tree-shake Sentry logger statements to reduce bundle size
54-
disableLogger: true,
55-
56-
// Disable Sentry telemetry
57-
telemetry: false,
58-
};
25+
// Conditionally enable Sentry configuration
26+
if (!process.env.NEXT_PUBLIC_SENTRY_DISABLED) {
27+
configWithPlugins = withSentryConfig(configWithPlugins, {
28+
// For all available options, see:
29+
// https://www.npmjs.com/package/@sentry/webpack-plugin#options
30+
// FIXME: Add your Sentry organization and project names
31+
org: 'nextjs-boilerplate-org',
32+
project: 'nextjs-boilerplate',
33+
34+
// Only print logs for uploading source maps in CI
35+
silent: !process.env.CI,
36+
37+
// For all available options, see:
38+
// https://docs.sentry.io/platforms/javascript/guides/nextjs/manual-setup/
39+
40+
// Upload a larger set of source maps for prettier stack traces (increases build time)
41+
widenClientFileUpload: true,
42+
43+
// Upload a larger set of source maps for prettier stack traces (increases build time)
44+
reactComponentAnnotation: {
45+
enabled: true,
46+
},
47+
48+
// Route browser requests to Sentry through a Next.js rewrite to circumvent ad-blockers.
49+
// This can increase your server load as well as your hosting bill.
50+
// Note: Check that the configured route will not match with your Next.js middleware, otherwise reporting of client-
51+
// side errors will fail.
52+
tunnelRoute: '/monitoring',
53+
54+
// Automatically tree-shake Sentry logger statements to reduce bundle size
55+
disableLogger: true,
56+
57+
// Disable Sentry telemetry
58+
telemetry: false,
59+
});
60+
}
5961

60-
export default withSentryConfig(nextConfig, sentryOptions);
62+
const nextConfig = configWithPlugins;
63+
export default nextConfig;

src/instrumentation.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,16 @@ const sentryOptions: Sentry.NodeOptions | Sentry.EdgeOptions = {
1818
};
1919

2020
export async function register() {
21-
if (process.env.NEXT_RUNTIME === 'nodejs') {
21+
if (!process.env.NEXT_PUBLIC_SENTRY_DISABLED) {
22+
if (process.env.NEXT_RUNTIME === 'nodejs') {
2223
// Node.js Sentry configuration
23-
Sentry.init(sentryOptions);
24-
}
24+
Sentry.init(sentryOptions);
25+
}
2526

26-
if (process.env.NEXT_RUNTIME === 'edge') {
27+
if (process.env.NEXT_RUNTIME === 'edge') {
2728
// Edge Sentry configuration
28-
Sentry.init(sentryOptions);
29+
Sentry.init(sentryOptions);
30+
}
2931
}
3032
}
3133

0 commit comments

Comments
 (0)