Skip to content

Conversation

@mariomc
Copy link

@mariomc mariomc commented Nov 8, 2024

Which problem is this PR solving?

Fixes #5122

In instrumentation-fetch and instrumentation-xhr, we're including logic to find preflight requests and create (nested) spans for them.
However, that is unnecessary complexity as OPTIONS/preflight calls for a cross-domain request are not added as an additional entry in the PerformanceEntry list and, much like redirects and other preconditions, are accounted for in the main resource entry (despite not being able to differentiate between one and the other).

A simple test can be done by executing the following:

(async () => {
  const CORS_URL = "https://httpbin.org/headers";
  await fetch(CORS_URL).then((a) => a.json());
  const entries = performance.getEntriesByName(CORS_URL);
  console.log("Number of entries:", entries.length);
})();

Short description of the changes

Removed CORS child span creation, filtering and other logic.

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration

  • Tested the demo for both instrumentation-fetch and instrumentation-xhr in: Google Chrome 130, Safari 18, Firefox 131. Noticed there were no child spans being created for OPTIONS/preflight requests nor performance entries being added for CORS-enabled requests.
  • Tested a simple html app doing a cross-domain fetch request and consulted the performance entries.

Checklist:

  • Followed the style guidelines of this project
  • Unit tests have been added
  • Documentation has been updated

@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Nov 8, 2024

CLA Signed

The committers listed above are authorized under a signed CLA.

@trentm trentm changed the title fix(instrumentation-fetch): removes CORS sub-span creation as it was … fix(instrumentation-fetch): removes CORS sub-span creation as it was not compliant with ResourceTiming spec Nov 27, 2024
@github-actions
Copy link

This PR is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 14 days.

@github-actions github-actions bot added the stale label Jan 27, 2025
@chancancode
Copy link
Contributor

chancancode commented Jan 30, 2025

@mariomc not sure if you are still working on this, but there have been some new developments since.

I worked on #5282, which completely rewrote the tests. They are now making real fetch() requests using a service worker interceptor, making the tests less susceptible to these kind of issues. As part of that, I also adjusted the tests as necessary to reflect the real-world CORS behavior.

So I think the test changes from this PR is already taken care of (please double check, though). The refactor to remove the runtime code (that does nothing, as you pointed out), is still needed, as I didn't want to touch the implementation while doing a big test refactor.

A slightly unfortunate thing is that, while the same refactor/general approach to would work for the XHR tests, and IMO a useful improvement, I ran out of time to do that myself. So the test suites have different paradigms, which may affect your plan to fix both, but it looks like you already figured out how to work with that anyway.

@mariomc
Copy link
Author

mariomc commented Jan 31, 2025

@mariomc not sure if you are still working on this, but there have been some new developments since.

I worked on #5282, which completely rewrote the tests. They are now making real fetch() requests using a service worker interceptor, making the tests less susceptible to these kind of issues. As part of that, I also adjusted the tests as necessary to reflect the real-world CORS behavior.

So I think the test changes from this PR is already taken care of (please double check, though). The refactor to remove the runtime code (that does nothing, as you pointed out), is still needed, as I didn't want to touch the implementation while doing a big test refactor.

A slightly unfortunate thing is that, while the same refactor/general approach to would work for the XHR tests, and IMO a useful improvement, I ran out of time to do that myself. So the test suites have different paradigms, which may affect your plan to fix both, but it looks like you already figured out how to work with that anyway.

I haven't kept up with the latest developments, but will keep up with them once I have an opening.
If you want to pick this up before that, be my guest! 😄

@github-actions github-actions bot removed the stale label Feb 3, 2025
@github-actions
Copy link

github-actions bot commented Apr 7, 2025

This PR is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 14 days.

@github-actions github-actions bot added the stale label Apr 7, 2025
@pichlermarc
Copy link
Member

Closing this PR, as this was already addressed IIUC - please open a new PR if this is incorrect. Thanks! 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CORS Preflight Requests not accounted for

3 participants