diff --git a/CHANGELOG.md b/CHANGELOG.md index b7fa15ee145d..dcd03e62a382 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ - [tracing] feat: Pick up sentry-trace in JS tag (#2703) - [tracing] fix: Respect sample decision when continuing trace from header in node (#2703) - [gatsby] fix: Package gatsby files properly (#2711) +- [tracing] fix: All options of adding fetch headers (#2712) ## 5.18.1 diff --git a/packages/apm/src/integrations/tracing.ts b/packages/apm/src/integrations/tracing.ts index 5226f2a3b34b..62b83ad83da4 100644 --- a/packages/apm/src/integrations/tracing.ts +++ b/packages/apm/src/integrations/tracing.ts @@ -1021,13 +1021,12 @@ function fetchCallback(handlerData: { [key: string]: any }): void { if (span) { const options = (handlerData.args[1] = (handlerData.args[1] as { [key: string]: any }) || {}); if (options.headers) { - if (Array.isArray(options.headers)) { - options.headers = [...options.headers, { 'sentry-trace': span.toTraceparent() }]; + if (typeof options.headers.append === 'function') { + options.headers.append('sentry-trace', span.toTraceparent()); + } else if (Array.isArray(options.headers)) { + options.headers = [...options.headers, ['sentry-trace', span.toTraceparent()]]; } else { - options.headers = { - ...options.headers, - 'sentry-trace': span.toTraceparent(), - }; + options.headers = { ...options.headers, 'sentry-trace': span.toTraceparent() }; } } else { options.headers = { 'sentry-trace': span.toTraceparent() };