@@ -5,17 +5,19 @@ import { VERSION } from '@opentelemetry/core';
55import type { InstrumentationConfig } from '@opentelemetry/instrumentation' ;
66import { InstrumentationBase , InstrumentationNodeModuleDefinition } from '@opentelemetry/instrumentation' ;
77import { getRequestInfo } from '@opentelemetry/instrumentation-http' ;
8- import { addBreadcrumb , dropUndefinedKeys , getClient , getIsolationScope , withIsolationScope } from '@sentry/core' ;
98import {
10- extractQueryParamsFromUrl ,
9+ addBreadcrumb ,
1110 getBreadcrumbLogLevelFromHttpStatusCode ,
11+ getClient ,
12+ getIsolationScope ,
1213 getSanitizedUrlString ,
13- headersToDict ,
14+ httpRequestToRequestData ,
1415 logger ,
1516 parseUrl ,
1617 stripUrlQueryAndFragment ,
18+ withIsolationScope ,
1719} from '@sentry/core' ;
18- import type { PolymorphicRequest , RequestEventData , SanitizedRequestData , Scope } from '@sentry/types' ;
20+ import type { RequestEventData , SanitizedRequestData , Scope } from '@sentry/types' ;
1921import { DEBUG_BUILD } from '../../debug-build' ;
2022import type { NodeClient } from '../../sdk/client' ;
2123import { getRequestUrl } from '../../utils/getRequestUrl' ;
@@ -133,7 +135,8 @@ export class SentryHttpInstrumentation extends InstrumentationBase<SentryHttpIns
133135
134136 const isolationScope = getIsolationScope ( ) . clone ( ) ;
135137 const request = args [ 0 ] as http . IncomingMessage ;
136- const normalizedRequest = httpRequestToRequestEventData ( request ) ;
138+
139+ const normalizedRequest = httpRequestToRequestData ( request ) ;
137140
138141 patchRequestToCaptureBody ( request , isolationScope ) ;
139142
@@ -428,32 +431,3 @@ function patchRequestToCaptureBody(req: IncomingMessage, isolationScope: Scope):
428431 // ignore errors if we can't patch stuff
429432 }
430433}
431-
432- /**
433- * Convert a HTTP request object to RequestEventData to be passed as normalizedRequest.
434- */
435- export function httpRequestToRequestEventData ( request : IncomingMessage ) : RequestEventData {
436- const headers = request . headers || { } ;
437- const host = headers . host || '<no host>' ;
438- const protocol = request . socket && ( request . socket as { encrypted ?: boolean } ) . encrypted ? 'https' : 'http' ;
439- const originalUrl = request . url || '' ;
440- const absoluteUrl = originalUrl . startsWith ( protocol ) ? originalUrl : `${ protocol } ://${ host } ${ originalUrl } ` ;
441-
442- // This is non-standard, but may be sometimes set
443- // It may be overwritten later by our own body handling
444- const data = ( request as PolymorphicRequest ) . body ;
445-
446- // This is non-standard, but may be set on e.g. Next.js or Express requests
447- const cookies = ( request as PolymorphicRequest ) . cookies ;
448-
449- const normalizedRequest : RequestEventData = dropUndefinedKeys ( {
450- url : absoluteUrl ,
451- method : request . method ,
452- query_string : extractQueryParamsFromUrl ( originalUrl ) ,
453- headers : headersToDict ( headers ) ,
454- cookies,
455- data,
456- } ) ;
457-
458- return normalizedRequest ;
459- }
0 commit comments