Skip to content

Commit bfe3c98

Browse files
authored
🥅 chore: add sentry (lobehub#2048)
* 🥅 chore: add sentry modules * Update package.json
1 parent dbfa63f commit bfe3c98

5 files changed

+114
-1
lines changed

next.config.mjs

+47-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import nextPWA from '@ducanh2912/next-pwa';
22
import analyzer from '@next/bundle-analyzer';
3+
import { withSentryConfig } from '@sentry/nextjs';
34

45
const isProd = process.env.NODE_ENV === 'production';
56
const buildWithDocker = process.env.DOCKER === 'true';
@@ -69,4 +70,49 @@ const withPWA = isProd
6970
})
7071
: noWrapper;
7172

72-
export default withBundleAnalyzer(withPWA(nextConfig));
73+
const hasSentry = !!process.env.NEXT_PUBLIC_SENTRY_DSN;
74+
const withSentry =
75+
isProd && hasSentry
76+
? (c) =>
77+
withSentryConfig(
78+
c,
79+
{
80+
// For all available options, see:
81+
// https://github.com/getsentry/sentry-webpack-plugin#options
82+
83+
// Suppresses source map uploading logs during build
84+
silent: true,
85+
org: process.env.SENTRY_ORG,
86+
project: process.env.SENTRY_PROJECT,
87+
},
88+
{
89+
// For all available options, see:
90+
// https://docs.sentry.io/platforms/javascript/guides/nextjs/manual-setup/
91+
92+
// Upload a larger set of source maps for prettier stack traces (increases build time)
93+
widenClientFileUpload: true,
94+
95+
// Transpiles SDK to be compatible with IE11 (increases bundle size)
96+
transpileClientSDK: true,
97+
98+
// Routes browser requests to Sentry through a Next.js rewrite to circumvent ad-blockers. (increases server load)
99+
// Note: Check that the configured route will not match with your Next.js middleware, otherwise reporting of client-
100+
// side errors will fail.
101+
tunnelRoute: '/monitoring',
102+
103+
// Hides source maps from generated client bundles
104+
hideSourceMaps: true,
105+
106+
// Automatically tree-shake Sentry logger statements to reduce bundle size
107+
disableLogger: true,
108+
109+
// Enables automatic instrumentation of Vercel Cron Monitors.
110+
// See the following for more information:
111+
// https://docs.sentry.io/product/crons/
112+
// https://vercel.com/docs/cron-jobs
113+
automaticVercelMonitors: true,
114+
},
115+
)
116+
: noWrapper;
117+
118+
export default withBundleAnalyzer(withPWA(withSentry(nextConfig)));

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@
9494
"@lobehub/tts": "latest",
9595
"@lobehub/ui": "^1.137.7",
9696
"@next/third-parties": "^14.1.4",
97+
"@sentry/nextjs": "^7.105.0",
9798
"@vercel/analytics": "^1.2.2",
9899
"@vercel/speed-insights": "^1.0.10",
99100
"ahooks": "^3.7.11",

sentry.client.config.ts

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// This file configures the initialization of Sentry on the client.
2+
// The config you add here will be used whenever a users loads a page in their browser.
3+
// https://docs.sentry.io/platforms/javascript/guides/nextjs/
4+
import * as Sentry from '@sentry/nextjs';
5+
6+
if (!!process.env.NEXT_PUBLIC_SENTRY_DSN) {
7+
Sentry.init({
8+
// Setting this option to true will print useful information to the console while you're setting up Sentry.
9+
debug: false,
10+
11+
dsn: process.env.NEXT_PUBLIC_SENTRY_DSN,
12+
// You can remove this option if you're not planning to use the Sentry Session Replay feature:
13+
integrations: [
14+
Sentry.replayIntegration({
15+
blockAllMedia: true,
16+
// Additional Replay configuration goes in here, for example:
17+
maskAllText: true,
18+
}),
19+
],
20+
21+
replaysOnErrorSampleRate: 1,
22+
23+
// This sets the sample rate to be 10%. You may want this to be 100% while
24+
// in development and sample at a lower rate in production
25+
replaysSessionSampleRate: 0.1,
26+
27+
// Adjust this value in production, or use tracesSampler for greater control
28+
tracesSampleRate: 1,
29+
});
30+
}

sentry.edge.config.ts

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
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+
import * as Sentry from '@sentry/nextjs';
6+
7+
if (!!process.env.NEXT_PUBLIC_SENTRY_DSN) {
8+
Sentry.init({
9+
// Setting this option to true will print useful information to the console while you're setting up Sentry.
10+
debug: false,
11+
12+
dsn: process.env.NEXT_PUBLIC_SENTRY_DSN,
13+
14+
// Adjust this value in production, or use tracesSampler for greater control
15+
tracesSampleRate: 1,
16+
});
17+
}

sentry.server.config.ts

+19
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+
import * as Sentry from '@sentry/nextjs';
5+
6+
if (!!process.env.NEXT_PUBLIC_SENTRY_DSN) {
7+
Sentry.init({
8+
// Setting this option to true will print useful information to the console while you're setting up Sentry.
9+
debug: false,
10+
11+
dsn: process.env.NEXT_PUBLIC_SENTRY_DSN,
12+
13+
// Adjust this value in production, or use tracesSampler for greater control
14+
tracesSampleRate: 1,
15+
16+
// uncomment the line below to enable Spotlight (https://spotlightjs.com)
17+
// spotlight: process.env.NODE_ENV === 'development',
18+
});
19+
}

0 commit comments

Comments
 (0)