Skip to content

Conversation

@noahsmartin
Copy link
Contributor

@noahsmartin noahsmartin commented Nov 2, 2025

This change may look big, but I've done everything that can be done to make it as small as possible. It only looks big because the generated API json file changed, the actual lines of code added are ~800. So many files were touched because I had to remove a bunch of imports of the objc class

This converts SentryOptions.h/.m to SentryOptions.swift and in doing so removes the last blocker for using SPM. It also cleans up a lot of gross bridging we had to do, like with SentryExperimentalOptions and the beforeSendLog callback. This is now replaced with one piece of cross bridging, which I'll get to later...

Almost all the relevant implementation here is in Options.swift. This matches the old ObjC API almost exactly, except that the class is now final. The API json file changed a lot structurally just because it represents Swift and ObjC differently, not because the actual API changed.

The tricky part of this is that we can't call an objc header that uses a swift type from Swift code. (This works in xcodebuild but not cocoapods/SPM) To work around this the value that gets passed toSentrySDKInternal needs to be type-erased. This is the same as what we had to do with types defined in Swift on SentryOptions.h prior to this PR. To make it easy to follow this change I've kept the Swift type almost everywhere, but in a few header files I had to use SentryOptionsObjc which is just an alias for NSObject. There are extensions at the end of Options.swift that explains what is done in more detail.

#skip-changelog

Closes #6690

@codecov
Copy link

codecov bot commented Nov 2, 2025

Codecov Report

❌ Patch coverage is 95.72954% with 12 lines in your changes missing coverage. Please review.
✅ Project coverage is 85.118%. Comparing base (68d6f41) to head (2d1b0eb).
⚠️ Report is 1 commits behind head on main.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
Sources/Swift/SentryClient.swift 0.000% 7 Missing ⚠️
Sources/Swift/Options.swift 97.163% 4 Missing ⚠️
Sources/Sentry/SentryClient.m 50.000% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@              Coverage Diff              @@
##              main     #6628       +/-   ##
=============================================
- Coverage   85.145%   85.118%   -0.027%     
=============================================
  Files          453       453               
  Lines        27689     27706       +17     
  Branches     12111     12143       +32     
=============================================
+ Hits         23576     23583        +7     
- Misses        4069      4078        +9     
- Partials        44        45        +1     
Files with missing lines Coverage Δ
SentryTestUtils/Sources/TestClient.swift 86.666% <100.000%> (ø)
SentryTestUtils/Sources/TestFileManager.swift 100.000% <100.000%> (ø)
Sources/Sentry/PrivateSentrySDKOnly.m 82.352% <ø> (ø)
Sources/Sentry/Profiling/SentryLaunchProfiling.m 80.681% <ø> (ø)
...entry/Profiling/SentryProfiledTracerConcurrency.mm 60.245% <ø> (ø)
...ces/Sentry/Profiling/SentryProfilingSwiftHelpers.m 100.000% <100.000%> (ø)
Sources/Sentry/SentryANRTrackingIntegration.m 94.400% <ø> (-0.800%) ⬇️
Sources/Sentry/SentryAppStartTrackingIntegration.m 100.000% <ø> (ø)
...s/Sentry/SentryAutoBreadcrumbTrackingIntegration.m 94.285% <ø> (ø)
...rces/Sentry/SentryAutoSessionTrackingIntegration.m 100.000% <ø> (ø)
... and 56 more

... and 4 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 68d6f41...2d1b0eb. Read the comment docs.

@noahsmartin noahsmartin force-pushed the clientHubSwift branch 4 times, most recently from 5169bbd to 1b852ec Compare November 3, 2025 01:47
Base automatically changed from clientHubSwift to main November 3, 2025 14:24
@noahsmartin noahsmartin force-pushed the optionsInSwift branch 19 times, most recently from 031e40c to 3581fc0 Compare November 5, 2025 03:50
@github-actions
Copy link
Contributor

github-actions bot commented Nov 5, 2025

Performance metrics 🚀

  Plain With Sentry Diff
Startup time 1216.23 ms 1264.74 ms 48.50 ms
Size 24.15 KiB 1.01 MiB 1015.24 KiB

Baseline results on branch: main

Startup times

Revision Plain With Sentry Diff
707c222 1223.06 ms 1260.67 ms 37.61 ms
5200f5b 1231.73 ms 1254.35 ms 22.62 ms
ea12acf 1217.67 ms 1252.69 ms 35.03 ms
005f255 1218.42 ms 1247.09 ms 28.67 ms
2137530 1223.39 ms 1253.25 ms 29.86 ms
ad964ca 1234.73 ms 1254.88 ms 20.15 ms
3cdbc22 1231.63 ms 1251.06 ms 19.43 ms
11853e6 1220.37 ms 1252.83 ms 32.46 ms
d72784d 1214.31 ms 1241.35 ms 27.04 ms
324c109 1228.35 ms 1252.47 ms 24.12 ms

App size

Revision Plain With Sentry Diff
707c222 23.75 KiB 1.00 MiB 1005.07 KiB
5200f5b 23.75 KiB 933.33 KiB 909.58 KiB
ea12acf 23.75 KiB 974.89 KiB 951.14 KiB
005f255 23.75 KiB 1.01 MiB 1016.13 KiB
2137530 23.75 KiB 933.33 KiB 909.58 KiB
ad964ca 23.75 KiB 913.17 KiB 889.42 KiB
3cdbc22 23.75 KiB 928.14 KiB 904.40 KiB
11853e6 23.75 KiB 1.01 MiB 1016.04 KiB
d72784d 23.75 KiB 988.01 KiB 964.27 KiB
324c109 23.75 KiB 919.91 KiB 896.16 KiB

Previous results on branch: optionsInSwift

Startup times

Revision Plain With Sentry Diff
607275f 1199.10 ms 1225.73 ms 26.63 ms
4d700d3 1226.50 ms 1255.66 ms 29.16 ms
e2114d5 1216.94 ms 1237.02 ms 20.08 ms
b65d755 1234.36 ms 1258.38 ms 24.02 ms

App size

Revision Plain With Sentry Diff
607275f 24.15 KiB 1.01 MiB 1015.07 KiB
4d700d3 24.15 KiB 1.01 MiB 1014.65 KiB
e2114d5 23.75 KiB 1.03 MiB 1.01 MiB
b65d755 23.75 KiB 1.03 MiB 1.01 MiB

@noahsmartin noahsmartin force-pushed the optionsInSwift branch 4 times, most recently from 796b619 to 29baa9f Compare November 5, 2025 18:06
@noahsmartin noahsmartin force-pushed the optionsInSwift branch 3 times, most recently from e29a276 to 4238cf0 Compare November 6, 2025 16:52
@noahsmartin noahsmartin added the ready-to-merge Use this label to trigger all PR workflows label Nov 7, 2025
Copy link
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, left minor comments and some of the tests are not compiling because of the refactoring. I believe it's good to go after fixing them

@noahsmartin noahsmartin force-pushed the optionsInSwift branch 2 times, most recently from a3442e1 to 2ae0f7f Compare November 10, 2025 15:26
@github-actions
Copy link
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
  • Sources/Sentry/SentryUIViewControllerSwizzling.m

@noahsmartin noahsmartin merged commit 2991d63 into main Nov 11, 2025
209 of 212 checks passed
@noahsmartin noahsmartin deleted the optionsInSwift branch November 11, 2025 02:21
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.

ref: SentryOptions in Swift

4 participants