Skip to content
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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Remove Sentry keys from cached HTTP request headers #1975

Merged
merged 5 commits into from
Jul 15, 2022

Conversation

kevinrenskers
Copy link
Contributor

@kevinrenskers kevinrenskers commented Jul 15, 2022

馃摐 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 a nil value for SentrySDK.currentHub.scope.span, the headers from the first request were sent along with the second request (cached by NSURLSession 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

  • I reviewed the submitted code
  • I added tests to verify the changes
  • I updated the docs if needed
  • Review from the native team if needed
  • No breaking changes

馃敭 Next steps

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.

Fixes #1827
@kevinrenskers kevinrenskers marked this pull request as ready for review July 15, 2022 13:57
Comment on lines +287 to +289
NSMutableDictionary *existingHeaders = headers.mutableCopy;
[existingHeaders removeObjectsForKeys:@[ SENTRY_TRACE_HEADER, SENTRY_BAGGAGE_HEADER ]];
return [existingHeaders copy];
Copy link
Contributor

Choose a reason for hiding this comment

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

Please just add a comment here why we removing the header.
Because NSURLSession itself caches its, and were good to go.

@kevinrenskers kevinrenskers merged commit ed11f35 into master Jul 15, 2022
@kevinrenskers kevinrenskers deleted the fix/1827-remove-cached-sentry-headers branch July 15, 2022 14:19
@philipphofmann
Copy link
Member

Thanks @kevinrenskers 馃憣

kevinrenskers added a commit that referenced this pull request Jul 18, 2022
* master:
  ref: Fix linter error (#1981)
  fix: read free_memory when the event is captured, not only at SDK startup (#1962)
  fix: Remove Sentry keys from cached HTTP request headers (#1975)
  release: 7.21.0
  ci: Don't run benchmarks on release (#1971)
  Don't track OOMs for simulators (#1970)
  feat: Automatic nest new spans with the ui life cycle function (#1959)
  docs: update some docs/comments to read a little better (#1966)
  ci: benchmarking updates (#1926)
  feat: upload list of slow/frozen rendered frame timestamps during a profile (#1910)
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.

TraceId persisting and not re-generating after Transactions Flush
3 participants