Skip to content

fix[tracing]: fetch headers #2712

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
- [tracing] feat: Pick up sentry-trace in JS <meta/> 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

Expand Down
11 changes: 5 additions & 6 deletions packages/apm/src/integrations/tracing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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() };
Expand Down