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
4 stars 1 forks source link

Update request-tracker-fetch.ts #434

Closed tpenaranda closed 2 months ago

tpenaranda commented 3 months ago

fetch() override is killing RTK Query headers. As soon I call BugsnagPerformance.start() all my RTK custom headers are lost. ('Content-Type', 'Accept'). Then, it completely breaks the project since the BE replies with http 415.

Goal

Let BugsnagPerformance to play well with a project setting custom headers at fetch() call input.

Design

Looks like that's the way how we set headers on a fetch() request. https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch#supplying_request_options

Changeset

So far I see how RequestTracker() is constructed, 'extraRequestHeaders' variable is always an empty array, and those headers set by the original fetch() call are set on 'input' variable (function param), then I'm suggesting to send 'input.headers' value to 'mergeRequestHeaders' call. Finally, those headers are merged in with the ones at 'init'. Honestly, I'm not 100% sure this is the right fix, but I'm pretty sure it's gonna help to understand/find/solve the issue. Additionally, IMHO, this global.fetch thing is a bit reckless.

Testing

Manual testing. Before fix, no headers are sent... later, everything is there.

clr182 commented 2 months ago

Hi @tpenaranda

Thank you for reaching out and raising this bug report.

This does seem to be an issue on our side that we will look to address soon. Once we have more information we will be sure to reach out and update you via this ticket thread.

Thanks!

yousif-bugsnag commented 2 months ago

Thanks again for raising this @tpenaranda - I'm going to close this in favour of #436, which we'll look to get out in the next release.

mclack commented 1 month ago

Hi @tpenaranda

I just wanted to let you know that this has been implemented as part of the v2.4.1 bugsnag-js-performance release: https://github.com/bugsnag/bugsnag-js-performance/releases/tag/v2.4.1

Thanks for raising this. Please let us know if you have any issues after upgrading.