Skip to content

fix(tracing-internal): Prefer fetch init headers over fetch input headers #10176

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

Lms24
Copy link
Member

@Lms24 Lms24 commented Jan 15, 2024

When a fetch call is made with a Request object as the input/resource param (i.e. the first) and additionally provided headers in the fetch init options (the second param),

const request = new Request('http://example.com/api/test/', {
  headers: { foo: '11' },
});

fetch(request, {
  headers: { bar: '22' },
});

browsers ignore the headers from the request object but only add the headers from the init options when making the request.

Our fetch instrumentation had it the other way around, preferring headers from the request object over the headers in the options, as reported in #10172 . This PR fixes this behaviour by essentially turning around the logic we previously had.

fixes #10172

@Lms24 Lms24 changed the title fix(tracing-internal): Prefer fetch options headers over fetch init headers fix(tracing-internal): Prefer fetch options headers over fetch init headers Jan 15, 2024
Copy link
Contributor

size-limit report 📦

Path Size
@sentry/browser (incl. Tracing, Replay, Feedback) - Webpack (gzipped) 77 KB (+0.01% 🔺)
@sentry/browser (incl. Tracing, Replay) - Webpack (gzipped) 68.37 KB (+0.01% 🔺)
@sentry/browser (incl. Tracing, Replay) - Webpack with treeshaking flags (gzipped) 62.02 KB (+0.01% 🔺)
@sentry/browser (incl. Tracing) - Webpack (gzipped) 32.4 KB (+0.02% 🔺)
@sentry/browser (incl. Feedback) - Webpack (gzipped) 30.99 KB (0%)
@sentry/browser - Webpack (gzipped) 22.33 KB (0%)
@sentry/browser (incl. Tracing, Replay, Feedback) - ES6 CDN Bundle (gzipped) 74.69 KB (+0.01% 🔺)
@sentry/browser (incl. Tracing, Replay) - ES6 CDN Bundle (gzipped) 66.33 KB (+0.01% 🔺)
@sentry/browser (incl. Tracing) - ES6 CDN Bundle (gzipped) 32.16 KB (+0.03% 🔺)
@sentry/browser - ES6 CDN Bundle (gzipped) 23.96 KB (0%)
@sentry/browser (incl. Tracing, Replay) - ES6 CDN Bundle (minified & uncompressed) 208.94 KB (+0.01% 🔺)
@sentry/browser (incl. Tracing) - ES6 CDN Bundle (minified & uncompressed) 96.99 KB (+0.02% 🔺)
@sentry/browser - ES6 CDN Bundle (minified & uncompressed) 71.59 KB (0%)
@sentry/browser (incl. Tracing) - ES5 CDN Bundle (gzipped) 35.17 KB (+0.02% 🔺)
@sentry/react (incl. Tracing, Replay) - Webpack (gzipped) 68.75 KB (+0.01% 🔺)
@sentry/react - Webpack (gzipped) 22.37 KB (0%)
@sentry/nextjs Client (incl. Tracing, Replay) - Webpack (gzipped) 85.41 KB (+0.01% 🔺)
@sentry/nextjs Client - Webpack (gzipped) 49.52 KB (+0.01% 🔺)
@sentry-internal/feedback - Webpack (gzipped) 17 KB (0%)

Copy link
Contributor

@lforst lforst left a comment

Choose a reason for hiding this comment

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

nice

@Lms24 Lms24 changed the title fix(tracing-internal): Prefer fetch options headers over fetch init headers fix(tracing-internal): Prefer fetch init headers over fetch input headers Jan 15, 2024
@Lms24 Lms24 merged commit f17bc54 into develop Jan 15, 2024
@Lms24 Lms24 deleted the lms/fix-tracing-internal-fetch-favor-options-headers-over-init-headers branch January 15, 2024 10:00
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.

Wrong request headers when instrument the fetch with 2 parameters and they both have headers
2 participants