-
Notifications
You must be signed in to change notification settings - Fork 979
fix(instrumentation-fetch): Handling null-body-status responses #6037
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
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #6037 +/- ##
=======================================
Coverage 95.14% 95.14%
=======================================
Files 315 316 +1
Lines 9161 9166 +5
Branches 2022 2023 +1
=======================================
+ Hits 8716 8721 +5
Misses 445 445 🚀 New features to boost your workflow:
|
| it('should be handled correctly', async () => { | ||
| assert.strictEqual(response?.status, 204); | ||
| }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Other tests make assertions that the spans were emitted rather then asserting on the response. Something like:
assert.strictEqual(exportedSpans.length, 1);
| it('should be handled correctly', async () => { | |
| assert.strictEqual(response?.status, 204); | |
| }); | |
| it('204 (No Content) will correctly end the span', async () => { | |
| assert.strictEqual(exportedSpans.length, 1); | |
| }); |
We also have untested functionality for other null-body content. 101, 205, 304 we could test those as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added separate test cases for each status code.
I did find a weird edge-case in 101 that IDK if is already handled correctly. I would expect a span to be exported, with the correct error code, but this either doesn't happen in tests due to how it's set up, or it actually wouldn't happen. @wolfgangcodes any ideas?
The fetch.ts endSpanOnError callback does happen in that case, but somehow the span is not there for inspection.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for adding those!
I don't have any immediate thoughts on what might be happening with 101s, but I like your approach of implementing what we can test easily right now for for common success responses.
We can always follow up with better support for 101s if they crop up or if we have more time to think about it!
I approved to show my support, but we'll need add'l approvals from the JS folks.
Co-authored-by: Wolfgang Therrien <[email protected]>
| const reader = body.getReader(); | ||
|
|
||
| const wrappedBody = withCancelPropagation(response.body, reader); | ||
| const isNullBodyStatus = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I assume these statuses are the ones with null body according to a spec. But my experience tells me some apis may not follow these specs and return body anyways. I wonder if it's okay to not process the body in this scenario
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new Response({ /* non-null-wrapped-body */ }, { status: 204 /* or 101, 205, 304 */ }) constructor always throws:
The only way of processing it further would mean avoid reconstructing it / preserving a code path that was in place prior to #5894
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
well, backends could be written in different languages and those may let the dev pass a payload. According to https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Status we should not expect payloads for these statuses so I'm fine. If there is interest in reading the body even with these cases we can add it later.
|
LGTM. I'll wait a bit so others can give feedback cc: @open-telemetry/javascript-approvers |
…-telemetry#6037) Co-authored-by: Wolfgang Therrien <[email protected]>
Which problem is this PR solving?
Fixes incorrect handling of null-body-status responses, and adds tests to ensure this doesn't go un-noticed again.
Fixes #6036
Short description of the changes
Fixing null-body-status response handling in instrumentation-fetch.
Type of change
Please delete options that are not relevant.
How Has This Been Tested?
Error was reproduced in unit tests and then fixed.
Checklist: