@@ -6,7 +6,7 @@ import type { InstrumentationConfig } from '@opentelemetry/instrumentation';
6
6
import { InstrumentationBase , InstrumentationNodeModuleDefinition } from '@opentelemetry/instrumentation' ;
7
7
import { getRequestInfo } from '@opentelemetry/instrumentation-http' ;
8
8
import { addBreadcrumb , getClient , getIsolationScope , setNormalizedRequest , withIsolationScope } from '@sentry/core' ;
9
- import type { PolymorphicRequest , RequestEventData , SanitizedRequestData } from '@sentry/types' ;
9
+ import type { PolymorphicRequest , RequestEventData , SanitizedRequestData , Scope } from '@sentry/types' ;
10
10
import {
11
11
getBreadcrumbLogLevelFromHttpStatusCode ,
12
12
getSanitizedUrlString ,
@@ -150,7 +150,7 @@ export class SentryHttpInstrumentation extends InstrumentationBase<SentryHttpIns
150
150
cookies,
151
151
} ;
152
152
153
- patchRequestToCaptureBody ( request , normalizedRequest ) ;
153
+ patchRequestToCaptureBody ( request , isolationScope ) ;
154
154
155
155
// Update the isolation scope, isolate this request
156
156
// TODO(v9): Stop setting `request`, we only rely on normalizedRequest anymore
@@ -349,7 +349,7 @@ function getBreadcrumbData(request: http.ClientRequest): Partial<SanitizedReques
349
349
* we monkey patch `req.on('data')` to intercept the body chunks.
350
350
* This way, we only read the body if the user also consumes the body, ensuring we do not change any behavior in unexpected ways.
351
351
*/
352
- function patchRequestToCaptureBody ( req : IncomingMessage , normalizedRequest : RequestEventData ) : void {
352
+ function patchRequestToCaptureBody ( req : IncomingMessage , isolationScope : Scope ) : void {
353
353
const chunks : Buffer [ ] = [ ] ;
354
354
355
355
function getChunksSize ( ) : number {
@@ -398,9 +398,8 @@ function patchRequestToCaptureBody(req: IncomingMessage, normalizedRequest: Requ
398
398
try {
399
399
const body = Buffer . concat ( chunks ) . toString ( 'utf-8' ) ;
400
400
401
- // We mutate the passed in normalizedRequest and add the body to it
402
401
if ( body ) {
403
- normalizedRequest . data = body ;
402
+ setNormalizedRequest ( { data : body } , isolationScope ) ;
404
403
}
405
404
} catch {
406
405
// ignore errors here
0 commit comments