Skip to content

Commit 3ad6cc6

Browse files
committed
ref(core): Store ipAddress as SDKProcessingMetadata
Instead of picking this from the plain `request` in `requestDartaIntegration`. Extracted from #14806
1 parent 64d36a9 commit 3ad6cc6

File tree

3 files changed

+6
-2
lines changed

3 files changed

+6
-2
lines changed

packages/core/src/integrations/requestdata.ts

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

8181
const { sdkProcessingMetadata = {} } = event;
82-
const { request, normalizedRequest } = sdkProcessingMetadata;
82+
const { request, normalizedRequest, ipAddress } = sdkProcessingMetadata;
8383

8484
const addRequestDataOptions = convertReqDataIntegrationOptsToAddReqDataOpts(_options);
8585

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

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

packages/core/src/scope.ts

Lines changed: 1 addition & 0 deletions
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

Lines changed: 4 additions & 0 deletions
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)