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 97.57085% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 85.189%. Comparing base (f246093) to head (4238cf0).
⚠️ Report is 3 commits behind head on main.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
Sources/Swift/Options.swift 97.278% 4 Missing ⚠️
Sources/Swift/SentryClient.swift 33.333% 2 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@              Coverage Diff              @@
##              main     #6628       +/-   ##
=============================================
+ Coverage   85.131%   85.189%   +0.058%     
=============================================
  Files          453       453               
  Lines        27689     27649       -40     
  Branches     12113     12119        +6     
=============================================
- Hits         23572     23554       -18     
+ Misses        4071      4049       -22     
  Partials        46        46               
Files with missing lines Coverage Δ
SentryTestUtils/Sources/TestClient.swift 86.666% <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% <ø> (ø)
Sources/Sentry/SentryAppStartTrackingIntegration.m 100.000% <ø> (ø)
...s/Sentry/SentryAutoBreadcrumbTrackingIntegration.m 94.285% <ø> (ø)
...rces/Sentry/SentryAutoSessionTrackingIntegration.m 100.000% <ø> (ø)
Sources/Sentry/SentryBaggage.m 100.000% <ø> (ø)
... and 53 more

... and 6 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 f246093...4238cf0. 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 1227.62 ms 1256.62 ms 28.99 ms
Size 23.75 KiB 1.01 MiB 1010.12 KiB

Baseline results on branch: main

Startup times

Revision Plain With Sentry Diff
7bd90de 1233.48 ms 1249.47 ms 15.99 ms
d1c4916 1236.25 ms 1266.76 ms 30.51 ms
7aaa0b6 1230.49 ms 1263.78 ms 33.29 ms
e3ebff3 1223.47 ms 1249.27 ms 25.80 ms
1a34ddc 1218.94 ms 1251.86 ms 32.92 ms
ec3fc3a 1212.92 ms 1245.06 ms 32.14 ms
daf8077 1202.78 ms 1235.52 ms 32.74 ms
b045d0a 1227.48 ms 1252.22 ms 24.75 ms
4a7a005 1229.15 ms 1243.35 ms 14.20 ms
d48a247 1243.59 ms 1273.27 ms 29.67 ms

App size

Revision Plain With Sentry Diff
7bd90de 23.75 KiB 933.33 KiB 909.58 KiB
d1c4916 23.75 KiB 981.15 KiB 957.40 KiB
7aaa0b6 23.75 KiB 989.97 KiB 966.23 KiB
e3ebff3 23.75 KiB 878.48 KiB 854.73 KiB
1a34ddc 23.75 KiB 919.88 KiB 896.13 KiB
ec3fc3a 23.74 KiB 1022.75 KiB 999.01 KiB
daf8077 23.75 KiB 971.82 KiB 948.07 KiB
b045d0a 23.75 KiB 880.21 KiB 856.46 KiB
4a7a005 23.75 KiB 979.96 KiB 956.22 KiB
d48a247 23.75 KiB 994.73 KiB 970.99 KiB

Previous results on branch: optionsInSwift

Startup times

Revision Plain With Sentry Diff
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
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 8 times, most recently from 897e7cb to e2fb674 Compare November 6, 2025 00:15
@noahsmartin noahsmartin marked this pull request as ready for review November 6, 2025 10:14
@noahsmartin noahsmartin force-pushed the optionsInSwift branch 2 times, most recently from d078a0f to 26bfb46 Compare November 6, 2025 13:38
Copy link

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

Bug: Inconsistent beforeSendLog exposure Across Swift Packages

The beforeSendLog callback is still conditionally excluded from dictionary initialization when SWIFT_PACKAGE is defined (#if !SWIFT_PACKAGE), but the new Swift Options class (introduced in this PR) always exposes the beforeSendLog property without any conditional compilation. This creates an inconsistency where dictionary-based initialization (via SentryOptionsInternal.initWithDict) will not properly set the beforeSendLog callback when using Swift Package Manager, even though the property exists and is accessible on the Swift Options class. The #if !SWIFT_PACKAGE guard should be removed to match the Swift implementation.

Sources/Sentry/SentryOptionsInternal.m#L116-L120

#if !SWIFT_PACKAGE
if ([self isBlock:options[@"beforeSendLog"]]) {
sentryOptions.beforeSendLog = options[@"beforeSendLog"];
}
#endif // !SWIFT_PACKAGE

Fix in Cursor Fix in Web


@noahsmartin noahsmartin force-pushed the optionsInSwift branch 2 times, most recently from f2f0e74 to d0ea6bc Compare November 6, 2025 14:39
@noahsmartin noahsmartin force-pushed the optionsInSwift branch 2 times, most recently from 2c25073 to e29a276 Compare November 6, 2025 16:26
@github-actions
Copy link
Contributor

github-actions bot commented Nov 6, 2025

🚨 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

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.

ref: SentryOptions in Swift

2 participants