Repository navigation
fix(cloudflare): Forward method, headers and body when a Request is passed as fetch init - #26368
Merged
andreiborza merged 3 commits intoNov 16, 2026
Conversation
…assed as fetch init
`instrumentFetcher` built the outgoing init with an object spread (`{ ...init }`).
When `init` is itself a Request (the common `stub.fetch(url, request)` Workers
idiom), its method, headers and body are prototype getters rather than own
properties, so the spread copied none of them. Behind an instrumented Durable
Object or service binding the call arrived as a bare GET with no headers and no
body, breaking WebSocket upgrades and forwarded POSTs that work without Sentry.
Handle a Request-valued `init` the same way the existing single-Request branch
does: rebuild through the Request constructor (which reads those members by
property access) and layer the tracing headers, which already include the
request's own headers, on top.
Fixes getsentry#26367
Member
|
Hi @Vivek1898, thank you for the contribution but next time please read our contribution guideline a bit closer. We typically don't accept contributions without prior discussion. |
JPeer264
reviewed
Nov 16, 2026
JPeer264
left a comment
Member
There was a problem hiding this comment.
LGTM. The description is out of date though
| expect(headers.get('baggage')).toBe('sentry-environment=production'); | ||
| }); | ||
|
|
||
| it('forwards method, headers and body when init is a Request', async () => { |
Member
There was a problem hiding this comment.
l: We should re-add the test to forward headers when tracing is disabled
Contributor
Author
There was a problem hiding this comment.
Re-added it in 79b82ef, and updated the description. Thanks for the review!
JPeer264
approved these changes
Nov 16, 2026
Covers the no-trace-data path for a Request-valued init: the method, headers and body are forwarded and no sentry-trace header is added.
msonnb
pushed a commit
that referenced
this pull request
Nov 16, 2026
This PR adds the external contributor to the CHANGELOG.md file, so that they are credited for their contribution. See #26368 Co-authored-by: andreiborza <168741329+andreiborza@users.noreply.github.com>
51 tasks done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #26367
The problem
instrumentFetcherbuilt the outgoing init with an object spread:Forwarding a request as
stub.fetch(url, request)is a common Workers idiom, soinitis often itself aRequest. ARequest'smethod,headers,bodyand the rest are prototype getters, not own enumerable properties, so the spread copied none of them. Behind an instrumented Durable Object namespace or service binding the call reached the object as a bareGETwith no headers and no body, which broke WebSocket upgrades (Upgrade: websocket) and every forwardedPOST. The same call works without Sentry.The fix
When
initis aRequest, normalize it up front into aRequestinput (new Request(originalInput, originalInit)), which readsmethod,headersandbodyby property access, and clearinit. The call then flows through the existinginput instanceof Request && init === undefinedbranch, which layers the tracing headers on top (or forwards the request as-is when tracing is disabled). Plain-objectinitstill goes through the spread path, so no other case changes.Tests
instrumentFetcher.test.tsadds cases for aRequest-valuedinit: method, headers and body are forwarded with tracing on, and forwarded with tracing disabled (nosentry-trace/baggageadded).