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

Conversation

philipszalla
Copy link
Contributor

Signed-off-by: Philip Szalla philip@szalla.de

Which problem is this PR solving?

opentelemetry-instrumentation-fetch removes headers from original request, when the init-object is not an instance of Request but the headers-property is an instance of Headers.
Fetch-requests made by https://github.com/pnp/pnpjs can cause this problem.

Short description of the changes

  • added additional check for headers-property

Signed-off-by: Philip Szalla <philip@szalla.de>
@philipszalla philipszalla requested a review from a team as a code owner August 23, 2021 22:01
@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Aug 23, 2021

CLA Signed

The committers are authorized under a signed CLA.

@@ -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.

@codecov
Copy link

codecov bot commented Aug 24, 2021

Codecov Report

Merging #2426 (ab31805) into main (c69251e) will increase coverage by 0.48%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##             main    #2426      +/-   ##
==========================================
+ Coverage   92.22%   92.70%   +0.48%     
==========================================
  Files         120      137      +17     
  Lines        4013     4993     +980     
  Branches      850     1056     +206     
==========================================
+ Hits         3701     4629     +928     
- Misses        312      364      +52     
Impacted Files Coverage Δ
...s/opentelemetry-instrumentation-fetch/src/fetch.ts 96.96% <100.00%> (ø)
...ation-xml-http-request/src/enums/AttributeNames.ts 100.00% <0.00%> (ø)
...emetry-instrumentation-xml-http-request/src/xhr.ts 97.58% <0.00%> (ø)
...es/opentelemetry-context-zone-peer-dep/src/util.ts 100.00% <0.00%> (ø)
...ry-exporter-collector/src/CollectorExporterBase.ts 92.15% <0.00%> (ø)
...lemetry-exporter-collector/src/transformMetrics.ts 95.71% <0.00%> (ø)
packages/opentelemetry-sdk-trace-web/src/types.ts 100.00% <0.00%> (ø)
...ry-context-zone-peer-dep/src/ZoneContextManager.ts 85.18% <0.00%> (ø)
...kages/opentelemetry-exporter-collector/src/util.ts 100.00% <0.00%> (ø)
... and 8 more

@obecny
Copy link
Member

obecny commented Aug 25, 2021

can you please add some unit tests to cover the fixes ?

@obecny obecny added the bug Something isn't working label Aug 26, 2021
@dyladan
Copy link
Member

dyladan commented Aug 27, 2021

@philipszalla can you please add a test to cover this?

@dyladan dyladan merged commit dbfabd2 into open-telemetry:main Aug 27, 2021
@dyladan dyladan mentioned this pull request Sep 13, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants