Skip to content

Commit 7cecea9

Browse files
committed
feat(sentry): add new required config changes, disable trace
1 parent 1702929 commit 7cecea9

File tree

9 files changed

+557
-448
lines changed

9 files changed

+557
-448
lines changed

next.config.mjs

Lines changed: 15 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -23,47 +23,33 @@ const nextConfig = {
2323
},
2424
],
2525
},
26+
webpack: (config, { webpack }) => {
27+
config.plugins.push(
28+
new webpack.DefinePlugin({
29+
__SENTRY_DEBUG__: false,
30+
__SENTRY_TRACING__: false,
31+
__RRWEB_EXCLUDE_IFRAME__: true,
32+
__RRWEB_EXCLUDE_SHADOW_DOM__: true,
33+
__SENTRY_EXCLUDE_REPLAY_WORKER__: true,
34+
}),
35+
);
36+
37+
// return the modified config
38+
return config;
39+
},
2640
};
2741

2842
export default withSentryConfig(withBundleAnalyzer(nextConfig), {
29-
// For all available options, see:
30-
// https://github.com/getsentry/sentry-webpack-plugin#options
31-
3243
org: 'jobstash',
3344
project: 'ecosystemvision',
34-
35-
// Only print logs for uploading source maps in CI
3645
silent: !process.env.CI,
37-
38-
// For all available options, see:
39-
// https://docs.sentry.io/platforms/javascript/guides/nextjs/manual-setup/
40-
41-
// Upload a larger set of source maps for prettier stack traces (increases build time)
4246
widenClientFileUpload: true,
43-
44-
// Automatically annotate React components to show their full name in breadcrumbs and session replay
4547
reactComponentAnnotation: {
4648
enabled: true,
4749
},
48-
49-
// Route browser requests to Sentry through a Next.js rewrite to circumvent ad-blockers.
50-
// This can increase your server load as well as your hosting bill.
51-
// Note: Check that the configured route will not match with your Next.js middleware, otherwise reporting of client-
52-
// side errors will fail.
53-
tunnelRoute: '/monitoring',
54-
55-
// Hides source maps from generated client bundles
50+
tunnelRoute: '/sentry-tunnel',
5651
hideSourceMaps: true,
57-
58-
// Automatically tree-shake Sentry logger statements to reduce bundle size
5952
disableLogger: true,
60-
61-
// Enables automatic instrumentation of Vercel Cron Monitors. (Does not yet work with App Router route handlers.)
62-
// See the following for more information:
63-
// https://docs.sentry.io/product/crons/
64-
// https://vercel.com/docs/cron-jobs
65-
automaticVercelMonitors: true,
66-
6753
sourcemaps: {
6854
deleteSourcemapsAfterUpload: true,
6955
},

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
"private": true,
55
"scripts": {
66
"dev": "next dev",
7-
"prebuild": "node tools/scripts/generate-sitemap.js",
87
"build": "next build",
98
"start": "next start",
109
"lint": "eslint ./src",
@@ -28,7 +27,7 @@
2827
"@heroui/react": "2.6.14",
2928
"@next/bundle-analyzer": "^14.2.5",
3029
"@next/third-parties": "^15.0.3",
31-
"@sentry/nextjs": "^9.1.0",
30+
"@sentry/nextjs": "^9.14.0",
3231
"@splinetool/react-spline": "^4.0.0",
3332
"@splinetool/runtime": "^1.9.28",
3433
"@tanstack/react-query": "^5.66.7",

pnpm-lock.yaml

Lines changed: 432 additions & 296 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sentry.client.config.ts

Lines changed: 0 additions & 49 deletions
This file was deleted.

sentry.edge.config.ts

Lines changed: 0 additions & 33 deletions
This file was deleted.

sentry.server.config.ts

Lines changed: 0 additions & 33 deletions
This file was deleted.

src/app/sentry-tunnel/route.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
const SENTRY_HOST = 'o4504495959703552.ingest.us.sentry.io';
2+
const SENTRY_PROJECT_IDS = ['4504526099447808'];
3+
4+
export const POST = async (req: Request) => {
5+
try {
6+
const envelopeBytes = await req.arrayBuffer();
7+
const envelope = new TextDecoder().decode(envelopeBytes);
8+
const piece = envelope.split('\n')[0];
9+
const header = JSON.parse(piece);
10+
const dsn = new URL(header['dsn']);
11+
const project_id = dsn.pathname?.replace('/', '');
12+
13+
if (dsn.hostname !== SENTRY_HOST) {
14+
throw new Error(`Invalid sentry hostname: ${dsn.hostname}`);
15+
}
16+
17+
if (!project_id || !SENTRY_PROJECT_IDS.includes(project_id)) {
18+
throw new Error(`Invalid sentry project id: ${project_id}`);
19+
}
20+
21+
const upstream_sentry_url = `https://${SENTRY_HOST}/api/${project_id}/envelope/`;
22+
await fetch(upstream_sentry_url, {
23+
method: 'POST',
24+
body: envelopeBytes,
25+
});
26+
27+
return Response.json({}, { status: 200 });
28+
} catch (e) {
29+
console.error('error tunneling to sentry', e);
30+
return Response.json(
31+
{ error: 'error tunneling to sentry' },
32+
{ status: 500 },
33+
);
34+
}
35+
};

src/instrumentation-client.ts

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import {
2+
breadcrumbsIntegration,
3+
browserApiErrorsIntegration,
4+
BrowserClient,
5+
captureRouterTransitionStart,
6+
dedupeIntegration,
7+
defaultStackParser,
8+
eventFiltersIntegration,
9+
getCurrentScope,
10+
globalHandlersIntegration,
11+
httpClientIntegration,
12+
httpContextIntegration,
13+
linkedErrorsIntegration,
14+
makeFetchTransport,
15+
} from '@sentry/nextjs';
16+
17+
const client = new BrowserClient({
18+
dsn: 'https://d9c07cf404c1777bcf744cb901dfc7c2@o4504495959703552.ingest.us.sentry.io/4504526099447808',
19+
tunnel: '/sentry-tunnel',
20+
tracesSampleRate: 0,
21+
replaysSessionSampleRate: 0,
22+
replaysOnErrorSampleRate: 0,
23+
debug: false,
24+
transport: makeFetchTransport,
25+
stackParser: defaultStackParser,
26+
integrations: [
27+
eventFiltersIntegration(),
28+
breadcrumbsIntegration(),
29+
globalHandlersIntegration(),
30+
linkedErrorsIntegration(),
31+
dedupeIntegration(),
32+
browserApiErrorsIntegration(),
33+
httpClientIntegration(),
34+
httpContextIntegration(),
35+
],
36+
37+
denyUrls: [/extensions\//i, /^chrome:\/\//i, /^chrome-extension:\/\//i],
38+
beforeSend(event) {
39+
const hasStack = event.exception?.values?.some((e) => e.stacktrace);
40+
return hasStack ? event : null;
41+
},
42+
});
43+
44+
if (process.env.NODE_ENV === 'production') {
45+
getCurrentScope().setClient(client);
46+
client.init();
47+
}
48+
49+
export const onRouterTransitionStart = captureRouterTransitionStart;

src/instrumentation.ts

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,28 @@
1+
import * as Sentry from '@sentry/nextjs';
2+
3+
const SENTRY_DSN =
4+
'https://0d295254822c41989ea49baec3c31a6d@o4504495959703552.ingest.us.sentry.io/4504526099447808';
5+
16
export async function register() {
2-
if (process.env.NEXT_RUNTIME === 'nodejs') {
3-
await import('../sentry.server.config');
4-
}
7+
if (process.env.NODE_ENV !== 'production') return;
8+
9+
Sentry.init({
10+
dsn: SENTRY_DSN,
11+
tracesSampleRate: 1,
12+
debug: false,
13+
denyUrls: [/extensions\//i, /^chrome:\/\//i, /^chrome-extension:\/\//i],
14+
beforeSend(event) {
15+
const hasStackTrace = event?.exception?.values?.some(
16+
(exceptionValue) => exceptionValue.stacktrace,
17+
);
518

6-
if (process.env.NEXT_RUNTIME === 'edge') {
7-
await import('../sentry.edge.config');
8-
}
19+
if (!hasStackTrace) {
20+
return null;
21+
}
22+
23+
return event;
24+
},
25+
});
926
}
27+
28+
export const onRequestError = Sentry.captureRequestError;

0 commit comments

Comments
 (0)