From 128475f7004f28fd38b21ca9ef375e4441e96a41 Mon Sep 17 00:00:00 2001 From: Abhijeet Prasad Date: Tue, 4 Mar 2025 08:38:50 -0500 Subject: [PATCH] pref(node): Store normalized request for processing This should help reduce the memory pressure of the SDK as we don't store the entire request in memory anymore. --- packages/node/src/integrations/tracing/express.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/packages/node/src/integrations/tracing/express.ts b/packages/node/src/integrations/tracing/express.ts index cf6f6b233cdf..2c79b1bfb828 100644 --- a/packages/node/src/integrations/tracing/express.ts +++ b/packages/node/src/integrations/tracing/express.ts @@ -4,6 +4,7 @@ import type { ExpressRequestInfo } from '@opentelemetry/instrumentation-express' import { ExpressInstrumentation } from '@opentelemetry/instrumentation-express'; import type { IntegrationFn } from '@sentry/core'; import { + httpRequestToRequestData, SEMANTIC_ATTRIBUTE_SENTRY_OP, captureException, defineIntegration, @@ -135,9 +136,10 @@ export function expressErrorHandler(options?: ExpressHandlerOptions): ExpressErr res: http.ServerResponse, next: (error: MiddlewareError) => void, ): void { + const normalizedRequest = httpRequestToRequestData(request); // Ensure we use the express-enhanced request here, instead of the plain HTTP one // When an error happens, the `expressRequestHandler` middleware does not run, so we set it here too - getIsolationScope().setSDKProcessingMetadata({ request }); + getIsolationScope().setSDKProcessingMetadata({ normalizedRequest }); const shouldHandleError = options?.shouldHandleError || defaultShouldHandleError; @@ -156,8 +158,9 @@ function expressRequestHandler(): ExpressMiddleware { _res: http.ServerResponse, next: () => void, ): void { + const normalizedRequest = httpRequestToRequestData(request); // Ensure we use the express-enhanced request here, instead of the plain HTTP one - getIsolationScope().setSDKProcessingMetadata({ request }); + getIsolationScope().setSDKProcessingMetadata({ normalizedRequest }); next(); };