Skip to content

Commit ddf9ced

Browse files
committed
merge with master
2 parents b9e7022 + 997a782 commit ddf9ced

File tree

9 files changed

+152
-99
lines changed

9 files changed

+152
-99
lines changed

packages/integrations/src/rewriteframes.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,16 +54,18 @@ export class RewriteFrames implements Integration {
5454
}
5555

5656
/** JSDoc */
57-
public process(event: Event): Event {
58-
if (event.exception && Array.isArray(event.exception.values)) {
59-
return this._processExceptionsEvent(event);
57+
public process(originalEvent: Event): Event {
58+
let processedEvent = originalEvent;
59+
60+
if (originalEvent.exception && Array.isArray(originalEvent.exception.values)) {
61+
processedEvent = this._processExceptionsEvent(processedEvent);
6062
}
6163

62-
if (event.stacktrace) {
63-
return this._processStacktraceEvent(event);
64+
if (originalEvent.stacktrace) {
65+
processedEvent = this._processStacktraceEvent(processedEvent);
6466
}
6567

66-
return event;
68+
return processedEvent;
6769
}
6870

6971
/**

packages/nextjs/package.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,11 @@
5555
"test": "run-s test:unit test:integration",
5656
"test:watch": "jest --watch",
5757
"test:unit": "jest",
58-
"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",
58+
"test:integration": "run-s test:integration:clean test:integration:build test:integration:server test:integration:client",
59+
"test:integration:clean": "cd test/integration && rimraf node_modules .next .env.local",
60+
"test:integration:build": "cd test/integration && yarn && yarn build",
61+
"test:integration:server": "cd test/integration && node test/server.js --silent",
62+
"test:integration:client": "cd test/integration && node test/client.js --silent",
6263
"pack": "npm pack",
6364
"vercel:branch": "source vercel/set-up-branch-for-test-app-use.sh",
6465
"vercel:project": "source vercel/make-project-use-current-branch.sh",

packages/nextjs/src/utils/config.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import * as path from 'path';
77

88
const SENTRY_CLIENT_CONFIG_FILE = './sentry.client.config.js';
99
const SENTRY_SERVER_CONFIG_FILE = './sentry.server.config.js';
10-
// this is where the transpiled/bundled version of `USER_SERVER_CONFIG_FILE` will end up
10+
// this is where the transpiled/bundled version of `SENTRY_SERVER_CONFIG_FILE` will end up
1111
export const SERVER_SDK_INIT_PATH = 'sentry/initServerSDK.js';
1212

1313
// eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -21,7 +21,7 @@ type WebpackConfig = {
2121
devtool: string;
2222
plugins: PlainObject[];
2323
entry: EntryProperty;
24-
output: { path: string };
24+
output: { filename: string; path: string };
2525
target: string;
2626
context: string;
2727
};
@@ -156,9 +156,13 @@ export function withSentryConfig(
156156
// if we're building server code, store the webpack output path as an env variable, so we know where to look for the
157157
// webpack-processed version of `sentry.server.config.js` when we need it
158158
if (config.target === 'node') {
159-
const serverSDKInitOutputPath = path.join(config.output.path, SERVER_SDK_INIT_PATH);
159+
const outputLocation = path.dirname(path.join(config.output.path, config.output.filename));
160+
const serverSDKInitOutputPath = path.join(outputLocation, SERVER_SDK_INIT_PATH);
160161
const projectDir = config.context;
161-
setRuntimeEnvVars(projectDir, { SENTRY_SERVER_INIT_PATH: serverSDKInitOutputPath });
162+
setRuntimeEnvVars(projectDir, {
163+
// ex: .next/server/sentry/initServerSdk.js
164+
SENTRY_SERVER_INIT_PATH: path.relative(projectDir, serverSDKInitOutputPath),
165+
});
162166
}
163167

164168
let newConfig = config;

packages/nextjs/src/utils/instrumentServer.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { fill, isString, logger, stripUrlQueryAndFragment } from '@sentry/utils'
55
import * as domain from 'domain';
66
import * as http from 'http';
77
import { default as createNextServer } from 'next';
8+
import * as path from 'path';
89
import * as querystring from 'querystring';
910
import * as url from 'url';
1011

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

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

packages/nextjs/test/integration/test/client/sessionNavigate.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ module.exports = async ({ page, url, requests }) => {
2424
errors: 0,
2525
});
2626

27+
await sleep(100);
28+
2729
expectSession(requests.sessions[2], {
2830
init: true,
2931
status: 'ok',

packages/nextjs/test/integration/yarn.lock

Lines changed: 76 additions & 76 deletions
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

packages/node/src/transports/base.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { logger, parseRetryAfterHeader, PromiseBuffer, SentryError } from '@sent
1515
import * as fs from 'fs';
1616
import * as http from 'http';
1717
import * as https from 'https';
18-
import * as url from 'url';
18+
import { URL } from 'url';
1919

2020
import { SDK_NAME } from '../version';
2121

@@ -30,7 +30,7 @@ export interface HTTPModule {
3030
* @param callback Callback when request is finished
3131
*/
3232
request(
33-
options: http.RequestOptions | https.RequestOptions | string | url.URL,
33+
options: http.RequestOptions | https.RequestOptions | string | URL,
3434
callback?: (res: http.IncomingMessage) => void,
3535
): http.ClientRequest;
3636

@@ -39,12 +39,15 @@ export interface HTTPModule {
3939
// versions:
4040

4141
// request(
42-
// url: string | url.URL,
42+
// url: string | URL,
4343
// options: http.RequestOptions | https.RequestOptions,
4444
// callback?: (res: http.IncomingMessage) => void,
4545
// ): http.ClientRequest;
4646
}
4747

48+
export type URLParts = Pick<URL, 'hostname' | 'pathname' | 'port' | 'protocol'>;
49+
export type UrlParser = (url: string) => URLParts;
50+
4851
const CATEGORY_MAPPING: {
4952
[key in SentryRequestType]: string;
5053
} = {
@@ -76,6 +79,9 @@ export abstract class BaseTransport implements Transport {
7679
this._api = new API(options.dsn, options._metadata);
7780
}
7881

82+
/** Default function used to parse URLs */
83+
public urlParser: UrlParser = url => new URL(url);
84+
7985
/**
8086
* @inheritDoc
8187
*/
@@ -119,12 +125,12 @@ export abstract class BaseTransport implements Transport {
119125
}
120126

121127
/** Returns a build request option object used by request */
122-
protected _getRequestOptions(uri: url.URL): http.RequestOptions | https.RequestOptions {
128+
protected _getRequestOptions(urlParts: URLParts): http.RequestOptions | https.RequestOptions {
123129
const headers = {
124130
...this._api.getRequestHeaders(SDK_NAME, SDK_VERSION),
125131
...this.options.headers,
126132
};
127-
const { hostname, pathname, port, protocol } = uri;
133+
const { hostname, pathname, port, protocol } = urlParts;
128134
// See https://github.com/nodejs/node/blob/38146e717fed2fabe3aacb6540d839475e0ce1c6/lib/internal/url.js#L1268-L1290
129135
// We ignore the query string on purpose
130136
const path = `${pathname}`;
@@ -224,7 +230,7 @@ export abstract class BaseTransport implements Transport {
224230
if (!this.module) {
225231
throw new SentryError('No module available');
226232
}
227-
const options = this._getRequestOptions(new url.URL(sentryReq.url));
233+
const options = this._getRequestOptions(this.urlParser(sentryReq.url));
228234
const req = this.module.request(options, (res: http.IncomingMessage) => {
229235
const statusCode = res.statusCode || 500;
230236
const status = Status.fromHttpCode(statusCode);

0 commit comments

Comments
 (0)