Skip to content

Conversation

@noahsmartin
Copy link
Contributor

@noahsmartin noahsmartin commented Jul 23, 2025

This converts SentrySDK to Swift. It's a pretty straightforward conversion since I had already refactored SentrySDKInternal to contain all the implementation, the biggest changes here are around SPM support. In SPM you can't have Swift code that calls an ObjC API that uses a Swift type. This means the Swift/ObjC bridge needs to only contains ObjC types. That leads to 3 changes in this PR:

  1. SentryLogger is handled directly in SentrySDK.swift and removed from SentrySDKInternal. SentryLogger is defined in Swift so the Swift code could not access it through SentrySDKInternal making it necessary to convert to Swift.
  2. Methods returning SentryId in SentrySDKInternal have been changed to return NSString. The Swift code creates the SentryId from the String. This is necessary because SentryId is written in Swift.
  3. The capture(userFeedback:) method of SentrySDKInternal has been changed to take the already serialized user feedback data. This is necessary because the UserFeedback type is written in Swift.

Other than those 3 changes this PR is just copying the interface to Swift. The number of lines changes is big because the sdk_api json files change but the changes are just internal to how the file represents Swift vs. ObjC definitions, not breaking changes.

#skip-changelog

@codecov
Copy link

codecov bot commented Jul 23, 2025

Codecov Report

Attention: Patch coverage is 86.66667% with 26 lines in your changes missing coverage. Please review.

Project coverage is 86.657%. Comparing base (84094e8) to head (e4a2a46).
Report is 14 commits behind head on main.

✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
Sources/Swift/Helper/SentrySDK.swift 85.906% 21 Missing ⚠️
Sources/Sentry/SentrySDKInternal.m 75.000% 4 Missing and 1 partial ⚠️
Additional details and impacted files

Impacted file tree graph

@@              Coverage Diff              @@
##              main     #5683       +/-   ##
=============================================
+ Coverage   86.565%   86.657%   +0.092%     
=============================================
  Files          421       422        +1     
  Lines        36049     36126       +77     
  Branches     15350     17014     +1664     
=============================================
+ Hits         31206     31306      +100     
+ Misses        4805      4772       -33     
- Partials        38        48       +10     
Files with missing lines Coverage Δ
SentryTestUtils/TestClient.swift 82.677% <100.000%> (-1.876%) ⬇️
Sources/Sentry/SentryClient.m 98.513% <100.000%> (+0.012%) ⬆️
Sources/Sentry/SentryDependencyContainer.m 88.073% <100.000%> (ø)
...rces/Sentry/SentryDependencyContainerSwiftHelper.m 100.000% <100.000%> (ø)
Sources/Sentry/SentryHub.m 98.080% <100.000%> (-1.034%) ⬇️
Sources/Sentry/SentrySDKInternal.m 86.698% <75.000%> (-1.386%) ⬇️
Sources/Swift/Helper/SentrySDK.swift 85.906% <85.906%> (ø)

... and 25 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 84094e8...e4a2a46. Read the comment docs.

@noahsmartin noahsmartin force-pushed the convertSentrySDKSwift branch from 8519c42 to 72c6377 Compare July 23, 2025 02:24
@noahsmartin noahsmartin changed the title feat(SPM) Covnert SentrySDK to Swift feat(SPM) Convert SentrySDK to Swift Jul 23, 2025
@noahsmartin noahsmartin force-pushed the convertSentrySDKSwift branch 5 times, most recently from 85f26c0 to 0ae81ed Compare July 23, 2025 20:06
@noahsmartin noahsmartin force-pushed the convertSentrySDKSwift branch from 0ae81ed to 09a529e Compare July 23, 2025 21:30
@noahsmartin noahsmartin marked this pull request as ready for review July 24, 2025 16:36
Copy link
Member

@armcknight armcknight left a comment

Choose a reason for hiding this comment

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

This looks great, thanks for taking it on! Feel free to merge when CI is happy 🤖

@github-actions
Copy link
Contributor

Performance metrics 🚀

  Plain With Sentry Diff
Startup time 1206.71 ms 1249.83 ms 43.12 ms
Size 23.75 KiB 911.62 KiB 887.87 KiB

Baseline results on branch: main

Startup times

Revision Plain With Sentry Diff
079bcc8 1217.88 ms 1234.88 ms 17.00 ms
d7461dc 1233.69 ms 1255.29 ms 21.60 ms
2691350 1224.92 ms 1255.82 ms 30.90 ms
f92cfa9 1217.94 ms 1240.06 ms 22.12 ms
53b722c 1222.33 ms 1244.90 ms 22.56 ms
43597ba 1214.88 ms 1243.52 ms 28.65 ms
d637379 1226.43 ms 1250.77 ms 24.34 ms
a2a3bfb 1227.94 ms 1261.26 ms 33.32 ms
bce9765 1229.42 ms 1243.49 ms 14.07 ms
7c7ac56 1225.90 ms 1250.22 ms 24.33 ms

App size

Revision Plain With Sentry Diff
079bcc8 23.74 KiB 874.07 KiB 850.33 KiB
d7461dc 23.75 KiB 874.45 KiB 850.70 KiB
2691350 23.75 KiB 850.73 KiB 826.98 KiB
f92cfa9 23.75 KiB 855.38 KiB 831.63 KiB
53b722c 23.75 KiB 906.08 KiB 882.33 KiB
43597ba 23.75 KiB 880.32 KiB 856.58 KiB
d637379 23.75 KiB 855.38 KiB 831.63 KiB
a2a3bfb 23.75 KiB 872.67 KiB 848.92 KiB
bce9765 23.74 KiB 874.06 KiB 850.32 KiB
7c7ac56 23.75 KiB 902.49 KiB 878.74 KiB

@noahsmartin noahsmartin merged commit c2982e7 into main Jul 24, 2025
135 of 136 checks passed
@noahsmartin noahsmartin deleted the convertSentrySDKSwift branch July 24, 2025 22:04
@noahsmartin noahsmartin restored the convertSentrySDKSwift branch August 15, 2025 15:50
philipsawyerdd added a commit to justin-doordash/sentry-cocoa that referenced this pull request Sep 25, 2025
philipsawyerdd added a commit to justin-doordash/sentry-cocoa that referenced this pull request Sep 25, 2025
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.

3 participants