From 24f7dda8d3082a0f9d071b37a1b7a45e6fdf6598 Mon Sep 17 00:00:00 2001 From: Abhijeet Prasad Date: Thu, 20 Mar 2025 21:23:50 -0400 Subject: [PATCH 1/2] perf(nestjs): Remove usage of addNonEnumerableProperty --- .../src/integrations/sentry-nest-instrumentation.ts | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/packages/nestjs/src/integrations/sentry-nest-instrumentation.ts b/packages/nestjs/src/integrations/sentry-nest-instrumentation.ts index c4f36728c906..51a835ed6146 100644 --- a/packages/nestjs/src/integrations/sentry-nest-instrumentation.ts +++ b/packages/nestjs/src/integrations/sentry-nest-instrumentation.ts @@ -8,7 +8,6 @@ import { import type { Span } from '@sentry/core'; import { SDK_VERSION, - addNonEnumerableProperty, getActiveSpan, isThenable, startInactiveSpan, @@ -90,7 +89,9 @@ export class SentryNestInstrumentation extends InstrumentationBase { /** * Creates a wrapper function for the @Injectable decorator. */ - private _createWrapInjectable() { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + private _createWrapInjectable(): (original: any) => (options?: unknown) => (target: InjectableTarget) => any { + const SeenNestjsContextSet = new Set(); // eslint-disable-next-line @typescript-eslint/no-explicit-any return function wrapInjectable(original: any) { return function wrappedInjectable(options?: unknown) { @@ -197,8 +198,8 @@ export class SentryNestInstrumentation extends InstrumentationBase { return withActiveSpan(parentSpan, () => { const handleReturnObservable = Reflect.apply(originalHandle, thisArgHandle, argsHandle); - if (!context._sentryInterceptorInstrumented) { - addNonEnumerableProperty(context, '_sentryInterceptorInstrumented', true); + if (!SeenNestjsContextSet.has(context)) { + SeenNestjsContextSet.add(context); afterSpan = startInactiveSpan( getMiddlewareSpanOptions(target, 'Interceptors - After Route'), ); @@ -209,8 +210,8 @@ export class SentryNestInstrumentation extends InstrumentationBase { } else { const handleReturnObservable = Reflect.apply(originalHandle, thisArgHandle, argsHandle); - if (!context._sentryInterceptorInstrumented) { - addNonEnumerableProperty(context, '_sentryInterceptorInstrumented', true); + if (!SeenNestjsContextSet.has(context)) { + SeenNestjsContextSet.add(context); afterSpan = startInactiveSpan(getMiddlewareSpanOptions(target, 'Interceptors - After Route')); } From c130c5b2a867c54f4ca00b0e9bb82c11654f9956 Mon Sep 17 00:00:00 2001 From: Abhijeet Prasad Date: Thu, 20 Mar 2025 22:00:21 -0400 Subject: [PATCH 2/2] Update packages/nestjs/src/integrations/sentry-nest-instrumentation.ts --- packages/nestjs/src/integrations/sentry-nest-instrumentation.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/nestjs/src/integrations/sentry-nest-instrumentation.ts b/packages/nestjs/src/integrations/sentry-nest-instrumentation.ts index 51a835ed6146..58060f844888 100644 --- a/packages/nestjs/src/integrations/sentry-nest-instrumentation.ts +++ b/packages/nestjs/src/integrations/sentry-nest-instrumentation.ts @@ -91,7 +91,7 @@ export class SentryNestInstrumentation extends InstrumentationBase { */ // eslint-disable-next-line @typescript-eslint/no-explicit-any private _createWrapInjectable(): (original: any) => (options?: unknown) => (target: InjectableTarget) => any { - const SeenNestjsContextSet = new Set(); + const SeenNestjsContextSet = new WeakSet(); // eslint-disable-next-line @typescript-eslint/no-explicit-any return function wrapInjectable(original: any) { return function wrappedInjectable(options?: unknown) {