From b1d5b9e27bfb0c011ee5bc4c0a10688645a9f4b4 Mon Sep 17 00:00:00 2001 From: Andrei Borza Date: Tue, 3 Jun 2025 17:04:36 +0200 Subject: [PATCH] fix(node): Ensure adding sentry-trace and baggage headers via SentryHttpInstrumentation doesn't crash On Node > 22.10.0, when spans are off, the `SentryHttpInstrumentation` attempts adding `sentry-trace` and `baggage` headers to requests. Due to race-conditions, this can error in cases where the request was already sent/finished prior to setting the headers. This fix prevents this by wrapping the logic in a try/catch. Fixes: #16438 --- .../http/SentryHttpInstrumentation.ts | 26 ++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/packages/node/src/integrations/http/SentryHttpInstrumentation.ts b/packages/node/src/integrations/http/SentryHttpInstrumentation.ts index ac82134fd07f..b8c339b30185 100644 --- a/packages/node/src/integrations/http/SentryHttpInstrumentation.ts +++ b/packages/node/src/integrations/http/SentryHttpInstrumentation.ts @@ -20,6 +20,7 @@ import { getSanitizedUrlString, getTraceData, httpRequestToRequestData, + isError, logger, LRUMap, parseUrl, @@ -262,15 +263,34 @@ export class SentryHttpInstrumentation extends InstrumentationBase