diff --git a/packages/node/src/integrations/undici/index.ts b/packages/node/src/integrations/undici/index.ts index 5c27841c462d..001f05814745 100644 --- a/packages/node/src/integrations/undici/index.ts +++ b/packages/node/src/integrations/undici/index.ts @@ -308,8 +308,13 @@ function setHeadersOnRequest( sentryTrace: string, sentryBaggageHeader: string | undefined, ): void { - const headerLines = request.headers.split('\r\n'); - const hasSentryHeaders = headerLines.some(headerLine => headerLine.startsWith('sentry-trace:')); + let hasSentryHeaders: boolean; + if (Array.isArray(request.headers)) { + hasSentryHeaders = request.headers.some(headerLine => headerLine === 'sentry-trace'); + } else { + const headerLines = request.headers.split('\r\n'); + hasSentryHeaders = headerLines.some(headerLine => headerLine.startsWith('sentry-trace:')); + } if (hasSentryHeaders) { return; diff --git a/packages/node/src/integrations/undici/types.ts b/packages/node/src/integrations/undici/types.ts index b51da3da2d34..05732811dc68 100644 --- a/packages/node/src/integrations/undici/types.ts +++ b/packages/node/src/integrations/undici/types.ts @@ -224,7 +224,9 @@ export interface UndiciRequest { // Originally was Dispatcher.HttpMethod, but did not want to vendor that in. method?: string; path: string; - headers: string; + // string for undici@<=6.6.2 and string[] for undici@>=6.7.0. + // see for more information: https://github.com/getsentry/sentry-javascript/issues/10936 + headers: string | string[]; addHeader(key: string, value: string): RequestWithSentry; }