|
1 | | -import { captureException, deepReadDirSync, getCurrentHub, startTransaction } from '@sentry/node'; |
| 1 | +import { captureException, deepReadDirSync, getCurrentHub, Handlers, startTransaction } from '@sentry/node'; |
2 | 2 | import { extractTraceparentData, getActiveTransaction, hasTracingEnabled } from '@sentry/tracing'; |
3 | | -import { Event as SentryEvent } from '@sentry/types'; |
4 | 3 | import { fill, isString, logger, stripUrlQueryAndFragment } from '@sentry/utils'; |
5 | 4 | import * as domain from 'domain'; |
6 | 5 | import * as http from 'http'; |
7 | 6 | import { default as createNextServer } from 'next'; |
8 | 7 | import * as querystring from 'querystring'; |
9 | 8 | import * as url from 'url'; |
10 | 9 |
|
| 10 | +const { parseRequest } = Handlers; |
| 11 | + |
11 | 12 | // eslint-disable-next-line @typescript-eslint/no-explicit-any |
12 | 13 | type PlainObject<T = any> = { [key: string]: T }; |
13 | 14 |
|
@@ -193,7 +194,7 @@ function makeWrappedReqHandler(origReqHandler: ReqHandler): WrappedReqHandler { |
193 | 194 | const currentScope = getCurrentHub().getScope(); |
194 | 195 |
|
195 | 196 | if (currentScope) { |
196 | | - currentScope.addEventProcessor(event => addRequestDataToEvent(event, req)); |
| 197 | + currentScope.addEventProcessor(event => parseRequest(event, req)); |
197 | 198 |
|
198 | 199 | // We only want to record page and API requests |
199 | 200 | if (hasTracingEnabled() && shouldTraceRequest(req.url, publicDirFiles)) { |
@@ -288,27 +289,3 @@ function shouldTraceRequest(url: string, publicDirFiles: Set<string>): boolean { |
288 | 289 | // `static` is a deprecated but still-functional location for static resources |
289 | 290 | return !url.startsWith('/_next/') && !url.startsWith('/static/') && !publicDirFiles.has(url); |
290 | 291 | } |
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