Skip to content

Commit f37baee

Browse files
committed
fix(nextjs): Use correct abs path for server init
closes #3648
1 parent 113be3a commit f37baee

File tree

4 files changed

+90
-83
lines changed

4 files changed

+90
-83
lines changed

packages/nextjs/package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,9 @@
5656
"test:watch": "jest --watch",
5757
"test:unit": "jest",
5858
"test:integration": "run-s test:integration:build test:integration:server test:integration:client",
59-
"test:integration:build": "cd test/integration && yarn && yarn build && cd ../..",
60-
"test:integration:server": "node test/integration/test/server.js --silent",
61-
"test:integration:client": "node test/integration/test/client.js --silent",
59+
"test:integration:build": "cd test/integration && rm -rf node_modules .next .env.local && yarn && yarn build",
60+
"test:integration:server": "cd test/integration && node test/server.js --silent",
61+
"test:integration:client": "cd test/integration && node test/client.js --silent",
6262
"pack": "npm pack",
6363
"vercel:branch": "source vercel/set-up-branch-for-test-app-use.sh",
6464
"vercel:project": "source vercel/make-project-use-current-branch.sh"

packages/nextjs/src/utils/config.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,10 @@ export function withSentryConfig(
158158
if (config.target === 'node') {
159159
const serverSDKInitOutputPath = path.join(config.output.path, SERVER_SDK_INIT_PATH);
160160
const projectDir = config.context;
161-
setRuntimeEnvVars(projectDir, { SENTRY_SERVER_INIT_PATH: serverSDKInitOutputPath });
161+
setRuntimeEnvVars(projectDir, {
162+
// ex: .next/server/sentry/initServerSdk.js
163+
SENTRY_SERVER_INIT_PATH: path.relative(projectDir, serverSDKInitOutputPath),
164+
});
162165
}
163166

164167
let newConfig = config;

packages/nextjs/src/utils/instrumentServer.ts

+7-3
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@ import { deepReadDirSync } from '@sentry/node';
22
import { extractTraceparentData, getActiveTransaction, hasTracingEnabled } from '@sentry/tracing';
33
import { Event as SentryEvent } from '@sentry/types';
44
import { fill, isString, logger, stripUrlQueryAndFragment } from '@sentry/utils';
5+
// import * as assert from 'assert';
56
import * as domain from 'domain';
67
import * as http from 'http';
78
import { default as createNextServer } from 'next';
9+
import * as path from 'path';
810
import * as querystring from 'querystring';
911
import * as url from 'url';
1012

@@ -114,11 +116,13 @@ function makeWrappedHandlerGetter(origHandlerGetter: HandlerGetter): WrappedHand
114116
try {
115117
// `SENTRY_SERVER_INIT_PATH` is set at build time, and points to a webpack-processed version of the user's
116118
// `sentry.server.config.js`. Requiring it starts the SDK.
117-
require(process.env.SENTRY_SERVER_INIT_PATH as string);
119+
require(path.resolve(process.env.SENTRY_SERVER_INIT_PATH as string));
118120
} catch (err) {
119121
// Log the error but don't bail - we still want the wrapping to happen, in case the user is doing something weird
120-
// and manually calling `Sentry.init()` somewhere else.
121-
logger.error(`[Sentry] Could not initialize SDK. Received error:\n${err}`);
122+
// and manually calling `Sentry.init()` somewhere else. We log to console instead of using logger from utils
123+
// because Sentry is not initialized.
124+
// eslint-disable-next-line no-console
125+
console.error(`[Sentry] Could not initialize SDK. Received error:\n${err}`);
122126
}
123127

124128
// stash this in the closure so that `makeWrappedReqHandler` can use it

packages/nextjs/test/integration/yarn.lock

+76-76
Original file line numberDiff line numberDiff line change
@@ -103,14 +103,14 @@
103103
resolved "https://registry.yarnpkg.com/@opentelemetry/context-base/-/context-base-0.14.0.tgz#c67fc20a4d891447ca1a855d7d70fa79a3533001"
104104
integrity sha512-sDOAZcYwynHFTbLo6n8kIbLiVF3a3BLkrmehJUyEbT9F+Smbi47kLGS2gG2g0fjBLR/Lr1InPD7kXL7FaTqEkw==
105105

106-
"@sentry/[email protected].0":
107-
version "6.5.0"
108-
resolved "https://registry.yarnpkg.com/@sentry/browser/-/browser-6.5.0.tgz#2382493691c3fac5d8b652ae46f09f1b29d288ef"
109-
integrity sha512-n1e8hNKwuVP4bLqRK5J0DHFqnnnrbv6h6+Bc1eNRbf32/e6eZ3Cb36PTplqDCxwnMnnIEEowd5F4ZWeTLPPY3A==
110-
dependencies:
111-
"@sentry/core" "6.5.0"
112-
"@sentry/types" "6.5.0"
113-
"@sentry/utils" "6.5.0"
106+
"@sentry/[email protected].1":
107+
version "6.5.1"
108+
resolved "https://registry.yarnpkg.com/@sentry/browser/-/browser-6.5.1.tgz#9a6ed5607b3b0f4e83f38720e3e202906f8c5bdb"
109+
integrity sha512-iVLCdEFwsoWAzE/hNknexPQjjDpMQV7mmaq9Z1P63bD6MfhwVTx4hG4pHn8HEvC38VvCVf1wv0v/LxtoODAYXg==
110+
dependencies:
111+
"@sentry/core" "6.5.1"
112+
"@sentry/types" "6.5.1"
113+
"@sentry/utils" "6.5.1"
114114
tslib "^1.9.3"
115115

116116
"@sentry/cli@^1.63.1":
@@ -125,106 +125,106 @@
125125
progress "^2.0.3"
126126
proxy-from-env "^1.1.0"
127127

128-
"@sentry/[email protected].0":
129-
version "6.5.0"
130-
resolved "https://registry.yarnpkg.com/@sentry/core/-/core-6.5.0.tgz#03ecbad7845b31f03a84eddf4884877c999bb6be"
131-
integrity sha512-Hx/WvhM5bXcXqfIiz+505TjYYfPjQ8mrxby/EWl+L7dYUCyI/W6IZKTc/MoHlLuM+JPUW9c1bw/97TzbgTzaAA==
128+
"@sentry/[email protected].1":
129+
version "6.5.1"
130+
resolved "https://registry.yarnpkg.com/@sentry/core/-/core-6.5.1.tgz#c8b6c3ed86ed07b193c95d599c1b9a4a161e500e"
131+
integrity sha512-Mh3sl/iUOT1myHmM6RlDy2ARzkUClx/g4DAt1rJ/IpQBOlDYQraplXSIW80i/hzRgQDfwhwgf4wUa5DicKBjKw==
132132
dependencies:
133-
"@sentry/hub" "6.5.0"
134-
"@sentry/minimal" "6.5.0"
135-
"@sentry/types" "6.5.0"
136-
"@sentry/utils" "6.5.0"
133+
"@sentry/hub" "6.5.1"
134+
"@sentry/minimal" "6.5.1"
135+
"@sentry/types" "6.5.1"
136+
"@sentry/utils" "6.5.1"
137137
tslib "^1.9.3"
138138

139-
"@sentry/[email protected].0":
140-
version "6.5.0"
141-
resolved "https://registry.yarnpkg.com/@sentry/hub/-/hub-6.5.0.tgz#ad3c9bcf83050ea217f3c25cc625e6b447f1d9d7"
142-
integrity sha512-vEChnLoozOJzEJoTUvaAsK/n7IHoQFx8P1TzQmnR+8XGZJZmGHG6bBXUH0iS2a9hhR1WkoEBeiL+t96R9uyf0A==
139+
"@sentry/[email protected].1":
140+
version "6.5.1"
141+
resolved "https://registry.yarnpkg.com/@sentry/hub/-/hub-6.5.1.tgz#135ef09d07d32e87a53f664c0ae8fcc4f5963519"
142+
integrity sha512-lBRMBVMYP8B4PfRiM70murbtJAXiIAao/asDEMIRNGMP6pI2ArqXfJCBYDkStukhikYD0Kqb4trXq+JYF07Hbg==
143143
dependencies:
144-
"@sentry/types" "6.5.0"
145-
"@sentry/utils" "6.5.0"
144+
"@sentry/types" "6.5.1"
145+
"@sentry/utils" "6.5.1"
146146
tslib "^1.9.3"
147147

148-
"@sentry/[email protected].0":
149-
version "6.5.0"
150-
resolved "https://registry.yarnpkg.com/@sentry/integrations/-/integrations-6.5.0.tgz#b97702f5d5e5456b9fae225b60141bd014671662"
151-
integrity sha512-pI8DESNTbsj60CDtLzIdLHex59NGzjTBR9Wpt7SG8NPhgEAuS3tUU4Thjyib7sGb7mxRw1sSQt/FsjDd7vMjLg==
148+
"@sentry/[email protected].1":
149+
version "6.5.1"
150+
resolved "https://registry.yarnpkg.com/@sentry/integrations/-/integrations-6.5.1.tgz#e7016f3023a98e2ef893daba18ba74bd8d62654b"
151+
integrity sha512-NYiW0rH7fwv7aRtrRnfCSIiwulfV2NoLjhmghCONsyo10DNtYmOpogLotCytZFWLDnTJW1+pmTomq8UW/OSTcQ==
152152
dependencies:
153-
"@sentry/types" "6.5.0"
154-
"@sentry/utils" "6.5.0"
153+
"@sentry/types" "6.5.1"
154+
"@sentry/utils" "6.5.1"
155155
localforage "^1.8.1"
156156
tslib "^1.9.3"
157157

158-
"@sentry/[email protected].0":
159-
version "6.5.0"
160-
resolved "https://registry.yarnpkg.com/@sentry/minimal/-/minimal-6.5.0.tgz#aa89b8e24c88aa85c99ef64e0b460497c90133f9"
161-
integrity sha512-MT83ONaBhTCFUlDIQFpsG/lq3ZjGK7jwQ10qxGadSg1KW6EvtQRg+OBwULeQ7C+nNEAhseNrC/qomZMT8brncg==
158+
"@sentry/[email protected].1":
159+
version "6.5.1"
160+
resolved "https://registry.yarnpkg.com/@sentry/minimal/-/minimal-6.5.1.tgz#b8c1b382c2ea788eec3d32d203e5081b00eb6838"
161+
integrity sha512-q9Do/oreu1RP695CXCLowVDuQyk7ilE6FGdz2QLpTXAfx8247qOwk6+zy9Kea/Djk93+BoSDVQUSneNiVwl0nQ==
162162
dependencies:
163-
"@sentry/hub" "6.5.0"
164-
"@sentry/types" "6.5.0"
163+
"@sentry/hub" "6.5.1"
164+
"@sentry/types" "6.5.1"
165165
tslib "^1.9.3"
166166

167167
"@sentry/nextjs@file:../..":
168-
version "6.5.0"
169-
dependencies:
170-
"@sentry/core" "6.5.0"
171-
"@sentry/integrations" "6.5.0"
172-
"@sentry/node" "6.5.0"
173-
"@sentry/react" "6.5.0"
174-
"@sentry/tracing" "6.5.0"
175-
"@sentry/utils" "6.5.0"
168+
version "6.5.1"
169+
dependencies:
170+
"@sentry/core" "6.5.1"
171+
"@sentry/integrations" "6.5.1"
172+
"@sentry/node" "6.5.1"
173+
"@sentry/react" "6.5.1"
174+
"@sentry/tracing" "6.5.1"
175+
"@sentry/utils" "6.5.1"
176176
"@sentry/webpack-plugin" "1.15.0"
177177
tslib "^1.9.3"
178178

179-
"@sentry/[email protected].0":
180-
version "6.5.0"
181-
resolved "https://registry.yarnpkg.com/@sentry/node/-/node-6.5.0.tgz#4c043792bae0b84de7c485fad605fd871be050a5"
182-
integrity sha512-KSypDtc8XPoyMdL1BCdkNokNmEaf+AZhD4HTElmIKHpIyiYvM1bSqiOpVohnwR3E+5qNeVVBPoVjDpHWRaNzQg==
179+
"@sentry/[email protected].1":
180+
version "6.5.1"
181+
resolved "https://registry.yarnpkg.com/@sentry/node/-/node-6.5.1.tgz#a572b380858de5aeaf98eade6d8d3afcba13d364"
182+
integrity sha512-Yh8J/QJ5e8gRBVL9VLCDpUvmiaxsxVZm0CInPHw3V/smgMkrzSKEiqxSeMq8ImPlaJrCFECqdpv4gnvYKI+mQQ==
183183
dependencies:
184-
"@sentry/core" "6.5.0"
185-
"@sentry/hub" "6.5.0"
186-
"@sentry/tracing" "6.5.0"
187-
"@sentry/types" "6.5.0"
188-
"@sentry/utils" "6.5.0"
184+
"@sentry/core" "6.5.1"
185+
"@sentry/hub" "6.5.1"
186+
"@sentry/tracing" "6.5.1"
187+
"@sentry/types" "6.5.1"
188+
"@sentry/utils" "6.5.1"
189189
cookie "^0.4.1"
190190
https-proxy-agent "^5.0.0"
191191
lru_map "^0.3.3"
192192
tslib "^1.9.3"
193193

194-
"@sentry/[email protected].0":
195-
version "6.5.0"
196-
resolved "https://registry.yarnpkg.com/@sentry/react/-/react-6.5.0.tgz#db2067e080cac24da046af24865b82d3567adbf4"
197-
integrity sha512-NyH+v8MwX+nzuhPRGy3+DHSB0es5yaCUNrtAdCtbe8EhERSoYvqAyWIQ+Fp5++PGjfAtYbz0W0IpsjguZbnT2Q==
194+
"@sentry/[email protected].1":
195+
version "6.5.1"
196+
resolved "https://registry.yarnpkg.com/@sentry/react/-/react-6.5.1.tgz#1c7019fc3d8b1168c1ab8936cb65971b314d060d"
197+
integrity sha512-YeGi7FzInhMZQxiy5fKqb7kS6W+u4NfsjzsVV3bLjJ1kiVtbpzZ2gs+ObHqW3zVE622V4nL7A4P8/CBHbcm5PA==
198198
dependencies:
199-
"@sentry/browser" "6.5.0"
200-
"@sentry/minimal" "6.5.0"
201-
"@sentry/types" "6.5.0"
202-
"@sentry/utils" "6.5.0"
199+
"@sentry/browser" "6.5.1"
200+
"@sentry/minimal" "6.5.1"
201+
"@sentry/types" "6.5.1"
202+
"@sentry/utils" "6.5.1"
203203
hoist-non-react-statics "^3.3.2"
204204
tslib "^1.9.3"
205205

206-
"@sentry/[email protected].0":
207-
version "6.5.0"
208-
resolved "https://registry.yarnpkg.com/@sentry/tracing/-/tracing-6.5.0.tgz#4d8efce53362a820d002838495f0ef446150aefc"
209-
integrity sha512-6jpmYM3Lt4w6dOeK8keGAis722ooLtX5UcPbekkTufXiqKRR5VWg8DLUp7z7oD6h4GLrLbeNtCiH6h20ZW2ggw==
206+
"@sentry/[email protected].1":
207+
version "6.5.1"
208+
resolved "https://registry.yarnpkg.com/@sentry/tracing/-/tracing-6.5.1.tgz#a5f3e497d4f1f319f36475df050e135cf65af750"
209+
integrity sha512-y1W/xFC2hAuKqSuuaovkElHY4pbli3XoXrreesg8PtO7ilX6ZbatOQbHsEsHQyoUv0F6aVA+MABOxWH2jt7tfw==
210210
dependencies:
211-
"@sentry/hub" "6.5.0"
212-
"@sentry/minimal" "6.5.0"
213-
"@sentry/types" "6.5.0"
214-
"@sentry/utils" "6.5.0"
211+
"@sentry/hub" "6.5.1"
212+
"@sentry/minimal" "6.5.1"
213+
"@sentry/types" "6.5.1"
214+
"@sentry/utils" "6.5.1"
215215
tslib "^1.9.3"
216216

217-
"@sentry/[email protected].0":
218-
version "6.5.0"
219-
resolved "https://registry.yarnpkg.com/@sentry/types/-/types-6.5.0.tgz#2cdb50875bb73d87708b9c0a80d4ca057b3596b5"
220-
integrity sha512-yQpTCIYxBsYT0GenqHNNKeXV8CSkkYlAxB1IGV2eac4IKC5ph5GW6TfDGwvlzQSQ297RsRmOSA8o3I5gGPd2yA==
217+
"@sentry/[email protected].1":
218+
version "6.5.1"
219+
resolved "https://registry.yarnpkg.com/@sentry/types/-/types-6.5.1.tgz#0a34ecfd1ae9275a416a105640eb4bed45a46a1d"
220+
integrity sha512-b/7a6CMoytaeFPx4IBjfxPw3nPvsQh7ui1C8Vw0LxNNDgBwVhPLzUOWeLWbo5YZCVbGEMIWwtCUQYWxneceZSA==
221221

222-
"@sentry/[email protected].0":
223-
version "6.5.0"
224-
resolved "https://registry.yarnpkg.com/@sentry/utils/-/utils-6.5.0.tgz#8722542b9a901623195cffaab5d18ce176c1e459"
225-
integrity sha512-CcHuaQN6vRuAsIC+3sA23NmWLRmUN0x/HNQxk0DHJylvYQdEA0AUNoLXogykaXh6NrCx4DNq9yCQTNTSC3mFxg==
222+
"@sentry/[email protected].1":
223+
version "6.5.1"
224+
resolved "https://registry.yarnpkg.com/@sentry/utils/-/utils-6.5.1.tgz#046baf7d1a6564d6d555437ad3674dba9bc0806a"
225+
integrity sha512-Wv86JYGQH+ZJ5XGFQX7h6ijl32667ikenoL9EyXMn8UoOYX/MLwZoQZin1P60wmKkYR9ifTNVmpaI9OoTaH+UQ==
226226
dependencies:
227-
"@sentry/types" "6.5.0"
227+
"@sentry/types" "6.5.1"
228228
tslib "^1.9.3"
229229

230230

0 commit comments

Comments
 (0)