Skip to content

fix: Get responseBodySize from body if content-length is missing#1793

Merged
metal-messiah merged 1 commit into
mainfrom
response-size-0
Jun 16, 2026
Merged

fix: Get responseBodySize from body if content-length is missing#1793
metal-messiah merged 1 commit into
mainfrom
response-size-0

Conversation

@metal-messiah

Copy link
Copy Markdown
Member

Addresses an issue where AjaxRequest events inaccurately reported a responseSize of 0 or undefined due to a lack of fallback mechanisms and overly restrictive falsy checks. Introduced a fallback mechanism that calculates response sizes from captured payloads for Fetch and XHR requests when the content-length header is missing.


Overview

This pull request resolves multiple edge cases where Ajax request responseSize tracking failed or defaulted to undefined instead of accurately reflecting the payload size.

Key Changes:

  • Fixed dataSize() Utility Bug: Adjusted src/common/util/data-size.js to ensure empty strings return 0 instead of falling through to undefined.
  • Fetch & XHR Fallbacks: Added fallback logic to onFetchDone and XHR end handlers to measure the captured response body payload when the content-length header or primary detection is missing (operational when payload capture is enabled).
  • Corrected Falsy Value Checks: Replaced restrictive if (!value) blocks with explicit if (value !== undefined) validation to ensure valid 0 sizes (e.g., 204 No Content responses) are not blocked or omitted.
  • Modernized Component Testing: Replaced old mock-based tests in instrument.test.js with integration tests utilizing real XMLHttpRequest objects to execute actual instrumentation flows.

Related Issue(s)

https://new-relic.atlassian.net/browse/NR-446528

Testing

Execute the following commands in your local development environment to verify the fixes and ensure no regressions exist:

# Run dataSize unit tests
npm test -- tests/unit/common/util/data-size.test.js

# Run ajax instrumentation component tests
npm test -- tests/components/ajax/instrument.test.js

# Run ajax e2e tests
npm test -- tests/specs/ajax/

@github-actions

Copy link
Copy Markdown

Supportability Metric Usage Changes:

No matching changes found

Supportability Metrics .md File Changes:

supportability_metrics.md was changed? false

New supportability metrics require changes to supportability_metrics.md, as well as a new PR to Angler. Please ensure an Angler PR is created and linked to this PR.

@github-actions

Copy link
Copy Markdown

Asset Size Report

Merging this pull request will result in the following asset size changes:

Agent Asset Previous Size New Size Diff
lite loader 26.79 kB / 10.24 kB (gzip) 26.79 kB / 10.24 kB (gzip) 0% / 0% (gzip)
lite async-chunk 58.92 kB / 19.76 kB (gzip) 58.92 kB / 19.76 kB (gzip) 0% / 0% (gzip)
pro loader 66.48 kB / 23.42 kB (gzip) 66.61 kB / 23.46 kB (gzip) 0.2% / 0.18% (gzip)
pro async-chunk 96.37 kB / 30.65 kB (gzip) 96.37 kB / 30.65 kB (gzip) 0% / 0% (gzip)
spa loader 68.87 kB / 24.19 kB (gzip) 69.01 kB / 24.24 kB (gzip) 0.19% / 0.19% (gzip)
spa async-chunk 108.52 kB / 33.76 kB (gzip) 108.52 kB / 33.76 kB (gzip) 0% / 0% (gzip)

@codecov

codecov Bot commented Jun 15, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 66.66667% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 89.45%. Comparing base (9121c6b) to head (6c09817).

Files with missing lines Patch % Lines
src/features/ajax/instrument/index.js 60.00% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1793      +/-   ##
==========================================
+ Coverage   88.90%   89.45%   +0.55%     
==========================================
  Files         213      213              
  Lines        7859     7864       +5     
  Branches     1654     1657       +3     
==========================================
+ Hits         6987     7035      +48     
+ Misses        776      746      -30     
+ Partials       96       83      -13     
Flag Coverage Δ
unit-tests 84.78% <66.66%> (+1.12%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@ellisong ellisong left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

looks fine to me if tests pass

@metal-messiah metal-messiah changed the title fix: Calculate responseBodySize from body contents when content-length is unavailable fix: Get responseBodySize from body if content-length is missing Jun 16, 2026
@github-actions

github-actions Bot commented Jun 16, 2026

Copy link
Copy Markdown

Static Badge

Last ran on June 15, 2026 20:05:43 CDT
Checking merge of (6c09817) into main (9121c6b)

@metal-messiah metal-messiah merged commit 58663ec into main Jun 16, 2026
34 of 37 checks passed
@metal-messiah metal-messiah deleted the response-size-0 branch June 16, 2026 01:23
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