Skip to content

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

Open
43jay wants to merge 19 commits intomainfrom
mobile-935/hook-up-sentry-network-tracker
Open

feat(network-details): Hook up request/response capture in SentryNetworkTracker#7588
43jay wants to merge 19 commits intomainfrom
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 c78bb2d

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 67.07317% with 54 lines in your changes missing coverage. Please review.
✅ Project coverage is 85.248%. Comparing base (6baf12d) to head (c78bb2d).
⚠️ 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 17.741% 51 Missing ⚠️
...ons/SessionReplay/SentryReplayNetworkDetails.swift 97.058% 3 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@              Coverage Diff              @@
##              main     #7588       +/-   ##
=============================================
+ Coverage   85.186%   85.248%   +0.062%     
=============================================
  Files          490       490               
  Lines        29520     29678      +158     
  Branches     12761     12841       +80     
=============================================
+ Hits         25147     25300      +153     
- Misses        4322      4328        +6     
+ Partials        51        50        -1     
Files with missing lines Coverage Δ
Sources/Sentry/SentrySwizzleWrapperHelper.m 52.427% <ø> (ø)
...ons/SessionReplay/SentryReplayNetworkDetails.swift 96.644% <97.058%> (+96.644%) ⬆️
Sources/Sentry/SentryNetworkTracker.m 85.100% <17.741%> (-14.552%) ⬇️

... and 8 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 6baf12d...c78bb2d. 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
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 28, 2026

Performance metrics 🚀

  Plain With Sentry Diff
Startup time 1219.50 ms 1258.90 ms 39.40 ms
Size 24.14 KiB 1.16 MiB 1.13 MiB

Baseline results on branch: mobile-935/extract-network-details

Startup times

Revision Plain With Sentry Diff
ef5b57a 1226.96 ms 1259.79 ms 32.83 ms
0390710 1214.67 ms 1245.27 ms 30.60 ms
ba67433 1228.73 ms 1248.05 ms 19.31 ms
00b9497 1212.87 ms 1240.63 ms 27.76 ms
4a5e66b 1228.77 ms 1254.27 ms 25.50 ms

App size

Revision Plain With Sentry Diff
ef5b57a 24.14 KiB 1.15 MiB 1.12 MiB
0390710 24.14 KiB 1.15 MiB 1.13 MiB
ba67433 24.14 KiB 1.15 MiB 1.13 MiB
00b9497 24.14 KiB 1.15 MiB 1.13 MiB
4a5e66b 24.14 KiB 1.15 MiB 1.13 MiB

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

Startup times

Revision Plain With Sentry Diff
251c343 1238.62 ms 1263.79 ms 25.17 ms
13c3140 1231.37 ms 1266.27 ms 34.90 ms
31cc0e7 1222.19 ms 1252.21 ms 30.02 ms

App size

Revision Plain With Sentry Diff
251c343 24.14 KiB 1.15 MiB 1.13 MiB
13c3140 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 added 19 commits April 29, 2026 06:00
1) Extracts bodies that are JSON, formurlencoded, or text.

Uses UTType to accurately classify content types as JSON
or text without maintaining a manual list. Falls back
to a string match for application/x-www-form-urlencoded
which has no UTType representation.

!Relies on having a valid `contentType`

2) Populates NetworkBodyWarning's for
 "MAYBE_JSON_TRUNCATED"
 "TEXT_TRUNCATED"
 "BODY_PARSE_ERROR"
 ^when encountered, these show custom dashboard UI.
Uses UTType to classify content types: only content positively identified
as text is decoded. Everything else gets a descriptive placeholder:
 Example - "[Body not captured: contentType=image/png (8 bytes)]"

Known text types (where UTType conforms to .text) are reliably classified
by UTType's type hierarchy. If a content type header is incorrect (e.g.
claims text but contains binary), the resulting decode failure is caught
by the existing bodyParseError warning.
UTType (UniformTypeIdentifiers) requires macOS 11+, but the SDK
targets macOS 10.14. Extract UTType-based MIME detection into a
separate method gated with @available(macOS 11, *) so the code
compiles on all macOS targets. Session Replay is not available on
macOS, so the fallback placeholder is fine.
Casts to lower-case before comparing headers.
ObjC setters now accept raw allHeaders and configuredHeaders instead
of pre-filtered headers, keeping the filtering logic in Swift.
#7585 (comment)

Parse MIME type and charset from Content-Type using
CFStringConvertIANACharSetNameToEncoding instead of
hardcoding UTF-8/ISO-Latin-1 fallbacks.
Replace force-unwraps and if-let/XCTFail patterns in
SentryReplayNetworkDetailsBodyTests with XCTUnwrap for optional
casts and Data(_:) for String-to-Data conversions.
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/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
@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

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