Skip to content

Commit 490a9cd

Browse files
committed
use parseRequest in instrumentServer
1 parent ef9f4de commit 490a9cd

File tree

1 file changed

+4
-27
lines changed

1 file changed

+4
-27
lines changed

packages/nextjs/src/utils/instrumentServer.ts

+4-27
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1-
import { captureException, deepReadDirSync, getCurrentHub, startTransaction } from '@sentry/node';
1+
import { captureException, deepReadDirSync, getCurrentHub, Handlers, startTransaction } from '@sentry/node';
22
import { extractTraceparentData, getActiveTransaction, hasTracingEnabled } from '@sentry/tracing';
3-
import { Event as SentryEvent } from '@sentry/types';
43
import { fill, isString, logger, stripUrlQueryAndFragment } from '@sentry/utils';
54
import * as domain from 'domain';
65
import * as http from 'http';
76
import { default as createNextServer } from 'next';
87
import * as querystring from 'querystring';
98
import * as url from 'url';
109

10+
const { parseRequest } = Handlers;
11+
1112
// eslint-disable-next-line @typescript-eslint/no-explicit-any
1213
type PlainObject<T = any> = { [key: string]: T };
1314

@@ -193,7 +194,7 @@ function makeWrappedReqHandler(origReqHandler: ReqHandler): WrappedReqHandler {
193194
const currentScope = getCurrentHub().getScope();
194195

195196
if (currentScope) {
196-
currentScope.addEventProcessor(event => addRequestDataToEvent(event, req));
197+
currentScope.addEventProcessor(event => parseRequest(event, req));
197198

198199
// We only want to record page and API requests
199200
if (hasTracingEnabled() && shouldTraceRequest(req.url, publicDirFiles)) {
@@ -288,27 +289,3 @@ function shouldTraceRequest(url: string, publicDirFiles: Set<string>): boolean {
288289
// `static` is a deprecated but still-functional location for static resources
289290
return !url.startsWith('/_next/') && !url.startsWith('/static/') && !publicDirFiles.has(url);
290291
}
291-
292-
/**
293-
* Harvest specific data from the request, and add it to the event.
294-
*
295-
* @param event The event to which to add request data
296-
* @param req The request whose data is being added
297-
* @returns The modified event
298-
*/
299-
export function addRequestDataToEvent(event: SentryEvent, req: NextRequest): SentryEvent {
300-
// TODO (breaking change): Replace all calls to this function with `parseRequest(event, req, { transaction: false })`
301-
// (this is breaking because doing so will change `event.request.url` from a path into an absolute URL, which might
302-
// mess up various automations in the Sentry web app - alert rules, auto assignment, saved searches, etc)
303-
event.request = {
304-
...event.request,
305-
data: req.body,
306-
url: req.url.split('?')[0],
307-
cookies: req.cookies,
308-
headers: req.headers,
309-
method: req.method,
310-
query_string: req.query,
311-
};
312-
313-
return event;
314-
}

0 commit comments

Comments
 (0)