Skip to content

feat(network-details): Hook up request/response capture in SentryNetworkTracker#7588

Open
43jay wants to merge 7 commits intomobile-935/extract-network-detailsfrom
mobile-935/hook-up-sentry-network-tracker
Open

feat(network-details): Hook up request/response capture in SentryNetworkTracker#7588
43jay wants to merge 7 commits intomobile-935/extract-network-detailsfrom
mobile-935/hook-up-sentry-network-tracker

Conversation

@43jay
Copy link
Copy Markdown
Collaborator

@43jay 43jay commented Mar 4, 2026

📜 Description

Hook the network details implementation into SentryNetworkTracker by implementing the 2 entrypoints

[SentryNetworkTracker captureRequestDetails:networkCaptureBodies:networkRequestHeaders:]
[SentryNetworkTracker captureResponseDetails:response:request:task:]

💡 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:

  • I added tests to verify the changes.
  • No new PII added or SDK only sends newly added PII if sendDefaultPII is enabled. requires SDKOptions config (networkDetailAllowUrls)
  • I updated the docs if needed. future PR
  • I updated the wizard if needed. n/a
  • Review from the native team if needed. n/a
  • No breaking change or entry added to the changelog. future PR #skip-changelog
  • No breaking change for hybrid SDKs or communicated to hybrid SDKs.

Closes #7589

@linear
Copy link
Copy Markdown

linear bot commented Mar 4, 2026

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 4, 2026

Semver Impact of This PR

🟡 Minor (new features)

📋 Changelog Preview

This is how your changes will appear in the changelog.
Entries from this PR are highlighted with a left border (blockquote style).


This PR will not appear in the changelog.


🤖 This preview updates automatically when you update the PR.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 4, 2026

Messages
📖 Do not forget to update Sentry-docs with your feature once the pull request gets approved.

Generated by 🚫 dangerJS against 44d3c4a

@43jay 43jay changed the title feat(network-details): Hook up request and response capture in SentryNetworkTracker feat(network-details): Hook up request/response capture in SentryNetworkTracker Mar 4, 2026
@codecov
Copy link
Copy Markdown

codecov bot commented Mar 4, 2026

Codecov Report

❌ Patch coverage is 22.72727% with 51 lines in your changes missing coverage. Please review.
✅ Project coverage is 84.881%. Comparing base (bd139bc) to head (44d3c4a).
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
Sources/Sentry/SentryNetworkTracker.m 17.741% 51 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@                           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               
Files with missing lines Coverage Δ
Sources/Sentry/SentrySwizzleWrapperHelper.m 52.427% <ø> (ø)
...ons/SessionReplay/SentryReplayNetworkDetails.swift 96.644% <100.000%> (ø)
Sources/Sentry/SentryNetworkTracker.m 85.100% <17.741%> (-14.552%) ⬇️

... and 3 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update bd139bc...44d3c4a. Read the comment docs.

@43jay 43jay force-pushed the mobile-935/hook-up-sentry-network-tracker branch from 5f57b05 to a4f221a Compare March 4, 2026 21:03
@43jay 43jay force-pushed the mobile-935/extract-network-details branch from 0d2b4c1 to 3547546 Compare March 4, 2026 21:03
@43jay 43jay force-pushed the mobile-935/hook-up-sentry-network-tracker branch from a4f221a to fde4a5e Compare March 4, 2026 22:00
@43jay 43jay force-pushed the mobile-935/extract-network-details branch from 3547546 to e7c5abb Compare March 4, 2026 22:00
@43jay 43jay force-pushed the mobile-935/hook-up-sentry-network-tracker branch from fde4a5e to 8b6853c Compare March 6, 2026 16:33
@43jay 43jay force-pushed the mobile-935/extract-network-details branch from e7c5abb to 2e9607e Compare March 6, 2026 16:33
@43jay 43jay marked this pull request as draft March 6, 2026 18:44
@43jay 43jay force-pushed the mobile-935/extract-network-details branch from 2e9607e to 6e5c5bb Compare March 6, 2026 19:25
@43jay 43jay force-pushed the mobile-935/hook-up-sentry-network-tracker branch from 8b6853c to 624e1f5 Compare March 6, 2026 19:25
@43jay 43jay force-pushed the mobile-935/extract-network-details branch from 6e5c5bb to 41cf944 Compare March 9, 2026 18:09
@43jay 43jay force-pushed the mobile-935/hook-up-sentry-network-tracker branch 2 times, most recently from d80d538 to d08a33e Compare March 9, 2026 19:02
@43jay 43jay force-pushed the mobile-935/extract-network-details branch from 41cf944 to 68fbe88 Compare March 9, 2026 19:02
@43jay 43jay force-pushed the mobile-935/hook-up-sentry-network-tracker branch from d08a33e to d5a8320 Compare March 9, 2026 19:48
@43jay 43jay force-pushed the mobile-935/extract-network-details branch from 68fbe88 to 6a06365 Compare March 9, 2026 19:48
@43jay 43jay force-pushed the mobile-935/extract-network-details branch from fbd791c to e586a59 Compare March 16, 2026 20:31
43jay added a commit that referenced this pull request Mar 17, 2026
We only support dataTasks, for whcih we will always have a bodyData
#7588 (comment)
@43jay 43jay force-pushed the mobile-935/hook-up-sentry-network-tracker branch from fea8910 to 05a57ee Compare March 17, 2026 16:37
@43jay 43jay marked this pull request as ready for review March 17, 2026 16:38
@43jay 43jay requested a review from philprime March 17, 2026 16:38
Copy link
Copy Markdown
Member

@philprime philprime left a comment

Choose a reason for hiding this comment

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

Almost LGTM

return;
}

SentryOptions *options = SentrySDK.startOption;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

What's the plan with the thread safety? Is this still an open task of yours?

return;
}

SentryReplayNetworkDetails *details = objc_getAssociatedObject(task, &SentryNetworkDetailsKey);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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 )

@43jay 43jay force-pushed the mobile-935/extract-network-details branch from e586a59 to 37167c7 Compare March 18, 2026 19:25
@43jay 43jay force-pushed the mobile-935/hook-up-sentry-network-tracker branch 2 times, most recently from e15e24c to c84ff73 Compare March 18, 2026 19:34
@43jay 43jay force-pushed the mobile-935/hook-up-sentry-network-tracker branch 2 times, most recently from 5ea8b46 to a741581 Compare March 19, 2026 19:46
@43jay 43jay force-pushed the mobile-935/extract-network-details branch from 5114950 to bb1abf8 Compare March 19, 2026 19:46
@43jay 43jay force-pushed the mobile-935/hook-up-sentry-network-tracker branch from a741581 to a925d4a Compare March 19, 2026 20:00
Copy link
Copy Markdown

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

43jay added 7 commits March 23, 2026 14:54
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).
@43jay 43jay force-pushed the mobile-935/hook-up-sentry-network-tracker branch from a925d4a to 44d3c4a Compare March 23, 2026 19:04
@github-actions
Copy link
Copy Markdown
Contributor

🚨 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:

  • Sources/Sentry/SentryNetworkTracker.m

Copy link
Copy Markdown
Member

@philprime philprime left a comment

Choose a reason for hiding this comment

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

LGTM, I reviewed it on code-level

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.

2 participants