add requestContentLength breadcrumb metadata for xhr and fetch requests #1925
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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()
orfetch()
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
orDocument
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
andDataView
objects). Otherwise the request body is serialized and aBlob
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.