Skip to content
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

fix[tracing]: fetch headers #2712

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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
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
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