Skip to content

Commit 3aba85e

Browse files
authored
fix[tracing]: fetch headers (#2712)
* fix[tracing]: fetch headers Fixes #2685 * meta: Changelog
1 parent 0defcdc commit 3aba85e

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
- [tracing] feat: Pick up sentry-trace in JS <meta/> tag (#2703)
1010
- [tracing] fix: Respect sample decision when continuing trace from header in node (#2703)
1111
- [gatsby] fix: Package gatsby files properly (#2711)
12+
- [tracing] fix: All options of adding fetch headers (#2712)
1213

1314
## 5.18.1
1415

packages/apm/src/integrations/tracing.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1021,13 +1021,12 @@ function fetchCallback(handlerData: { [key: string]: any }): void {
10211021
if (span) {
10221022
const options = (handlerData.args[1] = (handlerData.args[1] as { [key: string]: any }) || {});
10231023
if (options.headers) {
1024-
if (Array.isArray(options.headers)) {
1025-
options.headers = [...options.headers, { 'sentry-trace': span.toTraceparent() }];
1024+
if (typeof options.headers.append === 'function') {
1025+
options.headers.append('sentry-trace', span.toTraceparent());
1026+
} else if (Array.isArray(options.headers)) {
1027+
options.headers = [...options.headers, ['sentry-trace', span.toTraceparent()]];
10261028
} else {
1027-
options.headers = {
1028-
...options.headers,
1029-
'sentry-trace': span.toTraceparent(),
1030-
};
1029+
options.headers = { ...options.headers, 'sentry-trace': span.toTraceparent() };
10311030
}
10321031
} else {
10331032
options.headers = { 'sentry-trace': span.toTraceparent() };

0 commit comments

Comments
 (0)