apm-agent-rum-js icon indicating copy to clipboard operation
apm-agent-rum-js copied to clipboard

Instrumenting with `fetch` enabled removes the `Origin` header, among others

Open eaardal opened this issue 2 years ago • 0 comments

Hi I'm currently exploring apm rum and how to set it up for our website, but are having some issues when the fetch instrumentation is enabled, namely that all our own outgoing API calls fails with CORS error. This is not CORS to apm-server but CORS in our own API that is failing.

Said simply, if the fetch instrumentation is enabled, our Origin header, along with many others, is gone from all outgoing requests.

Here is an API request normally: Screenshot 2022-09-22 at 15 58 50

Here is the same API request with fetch instrumented/patched: Screenshot 2022-09-23 at 12 51 28

As you can see, I have a custom header that is being carried over when fetch is patched, but Origin (and many others) is not, so our CORS fails. This is the preflight request that failed so it would be a bit different than a "normal" request, but still, we need that Origin header.

I've traced it down to this line and confirmed that Origin is set in init but I can't read it back out in request after that line

Screenshot 2022-09-23 at 12 38 46

Some context info:

  • I'm running elastic, kibana and fleet locally using the docker-compose from https://github.com/elastic/apm-server and running apm-server by running runapm in the same repo, so this is all on my machine/localhost except the API I'm calling.
  • Other instrumentations (page-load, history, eventtarget, error) are collected correctly out of the box and showing up in my APM traces in Kibana on localhost.

Let me know if you need more info :)

eaardal avatar Sep 23 '22 11:09 eaardal