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

add requestContentLength breadcrumb metadata for xhr and fetch requests #1925

Conversation

yousif-bugsnag
Copy link
Contributor

Goal

Adds requestContentLength metadata to network breadcrumbs for XHR and fetch requests. This is the length of the request body in bytes.

Design

If a body is passed to XMLHTTPRequest.send() or fetch() the length in bytes of the body is calculated and recorded prior to calling into the respective native methods.

The content length is not calculated if the request body is a ReadableStream as these cannot be read without interfering with the successful completion of request.

The content length is also omitted if the request body is FormData or Document object as it's difficult to calculate accurately for these object types.

Where possible the byte length of the request body is read directly, (e.g. for Blob, TypedArray, ArrayBuffer and DataView objects). Otherwise the request body is serialized and a Blob is used to get the byte length of the UTF-8 encoded body.

Testing

Manually tested that the calculated content length matches the Content-Length header for the various request types.

Since the unit tests run in Node and not in the browser, this is covered by e2e tests. New e2e tests have been added to check that the content length is calculated for the various request types.

@github-actions
Copy link

@bugsnag/browser bundle size diff

Minified Minfied + Gzipped
Before 44.11 kB 13.47 kB
After 44.63 kB 13.64 kB
± ⚠️ +524 bytes ⚠️ +161 bytes

code coverage diff

<temporarily disabled>

Generated by 🚫 dangerJS against 7b71722

Copy link
Member

@gingerbenw gingerbenw left a comment

Choose a reason for hiding this comment

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

Forgive me, but what does reflect do?

@yousif-bugsnag yousif-bugsnag merged commit 0b0d800 into integration/v8 Feb 13, 2023
@yousif-bugsnag yousif-bugsnag deleted the PLAT-9444/network-breadcrumbs-requestcontentlength branch February 13, 2023 11:34
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.

2 participants