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(fetch): end span after body is received #2203

Merged
merged 4 commits into from
May 19, 2021

Conversation

mhennoch
Copy link
Contributor

@mhennoch mhennoch commented May 13, 2021

Which problem is this PR solving?

Currently fetch span end is called when fetch().then fires and 300ms wait time(for resource timings) is over. But fetch() promise resolves as soon as the server responds with headers so if getting the body takes more than 300ms there will never be any resource timings for this span and span end time will be incorrect also. To reproduce it just make a fetch and set connection speed slow in dev tools and you can see that none of the fetches have resource timings.

Short description of the changes

I clone the response and read the response body until it is done and end the span then. Not a pretty solution but this covers all of the cases I know about. Another potential way to fix this would be to wrap all body methods (.json .blob etc.) but that still leaves some use cases uncovered. Some changes to tests so done isn't called too early (took a looong time to get them stable). Also fixed some TS warnings in tests. Probably could get rid of the 300ms timeout now but I am not yet bold enough.

@codecov
Copy link

codecov bot commented May 13, 2021

Codecov Report

Merging #2203 (afcbdd6) into main (e379e59) will decrease coverage by 0.01%.
The diff coverage is 87.50%.

@@            Coverage Diff             @@
##             main    #2203      +/-   ##
==========================================
- Coverage   92.72%   92.71%   -0.02%     
==========================================
  Files         141      141              
  Lines        5089     5106      +17     
  Branches     1047     1049       +2     
==========================================
+ Hits         4719     4734      +15     
- Misses        370      372       +2     
Impacted Files Coverage Δ
...s/opentelemetry-instrumentation-fetch/src/fetch.ts 96.98% <87.50%> (-1.67%) ⬇️
...emetry-core/src/platform/node/RandomIdGenerator.ts 93.75% <0.00%> (+6.25%) ⬆️

Copy link
Member

@obecny obecny left a comment

Choose a reason for hiding this comment

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

this is really nice finding, thx for fixes, lgtm, just some name change suggestions

packages/opentelemetry-instrumentation-fetch/src/fetch.ts Outdated Show resolved Hide resolved
packages/opentelemetry-instrumentation-fetch/src/fetch.ts Outdated Show resolved Hide resolved
Copy link
Member

@johnbley johnbley left a comment

Choose a reason for hiding this comment

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

+1

@mhennoch
Copy link
Contributor Author

@dyladan @vmarchaud Can I get one more review and if possible get it merged soon? Would really like to have this before next release.

@vmarchaud vmarchaud merged commit cc44db1 into open-telemetry:main May 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants