Skip to content

fix: Support new URLSession HTTP loader - #8845

Merged
philprime merged 16 commits into
mainfrom
philprime/fix/support-urlsession-http-loaders
Sep 17, 2026
Merged

philprime merged 16 commits into
mainfrom
philprime/fix/support-urlsession-http-loaders

Conversation

@philprime

@philprime philprime commented Aug 24, 2026 •

Copy link
Copy Markdown
Member

📜 Description

Support automatic network lifecycle instrumentation when URLSessionConfiguration.usesClassicLoadingMode is disabled.

The SDK discovers the new loader's runtime session and task classes and installs typed wrappers for completion-handler data, download, and upload tasks. This preserves span completion, breadcrumbs, failed-request capture, response status, and cancellation status.

Delegate-only new-loader tasks are intentionally not instrumented because the new loader does not expose the state transition used by the classic loader and replacing application delegates would change callback semantics. Trace propagation also remains unavailable for the new loader because it does not expose the copy-and-replace request setter used by the race-safe classic implementation.

Duplicate wrapper-task handling is split into #8846.

💡 Motivation and Context

Apple introduced a Network.framework-based HTTP loader that may become the default in a future OS release. Its private class hierarchy bypasses the classic URLSessionTask state swizzles, causing missing automatic network lifecycle telemetry.

Fixes #5045

💚 How did you test it?

  • make format
  • make analyze
  • Xcode 16.4: make build-macos FOR_AGENTS=true
  • Xcode 26.6: make test-macos FOR_AGENTS=true TEST_PLAN=Sentry_TestServer
  • Targeted loader tests on iOS 18.4, Catalyst, tvOS, watchOS, and visionOS
  • Targeted typed-swizzle and network-tracker unit 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.
  • I updated the docs if needed.
  • I updated the wizard if needed.
  • Review from the native team if needed.
  • No breaking change or entry added to the changelog.
  • No breaking change for hybrid SDKs or communicated to hybrid SDKs.
  • Public API changes reviewed by another Mobile SDK team member or implemented according to the develop docs spec.
  • If I added a new public API, I also added it to the SentryObjC wrapper.

Track completion-handler data, download, and upload tasks when URLSession uses the Network framework HTTP loader. Preserve trace propagation and suppress duplicate wrapper-task spans.

Refs #5045
Keep this branch focused on new-loader lifecycle support and restore copy-and-replace trace propagation. Move duplicate wrapper-task handling to a separate change.
@philprime
philprime force-pushed the philprime/fix/support-urlsession-http-loaders branch from 791dc04 to c69265a Compare August 24, 2026 11:41
@philprime philprime self-assigned this Aug 24, 2026
@philprime philprime added the run-full-ci Allows gated GitHub Action workflows to run for a labelled pull request label Aug 24, 2026
@sentry

sentry Bot commented Aug 24, 2026 •

Copy link
Copy Markdown

📲 Install Builds

iOS

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

⚙️ sentry-cocoa Build Distribution Settings

@github-actions

github-actions Bot commented Aug 24, 2026 •

Copy link
Copy Markdown
Contributor

Performance metrics 🚀

  Plain With Sentry Diff
Startup time 1214.11 ms 1257.43 ms 43.33 ms
Size 24.14 KiB 1.34 MiB 1.31 MiB

Baseline results on branch: main

Startup times

Revision Plain With Sentry Diff
8ebae2f 1221.06 ms 1250.28 ms 29.22 ms
6b08499 1216.67 ms 1247.76 ms 31.08 ms
3efa7b5 1226.55 ms 1260.66 ms 34.11 ms
53097d6 1218.02 ms 1251.70 ms 33.68 ms
972e4d3 1244.02 ms 1270.69 ms 26.67 ms
3658407 1221.23 ms 1257.22 ms 35.99 ms
35901c8 1217.02 ms 1259.13 ms 42.11 ms
58bec0e 1222.40 ms 1266.04 ms 43.64 ms
d6af355 1214.83 ms 1252.78 ms 37.95 ms
7d833a3 1226.72 ms 1263.42 ms 36.70 ms

App size

Revision Plain With Sentry Diff
8ebae2f 24.14 KiB 1.23 MiB 1.20 MiB
6b08499 24.14 KiB 1.15 MiB 1.13 MiB
3efa7b5 24.14 KiB 1.22 MiB 1.19 MiB
53097d6 24.14 KiB 1.16 MiB 1.13 MiB
972e4d3 24.14 KiB 1.27 MiB 1.24 MiB
3658407 24.14 KiB 1.23 MiB 1.21 MiB
35901c8 24.14 KiB 1.24 MiB 1.21 MiB
58bec0e 24.14 KiB 1.33 MiB 1.30 MiB
d6af355 24.14 KiB 1.18 MiB 1.15 MiB
7d833a3 24.14 KiB 1.16 MiB 1.13 MiB

