Skip to content

Commit

Permalink
fix(node): support undici headers as strings or arrays (#10938)
Browse files Browse the repository at this point in the history
  • Loading branch information
jessezhang91 authored Mar 7, 2024
1 parent 07d83de commit 560a774
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
9 changes: 7 additions & 2 deletions packages/node/src/integrations/undici/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 3 additions & 1 deletion packages/node/src/integrations/undici/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

0 comments on commit 560a774

Please sign in to comment.