-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Changes from 4 commits
4b09457
6ffb168
88f1fbe
ca8f2ee
32c82fd
20b8698
99e4837
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -369,6 +369,9 @@ describe('fetch', () => { | |||||||||||||
| msw.http.get('/boom', () => { | ||||||||||||||
| return new msw.HttpResponse(null, { status: 500 }); | ||||||||||||||
| }), | ||||||||||||||
| msw.http.get('/null-body', () => { | ||||||||||||||
| return new msw.HttpResponse(null, { status: 204 }); | ||||||||||||||
| }), | ||||||||||||||
| ], | ||||||||||||||
| callback = () => fetch('/api/status.json'), | ||||||||||||||
| config = {}, | ||||||||||||||
|
|
@@ -391,6 +394,20 @@ describe('fetch', () => { | |||||||||||||
| return { rootSpan, response }; | ||||||||||||||
| }; | ||||||||||||||
|
|
||||||||||||||
| describe('null-bodied response', () => { | ||||||||||||||
| // https://chromium.googlesource.com/chromium/src/+/ac85ca2a9cb8c76a37f9d7a6c611c24114f1f05d/third_party/WebKit/Source/core/fetch/Response.cpp#106 | ||||||||||||||
| let response: Response | undefined; | ||||||||||||||
| beforeEach(async () => { | ||||||||||||||
| const result = await tracedFetch({ | ||||||||||||||
| callback: () => fetch('/null-body'), | ||||||||||||||
| }); | ||||||||||||||
| response = result.response; | ||||||||||||||
| }); | ||||||||||||||
| it('should be handled correctly', async () => { | ||||||||||||||
| assert.strictEqual(response?.status, 204); | ||||||||||||||
| }); | ||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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:
Suggested change
We also have untested functionality for other null-body content. 101, 205, 304 we could test those as well.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 We can always follow up with better support for I approved to show my support, but we'll need add'l approvals from the JS folks. |
||||||||||||||
| }); | ||||||||||||||
|
|
||||||||||||||
| describe('simple request', () => { | ||||||||||||||
| let rootSpan: api.Span | undefined; | ||||||||||||||
| let response: Response | undefined; | ||||||||||||||
|
|
||||||||||||||
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
Uh oh!
There was an error while loading. Please reload this page.
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.