fix: Remove Sentry keys from cached HTTP request headers #1975
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.
馃摐 Description
When an HTTP request is happening without a span, it used to just reuse the existing headers, which can include an old and unrelated traceId. This caused weird behavior where the request would seem to happen from a totally different part of the app.
馃挕 Motivation and Context
The root cause of the bug as described in #1827 was actually user error, by doing the HTTP request in a new transaction that wasn't bound to the scope at all. Contrast to the initial request which was done in the scope of
viewDidLoad
, which does get an automatic transaction added to the scope. But because the 2nd request happened with anil
value forSentrySDK.currentHub.scope.span
, the headers from the first request were sent along with the second request (cached byNSURLSession
itself!).By scrubbing the cached headers of the Sentry keys, we can prevent the weird behavior as described in the issue, and it'll make it more obvious to the user when the request doesn't show up as part of the trace at all.
Dhiogo and I came to this conclusion/solution together.
Fixes #1827
馃挌 How did you test it?
Unit test
馃摑 Checklist
馃敭 Next steps