Skip to content

Commit ec78f80

Browse files
authored
ref(core): Store ipAddress as SDKProcessingMetadata (#14899)
Instead of picking this from the plain `request` in `requestDartaIntegration`. Extracted from #14806
1 parent 8dd8ac5 commit ec78f80

File tree

3 files changed

+6
-2
lines changed

3 files changed

+6
-2
lines changed

packages/core/src/integrations/requestdata.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -69,14 +69,13 @@ const _requestDataIntegration = ((options: RequestDataIntegrationOptions = {}) =
6969
// that's happened, it will be easier to add this logic in without worrying about unexpected side effects.)
7070

7171
const { sdkProcessingMetadata = {} } = event;
72-
const { request, normalizedRequest } = sdkProcessingMetadata;
72+
const { request, normalizedRequest, ipAddress } = sdkProcessingMetadata;
7373

7474
const addRequestDataOptions = convertReqDataIntegrationOptsToAddReqDataOpts(_options);
7575

7676
// If this is set, it takes precedence over the plain request object
7777
if (normalizedRequest) {
7878
// Some other data is not available in standard HTTP requests, but can sometimes be augmented by e.g. Express or Next.js
79-
const ipAddress = request ? request.ip || (request.socket && request.socket.remoteAddress) : undefined;
8079
const user = request ? request.user : undefined;
8180

8281
addNormalizedRequestDataToEvent(event, normalizedRequest, { ipAddress, user }, addRequestDataOptions);

packages/core/src/scope.ts

+1
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ export interface SdkProcessingMetadata {
6767
capturedSpanScope?: Scope;
6868
capturedSpanIsolationScope?: Scope;
6969
spanCountBeforeProcessing?: number;
70+
ipAddress?: string;
7071
}
7172

7273
/**

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

+4
Original file line numberDiff line numberDiff line change
@@ -155,13 +155,17 @@ export class SentryHttpInstrumentation extends InstrumentationBase<SentryHttpIns
155155

156156
const normalizedRequest = httpRequestToRequestData(request);
157157

158+
// request.ip is non-standard but some frameworks set this
159+
const ipAddress = (request as { ip?: string }).ip || request.socket?.remoteAddress;
160+
158161
patchRequestToCaptureBody(request, isolationScope);
159162

160163
// Update the isolation scope, isolate this request
161164
// TODO(v9): Stop setting `request`, we only rely on normalizedRequest anymore
162165
isolationScope.setSDKProcessingMetadata({
163166
request,
164167
normalizedRequest,
168+
ipAddress,
165169
});
166170

167171
// attempt to update the scope's `transactionName` based on the request URL

0 commit comments

Comments
 (0)