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(opentelemetry-instrumentation-fetch): fixed override of headers #2426

Merged
Merged
5 changes: 5 additions & 0 deletions packages/opentelemetry-instrumentation-fetch/src/fetch.ts
Expand Up @@ -158,6 +158,11 @@ export class FetchInstrumentation extends InstrumentationBase<
api.propagation.inject(api.context.active(), options.headers, {
set: (h, k, v) => h.set(k, typeof v === 'string' ? v : String(v)),
});
} else if(options.headers instanceof Headers) {
// ||-operator causes ts type error
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this comment referring to?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried to use the ||-operator inside the if-statement to avoid the else if and the code duplication. But it caused a type error at the setter-parameter of the api.propagation.inject-function.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment is pretty unclear on its own. I would just remove it since it's a typing issue and not a functionality caveat.

api.propagation.inject(api.context.active(), options.headers, {
set: (h, k, v) => h.set(k, typeof v === 'string' ? v : String(v)),
});
} else {
const headers: Partial<Record<string, unknown>> = {};
api.propagation.inject(api.context.active(), headers);
Expand Down