Skip to content

Commit 6c6c146

Browse files
committed
switch to using finalization registry
1 parent 0f66175 commit 6c6c146

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,11 @@ export class SentryHttpInstrumentation extends InstrumentationBase<SentryHttpIns
140140
// eslint-disable-next-line @typescript-eslint/no-this-alias
141141
const instrumentation = this;
142142

143+
// @ts-expect-error: FinalizationRegistry is not yet in the Node types
144+
const finalizationRegistry = new FinalizationRegistry((isolationScope: Scope) => {
145+
isolationScope.setSDKProcessingMetadata({ normalizedRequest: undefined });
146+
});
147+
143148
return (
144149
original: (event: string, ...args: unknown[]) => boolean,
145150
): ((this: unknown, event: string, ...args: unknown[]) => boolean) => {
@@ -183,11 +188,8 @@ export class SentryHttpInstrumentation extends InstrumentationBase<SentryHttpIns
183188
});
184189
}
185190

186-
response.once('close', () => {
187-
// Remove normalized request from the scope after the response is finished
188-
// This is to avoid keeping the request body in memory for too long.
189-
isolationScope.setSDKProcessingMetadata({ normalizedRequest: undefined });
190-
});
191+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
192+
finalizationRegistry.register(response, isolationScope);
191193

192194
return withIsolationScope(isolationScope, () => {
193195
return withScope(scope => {

0 commit comments

Comments
 (0)