Previous results on branch: philprime/fix/support-urlsession-http-loaders

Startup times

Revision Plain With Sentry Diff
2cfb72d 1209.18 ms 1254.19 ms 45.00 ms
24ff139 1202.76 ms 1261.37 ms 58.61 ms
41218fd 1241.12 ms 1276.83 ms 35.71 ms
d7a9abe 1212.02 ms 1260.50 ms 48.48 ms
eb26eed 1243.04 ms 1274.91 ms 31.87 ms
ee32a50 1220.48 ms 1260.58 ms 40.10 ms
61afc2c 1230.82 ms 1263.22 ms 32.40 ms
b4af129 1226.89 ms 1274.91 ms 48.02 ms
f166b08 1225.07 ms 1259.28 ms 34.21 ms

App size

Revision Plain With Sentry Diff
2cfb72d 24.14 KiB 1.33 MiB 1.31 MiB
24ff139 24.14 KiB 1.34 MiB 1.31 MiB
41218fd 24.14 KiB 1.33 MiB 1.31 MiB
d7a9abe 24.14 KiB 1.34 MiB 1.31 MiB
eb26eed 24.14 KiB 1.33 MiB 1.31 MiB
ee32a50 24.14 KiB 1.31 MiB 1.29 MiB
61afc2c 24.14 KiB 1.31 MiB 1.28 MiB
b4af129 24.14 KiB 1.33 MiB 1.31 MiB
f166b08 24.14 KiB 1.34 MiB 1.31 MiB

@philprime

Copy link
Copy Markdown
Member Author

@sentry review

@sentry

sentry Bot commented Sep 15, 2026 •

Copy link
Copy Markdown

Size Analysis

1 component analyzed

iOS Builds

Name Configuration Version Download Size Install Size
SDK-Size (iOS)
io.sentry.sample.SDK-Size
Release 9.28.0 (1) 1.2 MB (+6.7 KB) 3.1 MB (+16.4 KB)

Configure sentry-cocoa status check rules

@philprime

Copy link
Copy Markdown
Member Author

@sentry review

@philprime
philprime marked this pull request as ready for review September 15, 2026 11:38

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Stale Bugbot comment from a previous run.

@philprime
philprime marked this pull request as draft September 15, 2026 12:10
Initialize replay details before response capture and add regressions.

Account for copied classic setters in loader runtime assertions.
@philprime
philprime marked this pull request as ready for review September 15, 2026 14:57

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Stale Bugbot comment from a previous run.

Comment thread Sources/Swift/Networking/SentryNetworkTracker.swift Outdated
Merge origin/main while preserving new-loader instrumentation and

task-lifetime protection. Capture replay method, headers, and body

from the original request when completion follows a redirect.

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Stale Bugbot comment from a previous run.

Comment thread Sources/Swift/Networking/SentryNetworkTracker.swift

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Stale Bugbot comment from a previous run.

@philprime
philprime marked this pull request as draft September 17, 2026 08:24
@github-actions github-actions Bot removed the approved label Sep 17, 2026
@philprime

Copy link
Copy Markdown
Member Author

Moved back to draft because I realized that this uses swizzling that should be gated by an experimental option first.

Default new-loader instrumentation to an experimental opt-in.

Gate retained hooks across restarts and report feature usage.

Expose the option to Objective-C and test disabled and enabled paths.
@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/Swift/Networking/SentryNetworkTracker.swift

@philprime

Copy link
Copy Markdown
Member Author

@sentry review

Comment thread Sources/Swift/Networking/SentryNetworkTracker.swift
@philprime
philprime marked this pull request as ready for review September 17, 2026 09:14
@philprime
philprime requested a review from a team as a code owner September 17, 2026 09:14
@philprime

Copy link
Copy Markdown
Member Author

@NinjaLikesCheez re-requesting review because I added a new public option

@philprime
philprime enabled auto-merge (squash) September 17, 2026 09:14
@philprime
philprime disabled auto-merge September 17, 2026 09:16

@cursor cursor Bot left a comment

Copy link
Copy Markdown

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.

Reviewed by Cursor Bugbot for commit 422fdb1. Configure here.

Comment thread Sources/Swift/Networking/SentryNetworkTracker.swift
@philprime
philprime enabled auto-merge (squash) September 17, 2026 10:06
@philprime
philprime merged commit 60722bb into main Sep 17, 2026
285 of 288 checks passed
@philprime
philprime deleted the philprime/fix/support-urlsession-http-loaders branch September 17, 2026 10:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved run-full-ci Allows gated GitHub Action workflows to run for a labelled pull request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Analyze potential impact of new HTTP loader in URLSession

2 participants