Skip to content

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

Merged
43jay merged 9 commits intomainfrom
mobile-935/hook-up-sentry-network-tracker
Apr 29, 2026
Merged

feat(network-details): Hook up request/response capture in SentryNetworkTracker#7588
43jay merged 9 commits intomainfrom
mobile-935/hook-up-sentry-network-tracker

Conversation

@43jay
Copy link
Copy Markdown
Contributor

@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 e816a31

Comment thread Sources/Sentry/SentryNetworkTracker.m Outdated
@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
Comment thread Sources/Sentry/SentryNetworkTracker.m Outdated
Comment thread Sources/Sentry/SentryNetworkTracker.m
Comment thread Sources/Sentry/SentryNetworkTracker.m Outdated
@codecov
Copy link
Copy Markdown

codecov Bot commented Mar 4, 2026

Codecov Report

❌ Patch coverage is 21.12676% with 56 lines in your changes missing coverage. Please review.
✅ Project coverage is 85.233%. Comparing base (65c13c5) to head (e816a31).
⚠️ Report is 1 commits behind head on main.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
Sources/Sentry/SentryNetworkTracker.m 18.032% 50 Missing ⚠️
Sources/Sentry/SentrySwizzleWrapperHelper.m 0.000% 6 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@              Coverage Diff              @@
##              main     #7588       +/-   ##
=============================================
- Coverage   85.331%   85.233%   -0.098%     
=============================================
  Files          487       487               
  Lines        29526     29588       +62     
  Branches     12780     12825       +45     
=============================================
+ Hits         25195     25219       +24     
- Misses        4280      4319       +39     
+ Partials        51        50        -1     
Files with missing lines Coverage Δ
...ons/SessionReplay/SentryReplayNetworkDetails.swift 96.644% <100.000%> (ø)
Sources/Sentry/SentrySwizzleWrapperHelper.m 52.427% <0.000%> (ø)
Sources/Sentry/SentryNetworkTracker.m 85.344% <18.032%> (-14.307%) ⬇️

... and 7 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 65c13c5...e816a31. 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
Comment thread Sources/Sentry/SentryNetworkTracker.m
@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
@itaybre itaybre added the ready-to-merge Use this label to trigger all PR workflows label Apr 28, 2026
@sentry
Copy link
Copy Markdown

sentry Bot commented Apr 28, 2026

📲 Install Builds

iOS

🔗 App Name App ID Version Configuration
SDK-Size io.sentry.sample.SDK-Size 9.11.0 (1) Release

⚙️ sentry-cocoa Build Distribution Settings

@43jay 43jay force-pushed the mobile-935/extract-network-details branch from c73b24f to dc3a7af Compare April 28, 2026 20:58
@43jay 43jay force-pushed the mobile-935/hook-up-sentry-network-tracker branch from ba69a41 to b9796f7 Compare April 28, 2026 20:58
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 28, 2026

Performance metrics 🚀

  Plain With Sentry Diff
Startup time 1212.62 ms 1243.45 ms 30.82 ms
Size 24.14 KiB 1.15 MiB 1.13 MiB

Baseline results on branch: main

Startup times

Revision Plain With Sentry Diff
e44b6f8 1225.98 ms 1249.20 ms 23.23 ms
a7c42d9 1217.25 ms 1253.98 ms 36.73 ms
65c13c5 1234.47 ms 1263.10 ms 28.63 ms
1c5ecda 1219.35 ms 1253.76 ms 34.41 ms
6c524d8 1217.83 ms 1254.02 ms 36.20 ms
29d546e 1224.06 ms 1257.05 ms 32.98 ms
adef457 1229.45 ms 1262.67 ms 33.22 ms
b6fa517 1218.83 ms 1257.47 ms 38.63 ms
df67624 1225.12 ms 1259.90 ms 34.78 ms
787537a 1218.35 ms 1251.72 ms 33.38 ms

App size

Revision Plain With Sentry Diff
e44b6f8 24.14 KiB 1.15 MiB 1.13 MiB
a7c42d9 24.14 KiB 1.15 MiB 1.13 MiB
65c13c5 24.14 KiB 1.15 MiB 1.12 MiB
1c5ecda 24.14 KiB 1.15 MiB 1.12 MiB
6c524d8 24.14 KiB 1.15 MiB 1.12 MiB
29d546e 24.14 KiB 1.15 MiB 1.13 MiB
adef457 24.14 KiB 1.15 MiB 1.13 MiB
b6fa517 24.14 KiB 1.14 MiB 1.12 MiB
df67624 24.14 KiB 1.14 MiB 1.12 MiB
787537a 24.14 KiB 1.15 MiB 1.12 MiB

Previous results on branch: mobile-935/hook-up-sentry-network-tracker

Startup times

Revision Plain With Sentry Diff
13c3140 1231.37 ms 1266.27 ms 34.90 ms
251c343 1238.62 ms 1263.79 ms 25.17 ms
5b50ca2 1223.27 ms 1262.45 ms 39.18 ms
93f9778 1219.50 ms 1258.90 ms 39.40 ms
31cc0e7 1222.19 ms 1252.21 ms 30.02 ms

App size

Revision Plain With Sentry Diff
13c3140 24.14 KiB 1.16 MiB 1.13 MiB
251c343 24.14 KiB 1.15 MiB 1.13 MiB
5b50ca2 24.14 KiB 1.15 MiB 1.13 MiB
93f9778 24.14 KiB 1.16 MiB 1.13 MiB
31cc0e7 24.14 KiB 1.15 MiB 1.13 MiB

@43jay 43jay force-pushed the mobile-935/extract-network-details branch from dc3a7af to 5372649 Compare April 28, 2026 21:40
@43jay 43jay force-pushed the mobile-935/hook-up-sentry-network-tracker branch 2 times, most recently from 251b0a8 to f0b8955 Compare April 28, 2026 22:19
@43jay 43jay force-pushed the mobile-935/extract-network-details branch 2 times, most recently from c1488f7 to 98d01fc Compare April 29, 2026 01:26
@43jay 43jay force-pushed the mobile-935/hook-up-sentry-network-tracker branch from f0b8955 to 2ab86d5 Compare April 29, 2026 01:26
Comment thread Sources/Sentry/SentryNetworkTracker.m
@43jay 43jay force-pushed the mobile-935/extract-network-details branch from 98d01fc to d0b9491 Compare April 29, 2026 10:00
@43jay 43jay force-pushed the mobile-935/hook-up-sentry-network-tracker branch from 2ab86d5 to c78bb2d Compare April 29, 2026 10:00
@43jay
Copy link
Copy Markdown
Contributor Author

43jay commented Apr 29, 2026

rebase main; make format

Comment thread Sources/Sentry/SentryNetworkTracker.m
Comment thread Sources/Sentry/SentryNetworkTracker.m
Comment thread Sources/Sentry/SentryNetworkTracker.m
43jay added 9 commits April 29, 2026 12:26
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).
@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

@43jay
Copy link
Copy Markdown
Contributor Author

43jay commented Apr 29, 2026

rebase on main; resolve bot comment

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-to-merge Use this label to trigger all PR workflows

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(network-details): Hook up request and response capture in SentryNetworkTracker

3 participants