feat(network-details): Hook up request/response capture in SentryNetworkTracker#7588
feat(network-details): Hook up request/response capture in SentryNetworkTracker#758843jay wants to merge 7 commits intomobile-935/extract-network-detailsfrom
Conversation
Semver Impact of This PR🟡 Minor (new features) 📋 Changelog PreviewThis is how your changes will appear in the changelog. This PR will not appear in the changelog. 🤖 This preview updates automatically when you update the PR. |
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## mobile-935/extract-network-details #7588 +/- ##
========================================================================
- Coverage 85.007% 84.881% -0.127%
========================================================================
Files 486 486
Lines 29054 29116 +62
Branches 12618 12639 +21
========================================================================
+ Hits 24698 24714 +16
- Misses 4308 4354 +46
Partials 48 48
... and 3 files with indirect coverage changes Continue to review full report in Codecov by Sentry.
|
5f57b05 to
a4f221a
Compare
0d2b4c1 to
3547546
Compare
a4f221a to
fde4a5e
Compare
3547546 to
e7c5abb
Compare
fde4a5e to
8b6853c
Compare
e7c5abb to
2e9607e
Compare
2e9607e to
6e5c5bb
Compare
8b6853c to
624e1f5
Compare
6e5c5bb to
41cf944
Compare
d80d538 to
d08a33e
Compare
41cf944 to
68fbe88
Compare
d08a33e to
d5a8320
Compare
68fbe88 to
6a06365
Compare
fbd791c to
e586a59
Compare
We only support dataTasks, for whcih we will always have a bodyData #7588 (comment)
fea8910 to
05a57ee
Compare
| return; | ||
| } | ||
|
|
||
| SentryOptions *options = SentrySDK.startOption; |
There was a problem hiding this comment.
The purpose fo SENTRY_UNWRAP_NULLABLE is just casting from a nullable type to-non-nullable type. We use this in cases where we already did a null check and are sure that it's not null. We use a macro because it allows us to find all cases again in the future
| } | ||
|
|
||
| // Store extracted network details data for session replay. | ||
| static const void *SentryNetworkDetailsKey = &SentryNetworkDetailsKey; |
There was a problem hiding this comment.
What's the plan with the thread safety? Is this still an open task of yours?
| return; | ||
| } | ||
|
|
||
| SentryReplayNetworkDetails *details = objc_getAssociatedObject(task, &SentryNetworkDetailsKey); |
There was a problem hiding this comment.
Okay, please add a 1-2 lines comment block to the code to explain why we chose associated objects over maps and also the reasoning behind it being safe to use (for future reference )
e586a59 to
37167c7
Compare
e15e24c to
c84ff73
Compare
5ea8b46 to
a741581
Compare
5114950 to
bb1abf8
Compare
a741581 to
a925d4a
Compare
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
We only support dataTasks, for whcih we will always have a bodyData #7588 (comment)
Synchronize objc_get/setAssociatedObject and SentryNetwokDetailsData locking on the NSURLSessionTask instance. `setState` - iOS internal API, undocumented threading model - calls captureRequestDetails `completionHandler` - callback queue (thread) configured by app. - calls captureResponseDetails captureRequestDetails To avoid introducing blocking on apple's thread, we use the lock to objc_getAssociated(task,..) but drop the lock before processing the request (SentryNetworkRequestDetails:setRequest). captureResponseDetails However we need the lock while processing response data (SentryNetworkRequestDetails:setResponse) b/c (later) it will race with calls to `SentryNetworkRequestDetails:serialize`. The completionHandler is on the app's network response path, so adding some thread contention here (worst-case) is less noticable (an i/o request just finished).
a925d4a to
44d3c4a
Compare
🚨 Detected changes in high risk code 🚨High-risk code can easily blow up and is hard to test. We had severe bugs in the past. Be extra careful when changing these files, and have an extra careful look at these:
|
philprime
left a comment
There was a problem hiding this comment.
LGTM, I reviewed it on code-level

📜 Description
Hook the network details implementation into SentryNetworkTracker by implementing the 2 entrypoints
💡 Motivation and Context
This PR updates SentryNetworkTracker to call into extraction logic introduced in previous PRs.
💚 How did you test it?
See other PRs for tests.
📝 Checklist
You have to check all boxes before merging:
sendDefaultPIIis enabled. requires SDKOptions config (networkDetailAllowUrls)Closes #7589