Skip to content

Commit be96f6c

Browse files
committed
fix body setting
1 parent 7fb7702 commit be96f6c

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

packages/node/src/integrations/http/SentryHttpInstrumentation.ts

+4-5
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import type { InstrumentationConfig } from '@opentelemetry/instrumentation';
66
import { InstrumentationBase, InstrumentationNodeModuleDefinition } from '@opentelemetry/instrumentation';
77
import { getRequestInfo } from '@opentelemetry/instrumentation-http';
88
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';
1010
import {
1111
getBreadcrumbLogLevelFromHttpStatusCode,
1212
getSanitizedUrlString,
@@ -150,7 +150,7 @@ export class SentryHttpInstrumentation extends InstrumentationBase<SentryHttpIns
150150
cookies,
151151
};
152152

153-
patchRequestToCaptureBody(request, normalizedRequest);
153+
patchRequestToCaptureBody(request, isolationScope);
154154

155155
// Update the isolation scope, isolate this request
156156
// TODO(v9): Stop setting `request`, we only rely on normalizedRequest anymore
@@ -349,7 +349,7 @@ function getBreadcrumbData(request: http.ClientRequest): Partial<SanitizedReques
349349
* we monkey patch `req.on('data')` to intercept the body chunks.
350350
* This way, we only read the body if the user also consumes the body, ensuring we do not change any behavior in unexpected ways.
351351
*/
352-
function patchRequestToCaptureBody(req: IncomingMessage, normalizedRequest: RequestEventData): void {
352+
function patchRequestToCaptureBody(req: IncomingMessage, isolationScope: Scope): void {
353353
const chunks: Buffer[] = [];
354354

355355
function getChunksSize(): number {
@@ -398,9 +398,8 @@ function patchRequestToCaptureBody(req: IncomingMessage, normalizedRequest: Requ
398398
try {
399399
const body = Buffer.concat(chunks).toString('utf-8');
400400

401-
// We mutate the passed in normalizedRequest and add the body to it
402401
if (body) {
403-
normalizedRequest.data = body;
402+
setNormalizedRequest({ data: body }, isolationScope);
404403
}
405404
} catch {
406405
// ignore errors here

0 commit comments

Comments
 (0)