Skip to content

Commit f05255b

Browse files
committed
fix(runtime): attempt to resolve http decoding error only in production, it may be due to sentry with node v22
1 parent 7f00201 commit f05255b

9 files changed

Lines changed: 2488 additions & 758 deletions
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1+
import type { Integration } from '@sentry/core';
12
import * as Sentry from '@sentry/nextjs';
23

34
import { beforeSend, dsn, environment, release } from '@etabli/src/utils/sentry';
45

5-
const integrations: any[] = [];
6+
const integrations: Integration[] = [];
67

78
Sentry.init({
89
dsn: dsn,
910
environment: environment,
1011
debug: false,
1112
release: release,
12-
autoSessionTracking: true,
1313
integrations,
1414
beforeSend: beforeSend,
1515
});

instrumentation-node.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import type { Integration } from '@sentry/core';
2+
import * as Sentry from '@sentry/nextjs';
3+
4+
import { beforeSend, dsn, environment, release } from '@etabli/src/utils/sentry';
5+
6+
const integrations: Integration[] = [];
7+
8+
Sentry.init({
9+
dsn: dsn,
10+
environment: environment,
11+
debug: false,
12+
release: release,
13+
integrations,
14+
beforeSend: beforeSend,
15+
});

instrumentation.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import * as Sentry from '@sentry/nextjs';
2+
3+
// Required by the Next.js App Router so server-side errors are forwarded to Sentry (replaces the v7 auto-capture)
4+
export const onRequestError = Sentry.captureRequestError;
5+
6+
export async function register() {
7+
// Only initialize for deployed environments (the DSN is also gated to production in `utils/sentry.ts`)
8+
if (process.env.NODE_ENV !== 'production') {
9+
return;
10+
}
11+
12+
if (process.env.NEXT_RUNTIME === 'nodejs') {
13+
await import('./instrumentation-node');
14+
}
15+
16+
if (process.env.NEXT_RUNTIME === 'edge') {
17+
await import('./instrumentation-edge');
18+
}
19+
20+
// Note: the browser SDK is initialized from `sentry.client.config.ts` (we are on Next 14, which does not support
21+
// the `instrumentation-client.ts` file — that one requires Next 15.3+).
22+
}

next.config.js

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ const moduleExports = async () => {
7171
], // Note that folders starting with a dot are already ignored after verification
7272
},
7373
swcPlugins: [['next-superjson-plugin', { excluded: [] }]],
74+
instrumentationHook: true, // [Next 14] required so `instrumentation.ts` `register()` runs server-side (it becomes the default in Next 15)
7475
},
7576
async rewrites() {
7677
return [
@@ -142,11 +143,6 @@ const moduleExports = async () => {
142143

143144
return config;
144145
},
145-
sentry: {
146-
hideSourceMaps: mode === 'prod', // Do not serve sourcemaps in `prod`
147-
// disableServerWebpackPlugin: true, // TODO
148-
// disableClientWebpackPlugin: true, // TODO
149-
},
150146
poweredByHeader: false,
151147
generateBuildId: async () => {
152148
return await getTechnicalVersion();
@@ -155,30 +151,35 @@ const moduleExports = async () => {
155151

156152
const uploadToSentry = process.env.SENTRY_RELEASE_UPLOAD === 'true' && process.env.NODE_ENV === 'production';
157153

158-
const sentryWebpackPluginOptions = {
159-
dryRun: !uploadToSentry,
154+
const sentryBuildOptions = {
155+
unstable_sentryWebpackPluginOptions: {
156+
disable: !uploadToSentry,
157+
},
160158
debug: false,
161159
silent: false,
162-
release: appHumanVersion,
163-
setCommits: {
164-
// TODO: get error: caused by: sentry reported an error: You do not have permission to perform this action. (http status: 403)
165-
// Possible ref: https://github.com/getsentry/sentry-cli/issues/1388#issuecomment-1306137835
166-
// Note: not able to bind our repository to our on-premise Sentry as specified in the article... leaving it manual for now (no commit details...)
167-
auto: false,
168-
commit: getCommitSha(),
169-
// auto: true,
160+
release: {
161+
name: appHumanVersion,
162+
setCommits: {
163+
// TODO: get error: caused by: sentry reported an error: You do not have permission to perform this action. (http status: 403)
164+
// Possible ref: https://github.com/getsentry/sentry-cli/issues/1388#issuecomment-1306137835
165+
// Note: not able to bind our repository to our on-premise Sentry as specified in the article... leaving it manual for now (no commit details...)
166+
auto: false,
167+
commit: getCommitSha(),
168+
},
169+
deploy: {
170+
env: mode,
171+
},
170172
},
171-
deploy: {
172-
env: mode,
173+
widenClientFileUpload: false,
174+
// tunnelRoute: '/monitoring', // Helpful to avoid adblockers, but requires Sentry SaaS
175+
sourcemaps: {
176+
disable: process.env.NODE_ENV === 'development',
177+
deleteSourcemapsAfterUpload: mode === 'prod', // do not serve sourcemaps in `prod` (replaces the former `hideSourceMaps`)
173178
},
179+
disableLogger: false,
174180
};
175181

176-
return withSentryConfig(standardModuleExports, sentryWebpackPluginOptions, {
177-
transpileClientSDK: true,
178-
// tunnelRoute: '/monitoring', // Helpful to avoid adblockers, but requires Sentry SaaS
179-
hideSourceMaps: false,
180-
disableLogger: false,
181-
});
182+
return withSentryConfig(standardModuleExports, sentryBuildOptions);
182183
};
183184

184185
module.exports = moduleExports;

0 commit comments

Comments
 (0)