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(trace): add sw8 to header when using Fetch with Request to query #128

Merged
merged 1 commit into from
Jun 25, 2024
Merged
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
25 changes: 14 additions & 11 deletions src/trace/interceptors/fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@ export default function windowFetch(options: CustomOptionsType, segments: Segmen
url = new URL(window.location.href);
url.pathname = args[0];
}
}

}

const noTraceOrigins = customConfig.noTraceOrigins.some((rule: string | RegExp) => {
if (typeof rule === 'string') {
Expand Down Expand Up @@ -79,16 +78,20 @@ export default function windowFetch(options: CustomOptionsType, segments: Segmen
const index = segment.spans.length;
const values = `${1}-${traceIdStr}-${segmentId}-${index}-${service}-${instance}-${endpoint}-${peer}`;

if (!args[1]) {
args[1] = {};
}
if (!args[1].headers) {
args[1].headers = new Headers();
}
if (args[1].headers instanceof Headers) {
args[1].headers.append('sw8', values);
if (args[0] instanceof Request) {
args[0].headers.append('sw8', values);
} else {
args[1].headers['sw8'] = values;
if (!args[1]) {
args[1] = {};
}
if (!args[1].headers) {
args[1].headers = new Headers();
}
if (args[1].headers instanceof Headers) {
args[1].headers.append('sw8', values);
} else {
args[1].headers['sw8'] = values;
}
}
}

Expand Down
Loading