bugsnag / bugsnag-js-performance

Monitor the performance of your JavaScript (web and React Native) and see the results in your BugSnag dashboard.
https://docs.bugsnag.com/performance/integration-guides
MIT License
5 stars 3 forks source link

Ensure existing headers are preserved for fetch requests #436

Closed yousif-bugsnag closed 7 months ago

yousif-bugsnag commented 7 months ago

Goal

Fixes a bug in the fetch request tracker where any headers that are set in a Request object passed to fetch were not being preserved. Similarly if headers are set using the Headers class in the request options these would also be wiped.

This is because trace propagation headers were always being merged with the options object (the second argument passed to fetch) as an object literal, however request headers can be set in a few different ways:

The behaviour of fetch is such that if headers are set in the options object these will take precedence, and any headers defined in a Request object are ignored.

Design

Reworked the mergeRequestHeaders logic to handle all of the cases listed above, with headers defined in fetch options taking precedence.

Testing

Added additional unit test cases and e2e scenarios

github-actions[bot] commented 7 months ago

Browser bundle size

NPM build

Package
Before 183.98 kB
After 183.98 kB
± No change

CDN build

Unminified Minfied Minified + gzipped
Before 91.76 kB 34.46 kB 10.41 kB
After 92.67 kB 34.77 kB 10.48 kB
± +905 bytes ⚠️ +312 bytes ⚠️ +74 bytes ⚠️

Code coverage

Ok File (✨=New File) Lines Branches Functions Statements
🔴 /home/runner/work/bugsnag-js-performance/bugsnag-js-performance/packages/request-tracker/lib/request-tracker-fetch.ts 73.58%
(-11.26%)
54.9%
(-2.67%)
55%
(-15%)
60.56%
(-9.2%)

Total:

Lines Branches Functions Statements
87.58%(-0.39%) 78.62%(-0.83%) 88.14%(-1.1%) 84.21%(-0.57%)

Generated against 3de148a55a2382345a82bbecd6d535b88cf1ca62 on 12 April 2024 at 11:39:39 UTC